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

AddonTestUtils.init(this);

add_task(async function testEmptySchema() {
  function background() {
    browser.test.assertEq(
      undefined,
      browser.manifest,
      "browser.manifest is not defined"
    );
    browser.test.assertTrue(
      !!browser.storage,
      "browser.storage should be defined"
    );
    browser.test.assertEq(
      undefined,
      browser.contextMenus,
      "browser.contextMenus should not be defined"
    );
    browser.test.notifyPass("schema");
  }

  let extension = ExtensionTestUtils.loadExtension({
    background,
    manifest: {
      permissions: ["storage"],
    },
  });

  await extension.startup();
  await extension.awaitFinish("schema");
  await extension.unload();
});

add_task(async function test_warnings_as_errors() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: { unrecognized_property_that_should_be_treated_as_a_warning: 1 },
  });

  // Tests should be run with extensions.webextensions.warnings-as-errors=true
  // by default, and prevent extensions with manifest warnings from loading.
  await Assert.rejects(
    extension.startup(),
    /unrecognized_property_that_should_be_treated_as_a_warning/,
    "extension with invalid manifest should not load if warnings-as-errors=true"
  );
  // When ExtensionTestUtils.failOnSchemaWarnings(false) is called, startup is
  // expected to succeed, as shown by the next "testUnknownProperties" test.
});

add_task(async function testUnknownProperties() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      permissions: ["unknownPermission"],

      unknown_property: {},
    },

    background() {},
  });

  let { messages } = await promiseConsoleOutput(async () => {
    ExtensionTestUtils.failOnSchemaWarnings(false);
    await extension.startup();
    ExtensionTestUtils.failOnSchemaWarnings(true);
  });

  AddonTestUtils.checkMessages(messages, {
    expected: [
      { message: /processing permissions\.0: Value "unknownPermission"/ },
      {
        message:
          /processing unknown_property: An unexpected property was found in the WebExtension manifest/,
      },
    ],
  });

  await extension.unload();
});