summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_webapi_theme.js
blob: dd1df90907f5f5d324315c301ac558161fe4896e (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
69
70
71
72
73
74
75
76
77
78
79
"use strict";

const TESTPAGE = `${SECURE_TESTROOT}webapi_checkavailable.html`;
const URL = `${SECURE_TESTROOT}addons/browser_theme.xpi`;

add_task(async function test_theme_install() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.webapi.testing", true],
      ["extensions.install.requireBuiltInCerts", false],
    ],
  });

  await BrowserTestUtils.withNewTab(TESTPAGE, async browser => {
    let updates = [];
    function observer(subject, topic, data) {
      updates.push(JSON.stringify(subject.wrappedJSObject));
    }
    Services.obs.addObserver(observer, "lightweight-theme-styling-update");
    registerCleanupFunction(() => {
      Services.obs.removeObserver(observer, "lightweight-theme-styling-update");
    });

    let sawConfirm = false;
    promisePopupNotificationShown("addon-install-confirmation").then(panel => {
      sawConfirm = true;
      panel.button.click();
    });

    let prompt1 = waitAppMenuNotificationShown(
      "addon-installed",
      "theme@tests.mozilla.org",
      false
    );
    let installPromise = SpecialPowers.spawn(browser, [URL], async url => {
      let install = await content.navigator.mozAddonManager.createInstall({
        url,
      });
      return install.install();
    });
    await prompt1;

    ok(sawConfirm, "Confirm notification was displayed before installation");

    // Open a new window and test the app menu panel from there.  This verifies the
    // incognito checkbox as well as finishing install in this case.
    let newWin = await BrowserTestUtils.openNewBrowserWindow();
    await waitAppMenuNotificationShown(
      "addon-installed",
      "theme@tests.mozilla.org",
      true,
      newWin
    );
    await installPromise;
    ok(true, "Theme install completed");

    await BrowserTestUtils.closeWindow(newWin);

    Assert.equal(updates.length, 1, "Got a single theme update");
    let parsed = JSON.parse(updates[0]);
    ok(
      parsed.theme.headerURL.endsWith("/testImage.png"),
      "Theme update has the expected headerURL"
    );
    is(
      parsed.theme.id,
      "theme@tests.mozilla.org",
      "Theme update includes the theme ID"
    );
    is(
      parsed.theme.version,
      "1.0",
      "Theme update includes the theme's version"
    );

    let addon = await AddonManager.getAddonByID(parsed.theme.id);
    await addon.uninstall();
  });
});