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 367227 60618c6f74d22b886b776403876e7acb6e42aeab
parent 367226 c8cefb50d5a80b546777cc712d4de17ca92154f3
child 367228 9170cc2ab18df31eaf7fffc5b6b5a26ebcbb4ec3
push id6960
push userryanvm@gmail.com
push dateWed, 22 Feb 2017 17:16:59 +0000
treeherdermozilla-beta@10bce9625147 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, test-only
bugs1307015, 623893
milestone52.0
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, false);
-    is(gBrowser.sessionHistory.index, start + delta, msg);
-    executeSoon(cb);
-  }, false);
-}
+  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);
+});