Bug 1253565 - [webext] test "UnrecognizedProperty" on content_scripts manifest properties. r=kmag
authorLuca Greco <lgreco@mozilla.com>
Tue, 15 Mar 2016 01:11:18 +0100
changeset 288935 96c02999683fcc53b23aafa0987211a4c0659ffc
parent 288934 46794fe72b80b118bcafcf7ce9c830c7c8073a3a
child 288936 229b9d4e139665815f2339e9a566400517bb2f47
push id18202
push usercbook@mozilla.com
push dateWed, 16 Mar 2016 15:51:57 +0000
treeherderfx-team@c715f7a51827 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1253565
milestone48.0a1
Bug 1253565 - [webext] test "UnrecognizedProperty" on content_scripts manifest properties. r=kmag MozReview-Commit-ID: CpNmXmHHOzO
toolkit/components/extensions/test/mochitest/chrome.ini
toolkit/components/extensions/test/mochitest/test_chrome_ext_contentscript_unrecognizedprop_warning.html
--- a/toolkit/components/extensions/test/mochitest/chrome.ini
+++ b/toolkit/components/extensions/test/mochitest/chrome.ini
@@ -1,11 +1,13 @@
 [DEFAULT]
 skip-if = os == 'android'
 support-files =
   file_download.html
   file_download.txt
   interruptible.sjs
+  file_sample.html
 
 [test_chrome_ext_downloads_download.html]
 [test_chrome_ext_downloads_misc.html]
 [test_chrome_ext_downloads_search.html]
 [test_chrome_ext_eventpage_warning.html]
+[test_chrome_ext_contentscript_unrecognizedprop_warning.html]
copy from toolkit/components/extensions/test/mochitest/test_ext_contentscript.html
copy to toolkit/components/extensions/test/mochitest/test_chrome_ext_contentscript_unrecognizedprop_warning.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_contentscript_unrecognizedprop_warning.html
@@ -1,115 +1,80 @@
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Test for content script</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+  <title>Test for content script unrecognized property on manifest</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" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
 </head>
 <body>
 
 <script type="text/javascript">
 "use strict";
 
+const BASE = "http://mochi.test:8888/chrome/toolkit/components/extensions/test/mochitest";
+
 add_task(function* test_contentscript() {
   function backgroundScript() {
-    browser.runtime.onMessage.addListener(([msg, expectedState, readyState], sender) => {
-      if (msg == "chrome-namespace-ok") {
-        browser.test.sendMessage(msg);
-        return;
+    browser.runtime.onMessage.addListener((msg) => {
+      if (msg == "loaded") {
+        browser.tabs.query({active: true, currentWindow: true}).then((tabs) => {
+          // NOTE: we're removing the tab from here because doing a win.close()
+          // from the chrome test code is raising a "TypeError: can 't access
+          // dead object" exception.
+          browser.tabs.remove(tabs[0].id);
+
+          browser.test.notifyPass("content-script-loaded");
+        });
       }
-
-      browser.test.assertEq(msg, "script-run", "message type is correct");
-      browser.test.assertEq(readyState, expectedState, "readyState is correct");
-      browser.test.sendMessage("script-run-" + expectedState);
     });
   }
 
-  function contentScriptStart() {
-    browser.runtime.sendMessage(["script-run", "loading", document.readyState]);
-  }
-  function contentScriptEnd() {
-    browser.runtime.sendMessage(["script-run", "interactive", document.readyState]);
-  }
-  function contentScriptIdle() {
-    browser.runtime.sendMessage(["script-run", "complete", document.readyState]);
-  }
-
   function contentScript() {
-    let manifest = browser.runtime.getManifest();
-    void manifest.applications.gecko.id;
-    chrome.runtime.sendMessage(["chrome-namespace-ok"]);
+    chrome.runtime.sendMessage("loaded");
   }
 
   let extensionData = {
     manifest: {
       content_scripts: [
         {
           "matches": ["http://mochi.test/*/file_sample.html"],
-          "js": ["content_script_start.js"],
-          "run_at": "document_start",
-        },
-        {
-          "matches": ["http://mochi.test/*/file_sample.html"],
-          "js": ["content_script_end.js"],
-          "run_at": "document_end",
-        },
-        {
-          "matches": ["http://mochi.test/*/file_sample.html"],
-          "js": ["content_script_idle.js"],
-          "run_at": "document_idle",
-        },
-        {
-          "matches": ["http://mochi.test/*/file_sample.html"],
           "js": ["content_script.js"],
           "run_at": "document_idle",
+          "unrecognized_property": "with-a-random-value",
         },
       ],
     },
     background: "(" + backgroundScript.toString() + ")()",
 
     files: {
-      "content_script_start.js": "(" + contentScriptStart.toString() + ")()",
-      "content_script_end.js": "(" + contentScriptEnd.toString() + ")()",
-      "content_script_idle.js": "(" + contentScriptIdle.toString() + ")()",
       "content_script.js": "(" + contentScript.toString() + ")()",
     },
   };
 
   let extension = ExtensionTestUtils.loadExtension(extensionData);
 
-  let loadingCount = 0;
-  let interactiveCount = 0;
-  let completeCount = 0;
-  extension.onMessage("script-run-loading", () => { loadingCount++; });
-  extension.onMessage("script-run-interactive", () => { interactiveCount++; });
-
-  let completePromise = new Promise(resolve => {
-    extension.onMessage("script-run-complete", () => { completeCount++; resolve(); });
+  SimpleTest.waitForExplicitFinish();
+  let waitForConsole = new Promise(resolve => {
+    SimpleTest.monitorConsole(resolve, [{
+      message: /Reading manifest: Error processing content_scripts.*.unrecognized_property: An unexpected property was found/,
+    }]);
   });
 
-  let chromeNamespacePromise = extension.awaitMessage("chrome-namespace-ok");
-
   yield extension.startup();
-  info("extension loaded");
 
-  let win = window.open("file_sample.html");
+  window.open(`${BASE}/file_sample.html`);
 
-  yield Promise.all([waitForLoad(win), completePromise, chromeNamespacePromise]);
+  yield Promise.all([extension.awaitFinish("content-script-loaded")]);
   info("test page loaded");
 
-  win.close();
+  yield extension.unload();
 
-  is(loadingCount, 1, "document_start script ran exactly once");
-  is(interactiveCount, 1, "document_end script ran exactly once");
-  is(completeCount, 1, "document_idle script ran exactly once");
-
-  yield extension.unload();
-  info("extension unloaded");
+  SimpleTest.endMonitorConsole();
+  yield waitForConsole;
 });
 </script>
 
 </body>
 </html>