summaryrefslogtreecommitdiffstats
path: root/toolkit/components/webextensions/test/mochitest/test_chrome_ext_eventpage_warning.html
blob: ecea8237ef0b68e4cae6290283112f6e12fd6ceb (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for WebExtension EventPage Warning</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script type="text/javascript" src="chrome_head.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="text/javascript">
"use strict";

function createEventPageExtension(eventPage) {
  function eventPageScript() {
    browser.test.log("running event page as background script");
    browser.test.sendMessage("running", 1);
  }

  return ExtensionTestUtils.loadExtension({
    manifest: {
      "background": eventPage,
    },
    files: {
      "event-page-script.js": eventPageScript,
      "event-page.html": `<html><head>
        <meta charset="utf-8">
        <script src="event-page-script.js"><\/script>
      </head></html>`,
    },
  });
}

add_task(function* test_eventpages() {
  // Used in other tests to prevent the monitorConsole to grip.
  SimpleTest.waitForExplicitFinish();

  let testCases = [
    {
      message: "testing event page running as a background page",
      eventPage: {
        "page": "event-page.html",
        "persistent": false,
      },
    },
    {
      message: "testing event page scripts running as a background page",
      eventPage: {
        "scripts": ["event-page-script.js"],
        "persistent": false,
      },
    },
  ];

  for (let {message, eventPage} of testCases) {
    info(message);

    // Wait for the expected logged warnings from the manifest validation.
    let waitForConsole = new Promise(resolve => {
      SimpleTest.monitorConsole(resolve, [{message: /Event pages are not currently supported./}]);
    });

    let extension = createEventPageExtension(eventPage);

    info("load complete");
    let [, x] = yield Promise.all([extension.startup(), extension.awaitMessage("running")]);
    is(x, 1, "got correct value from extension");
    info("test complete");
    yield extension.unload();
    info("extension unloaded successfully");

    SimpleTest.endMonitorConsole();
    yield waitForConsole;

    waitForConsole = new Promise(resolve => {
      SimpleTest.monitorConsole(resolve, [{
        message: /Reading manifest: Error processing background.nonExistentProp: An unexpected property was found/,
      }]);
    });

    info("testing additional unrecognized properties on background page");

    extension = createEventPageExtension({
      "scripts": ["event-page-script.js"],
      "nonExistentProp": true,
    });

    info("load complete");
    [, x] = yield Promise.all([extension.startup(), extension.awaitMessage("running")]);
    is(x, 1, "got correct value from extension");
    info("test complete");
    yield extension.unload();
    info("extension unloaded successfully");

    SimpleTest.endMonitorConsole();
    yield waitForConsole;
  }
});

</script>

</body>
</html>