Bug 1070250 - Split browser_toolbox_options_disable_cache.js into two separate tests to avoid timeouts. r=miker
authorSami Jaktholm <sjakthol@outlook.com>
Tue, 30 Dec 2014 19:25:21 +0200
changeset 248784 8455c5f7dbb17db8a00ff61a0d758f9da6037814
parent 248783 16061a0b13e2ad5b9f21c237e53e215467516b26
child 248785 866d1d62ea5cb503e6dc4625bd00e29ed1c01b0d
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker
bugs1070250
milestone37.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 1070250 - Split browser_toolbox_options_disable_cache.js into two separate tests to avoid timeouts. r=miker
browser/devtools/framework/test/browser.ini
browser/devtools/framework/test/browser_toolbox_options_disable_cache-01.js
browser/devtools/framework/test/browser_toolbox_options_disable_cache-02.js
browser/devtools/framework/test/browser_toolbox_options_disable_cache.js
browser/devtools/framework/test/head.js
browser/devtools/framework/test/helper_disable_cache.js
--- a/browser/devtools/framework/test/browser.ini
+++ b/browser/devtools/framework/test/browser.ini
@@ -1,15 +1,16 @@
 [DEFAULT]
 subsuite = devtools
 support-files =
   browser_toolbox_options_disable_js.html
   browser_toolbox_options_disable_js_iframe.html
   browser_toolbox_options_disable_cache.sjs
   head.js
+  helper_disable_cache.js
   doc_theme.css
 
 [browser_devtools_api.js]
 skip-if = e10s # Bug 1090340
 [browser_devtools_api_destroy.js]
 skip-if = e10s # Bug 1070837 - devtools/framework/toolbox.js |doc| getter not e10s friendly
 [browser_dynamic_tool_enabling.js]
 [browser_keybindings.js]
@@ -20,17 +21,19 @@ skip-if = e10s # Bug 1070837 - devtools/
 [browser_two_tabs.js]
 [browser_toolbox_dynamic_registration.js]
 [browser_toolbox_getpanelwhenready.js]
 [browser_toolbox_highlight.js]
 [browser_toolbox_hosts.js]
 [browser_toolbox_options.js]
 [browser_toolbox_options_devedition.js]
 [browser_toolbox_options_disable_buttons.js]
-[browser_toolbox_options_disable_cache.js]
+[browser_toolbox_options_disable_cache-01.js]
+skip-if = e10s # Bug 1030318
+[browser_toolbox_options_disable_cache-02.js]
 skip-if = e10s # Bug 1030318
 [browser_toolbox_options_disable_js.js]
 skip-if = e10s # Bug 1070837 - devtools/framework/toolbox.js |doc| getter not e10s friendly
 # [browser_toolbox_raise.js] # Bug 962258
 # skip-if = os == "win"
 [browser_toolbox_ready.js]
 [browser_toolbox_select_event.js]
 skip-if = e10s # Bug 1069044 - destroyInspector may hang during shutdown
