From 073ddfc9019bf00582665ee8b7fef0f9008be48e Mon Sep 17 00:00:00 2001 From: Steven MacLeod Date: Thu, 5 Mar 2015 16:02:58 -0500 Subject: [PATCH] Bug 1132566 - Make test e10s compatible: browser_privatebrowsing_placesTitleNoUpdate.js; r=ttaubert --HG-- extra : rebase_source : ecc10e11362e28dd7a2498141f46e9bc072b4a0a --- .../privatebrowsing/test/browser/browser.ini | 1 - ...ser_privatebrowsing_placesTitleNoUpdate.js | 137 +++++++----------- 2 files changed, 49 insertions(+), 89 deletions(-) diff --git a/browser/components/privatebrowsing/test/browser/browser.ini b/browser/components/privatebrowsing/test/browser/browser.ini index 61be4f93c8f3..6249827c8adb 100644 --- a/browser/components/privatebrowsing/test/browser/browser.ini +++ b/browser/components/privatebrowsing/test/browser/browser.ini @@ -38,7 +38,6 @@ skip-if = e10s # Bug 1139953 - Accept cookie dialog shown in private window when [browser_privatebrowsing_nonbrowser.js] [browser_privatebrowsing_opendir.js] [browser_privatebrowsing_placesTitleNoUpdate.js] -skip-if = e10s [browser_privatebrowsing_placestitle.js] skip-if = e10s [browser_privatebrowsing_popupblocker.js] diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js index 250b2e67160f..97c5c5ffcd9a 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js @@ -4,108 +4,69 @@ // Test to make sure that the visited page titles do not get updated inside the // private browsing mode. +"use strict"; Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/PlacesUtils.jsm"); -function test() { - waitForExplicitFinish(); +add_task(function* test() { const TEST_URL = "http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.html" const TEST_URI = Services.io.newURI(TEST_URL, null, null); const TITLE_1 = "Title 1"; const TITLE_2 = "Title 2"; - let selectedWin = null; - let windowsToClose = []; - let tabToClose = null; - let testNumber = 0; - let historyObserver; + function waitForTitleChanged() { + return new Promise(resolve => { + let historyObserver = { + onTitleChanged: function(uri, pageTitle) { + PlacesUtils.history.removeObserver(historyObserver, false); + resolve({uri: uri, pageTitle: pageTitle}); + }, + onBeginUpdateBatch: function () {}, + onEndUpdateBatch: function () {}, + onVisit: function () {}, + onDeleteURI: function () {}, + onClearHistory: function () {}, + onPageChanged: function () {}, + onDeleteVisits: function() {}, + QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) + }; - - registerCleanupFunction(function() { - PlacesUtils.history.removeObserver(historyObserver, false); - windowsToClose.forEach(function(aWin) { - aWin.close(); + PlacesUtils.history.addObserver(historyObserver, false); }); - gBrowser.removeTab(tabToClose); + }; + + yield PlacesTestUtils.clearHistory(); + + let tabToClose = gBrowser.selectedTab = gBrowser.addTab(TEST_URL); + yield waitForTitleChanged(); + is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1, "The title matches the orignal title after first visit"); + + let place = { + uri: TEST_URI, + title: TITLE_2, + visits: [{ + visitDate: Date.now() * 1000, + transitionType: Ci.nsINavHistoryService.TRANSITION_LINK + }] + }; + PlacesUtils.asyncHistory.updatePlaces(place, { + handleError: function () ok(false, "Unexpected error in adding visit."), + handleResult: function () { }, + handleCompletion: function () {} }); + yield waitForTitleChanged(); + is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title matches the updated title after updating visit"); - PlacesTestUtils.clearHistory().then(() => { - historyObserver = { - onTitleChanged: function(aURI, aPageTitle) { - switch (++testNumber) { - case 1: - afterFirstVisit(); - break; - case 2: - afterUpdateVisit(); - break; - } - }, - onBeginUpdateBatch: function () {}, - onEndUpdateBatch: function () {}, - onVisit: function () {}, - onDeleteURI: function () {}, - onClearHistory: function () {}, - onPageChanged: function () {}, - onDeleteVisits: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) - }; - PlacesUtils.history.addObserver(historyObserver, false); + let privateWin = yield BrowserTestUtils.openNewBrowserWindow({private:true}); + yield BrowserTestUtils.browserLoaded(privateWin.gBrowser.addTab(TEST_URL).linkedBrowser); - tabToClose = gBrowser.addTab(); - gBrowser.selectedTab = tabToClose; - whenPageLoad(window, function() {}); - }); + is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title remains the same after visiting in private window"); + yield PlacesTestUtils.clearHistory(); - function afterFirstVisit() { - is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1, "The title matches the orignal title after first visit"); - - let place = { - uri: TEST_URI, - title: TITLE_2, - visits: [{ - visitDate: Date.now() * 1000, - transitionType: Ci.nsINavHistoryService.TRANSITION_LINK - }] - }; - PlacesUtils.asyncHistory.updatePlaces(place, { - handleError: function () do_throw("Unexpected error in adding visit."), - handleResult: function () { }, - handleCompletion: function () {} - }); - } - - function afterUpdateVisit() { - is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title matches the updated title after updating visit"); - - testOnWindow(true, function(aWin) { - whenPageLoad(aWin, function() { - executeSoon(afterFirstVisitInPrivateWindow); - }); - }); - } - - function afterFirstVisitInPrivateWindow() { - is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title remains the same after visiting in private window"); - PlacesTestUtils.clearHistory().then(finish); - } - - 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); - } - - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({ private: aPrivate }, function(aWin) { - selectedWin = aWin; - windowsToClose.push(aWin); - executeSoon(function() { aCallback(aWin) }); - }); - } -} + // Cleanup + BrowserTestUtils.closeWindow(privateWin); + gBrowser.removeTab(tabToClose); +});