summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpinstall/browser_bug638292.js
blob: 078d94cb5044e91b049765ec40f53d6de01fb8f0 (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
// ----------------------------------------------------------------------------
// Test whether an InstallTrigger.enabled is working
add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.InstallTrigger.enabled", true],
      ["extensions.InstallTriggerImpl.enabled", true],
    ],
  });

  let testtab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TESTROOT + "bug638292.html"
  );

  async function verify(link, button) {
    info("Clicking " + link);

    let loadedPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);

    await BrowserTestUtils.synthesizeMouseAtCenter(
      "#" + link,
      { button },
      gBrowser.selectedBrowser
    );

    let newtab = await loadedPromise;

    let result = await SpecialPowers.spawn(
      newtab.linkedBrowser,
      [],
      async function () {
        return content.document.getElementById("enabled").textContent == "true";
      }
    );

    ok(result, "installTrigger for " + link + " should have been enabled");

    // Focus the old tab (link3 is opened in the background)
    if (link != "link3") {
      await BrowserTestUtils.switchTab(gBrowser, testtab);
    }
    gBrowser.removeTab(newtab);
  }

  await verify("link1", 0);
  await verify("link2", 0);
  await verify("link3", 1);

  gBrowser.removeCurrentTab();
});