summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/serviceworkers/notification_get_sw.js
blob: 540c9d93cc33984382bbdb3639ef10c942468478 (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
function postAll(data) {
  self.clients.matchAll().then(function(clients) {
    if (clients.length == 0) {
      dump("***************** NO CLIENTS FOUND! Test messages are being lost *******************\n");
    }
    clients.forEach(function(client) {
      client.postMessage(data);
    });
  });
}

function ok(a, msg) {
  postAll({type: 'status', status: !!a, msg: a + ": " + msg });
}

function is(a, b, msg) {
  postAll({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
}

function done() {
  postAll({type: 'finish'});
}

onmessage = function(e) {
dump("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MESSAGE " + e.data + "\n");
  var start;
  if (e.data == 'create') {
    start = registration.showNotification("This is a title");
  } else {
    start = Promise.resolve();
  }

  start.then(function() {
  dump("CALLING getNotification\n");
    registration.getNotifications().then(function(notifications) {
  dump("RECD getNotification\n");
      is(notifications.length, 1, "There should be one stored notification");
      var notification = notifications[0];
      if (!notification) {
        done();
        return;
      }
      ok(notification instanceof Notification, "Should be a Notification");
      is(notification.title, "This is a title", "Title should match");
      notification.close();
      done();
    });
  });
}