summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_embedderDisabled.js
blob: 943b3cf0c3d557586c61360934de0fedea982f2a (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

const ADDON_ID = "embedder-disabled@tests.mozilla.org";
const PREF_IS_EMBEDDED = "extensions.isembedded";

createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "49");

registerCleanupFunction(() => {
  Services.prefs.clearUserPref(PREF_IS_EMBEDDED);
});

async function installExtension() {
  return promiseInstallWebExtension({
    manifest: {
      browser_specific_settings: { gecko: { id: ADDON_ID } },
    },
  });
}

add_task(async function test_setup() {
  await promiseStartupManager();
});

add_task(async function embedder_disabled_while_not_embedding() {
  const addon = await installExtension();
  let exceptionThrown = false;
  try {
    await addon.setEmbedderDisabled(true);
  } catch (exception) {
    exceptionThrown = true;
  }

  equal(exceptionThrown, true);

  // Verify that the addon is not affected
  equal(addon.isActive, true);
  equal(addon.embedderDisabled, undefined);

  await addon.uninstall();
});

add_task(async function unset_embedder_disabled_while_not_embedding() {
  Services.prefs.setBoolPref(PREF_IS_EMBEDDED, true);

  const addon = await installExtension();
  await addon.setEmbedderDisabled(true);

  // Verify the addon is not active anymore
  equal(addon.isActive, false);
  equal(addon.embedderDisabled, true);

  Services.prefs.setBoolPref(PREF_IS_EMBEDDED, false);

  // Verify that embedder disabled cannot be read if not embedding
  equal(addon.embedderDisabled, undefined);

  await addon.disable();
  await addon.enable();

  // Verify that embedder disabled can be removed
  equal(addon.isActive, true);
  equal(addon.embedderDisabled, undefined);

  await addon.uninstall();
});

add_task(async function embedder_disabled_while_embedding() {
  Services.prefs.setBoolPref(PREF_IS_EMBEDDED, true);

  const addon = await installExtension();
  await addon.setEmbedderDisabled(true);

  // Verify the addon is not active anymore
  equal(addon.embedderDisabled, true);
  equal(addon.isActive, false);

  await addon.setEmbedderDisabled(false);

  // Verify that the addon is now enabled again
  equal(addon.isActive, true);
  equal(addon.embedderDisabled, false);
  await addon.uninstall();

  Services.prefs.setBoolPref(PREF_IS_EMBEDDED, false);
});

add_task(async function embedder_disabled_while_user_disabled() {
  Services.prefs.setBoolPref(PREF_IS_EMBEDDED, true);

  const addon = await installExtension();
  await addon.disable();

  // Verify that the addon is userDisabled
  equal(addon.isActive, false);
  equal(addon.userDisabled, true);
  equal(addon.embedderDisabled, false);

  await addon.setEmbedderDisabled(true);

  // Verify that the addon can be userDisabled and embedderDisabled
  equal(addon.isActive, false);
  equal(addon.userDisabled, true);
  equal(addon.embedderDisabled, true);

  await addon.setEmbedderDisabled(false);

  // Verify that unsetting embedderDisabled doesn't enable the addon
  equal(addon.isActive, false);
  equal(addon.userDisabled, true);
  equal(addon.embedderDisabled, false);

  await addon.enable();

  // Verify that the addon can be enabled after unsetting userDisabled
  equal(addon.isActive, true);
  equal(addon.userDisabled, false);
  equal(addon.embedderDisabled, false);

  await addon.uninstall();

  Services.prefs.setBoolPref(PREF_IS_EMBEDDED, false);
});