Bug 914403 - Part 2: Convert basic highlighter test to Task.jsm. r=paul, a=lsblakk
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 16 Sep 2013 19:26:51 -0500
changeset 160342 a72a845b6892e034c089df25d90430f2404847e7
parent 160341 b7c012b45bf6cb702c2e479a7806dd3ee246acf2
child 160343 6dedfabac6906f06e27deab9b0abb6465fedd455
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul, lsblakk
bugs914403
milestone26.0a2
Bug 914403 - Part 2: Convert basic highlighter test to Task.jsm. r=paul, a=lsblakk
browser/devtools/inspector/test/browser_inspector_basic_highlighter.js
--- a/browser/devtools/inspector/test/browser_inspector_basic_highlighter.js
+++ b/browser/devtools/inspector/test/browser_inspector_basic_highlighter.js
@@ -1,57 +1,79 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
-function test()
-{
+function test() {
   let inspector, doc;
   let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
   let {require} = devtools;
+  let promise = require("sdk/core/promise");
+  let { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
 
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onload() {
     gBrowser.selectedBrowser.removeEventListener("load", onload, true);
     doc = content.document;
     waitForFocus(setupTest, content);
   }, true);
 
   content.location = "data:text/html,<h1>foo<h1><h2>bar</h2>";
 
-  function setupTest()
-  {
+  function setupTest() {
     let h = require("devtools/inspector/highlighter");
     h._forceBasic.value = true;
     openInspector(runTests);
   }
 
-  function runTests(aInspector)
-  {
+  function runTests(aInspector) {
     inspector = aInspector;
-    let h1 = doc.querySelector("h1");
-    inspector.selection.once("new-node-front", () => executeSoon(testH1Selected));
-    inspector.selection.setNode(h1);
+
+    Task.spawn(function() {
+      yield selectH1();
+      yield verifyH1Selected();
+      yield deselect();
+      yield verifyNoNodeSelected();
+      finishUp();
+    }).then(null, Cu.reportError);
   }
 
-  function testH1Selected() {
+  function selectH1() {
+    let deferred = promise.defer();
+    let h1 = doc.querySelector("h1");
+    inspector.selection.once("new-node-front", () => {
+      executeSoon(deferred.resolve);
+    });
+    inspector.selection.setNode(h1);
+    return deferred.promise;
+  }
+
+  function verifyH1Selected() {
     let h1 = doc.querySelector("h1");
     let nodes = doc.querySelectorAll(":-moz-devtools-highlighted");
     is(nodes.length, 1, "only one node selected");
     is(nodes[0], h1, "h1 selected");
-    inspector.selection.once("new-node-front", () => executeSoon(testNoNodeSelected));
-    inspector.selection.setNode(null);
+    return promise.resolve();
   }
 
-  function testNoNodeSelected() {
+  function deselect() {
+    let deferred = promise.defer();
+    inspector.selection.once("new-node-front", () => {
+      executeSoon(deferred.resolve);
+    });
+    inspector.selection.setNode(null);
+    return deferred.promise;
+  }
+
+  function verifyNoNodeSelected() {
     ok(doc.querySelectorAll(":-moz-devtools-highlighted").length === 0, "no node selected");
-    finishUp();
+    return promise.resolve();
   }
 
   function finishUp() {
     let h = require("devtools/inspector/highlighter");
     h._forceBasic.value = false;
     gBrowser.removeCurrentTab();
     finish();
   }