summaryrefslogtreecommitdiffstats
path: root/browser/components/enterprisepolicies/tests/browser/browser_policy_app_auto_update.js
blob: 0cae8369e415cb061c94ec299a56c82adbc82d57 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";
ChromeUtils.defineESModuleGetters(this, {
  UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs",
});

async function test_app_update_auto(expectedEnabled, expectedLocked) {
  let actualEnabled = await UpdateUtils.getAppUpdateAutoEnabled();
  is(
    actualEnabled,
    expectedEnabled,
    `Actual auto update enabled setting should match the expected value of ${expectedEnabled}`
  );

  let actualLocked = UpdateUtils.appUpdateAutoSettingIsLocked();
  is(
    actualLocked,
    expectedLocked,
    `Auto update enabled setting ${
      expectedLocked ? "should" : "should not"
    } be locked`
  );

  let setSuccess = true;
  try {
    await UpdateUtils.setAppUpdateAutoEnabled(actualEnabled);
  } catch (error) {
    setSuccess = false;
  }
  is(
    setSuccess,
    !expectedLocked,
    `Setting auto update ${expectedLocked ? "should" : "should not"} fail`
  );

  await BrowserTestUtils.withNewTab("about:preferences", browser => {
    is(
      browser.contentDocument.getElementById("updateSettingsContainer").hidden,
      expectedLocked,
      `When auto update ${
        expectedLocked ? "is" : "isn't"
      } locked, the corresponding preferences entry ${
        expectedLocked ? "should" : "shouldn't"
      } be hidden`
    );
  });
}

add_task(async function test_app_auto_update_policy() {
  let originalUpdateAutoValue = await UpdateUtils.getAppUpdateAutoEnabled();
  registerCleanupFunction(async () => {
    await UpdateUtils.setAppUpdateAutoEnabled(originalUpdateAutoValue);
  });

  await UpdateUtils.setAppUpdateAutoEnabled(true);
  await test_app_update_auto(true, false);

  await setupPolicyEngineWithJson({
    policies: {
      AppAutoUpdate: false,
    },
  });
  await test_app_update_auto(false, true);

  await setupPolicyEngineWithJson({});
  await UpdateUtils.setAppUpdateAutoEnabled(false);
  await test_app_update_auto(false, false);

  await setupPolicyEngineWithJson({
    policies: {
      AppAutoUpdate: true,
    },
  });
  await test_app_update_auto(true, true);
});