Bug 1132566 - Make test e10s compatible: browser_privatebrowsing_placestitle.js; r=ttaubert
authorSteven MacLeod <smacleod@mozilla.com>
Wed, 11 Mar 2015 14:54:30 -0400
changeset 233787 9b7f81054f06293a23ed390060c1a787c439a94c
parent 233786 85840d8c32427d8e24db2a44b4ec732e37ad6f76
child 233788 dd371585e02896d7ae50e4a5ac3b36e0a2ba6fbf
push id11789
push usersmacleod@mozilla.com
push dateMon, 16 Mar 2015 15:39:34 +0000
treeherderfx-team@02ea96f256cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs1132566
milestone39.0a1
Bug 1132566 - Make test e10s compatible: browser_privatebrowsing_placestitle.js; r=ttaubert
browser/components/privatebrowsing/test/browser/browser.ini
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js
browser/components/privatebrowsing/test/browser/head.js
--- a/browser/components/privatebrowsing/test/browser/browser.ini
+++ b/browser/components/privatebrowsing/test/browser/browser.ini
@@ -34,17 +34,16 @@ skip-if = e10s # Bug 1139953 - Accept co
 [browser_privatebrowsing_lastpbcontextexited.js]
 [browser_privatebrowsing_localStorage.js]
 [browser_privatebrowsing_localStorage_before_after.js]
 [browser_privatebrowsing_noSessionRestoreMenuOption.js]
 [browser_privatebrowsing_nonbrowser.js]
 [browser_privatebrowsing_opendir.js]
 [browser_privatebrowsing_placesTitleNoUpdate.js]
 [browser_privatebrowsing_placestitle.js]
-skip-if = e10s
 [browser_privatebrowsing_popupblocker.js]
 skip-if = e10s
 [browser_privatebrowsing_protocolhandler.js]
 skip-if = e10s
 [browser_privatebrowsing_sidebar.js]
 skip-if = e10s
 [browser_privatebrowsing_theming.js]
 skip-if = e10s
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js
@@ -1,58 +1,50 @@
 /* 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/. */
 
 // This test makes sure that the title of existing history entries does not
 // change inside a private window.
 
-function test() {
-  waitForExplicitFinish();
-
+add_task(function* test() {
   const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
                    "privatebrowsing/test/browser/title.sjs";
-  let cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
+  let cm = Services.cookies;
 
-  function waitForCleanup(aCallback) {
+  function cleanup() {
     // delete all cookies
     cm.removeAll();
     // delete all history items
-    PlacesTestUtils.clearHistory().then(aCallback);
+    return PlacesTestUtils.clearHistory();
   }
 
+  yield cleanup();
+
+  let deferredFirst = PromiseUtils.defer();
+  let deferredSecond = PromiseUtils.defer();
+  let deferredThird = PromiseUtils.defer();
+
   let testNumber = 0;
   let historyObserver = {
     onTitleChanged: function(aURI, aPageTitle) {
       if (aURI.spec != TEST_URL)
         return;
       switch (++testNumber) {
         case 1:
           // The first time that the page is loaded
-          is(aPageTitle, "No Cookie",
-             "The page should be loaded without any cookie for the first time");
-          openTestPage(selectedWin);
+          deferredFirst.resolve(aPageTitle);
           break;
         case 2:
           // The second time that the page is loaded
-          is(aPageTitle, "Cookie",
-             "The page should be loaded with a cookie for the second time");
-          waitForCleanup(function () {
-            openTestPage(selectedWin);
-          });
+          deferredSecond.resolve(aPageTitle);
           break;
         case 3:
           // After clean up
-          is(aPageTitle, "No Cookie",
-             "The page should be loaded without any cookie again");
-          testOnWindow(true, function(win) {
-            whenPageLoad(win, function() {
-              waitForCleanup(finish);
-            });
-          });
+          deferredThird.resolve(aPageTitle);
           break;
         default:
           // Checks that opening the page in a private window should not fire a
           // title change.
           ok(false, "Title changed. Unexpected pass: " + testNumber);
       }
     },
 
@@ -62,43 +54,42 @@ function test() {
     onDeleteURI: function () {},
     onClearHistory: function () {},
     onPageChanged: function () {},
     onDeleteVisits: function() {},
     QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
   };
   PlacesUtils.history.addObserver(historyObserver, false);
 
-  let selectedWin = null;
-  let windowsToClose = [];
-  registerCleanupFunction(function() {
-    PlacesUtils.history.removeObserver(historyObserver);
-    windowsToClose.forEach(function(win) {
-      win.close();
-    });
-  });
+
+  let win = yield BrowserTestUtils.openNewBrowserWindow();
+  win.gBrowser.selectedTab = win.gBrowser.addTab(TEST_URL);
+  let aPageTitle = yield deferredFirst.promise;
+  // The first time that the page is loaded
+  is(aPageTitle, "No Cookie",
+     "The page should be loaded without any cookie for the first time");
 
-  function openTestPage(aWin) {
-    aWin.gBrowser.selectedTab = aWin.gBrowser.addTab(TEST_URL);
-  }
+  win.gBrowser.selectedTab = win.gBrowser.addTab(TEST_URL);
+  aPageTitle = yield deferredSecond.promise;
+  // The second time that the page is loaded
+  is(aPageTitle, "Cookie",
+     "The page should be loaded with a cookie for the second time");
+
+  yield cleanup();
 
-  function whenPageLoad(aWin, aCallback) {
-    aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
-      aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
-      aCallback();
-    }, true);
-    aWin.gBrowser.selectedBrowser.loadURI(TEST_URL);
-  }
+  win.gBrowser.selectedTab = win.gBrowser.addTab(TEST_URL);
+  aPageTitle = yield deferredThird.promise;
+  // After clean up
+  is(aPageTitle, "No Cookie",
+     "The page should be loaded without any cookie again");
+
+  let win2 = yield BrowserTestUtils.openNewBrowserWindow({private: true});
 
-  function testOnWindow(aPrivate, aCallback) {
-    whenNewWindowLoaded({ private: aPrivate }, function(win) {
-      selectedWin = win;
-      windowsToClose.push(win);
-      executeSoon(function() { aCallback(win) });
-    });
-  }
+  let private_tab = win2.gBrowser.addTab(TEST_URL);
+  win2.gBrowser.selectedTab = private_tab;
+  yield BrowserTestUtils.browserLoaded(private_tab.linkedBrowser);
 
-  waitForCleanup(function() {
-    testOnWindow(false, function(win) {
-      openTestPage(win);
-    });
-  });
-}
+  // Cleanup
+  yield cleanup();
+  PlacesUtils.history.removeObserver(historyObserver);
+  yield BrowserTestUtils.closeWindow(win);
+  yield BrowserTestUtils.closeWindow(win2);
+});
--- a/browser/components/privatebrowsing/test/browser/head.js
+++ b/browser/components/privatebrowsing/test/browser/head.js
@@ -1,11 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+let {PromiseUtils} = Cu.import("resource://gre/modules/PromiseUtils.jsm", {});
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
   "resource://testing-common/PlacesTestUtils.jsm");
 
 function whenNewWindowLoaded(aOptions, aCallback) {
   let win = OpenBrowserWindow(aOptions);
   let gotLoad = false;
   let gotActivate = Services.focus.activeWindow == win;