rename from browser/devtools/framework/test/browser_toolbox_options_disable_cache.js
rename to browser/devtools/framework/test/browser_toolbox_options_disable_cache-01.js
--- a/browser/devtools/framework/test/browser_toolbox_options_disable_cache.js
+++ b/browser/devtools/framework/test/browser_toolbox_options_disable_cache-01.js
@@ -1,162 +1,30 @@
+/* vim: set 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 the cache for a tab works as it should.
+"use strict";
 
-const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" +
-                 "test/browser_toolbox_options_disable_cache.sjs";
-let tabs = [
-{
-  title: "Tab 0",
-  desc: "Toggles cache on.",
-  startToolbox: true
-},
-{
-  title: "Tab 1",
-  desc: "Toolbox open before Tab 1 toggles cache.",
-  startToolbox: true
-},
-{
-  title: "Tab 2",
-  desc: "Opens toolbox after Tab 1 has toggled cache. Also closes and opens.",
-  startToolbox: false
-},
-{
-  title: "Tab 3",
-  desc: "No toolbox",
-  startToolbox: false
-}];
+// Tests that disabling the cache for a tab works as it should when toolboxes
+// are not toggled.
+loadHelperScript("helper_disable_cache.js");
 
 add_task(function*() {
+  // Ensure that the setting is cleared after the test.
+  registerCleanupFunction(() => {
+    info("Resetting devtools.cache.disabled to false.");
+    Services.prefs.setBoolPref("devtools.cache.disabled", false);
+  });
+
   // Initialise tabs: 1 and 2 with a toolbox, 3 and 4 without.
   for (let tab of tabs) {
     yield initTab(tab, tab.startToolbox);
   }
 
   // Ensure cache is enabled for all tabs.
   yield checkCacheStateForAllTabs([true, true, true, true]);
 
   // Check the checkbox in tab 0 and ensure cache is disabled for tabs 0 and 1.
   yield setDisableCacheCheckboxChecked(tabs[0], true);
   yield checkCacheStateForAllTabs([false, false, true, true]);
 
-  // Open toolbox in tab 2 and ensure the cache is then disabled.
-  tabs[2].toolbox = yield gDevTools.showToolbox(tabs[2].target, "options");
-  yield checkCacheEnabled(tabs[2], false);
-
-  // Close toolbox in tab 2 and ensure the cache is enabled again
-  yield tabs[2].toolbox.destroy();
-  tabs[2].target = TargetFactory.forTab(tabs[2].tab);
-  yield checkCacheEnabled(tabs[2], true);
-
-  // Open toolbox in tab 2 and ensure the cache is then disabled.
-  tabs[2].toolbox = yield gDevTools.showToolbox(tabs[2].target, "options");
-  yield checkCacheEnabled(tabs[2], false);
-
-  // Check the checkbox in tab 2 and ensure cache is enabled for all tabs.
-  yield setDisableCacheCheckboxChecked(tabs[2], false);
-  yield checkCacheStateForAllTabs([true, true, true, true]);
-
   yield finishUp();
 });
-
-function* initTab(tabX, startToolbox) {
-  tabX.tab = yield addTab(TEST_URI);
-  tabX.target = TargetFactory.forTab(tabX.tab);
-
-  if (startToolbox) {
-    tabX.toolbox = yield gDevTools.showToolbox(tabX.target, "options");
-  }
-}
-
-function* checkCacheStateForAllTabs(states) {
-  for (let i = 0; i < tabs.length; i ++) {
-    let tab = tabs[i];
-    yield checkCacheEnabled(tab, states[i]);
-  }
-}
-
-function* checkCacheEnabled(tabX, expected) {
-  gBrowser.selectedTab = tabX.tab;
-
-  yield reloadTab(tabX);
-
-  let doc = content.document;
-  let h1 = doc.querySelector("h1");
-  let oldGuid = h1.textContent;
-
-  yield reloadTab(tabX);
-
-  doc = content.document;
-  h1 = doc.querySelector("h1");
-  let guid = h1.textContent;
-
-  if (expected) {
-    is(guid, oldGuid, tabX.title + " cache is enabled");
-  } else {
-    isnot(guid, oldGuid, tabX.title + " cache is not enabled");
-  }
-}
-
-function* setDisableCacheCheckboxChecked(tabX, state) {
-  gBrowser.selectedTab = tabX.tab;
-
-  let panel = tabX.toolbox.getCurrentPanel();
-  let cbx = panel.panelDoc.getElementById("devtools-disable-cache");
-
-  cbx.scrollIntoView();
-
-  // After uising scrollIntoView() we need to wait for the browser to scroll.
-  yield waitForTick();
-
-  if (cbx.checked !== state) {
-    info("Setting disable cache checkbox to " + state + " for " + tabX.title);
-    EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin);
-
-    // We need to wait for all checkboxes to be updated and the docshells to
-    // apply the new cache settings.
-    yield waitForTick();
-  }
-}
-
-function reloadTab(tabX) {
-  let def = promise.defer();
-  let browser = gBrowser.selectedBrowser;
-
-  // once() doesn't work here so we use a standard handler instead.
-  browser.addEventListener("load", function onLoad() {
-    browser.removeEventListener("load", onLoad, true);
-    info("Reloaded tab " + tabX.title);
-    def.resolve();
-  }, true);
-
-  info("Reloading tab " + tabX.title);
-  let mm = getFrameScript();
-  mm.sendAsyncMessage("devtools:test:reload");
-
-  return def.promise;
-}
-
-function* destroyTab(tabX) {
-  let toolbox = gDevTools.getToolbox(tabX.target);
-
-  let onceDestroyed = promise.resolve();
-  if (toolbox) {
-    onceDestroyed = gDevTools.once("toolbox-destroyed");
-  }
-
-  info("Removing tab " + tabX.title);
-  gBrowser.removeTab(tabX.tab);
-  info("Removed tab " + tabX.title);
-
-  info("Waiting for toolbox-destroyed");
-  yield onceDestroyed;
-}
-
-function* finishUp() {
-  for (let tab of tabs) {
-    yield destroyTab(tab);
-  }
-
-  tabs = null;
-}
new file mode 100644
--- /dev/null
+++ b/browser/devtools/framework/test/browser_toolbox_options_disable_cache-02.js
@@ -0,0 +1,43 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Tests that disabling the cache for a tab works as it should when toolboxes
+// are toggled.
+loadHelperScript("helper_disable_cache.js");
+
+add_task(function*() {
+  // Ensure that the setting is cleared after the test.
+  registerCleanupFunction(() => {
+    info("Resetting devtools.cache.disabled to false.");
+    Services.prefs.setBoolPref("devtools.cache.disabled", false);
+  });
+
+  // Initialise tabs: 1 and 2 with a toolbox, 3 and 4 without.
+  for (let tab of tabs) {
+    yield initTab(tab, tab.startToolbox);
+  }
+
+  // Disable cache in tab 0
+  yield setDisableCacheCheckboxChecked(tabs[0], true);
+
+  // Open toolbox in tab 2 and ensure the cache is then disabled.
+  tabs[2].toolbox = yield gDevTools.showToolbox(tabs[2].target, "options");
+  yield checkCacheEnabled(tabs[2], false);
+
+  // Close toolbox in tab 2 and ensure the cache is enabled again
+  yield tabs[2].toolbox.destroy();
+  tabs[2].target = TargetFactory.forTab(tabs[2].tab);
+  yield checkCacheEnabled(tabs[2], true);
+
+  // Open toolbox in tab 2 and ensure the cache is then disabled.
+  tabs[2].toolbox = yield gDevTools.showToolbox(tabs[2].target, "options");
+  yield checkCacheEnabled(tabs[2], false);
+
+  // Check the checkbox in tab 2 and ensure cache is enabled for all tabs.
+  yield setDisableCacheCheckboxChecked(tabs[2], false);
+  yield checkCacheStateForAllTabs([true, true, true, true]);
+
+  yield finishUp();
+});
--- a/browser/devtools/framework/test/head.js
+++ b/browser/devtools/framework/test/head.js
@@ -110,16 +110,32 @@ function once(target, eventName, useCapt
       }, useCapture);
       break;
     }
   }
 
   return deferred.promise;
 }
 
+/**
+ * Some tests may need to import one or more of the test helper scripts.
+ * A test helper script is simply a js file that contains common test code that
+ * is either not common-enough to be in head.js, or that is located in a separate
+ * directory.
+ * The script will be loaded synchronously and in the test's scope.
+ * @param {String} filePath The file path, relative to the current directory.
+ *                 Examples:
+ *                 - "helper_attributes_test_runner.js"
+ *                 - "../../../commandline/test/helpers.js"
+ */
+function loadHelperScript(filePath) {
+  let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
+  Services.scriptloader.loadSubScript(testDir + "/" + filePath, this);
+}
+
 function waitForTick() {
   let deferred = promise.defer();
   executeSoon(deferred.resolve);
   return deferred.promise;
 }
 
 function toggleAllTools(state) {
   for (let [, tool] of gDevTools._tools) {
new file mode 100644
--- /dev/null
+++ b/browser/devtools/framework/test/helper_disable_cache.js
@@ -0,0 +1,130 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Common code shared by browser_toolbox_options_disable_cache-*.js
+const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" +
+                 "test/browser_toolbox_options_disable_cache.sjs";
+let tabs = [
+{
+  title: "Tab 0",
+  desc: "Toggles cache on.",
+  startToolbox: true
+},
+{
+  title: "Tab 1",
+  desc: "Toolbox open before Tab 1 toggles cache.",
+  startToolbox: true
+},
+{
+  title: "Tab 2",
+  desc: "Opens toolbox after Tab 1 has toggled cache. Also closes and opens.",
+  startToolbox: false
+},
+{
+  title: "Tab 3",
+  desc: "No toolbox",
+  startToolbox: false
+}];
+
+function* initTab(tabX, startToolbox) {
+  tabX.tab = yield addTab(TEST_URI);
+  tabX.target = TargetFactory.forTab(tabX.tab);
+
+  if (startToolbox) {
+    tabX.toolbox = yield gDevTools.showToolbox(tabX.target, "options");
+  }
+}
+
+function* checkCacheStateForAllTabs(states) {
+  for (let i = 0; i < tabs.length; i ++) {
+    let tab = tabs[i];
+    yield checkCacheEnabled(tab, states[i]);
+  }
+}
+
+function* checkCacheEnabled(tabX, expected) {
+  gBrowser.selectedTab = tabX.tab;
+
+  yield reloadTab(tabX);
+
+  let doc = content.document;
+  let h1 = doc.querySelector("h1");
+  let oldGuid = h1.textContent;
+
+  yield reloadTab(tabX);
+
+  doc = content.document;
+  h1 = doc.querySelector("h1");
+  let guid = h1.textContent;
+
+  if (expected) {
+    is(guid, oldGuid, tabX.title + " cache is enabled");
+  } else {
+    isnot(guid, oldGuid, tabX.title + " cache is not enabled");
+  }
+}
+
+function* setDisableCacheCheckboxChecked(tabX, state) {
+  gBrowser.selectedTab = tabX.tab;
+
+  let panel = tabX.toolbox.getCurrentPanel();
+  let cbx = panel.panelDoc.getElementById("devtools-disable-cache");
+
+  cbx.scrollIntoView();
+
+  // After uising scrollIntoView() we need to wait for the browser to scroll.
+  yield waitForTick();
+
+  if (cbx.checked !== state) {
+    info("Setting disable cache checkbox to " + state + " for " + tabX.title);
+    EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin);
+
+    // We need to wait for all checkboxes to be updated and the docshells to
+    // apply the new cache settings.
+    yield waitForTick();
+  }
+}
+
+function reloadTab(tabX) {
+  let def = promise.defer();
+  let browser = gBrowser.selectedBrowser;
+
+  // once() doesn't work here so we use a standard handler instead.
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    info("Reloaded tab " + tabX.title);
+    def.resolve();
+  }, true);
+
+  info("Reloading tab " + tabX.title);
+  let mm = getFrameScript();
+  mm.sendAsyncMessage("devtools:test:reload");
+
+  return def.promise;
+}
+
+function* destroyTab(tabX) {
+  let toolbox = gDevTools.getToolbox(tabX.target);
+
+  let onceDestroyed = promise.resolve();
+  if (toolbox) {
+    onceDestroyed = gDevTools.once("toolbox-destroyed");
+  }
+
+  info("Removing tab " + tabX.title);
+  gBrowser.removeTab(tabX.tab);
+  info("Removed tab " + tabX.title);
+
+  info("Waiting for toolbox-destroyed");
+  yield onceDestroyed;
+}
+
+function* finishUp() {
+  for (let tab of tabs) {
+    yield destroyTab(tab);
+  }
+
+  tabs = null;
+}