Bug 1362047 - Fix content_script.run_at default value, add test r=mixedpuppy
☠☠ backed out by cf287e42cf70 ☠ ☠
authorTomislav Jovanovic <tomica@gmail.com>
Wed, 10 May 2017 02:00:29 +0200
changeset 358217 3397cb95fb95c0563b0d6373faec06215e10863e
parent 358216 09651571077f53922ad313d8f40cbe7620a8ebc5
child 358218 b7e1e89f4dff5979e00330bf0f9159d6dc1c3dfd
push id42637
push userryanvm@gmail.com
push dateSat, 13 May 2017 22:49:16 +0000
treeherderautoland@3397cb95fb95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1362047
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1362047 - Fix content_script.run_at default value, add test r=mixedpuppy MozReview-Commit-ID: CiBaSkZ0TqQ
browser/components/extensions/test/browser/browser_ext_tabs_executeScript_runAt.js
toolkit/components/extensions/schemas/extension_types.json
toolkit/components/extensions/schemas/manifest.json
toolkit/components/extensions/test/xpcshell/test_ext_contentscript.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_executeScript_runAt.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_executeScript_runAt.js
@@ -47,16 +47,20 @@ add_task(async function testExecuteScrip
         await loadingPromise;
 
         let states = await Promise.all([
           // Send the executeScript requests in the reverse order that we expect
           // them to execute in, to avoid them passing only because of timing
           // races.
           browser.tabs.executeScript({
             code: "document.readyState",
+            // Testing default `runAt`.
+          }),
+          browser.tabs.executeScript({
+            code: "document.readyState",
             runAt: "document_idle",
           }),
           browser.tabs.executeScript({
             code: "document.readyState",
             runAt: "document_end",
           }),
           browser.tabs.executeScript({
             code: "document.readyState",
@@ -72,17 +76,18 @@ add_task(async function testExecuteScrip
                                 `document_end state is valid: ${states[1]}`);
         browser.test.assertTrue(states[2] == "complete",
                                 `document_idle state is valid: ${states[2]}`);
 
         // If we have the earliest valid states for each script, we're done.
         // Otherwise, try again.
         success = (states[0] == "loading" &&
                    states[1] == "interactive" &&
-                   states[2] == "complete");
+                   states[2] == "complete" &&
+                   states[3] == "complete");
       }
 
       browser.test.assertTrue(success, "Got the earliest expected states at least once");
 
       browser.test.notifyPass("executeScript-runAt");
     } catch (e) {
       browser.test.fail(`Error: ${e} :: ${e.stack}`);
       browser.test.notifyFail("executeScript-runAt");
--- a/toolkit/components/extensions/schemas/extension_types.json
+++ b/toolkit/components/extensions/schemas/extension_types.json
@@ -57,16 +57,17 @@
             "type": "integer",
             "minimum": 0,
             "optional": true,
             "description": "The ID of the frame to inject the script into. This may not be used in combination with <code>allFrames</code>."
           },
           "runAt": {
             "$ref": "RunAt",
             "optional": true,
+            "default": "document_idle",
             "description": "The soonest that the JavaScript or CSS will be injected into the tab. Defaults to \"document_idle\"."
           },
           "cssOrigin": {
             "$ref": "CSSOrigin",
             "optional": true,
             "description": "The css origin of the stylesheet to inject. Defaults to \"author\"."
           }
         }
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -357,16 +357,17 @@
             "description": "The list of CSS files to inject",
             "items": { "$ref": "ExtensionURL" }
           },
           "all_frames": {"type": "boolean", "optional": true, "description": "If allFrames is <code>true</code>, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it's <code>false</code> and is only injected into the top frame."},
           "match_about_blank": {"type": "boolean", "optional": true, "description": "If matchAboutBlank is true, then the code is also injected in about:blank and about:srcdoc frames if your extension has access to its parent document. Code cannot be inserted in top-level about:-frames. By default it is <code>false</code>."},
           "run_at": {
             "$ref": "extensionTypes.RunAt",
             "optional": true,
+            "default": "document_idle",
             "description": "The soonest that the JavaScript or CSS will be injected into the tab. Defaults to \"document_idle\"."
           }
         }
       },
       {
         "id": "IconPath",
         "choices": [
           {
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript.js
@@ -2,17 +2,17 @@
 
 const server = createHttpServer();
 server.registerDirectory("/data/", do_get_file("data"));
 
 const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
 
 ExtensionTestUtils.mockAppInfo();
 
-add_task(async function test_contentscript() {
+add_task(async function test_contentscript_runAt() {
   function background() {
     browser.runtime.onMessage.addListener(([msg, expectedStates, readyState], sender) => {
       if (msg == "chrome-namespace-ok") {
         browser.test.sendMessage(msg);
         return;
       }
 
       browser.test.assertEq("script-run", msg, "message type is correct");
@@ -54,16 +54,21 @@ add_task(async function test_contentscri
         },
         {
           "matches": ["http://*/*/file_sample.html"],
           "js": ["content_script_idle.js"],
           "run_at": "document_idle",
         },
         {
           "matches": ["http://*/*/file_sample.html"],
+          "js": ["content_script_idle.js"],
+          // Test default `run_at`.
+        },
+        {
+          "matches": ["http://*/*/file_sample.html"],
           "js": ["content_script.js"],
           "run_at": "document_idle",
         },
       ],
     },
     background,
 
     files: {
@@ -78,27 +83,32 @@ add_task(async function test_contentscri
 
   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(); });
+    extension.onMessage("script-run-complete", () => {
+      completeCount++;
+      if (completeCount > 1) {
+        resolve();
+      }
+    });
   });
 
   let chromeNamespacePromise = extension.awaitMessage("chrome-namespace-ok");
 
   await extension.startup();
 
   let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
 
   await Promise.all([completePromise, chromeNamespacePromise]);
 
   await contentPage.close();
 
   equal(loadingCount, 1, "document_start script ran exactly once");
   equal(interactiveCount, 1, "document_end script ran exactly once");
-  equal(completeCount, 1, "document_idle script ran exactly once");
+  equal(completeCount, 2, "document_idle script ran exactly twice");
 
   await extension.unload();
 });