summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_notifications_unsupported.js
blob: 1213ae4f2385e7c9cffaf70de7a96d86cb977155 (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
const registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(
  Components.ID("{18f25bb4-ab12-4e24-b3b0-69215056160b}"),
  "unsupported alerts service",
  ALERTS_SERVICE_CONTRACT_ID,
  {} // This object lacks an implementation of nsIAlertsService.
);

add_task(async function test_notification_unsupported_backend() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      permissions: ["notifications"],
    },
    async background() {
      let closedPromise = new Promise(resolve => {
        browser.notifications.onClosed.addListener(resolve);
      });
      let createdId = await browser.notifications.create("notifid", {
        type: "basic",
        title: "titl",
        message: "msg",
      });
      let closedId = await closedPromise;
      browser.test.assertEq(createdId, closedId, "ID of closed notification");
      browser.test.assertEq(
        "{}",
        JSON.stringify(await browser.notifications.getAll()),
        "no notifications left"
      );
      browser.test.sendMessage("notification_closed");
    },
  });
  await extension.startup();
  await extension.awaitMessage("notification_closed");
  await extension.unload();
});