Bug 1307015 - Remove CPOWs from browser_bug623893.js r=felipe
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 17 Feb 2017 15:32:00 -0800
changeset 344039 1b501700e807b502c4d04e842a881c42c85eb8ef
parent 344038 fbd5216f6a4979679dfab4f415fc86777dd88b01
child 344040 f52fb0ffd8806d7d4b2e637b2d3f06668082beba
push id87273
push usermrbkap@mozilla.com
push dateTue, 21 Feb 2017 22:51:15 +0000
treeherdermozilla-inbound@1b501700e807 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1307015, 623893
milestone54.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 1307015 - Remove CPOWs from browser_bug623893.js r=felipe 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,45 +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() {
-    is(gBrowser.sessionHistory.index, start + delta, msg);
-    executeSoon(cb);
-  }, {once: true});
-}
+  yield BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
 
-function loadAndWait(url, cb) {
-  gBrowser.selectedBrowser.addEventListener("load", function() {
-    executeSoon(cb);
-  }, {capture: true, once: true});
-
-  gBrowser.loadURI(url);
-}
+  let endIndex = yield promiseGetIndex(gBrowser.selectedBrowser);
+  is(endIndex, startIndex + delta, msg);
+});