Bug 1253565 - [webext] Run event pages as background pages and log warning on persistent manifest attribute. r?kmag draft
authorLuca Greco <lgreco@mozilla.com>
Fri, 04 Mar 2016 01:29:54 +0100
changeset 336933 40c6845f751c76229e51ae95e1d7b4ff2593cb6d
parent 336538 48199a0c1e54d75528ee860c425a2235c4df1fee
child 515523 be6eb9f08b231e8e2e5d1d152c98c48f9184484b
push id12210
push userluca.greco@alcacoop.it
push dateFri, 04 Mar 2016 12:04:35 +0000
reviewerskmag
bugs1253565
milestone47.0a1
Bug 1253565 - [webext] Run event pages as background pages and log warning on persistent manifest attribute. r?kmag MozReview-Commit-ID: 9QWvRkADsQD
toolkit/components/extensions/schemas/manifest.json
toolkit/components/extensions/test/mochitest/chrome.ini
toolkit/components/extensions/test/mochitest/test_chrome_ext_eventpage_warning.html
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -85,25 +85,33 @@
             }
           },
 
           "background": {
             "choices": [
               {
                 "type": "object",
                 "properties": {
-                  "page": { "$ref": "ExtensionURL" }
+                  "page": { "$ref": "ExtensionURL" },
+                  "persistent": {
+                    "optional": true,
+                    "$ref": "BackgroundPagePersistentPropertyUnsupported"
+                  }
                 }
               },
               {
                 "type": "object",
                 "properties": {
                   "scripts": {
                     "type": "array",
                     "items": { "$ref": "ExtensionURL" }
+                  },
+                  "persistent": {
+                    "optional": true,
+                    "$ref": "BackgroundPagePersistentPropertyUnsupported"
                   }
                 }
               }
             ],
             "optional": true
           },
 
           "content_scripts": {
@@ -252,12 +260,17 @@
             },
             "additionalProperties": false
           },
           {
             "type": "object",
             "isInstanceOf": "ImageData"
           }
         ]
+      },
+      {
+        "id": "BackgroundPagePersistentPropertyUnsupported",
+        "type": "boolean",
+        "deprecated": "Event Pages are not currently supported. This will run as a persistent Background Page."
       }
     ]
   }
 ]
--- a/toolkit/components/extensions/test/mochitest/chrome.ini
+++ b/toolkit/components/extensions/test/mochitest/chrome.ini
@@ -1,6 +1,7 @@
 [DEFAULT]
 skip-if = os == 'android'
 support-files =
   file_download.txt
 
 [test_chrome_ext_downloads_download.html]
+[test_chrome_ext_eventpage_warning.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_eventpage_warning.html
@@ -0,0 +1,83 @@
+<!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="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() {
+  // Not necessary in browser-chrome tests, but monitorConsole gripes
+  // if we don't call it.
+  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);
+
+    // Check that we do have a console message when lastError is not checked.
+    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;
+  }
+});
+
+</script>
+
+</body>
+</html>