Bug 1338493 - Part 1, make webReqeust test to fiddle the main event loop after loading CSS/JS. r=kmag
authorShih-Chiang Chien <schien@mozilla.com>
Mon, 22 May 2017 11:41:08 +0800
changeset 366774 e46c37ddd5ff13b8093913cbbba8e4fb0562d85a
parent 366773 ce2eee8297d12142308cdfa050184621faea8e65
child 366775 6ad9b54d57a9cc88fa808aec580d5ad45309870d
push id32108
push usercbook@mozilla.com
push dateFri, 30 Jun 2017 10:57:12 +0000
treeherdermozilla-central@a578ce873d80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1338493
milestone56.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 1338493 - Part 1, make webReqeust test to fiddle the main event loop after loading CSS/JS. r=kmag Making ODA completely off-main-thread will make the order webRequest.onCompleted and CSS/JS execution unpredictable. |window.requestIdleCallback| is used to fiddle the main thread event queue. MozReview-Commit-ID: LIk0T96K6p1
toolkit/components/extensions/test/mochitest/test_ext_webrequest_basic.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_basic.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_basic.html
@@ -7,16 +7,24 @@
   <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
   <script type="text/javascript" src="head_webrequest.js"></script>
   <script type="text/javascript" src="head.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 <script>
 "use strict";
 
+function spinEventLoop() {
+  return new Promise((resolve, reject) => {
+    window.requestIdleCallback(() => {
+      resolve();
+    });
+  });
+}
+
 if (AppConstants.platform === "android") {
   SimpleTest.requestLongerTimeout(3);
 }
 
 let extension;
 add_task(async function setup() {
   // Clear the image cache, since it gets in the way otherwise.
   let imgTools = SpecialPowers.Cc["@mozilla.org/image/tools;1"].getService(SpecialPowers.Ci.imgITools);
@@ -59,16 +67,18 @@ add_task(async function test_webRequest_
   extension.sendMessage("set-expected", {expect, origin: location.href});
   await extension.awaitMessage("continue");
   addStylesheet("file_style_bad.css");
   await extension.awaitMessage("cancelled");
   // we redirect to style_good which completes the test
   addStylesheet("file_style_redirect.css");
   await extension.awaitMessage("done");
 
+  // waiting for CSS applied.
+  await spinEventLoop();
   let style = window.getComputedStyle(document.getElementById("test"));
   is(style.getPropertyValue("color"), "rgb(255, 0, 0)", "Good CSS loaded");
 });
 
 add_task(async function test_webRequest_images() {
   let expect = {
     "file_image_bad.png": {
       type: "image",
@@ -114,16 +124,18 @@ add_task(async function test_webRequest_
   extension.sendMessage("set-expected", {expect, origin: location.href});
   await extension.awaitMessage("continue");
   addScript("file_script_bad.js");
   await extension.awaitMessage("cancelled");
   // we redirect to script_good which completes the test
   addScript("file_script_redirect.js");
   await extension.awaitMessage("done");
 
+  // wait for JS executed
+  await spinEventLoop();
   is(window.success, 1, "Good script ran");
   is(window.failure, undefined, "Failure script didn't run");
 });
 
 add_task(async function test_webRequest_xhr_get() {
   let expect = {
     "file_script_xhr.js": {
       type: "script",
@@ -175,16 +187,18 @@ add_task(async function test_webRequest_
   extension.sendMessage("set-expected", {expect, origin: location.href});
   await extension.awaitMessage("continue");
   addImage("file_image_good.png");
   addScript("file_script_good.js");
   addStylesheet("file_style_good.css");
   addScript("nonexistent_script_url.js");
   await extension.awaitMessage("done");
 
+  // wait for JS executed
+  await spinEventLoop();
   is(window.success, 2, "Good script ran");
   is(window.failure, undefined, "Failure script didn't run");
 });
 
 add_task(async function test_webRequest_headers() {
   let expect = {
     "file_script_nonexistent.js": {
       type: "script",