summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_themes_validation.js
blob: c004363a6b37b1c8263e5a298de0912b13f8ef51 (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
"use strict";

PromiseTestUtils.allowMatchingRejectionsGlobally(/packaging errors/);

/**
 * Helper function for testing a theme with invalid properties.
 *
 * @param {object} invalidProps The invalid properties to load the theme with.
 */
async function testThemeWithInvalidProperties(invalidProps) {
  let manifest = {
    theme: {},
  };

  invalidProps.forEach(prop => {
    // Some properties require additional information:
    switch (prop) {
      case "background":
        manifest[prop] = { scripts: ["background.js"] };
        break;
      case "permissions":
        manifest[prop] = ["tabs"];
        break;
      case "omnibox":
        manifest[prop] = { keyword: "test" };
        break;
      default:
        manifest[prop] = {};
    }
  });

  let extension = ExtensionTestUtils.loadExtension({ manifest });
  await Assert.rejects(
    extension.startup(),
    /startup failed/,
    "Theme should fail to load if it contains invalid properties"
  );
}

add_task(
  async function test_that_theme_with_invalid_properties_fails_to_load() {
    let invalidProps = [
      "page_action",
      "browser_action",
      "background",
      "permissions",
      "omnibox",
      "commands",
    ];
    for (let prop in invalidProps) {
      await testThemeWithInvalidProperties([prop]);
    }
    await testThemeWithInvalidProperties(invalidProps);
  }
);