summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js
blob: b8ee1b254f1921e0e476998bfe428d57fb090635 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.InstallTrigger.enabled", true],
      ["extensions.InstallTriggerImpl.enabled", true],
      // Relax the user input requirements while running this test.
      ["xpinstall.userActivation.required", false],
    ],
  });
});

// Test whether an InstallTrigger.enabled is working
add_task(async function test_enabled() {
  await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TESTROOT + "enabled.html"
  );

  let text = await ContentTask.spawn(
    gBrowser.selectedBrowser,
    undefined,
    () => content.document.getElementById("enabled").textContent
  );

  is(text, "true", "installTrigger should have been enabled");
  gBrowser.removeCurrentTab();
});

// Test whether an InstallTrigger.enabled is working
add_task(async function test_disabled() {
  Services.prefs.setBoolPref("xpinstall.enabled", false);
  await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TESTROOT + "enabled.html"
  );

  let text = await ContentTask.spawn(
    gBrowser.selectedBrowser,
    undefined,
    () => content.document.getElementById("enabled").textContent
  );

  is(text, "false", "installTrigger should have not been enabled");
  Services.prefs.clearUserPref("xpinstall.enabled");
  gBrowser.removeCurrentTab();
});

// Test whether an InstallTrigger.install call fails when xpinstall is disabled
add_task(async function test_disabled2() {
  let installDisabledCalled = false;

  Harness.installDisabledCallback = installInfo => {
    installDisabledCalled = true;
    ok(true, "Saw installation disabled");
  };

  Harness.installBlockedCallback = installInfo => {
    ok(false, "Should never see the blocked install notification");
    return false;
  };

  Harness.installConfirmCallback = panel => {
    ok(false, "Should never see an install confirmation dialog");
    return false;
  };

  Harness.setup();
  Services.prefs.setBoolPref("xpinstall.enabled", false);

  var triggers = encodeURIComponent(
    JSON.stringify({
      "Unsigned XPI": TESTROOT + "amosigned.xpi",
    })
  );

  BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TESTROOT + "installtrigger.html?" + triggers
  );

  await BrowserTestUtils.waitForContentEvent(
    gBrowser.selectedBrowser,
    "InstallTriggered",
    true,
    undefined,
    true
  );

  let text = await ContentTask.spawn(
    gBrowser.selectedBrowser,
    undefined,
    () => content.document.getElementById("return").textContent
  );

  is(text, "false", "installTrigger should have not been enabled");
  ok(installDisabledCalled, "installDisabled callback was called");

  Services.prefs.clearUserPref("xpinstall.enabled");
  gBrowser.removeCurrentTab();
  Harness.finish();
});