Bug 1307015 - Remove CPOWs from browser_bug623893.js. r=felipe, a=test-only
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 17 Feb 2017 15:32:00 -0800
changeset 376363 bfb5c94e40150a801c78b395201d39baa08576bd
parent 376362 05cb73582bb6488a3aa6ddd809ccd265cd7d993d
child 376364 06b5866b0bd8c7023479c9ea031713c3df5aa7aa
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, test-only
bugs1307015, 623893
milestone53.0a2
Bug 1307015 - Remove CPOWs from browser_bug623893.js. r=felipe, a=test-only It took me a little bit to understand what the test was doing. It was actually using the default tab to navigate to three pages. Then, it duplicated it immediatedly closed that tab. Finally, it duplicated the original tab, then duplicated the duplicate before closing both of those tabs. MozReview-Commit-ID: 85eY3FhZniA
browser/base/content/test/general/browser_bug623893.js
--- a/browser/base/content/test/general/browser_bug623893.js
+++ b/browser/base/content/test/general/browser_bug623893.js
@@ -1,47 +1,37 @@
-function test() {
-  waitForExplicitFinish();
+add_task(function* test() {
+  yield BrowserTestUtils.withNewTab("data:text/plain;charset=utf-8,1", function* (browser) {
+    BrowserTestUtils.loadURI(browser, "data:text/plain;charset=utf-8,2");
+    yield BrowserTestUtils.browserLoaded(browser);
+
+    BrowserTestUtils.loadURI(browser, "data:text/plain;charset=utf-8,3");
+    yield BrowserTestUtils.browserLoaded(browser);
+
+    yield duplicate(0, "maintained the original index");
+    yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 
-  loadAndWait("data:text/plain,1", function() {
-    loadAndWait("data:text/plain,2", function() {
-      loadAndWait("data:text/plain,3", runTests);
-    });
+    yield duplicate(-1, "went back");
+    yield duplicate(1, "went forward");
+    yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+    yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+  });
+});
+
+function promiseGetIndex(browser) {
+  return ContentTask.spawn(browser, null, function() {
+    let shistory = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                           .getInterface(Ci.nsISHistory);
+    return shistory.index;
   });
 }
 
-function runTests() {
-  duplicate(0, "maintained the original index", function() {
-    gBrowser.removeCurrentTab();
-
-    duplicate(-1, "went back", function() {
-      duplicate(1, "went forward", function() {
-        gBrowser.removeCurrentTab();
-        gBrowser.removeCurrentTab();
-        gBrowser.addTab();
-        gBrowser.removeCurrentTab();
-        finish();
-      });
-    });
-  });
-}
-
-function duplicate(delta, msg, cb) {
-  var start = gBrowser.sessionHistory.index;
+let duplicate = Task.async(function* (delta, msg, cb) {
+  var startIndex = yield promiseGetIndex(gBrowser.selectedBrowser);
 
   duplicateTabIn(gBrowser.selectedTab, "tab", delta);
+
   let tab = gBrowser.selectedTab;
-
-  tab.addEventListener("SSTabRestored", function tabRestoredListener() {
-    tab.removeEventListener("SSTabRestored", tabRestoredListener);
-    is(gBrowser.sessionHistory.index, start + delta, msg);
-    executeSoon(cb);
-  });
-}
+  yield BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
 
-function loadAndWait(url, cb) {
-  gBrowser.selectedBrowser.addEventListener("load", function() {
-    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
-    executeSoon(cb);
-  }, true);
-
-  gBrowser.loadURI(url);
-}
+  let endIndex = yield promiseGetIndex(gBrowser.selectedBrowser);
+  is(endIndex, startIndex + delta, msg);
+});