Bug 1307015 - Remove CPOWs from browser_bug623893.js r=felipe draft
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 17 Feb 2017 15:32:00 -0800
changeset 486471 2b4868714ef405e1f179f0d3bfc395b1cecd5d72
parent 486470 d10241bb93ca8f3105e0b005dfc8dba1def8a0c3
child 546252 fa81daffa4f149ac4b8932cd6521ea430847b5af
push id45990
push userbmo:mrbkap@mozilla.com
push dateFri, 17 Feb 2017 23:36:54 +0000
reviewersfelipe
bugs1307015, 623893
milestone54.0a1
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);
+});