summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/xpcshell/test_ext_manifest_permissions.js
blob: fed7af5d5bf032c2ddbb9318139023b5bef6a9ec (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

/* globals chrome */

Services.prefs.setBoolPref("extensions.manifestV3.enabled", true);

async function testPermission(options) {
  function background(bgOptions) {
    browser.test.sendMessage("typeof-namespace", {
      browser: typeof browser[bgOptions.namespace],
      chrome: typeof chrome[bgOptions.namespace],
    });
  }

  let extensionDetails = {
    background: `(${background})(${JSON.stringify(options)})`,
  };

  let extension = ExtensionTestUtils.loadExtension(extensionDetails);

  await extension.startup();

  let types = await extension.awaitMessage("typeof-namespace");
  equal(
    types.browser,
    "undefined",
    `Type of browser.${options.namespace} without manifest entry`
  );
  equal(
    types.chrome,
    "undefined",
    `Type of chrome.${options.namespace} without manifest entry`
  );

  await extension.unload();

  extensionDetails.manifest = options.manifest;
  extension = ExtensionTestUtils.loadExtension(extensionDetails);

  await extension.startup();

  types = await extension.awaitMessage("typeof-namespace");
  equal(
    types.browser,
    "object",
    `Type of browser.${options.namespace} with manifest entry`
  );
  equal(
    types.chrome,
    "object",
    `Type of chrome.${options.namespace} with manifest entry`
  );

  await extension.unload();
}

add_task(async function test_action() {
  await testPermission({
    namespace: "action",
    manifest: {
      manifest_version: 3,
      action: {},
    },
  });
});

add_task(async function test_browserAction() {
  await testPermission({
    namespace: "browserAction",
    manifest: {
      browser_action: {},
    },
  });
});

add_task(async function test_pageAction() {
  await testPermission({
    namespace: "pageAction",
    manifest: {
      page_action: {},
    },
  });
});