summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_change_backgroundServiceWorker_enabled_pref_false.js
blob: 0be36788c16d09411fe6b54dc771062d00fecd72 (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
"use strict";

// extensions.backgroundServiceWorker.enabled=false is set in the test manifest
// because there is no guarantee that the pref value set at runtime takes effect
// due to the pref being declared "mirror: once". The value of this pref is
// frozen upon the first access to any "mirror:once" pref, and we can therefore
// not assume the pref value to be mutable at runtime.
const PREF_EXT_SW_ENABLED = "extensions.backgroundServiceWorker.enabled";

add_task(async function test_backgroundServiceWorkerEnabled() {
  // Sanity check:
  Assert.equal(
    Services.prefs.getBoolPref(PREF_EXT_SW_ENABLED),
    false,
    "Pref value should be false"
  );
  Assert.equal(
    WebExtensionPolicy.backgroundServiceWorkerEnabled,
    false,
    "backgroundServiceWorkerEnabled should be false"
  );

  if (AppConstants.MOZ_WEBEXT_WEBIDL_ENABLED) {
    Assert.ok(
      !Services.prefs.prefIsLocked(PREF_EXT_SW_ENABLED),
      "Pref should be not locked when MOZ_WEBEXT_WEBIDL_ENABLED is true"
    );
  } else {
    Assert.ok(
      Services.prefs.prefIsLocked(PREF_EXT_SW_ENABLED),
      "Pref should be locked when MOZ_WEBEXT_WEBIDL_ENABLED is false"
    );
    Services.prefs.unlockPref(PREF_EXT_SW_ENABLED);
  }

  // Flip pref and test result.
  Services.prefs.setBoolPref(PREF_EXT_SW_ENABLED, true);
  Assert.ok(
    Services.prefs.getBoolPref(PREF_EXT_SW_ENABLED),
    "pref can change after setting it"
  );
  Assert.equal(
    WebExtensionPolicy.backgroundServiceWorkerEnabled,
    false,
    "backgroundServiceWorkerEnabled is still false despite the pref flip"
  );
});