Bug 825427 - Intermittent browser_responsiveruleview.js. r=miker, a=test-only
authorPatrick Brosset <pbrosset@mozilla.com>
Fri, 18 Apr 2014 10:11:30 +0200
changeset 192978 e0d0e0a2085425cf7d00b73fb6848ba4ca4b211c
parent 192977 47a15ec03ea7658cc92cdd6cbd65c847fed9640e
child 192979 d040c6d4369ce40da3576261a209b0f52be79ee3
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker, test-only
bugs825427
milestone30.0a2
Bug 825427 - Intermittent browser_responsiveruleview.js. r=miker, a=test-only
browser/devtools/responsivedesign/test/browser_responsivecomputedview.js
browser/devtools/responsivedesign/test/browser_responsiveruleview.js
browser/devtools/responsivedesign/test/head.js
--- a/browser/devtools/responsivedesign/test/browser_responsivecomputedview.js
+++ b/browser/devtools/responsivedesign/test/browser_responsivecomputedview.js
@@ -10,17 +10,17 @@ function test() {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onload() {
     gBrowser.selectedBrowser.removeEventListener("load", onload, true);
     waitForFocus(startTest, content);
   }, true);
 
-  content.location = "data:text/html,<html><style>" +
+  content.location = "data:text/html;charset=utf-8,<html><style>" +
     "div {" +
     "  width: 500px;" +
     "  height: 10px;" +
     "  background: purple;" +
     "} " +
     "@media screen and (max-width: 200px) {" +
     "  div { " +
     "    width: 100px;" +
@@ -48,34 +48,31 @@ function test() {
 
     instance.stack.setAttribute("notransition", "true");
     registerCleanupFunction(function() {
       instance.stack.removeAttribute("notransition");
     });
 
     instance.setSize(500, 500);
 
-    openView("computedview", onInspectorUIOpen);
+    openComputedView().then(onInspectorUIOpen);
   }
 
