summaryrefslogtreecommitdiffstats
path: root/dom/push/test/xpcshell/test_unregister_error.js
blob: 53d5929185fcbe6e3fc124337cafb97aec86b2a8 (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
57
58
59
60
61
62
63
64
65
66
67
68
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

'use strict';

const {PushDB, PushService, PushServiceWebSocket} = serviceExports;

const channelID = '00c7fa13-7b71-447d-bd27-a91abc09d1b2';

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

add_task(function* test_unregister_error() {
  let db = PushServiceWebSocket.newPushDB();
  do_register_cleanup(() => {return db.drop().then(_ => db.close());});
  yield db.put({
    channelID: channelID,
    pushEndpoint: 'https://example.org/update/failure',
    scope: 'https://example.net/page/failure',
    originAttributes: '',
    version: 1,
    quota: Infinity,
  });

  let unregisterDone;
  let unregisterPromise = new Promise(resolve => unregisterDone = resolve);
  PushService.init({
    serverURI: "wss://push.example.org/",
    db,
    makeWebSocket(uri) {
      return new MockWebSocket(uri, {
        onHello(request) {
          this.serverSendMsg(JSON.stringify({
            messageType: 'hello',
            status: 200,
            uaid: '083e6c17-1063-4677-8638-ab705aebebc2'
          }));
        },
        onUnregister(request) {
          // The server is notified out-of-band. Since channels may be pruned,
          // any failures are swallowed.
          equal(request.channelID, channelID, 'Unregister: wrong channel ID');
          this.serverSendMsg(JSON.stringify({
            messageType: 'unregister',
            status: 500,
            error: 'omg, everything is exploding',
            channelID
          }));
          unregisterDone();
        }
      });
    }
  });

  yield PushService.unregister({
    scope: 'https://example.net/page/failure',
    originAttributes: '',
  });

  let result = yield db.getByKeyID(channelID);
  ok(!result, 'Deleted push record exists');

  // Make sure we send a request to the server.
  yield unregisterPromise;
});