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

const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
  "resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);

// Load policy engine
Services.policies; // eslint-disable-line no-unused-expressions

AddonTestUtils.init(this);

add_task(async function test_storage_managed_policy() {
  await ExtensionTestUtils.startAddonManager();

  await EnterprisePolicyTesting.setupPolicyEngineWithJson({
    policies: {
      "3rdparty": {
        Extensions: {
          "test-storage-managed-policy@mozilla.com": {
            string: "value",
          },
        },
      },
    },
  });

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      browser_specific_settings: {
        gecko: { id: "test-storage-managed-policy@mozilla.com" },
      },
      permissions: ["storage"],
    },

    async background() {
      let str = await browser.storage.managed.get("string");
      browser.test.sendMessage("results", str);
    },
  });

  await extension.startup();
  deepEqual(await extension.awaitMessage("results"), { string: "value" });
  await extension.unload();
});