summaryrefslogtreecommitdiffstats
path: root/dom/notification/test/unit/test_notificationdb_bug1024090.js
blob: 68dfb164ce7b9c5527c9f9cabf0ef1c2ec730482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";

function run_test() {
  do_get_profile();
  run_next_test();
}

/// For bug 1024090: test edge case of notificationstore.json
add_test(function test_bug1024090_purge() {
  Cu.import("resource://gre/modules/osfile.jsm");
  const NOTIFICATION_STORE_PATH =
    OS.Path.join(OS.Constants.Path.profileDir, "notificationstore.json");
  let cleanup = OS.File.writeAtomic(NOTIFICATION_STORE_PATH, "");
  cleanup.then(
    function onSuccess() {
      ok(true, "Notification database cleaned.");
    },
    function onError(reason) {
      ok(false, "Notification database error when cleaning: " + reason);
    }
  ).then(function next() {
    do_print("Cleanup steps completed: " + NOTIFICATION_STORE_PATH);
    startNotificationDB();
    run_next_test();
  });
});

// Store one notification
add_test(function test_bug1024090_send_one() {
  let requestID = 1;
  let msgReply = "Notification:Save:Return:OK";
  let msgHandler = function(message) {
    equal(requestID, message.data.requestID, "Checking requestID");
  };

  addAndSend("Notification:Save", msgReply, msgHandler, {
    origin: systemNotification.origin,
    notification: systemNotification,
    requestID: requestID
  });
});

// Get one notification, one exists
add_test(function test_bug1024090_get_one() {
  let requestID = 2;
  let msgReply = "Notification:GetAll:Return:OK";
  let msgHandler = function(message) {
    equal(requestID, message.data.requestID, "Checking requestID");
    equal(1, message.data.notifications.length, "One notification stored");
  };

  addAndSend("Notification:GetAll", msgReply, msgHandler, {
    origin: systemNotification.origin,
    requestID: requestID
  });
});