Bug 1132566 - Make test e10s compatible: browser_privatebrowsing_placesTitleNoUpdate.js; r=ttaubert

--HG--
extra : rebase_source : ecc10e11362e28dd7a2498141f46e9bc072b4a0a
This commit is contained in:
Steven MacLeod 2015-03-05 16:02:58 -05:00
Родитель 3eab0e024f
Коммит 073ddfc901
2 изменённых файлов: 49 добавлений и 89 удалений

Просмотреть файл

@ -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]

Просмотреть файл

@ -4,44 +4,23 @@
// 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;
registerCleanupFunction(function() {
function waitForTitleChanged() {
return new Promise(resolve => {
let historyObserver = {
onTitleChanged: function(uri, pageTitle) {
PlacesUtils.history.removeObserver(historyObserver, false);
windowsToClose.forEach(function(aWin) {
aWin.close();
});
gBrowser.removeTab(tabToClose);
});
PlacesTestUtils.clearHistory().then(() => {
historyObserver = {
onTitleChanged: function(aURI, aPageTitle) {
switch (++testNumber) {
case 1:
afterFirstVisit();
break;
case 2:
afterUpdateVisit();
break;
}
resolve({uri: uri, pageTitle: pageTitle});
},
onBeginUpdateBatch: function () {},
onEndUpdateBatch: function () {},
@ -52,14 +31,15 @@ function test() {
onDeleteVisits: function() {},
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
};
PlacesUtils.history.addObserver(historyObserver, false);
tabToClose = gBrowser.addTab();
gBrowser.selectedTab = tabToClose;
whenPageLoad(window, function() {});
});
};
function afterFirstVisit() {
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 = {
@ -71,41 +51,22 @@ function test() {
}]
};
PlacesUtils.asyncHistory.updatePlaces(place, {
handleError: function () do_throw("Unexpected error in adding visit."),
handleError: function () ok(false, "Unexpected error in adding visit."),
handleResult: function () { },
handleCompletion: function () {}
});
}
function afterUpdateVisit() {
yield waitForTitleChanged();
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);
});
});
}
let privateWin = yield BrowserTestUtils.openNewBrowserWindow({private:true});
yield BrowserTestUtils.browserLoaded(privateWin.gBrowser.addTab(TEST_URL).linkedBrowser);
function afterFirstVisitInPrivateWindow() {
is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title remains the same after visiting in private window");
PlacesTestUtils.clearHistory().then(finish);
}
yield PlacesTestUtils.clearHistory();
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);
});