-  function onInspectorUIOpen(aInspector, aComputedView) {
-    inspector = aInspector;
+  function onInspectorUIOpen(args) {
+    inspector = args.inspector;
+    computedView = args.view;
     ok(inspector, "Got inspector instance");
 
     let div = content.document.getElementsByTagName("div")[0];
 
     inspector.selection.setNode(div);
     inspector.once("inspector-updated", testShrink);
-
   }
 
   function testShrink() {
-    computedView = inspector.sidebar.getWindowForTab("computedview").computedview.view;
-    ok(computedView, "We have access to the Computed View object");
-
     is(computedWidth(), "500px", "Should show 500px initially.");
 
     inspector.once("computed-view-refreshed", function onShrink() {
       is(computedWidth(), "100px", "div should be 100px after shrinking.");
       testGrow();
     });
 
     instance.setSize(100, 100);
--- a/browser/devtools/responsivedesign/test/browser_responsiveruleview.js
+++ b/browser/devtools/responsivedesign/test/browser_responsiveruleview.js
@@ -11,17 +11,17 @@ function test() {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onload() {
     gBrowser.selectedBrowser.removeEventListener("load", onload, true);
     waitForFocus(startTest, content);
   }, true);
 
-  content.location = "data:text/html,<html><style>" +
+  content.location = "data:text/html;charset=utf-8,<html><style>" +
     "div {" +
     "  width: 500px;" +
     "  height: 10px;" +
     "  background: purple;" +
     "} " +
     "@media screen and (max-width: 200px) {" +
     "  div { " +
     "    width: 100px;" +
@@ -44,22 +44,22 @@ function test() {
 
     instance.stack.setAttribute("notransition", "true");
     registerCleanupFunction(function() {
       instance.stack.removeAttribute("notransition");
     });
 
     instance.setSize(500, 500);
 
-    openView("ruleview", onInspectorUIOpen);
+    openRuleView().then(onInspectorUIOpen);
   }
 
-  function onInspectorUIOpen(aInspector, aRuleView) {
-    inspector = aInspector;
-    ruleView = aRuleView;
+  function onInspectorUIOpen(args) {
+    inspector = args.inspector;
+    ruleView = args.view;
     ok(inspector, "Got inspector instance");
 
     let div = content.document.getElementsByTagName("div")[0];
     inspector.selection.setNode(div);
     inspector.once("inspector-updated", testShrink);
   }
 
   function testShrink() {
--- a/browser/devtools/responsivedesign/test/head.js
+++ b/browser/devtools/responsivedesign/test/head.js
@@ -10,32 +10,114 @@ let TargetFactory = devtools.TargetFacto
 let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
 Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this);
 
 gDevTools.testing = true;
 SimpleTest.registerCleanupFunction(() => {
   gDevTools.testing = false;
 });
 
-function openInspector(callback)
-{
+/**
+ * Open the toolbox, with the inspector tool visible.
+ * @return a promise that resolves when the inspector is ready
+ */
+let openInspector = Task.async(function*() {
+  info("Opening the inspector");
   let target = TargetFactory.forTab(gBrowser.selectedTab);
-  gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
-    callback(toolbox.getCurrentPanel());
-  });
+
+  let inspector, toolbox;
+
+  // Checking if the toolbox and the inspector are already loaded
+  // The inspector-updated event should only be waited for if the inspector
+  // isn't loaded yet
+  toolbox = gDevTools.getToolbox(target);
+  if (toolbox) {
+    inspector = toolbox.getPanel("inspector");
+    if (inspector) {
+      info("Toolbox and inspector already open");
+      return {
+        toolbox: toolbox,
+        inspector: inspector
+      };
+    }
+  }
+
+  info("Opening the toolbox");
+  toolbox = yield gDevTools.showToolbox(target, "inspector");
+  yield waitForToolboxFrameFocus(toolbox);
+  inspector = toolbox.getPanel("inspector");
+
+  info("Waiting for the inspector to update");
+  yield inspector.once("inspector-updated");
+
+  return {
+    toolbox: toolbox,
+    inspector: inspector
+  };
+});
+
+/**
+ * Wait for the toolbox frame to receive focus after it loads
+ * @param {Toolbox} toolbox
+ * @return a promise that resolves when focus has been received
+ */
+function waitForToolboxFrameFocus(toolbox) {
+  info("Making sure that the toolbox's frame is focused");
+  let def = promise.defer();
+  let win = toolbox.frame.contentWindow;
+  waitForFocus(def.resolve, win);
+  return def.promise;
 }
 
-function openView(name, callback)
-{
-  openInspector(inspector => {
-    function onReady() {
-      inspector.sidebar.select(name);
-      let { view } = inspector.sidebar.getWindowForTab(name)[name];
-      callback(inspector, view);
-    }
+/**
+ * Open the toolbox, with the inspector tool visible, and the sidebar that
+ * corresponds to the given id selected
+ * @return a promise that resolves when the inspector is ready and the sidebar
+ * view is visible and ready
+ */
+let openInspectorSideBar = Task.async(function*(id) {
+  let {toolbox, inspector} = yield openInspector();
+
+  if (!hasSideBarTab(inspector, id)) {
+    info("Waiting for the " + id + " sidebar to be ready");
+    yield inspector.sidebar.once(id + "-ready");
+  }
+
+  info("Selecting the " + id + " sidebar");
+  inspector.sidebar.select(id);
+
+  return {
+    toolbox: toolbox,
+    inspector: inspector,
+    view: inspector.sidebar.getWindowForTab(id)[id].view
+  };
+});
 
-    if (inspector.sidebar.getTab(name)) {
-      onReady();
-    } else {
-      inspector.sidebar.once(name + "-ready", onReady);
-    }
-  });
+/**
+ * Checks whether the inspector's sidebar corresponding to the given id already
+ * exists
+ * @param {InspectorPanel}
+ * @param {String}
+ * @return {Boolean}
+ */
+function hasSideBarTab(inspector, id) {
+  return !!inspector.sidebar.getWindowForTab(id);
 }
+
+/**
+ * Open the toolbox, with the inspector tool visible, and the computed-view
+ * sidebar tab selected.
+ * @return a promise that resolves when the inspector is ready and the computed
+ * view is visible and ready
+ */
+function openComputedView() {
+  return openInspectorSideBar("computedview");
+}
+
+/**
+ * Open the toolbox, with the inspector tool visible, and the rule-view
+ * sidebar tab selected.
+ * @return a promise that resolves when the inspector is ready and the rule
+ * view is visible and ready
+ */
+function openRuleView() {
+  return openInspectorSideBar("ruleview");
+}