Bug 1422496 - Part 2: wait the bg iframe to be loaded in content scripts register unload; r=rpl
authorLiang-Heng Chen <xeonchen@gmail.com>
Tue, 09 Jan 2018 07:29:00 +0200
changeset 450358 1adb2c87c080fa673ed8c4b2bb04ffec6beee436
parent 450357 80022d102ad70a0936ef4a2462eab1d5ec3315a2
child 450359 6984e56259d8dd3d7260cf70ba4a5fc2b1ce6673
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1422496
milestone59.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 1422496 - Part 2: wait the bg iframe to be loaded in content scripts register unload; r=rpl MozReview-Commit-ID: 721qqA2roes
toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
@@ -121,29 +121,29 @@ add_task(async function test_contentscri
   equal(registeredStylesResults.registeredExtensionUrlStyleBG, "rgb(255, 0, 0)",
         "The expected style has been applied from the registered extension url style");
   equal(registeredStylesResults.registeredExtensionBlobStyleBG, "rgb(0, 0, 255)",
         "The expected style has been applied from the registered extension blob style");
 
   extension.sendMessage("unregister-file");
   await extension.awaitMessage("unregister-file:done");
 
-  contentPage.loadURL(`${BASE_URL}/file_sample_registered_styles.html`);
+  await contentPage.loadURL(`${BASE_URL}/file_sample_registered_styles.html`);
 
   const unregisteredURLStylesResults = await extension.awaitMessage("registered-styles-results");
 
   equal(unregisteredURLStylesResults.registeredExtensionUrlStyleBG, "rgba(0, 0, 0, 0)",
         "The expected style has been applied once extension url style has been unregistered");
   equal(unregisteredURLStylesResults.registeredExtensionBlobStyleBG, "rgb(0, 0, 255)",
         "The expected style has been applied from the registered extension blob style");
 
   extension.sendMessage("unregister-text");
   await extension.awaitMessage("unregister-text:done");
 
-  contentPage.loadURL(`${BASE_URL}/file_sample_registered_styles.html`);
+  await contentPage.loadURL(`${BASE_URL}/file_sample_registered_styles.html`);
 
   const unregisteredBlobStylesResults = await extension.awaitMessage("registered-styles-results");
 
   equal(unregisteredBlobStylesResults.registeredExtensionUrlStyleBG, "rgba(0, 0, 0, 0)",
         "The expected style has been applied once extension url style has been unregistered");
   equal(unregisteredBlobStylesResults.registeredExtensionBlobStyleBG, "rgba(0, 0, 0, 0)",
         "The expected style has been applied once extension blob style has been unregistered");
 
@@ -173,16 +173,18 @@ add_task(async function test_contentscri
   }
 
   async function background_frame() {
     await browser.contentScripts.register({
       css: [{file: "registered_ext_style.css"}],
       matches: ["http://localhost/*/file_sample_registered_styles.html"],
       runAt: "document_start",
     });
+
+    browser.test.sendMessage("background_frame_ready");
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: [
         "http://localhost/*/file_sample_registered_styles.html",
       ],
       content_scripts: [
@@ -214,16 +216,20 @@ add_task(async function test_contentscri
       `,
     },
   });
 
   await extension.startup();
 
   await extension.awaitMessage("background_ready");
 
+  // Wait the background frame to have been loaded and its script
+  // executed.
+  await extension.awaitMessage("background_frame_ready");
+
   // Ensure that a content page running in a content process and which has been
   // started after the content scripts has been registered, it still receives
   // and registers the expected content scripts.
   let contentPage = await ExtensionTestUtils.loadContentPage(`about:blank`);
 
   await contentPage.loadURL(`${BASE_URL}/file_sample_registered_styles.html`);
 
   const registeredStylesResults = await extension.awaitMessage("registered-styles-results");
@@ -389,17 +395,17 @@ add_task(async function test_contentscri
   // Ensure that a content page running in a content process and which has been
   // already loaded when the content scripts has been registered, it has received
   // and registered the expected content scripts.
   let contentPage = await ExtensionTestUtils.loadContentPage(`about:blank`);
 
   await extension.startup();
   await extension.awaitMessage("background-ready");
 
-  contentPage.loadURL(`${BASE_URL}/file_sample.html`);
+  await contentPage.loadURL(`${BASE_URL}/file_sample.html`);
 
   await Promise.all([completePromise, chromeNamespacePromise]);
 
   await contentPage.close();
 
   // Expect two content scripts to run (one registered using an extension URL
   // and one registered from plain JS code).
   equal(loadingCount, 2, "document_start script ran exactly twice");