Bug 1261714 - Fix dead CPOW intermittent on browser_toolbox_options_disable_js.js. r=jryans
authorNicolas Chevobbe <chevobbe.nicolas@gmail.com>
Tue, 05 Jul 2016 23:24:21 +0200
changeset 344023 ff46fbd4ef08f8cd2f95bf218d39b77be3bd3b24
parent 344022 c598237110de0bc8006571863529a81fceb6319b
child 344024 33a91e8bceb3c8de81749ff407fbf76934107b16
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1261714
milestone50.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 1261714 - Fix dead CPOW intermittent on browser_toolbox_options_disable_js.js. r=jryans MozReview-Commit-ID: G2De93K0Tgv
devtools/client/framework/test/browser_toolbox_options_disable_js.js
--- a/devtools/client/framework/test/browser_toolbox_options_disable_js.js
+++ b/devtools/client/framework/test/browser_toolbox_options_disable_js.js
@@ -2,108 +2,123 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Tests that disabling JavaScript for a tab works as it should.
 
 const TEST_URI = URL_ROOT + "browser_toolbox_options_disable_js.html";
 
-var doc;
-var toolbox;
-
 function test() {
   gBrowser.selectedTab = gBrowser.addTab();
   let target = TargetFactory.forTab(gBrowser.selectedTab);
 
   gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
     gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
-    doc = content.document;
     gDevTools.showToolbox(target).then(testSelectTool);
   }, true);
 
-  content.location = TEST_URI;
+  BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_URI);
 }
 
-function testSelectTool(aToolbox) {
-  toolbox = aToolbox;
-  toolbox.once("options-selected", testJSEnabled);
+function testSelectTool(toolbox) {
+  toolbox.once("options-selected", () => testToggleJS(toolbox));
   toolbox.selectTool("options");
 }
 
-function testJSEnabled(event, tool, secondPass) {
+let testToggleJS = Task.async(function* (toolbox) {
   ok(true, "Toolbox selected via selectTool method");
+
+  yield testJSEnabled();
+  yield testJSEnabledIframe();
+
+  // Disable JS.
+  yield toggleJS(toolbox);
+
+  yield testJSDisabled();
+  yield testJSDisabledIframe();
+
+  // Re-enable JS.
+  yield toggleJS(toolbox);
+
+  yield testJSEnabled();
+  yield testJSEnabledIframe();
+
+  finishUp(toolbox);
+});
+
+function* testJSEnabled() {
   info("Testing that JS is enabled");
 
-  // We use executeSoon here because switching docSehll.allowJavascript to true
+  // We use waitForTick here because switching docShell.allowJavascript to true
   // takes a while to become live.
-  executeSoon(function () {
+  yield waitForTick();
+
+  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
+    let doc = content.document;
     let output = doc.getElementById("output");
     doc.querySelector("#logJSEnabled").click();
     is(output.textContent, "JavaScript Enabled", 'Output is "JavaScript Enabled"');
-    testJSEnabledIframe(secondPass);
   });
 }
 
-function testJSEnabledIframe(secondPass) {
+function* testJSEnabledIframe() {
   info("Testing that JS is enabled in the iframe");
 
-  let iframe = doc.querySelector("iframe");
-  let iframeDoc = iframe.contentDocument;
-  let output = iframeDoc.getElementById("output");
-  iframeDoc.querySelector("#logJSEnabled").click();
-  is(output.textContent, "JavaScript Enabled",
-                          'Output is "JavaScript Enabled" in iframe');
-  if (secondPass) {
-    finishUp();
-  } else {
-    toggleJS().then(testJSDisabled);
-  }
+  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
+    let doc = content.document;
+    let iframe = doc.querySelector("iframe");
+    let iframeDoc = iframe.contentDocument;
+    let output = iframeDoc.getElementById("output");
+    iframeDoc.querySelector("#logJSEnabled").click();
+    is(output.textContent, "JavaScript Enabled",
+                            'Output is "JavaScript Enabled" in iframe');
+  });
 }
 
-let toggleJS = Task.async(function* () {
+function* toggleJS(toolbox) {
   let panel = toolbox.getCurrentPanel();
   let cbx = panel.panelDoc.getElementById("devtools-disable-javascript");
 
   if (cbx.checked) {
     info("Clearing checkbox to re-enable JS");
   } else {
     info("Checking checkbox to disable JS");
   }
 
   let browserLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
   cbx.click();
   yield browserLoaded;
-  doc = content.document;
-});
+}
 
-function testJSDisabled() {
+function* testJSDisabled() {
   info("Testing that JS is disabled");
 
-  let output = doc.getElementById("output");
-  doc.querySelector("#logJSDisabled").click();
-
-  ok(output.textContent !== "JavaScript Disabled",
-     'output is not "JavaScript Disabled"');
-  testJSDisabledIframe();
-}
+  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
+    let doc = content.document;
+    let output = doc.getElementById("output");
+    doc.querySelector("#logJSDisabled").click();
 
-function testJSDisabledIframe() {
-  info("Testing that JS is disabled in the iframe");
-
-  let iframe = doc.querySelector("iframe");
-  let iframeDoc = iframe.contentDocument;
-  let output = iframeDoc.getElementById("output");
-  iframeDoc.querySelector("#logJSDisabled").click();
-  ok(output.textContent !== "JavaScript Disabled",
-     'output is not "JavaScript Disabled" in iframe');
-  toggleJS().then(function () {
-    testJSEnabled(null, null, true);
+    ok(output.textContent !== "JavaScript Disabled",
+       'output is not "JavaScript Disabled"');
   });
 }
 
-function finishUp() {
+function* testJSDisabledIframe() {
+  info("Testing that JS is disabled in the iframe");
+
+  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
+    let doc = content.document;
+    let iframe = doc.querySelector("iframe");
+    let iframeDoc = iframe.contentDocument;
+    let output = iframeDoc.getElementById("output");
+    iframeDoc.querySelector("#logJSDisabled").click();
+    ok(output.textContent !== "JavaScript Disabled",
+       'output is not "JavaScript Disabled" in iframe');
+  });
+}
+
+function finishUp(toolbox) {
   toolbox.destroy().then(function () {
     gBrowser.removeCurrentTab();
-    toolbox = doc = null;
     finish();
   });
 }