Bug 1243928 - Make these tests work in e10s. r=felipe

This commit is contained in:
Blake Kaplan 2016-02-02 13:44:11 -08:00
Родитель 6dbe3327a3
Коммит 31fb709fc3
6 изменённых файлов: 161 добавлений и 192 удалений

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

@ -42,9 +42,6 @@ tags = trackingprotection
[browser_privatebrowsing_ui.js]
[browser_privatebrowsing_urlbarfocus.js]
[browser_privatebrowsing_windowtitle.js]
skip-if = e10s
[browser_privatebrowsing_zoom.js]
skip-if = e10s
[browser_privatebrowsing_zoomrestore.js]
skip-if = e10s
[browser_privatebrowsing_newtab_from_popup.js]

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

@ -5,10 +5,9 @@
// This test makes sure that the window title changes correctly while switching
// from and to private browsing mode.
function test() {
add_task(function test() {
const testPageURL = "http://mochi.test:8888/browser/" +
"browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle_page.html";
waitForExplicitFinish();
requestLongerTimeout(2);
// initialization of expected titles
@ -38,69 +37,41 @@ function test() {
pb_about_pb_title = "You're browsing privately - " + app_name + " (Private Browsing)";
}
function testTabTitle(aWindow, url, insidePB, expected_title, funcNext) {
executeSoon(function () {
let tab = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab();
let browser = aWindow.gBrowser.selectedBrowser;
browser.stop();
// ensure that the test is run after the titlebar has been updated
browser.addEventListener("load", function () {
browser.removeEventListener("load", arguments.callee, true);
executeSoon(function () {
if (aWindow.document.title != expected_title) {
executeSoon(arguments.callee);
return;
}
is(aWindow.document.title, expected_title, "The window title for " + url +
" is correct (" + (insidePB ? "inside" : "outside") +
" private browsing mode)");
function* testTabTitle(aWindow, url, insidePB, expected_title) {
let tab = (yield BrowserTestUtils.openNewForegroundTab(aWindow.gBrowser));
yield BrowserTestUtils.loadURI(tab.linkedBrowser, url);
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let win = aWindow.gBrowser.replaceTabWithWindow(tab);
win.addEventListener("load", function() {
win.removeEventListener("load", arguments.callee, false);
executeSoon(function() {
if (win.document.title != expected_title) {
executeSoon(arguments.callee);
return;
}
is(win.document.title, expected_title, "The window title for " + url +
" detached tab is correct (" + (insidePB ? "inside" : "outside") +
" private browsing mode)");
win.close();
aWindow.close();
setTimeout(funcNext, 0);
});
}, false);
});
}, true);
browser.loadURI(url);
yield BrowserTestUtils.waitForCondition(() => {
return aWindow.document.title === expected_title;
});
is(aWindow.document.title, expected_title, "The window title for " + url +
" is correct (" + (insidePB ? "inside" : "outside") +
" private browsing mode)");
let win = aWindow.gBrowser.replaceTabWithWindow(tab);
yield BrowserTestUtils.waitForEvent(win, "load", false);
yield BrowserTestUtils.waitForCondition(() => {
return win.document.title === expected_title;
});
is(win.document.title, expected_title, "The window title for " + url +
" detached tab is correct (" + (insidePB ? "inside" : "outside") +
" private browsing mode)");
yield Promise.all([ BrowserTestUtils.closeWindow(win),
BrowserTestUtils.closeWindow(aWindow) ]);
}
whenNewWindowLoaded({private: false}, function(win) {
testTabTitle(win, "about:blank", false, page_without_title, function() {
whenNewWindowLoaded({private: false}, function(win) {
testTabTitle(win, testPageURL, false, page_with_title, function() {
whenNewWindowLoaded({private: false}, function(win) {
testTabTitle(win, "about:privatebrowsing", false, about_pb_title, function() {
whenNewWindowLoaded({private: true}, function(win) {
testTabTitle(win, "about:blank", true, pb_page_without_title, function() {
whenNewWindowLoaded({private: true}, function(win) {
testTabTitle(win, testPageURL, true, pb_page_with_title, function() {
whenNewWindowLoaded({private: true}, function(win) {
testTabTitle(win, "about:privatebrowsing", true, pb_about_pb_title, finish);
});
});
});
});
});
});
});
});
});
});
});
return;
}
function openWin(private) {
return BrowserTestUtils.openNewBrowserWindow({ private });
}
yield Task.spawn(testTabTitle((yield openWin(false)), "about:blank", false, page_without_title));
yield Task.spawn(testTabTitle((yield openWin(false)), testPageURL, false, page_with_title));
yield Task.spawn(testTabTitle((yield openWin(false)), "about:privatebrowsing", false, about_pb_title));
yield Task.spawn(testTabTitle((yield openWin(true)), "about:blank", true, pb_page_without_title));
yield Task.spawn(testTabTitle((yield openWin(true)), testPageURL, true, pb_page_with_title));
yield Task.spawn(testTabTitle((yield openWin(true)), "about:privatebrowsing", true, pb_about_pb_title));
});

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

@ -5,56 +5,33 @@
// This test makes sure that private browsing turns off doesn't cause zoom
// settings to be reset on tab switch (bug 464962)
function test() {
waitForExplicitFinish();
add_task(function* test() {
let win = (yield BrowserTestUtils.openNewBrowserWindow({ private: true }));
let tabAbout = (yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:"));
let tabMozilla = (yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:"));
function testZoom(aWindow, aCallback) {
executeSoon(function() {
let tabAbout = aWindow.gBrowser.addTab();
aWindow.gBrowser.selectedTab = tabAbout;
let mozillaZoom = win.ZoomManager.zoom;
let aboutBrowser = aWindow.gBrowser.getBrowserForTab(tabAbout);
aboutBrowser.addEventListener("load", function onAboutBrowserLoad() {
aboutBrowser.removeEventListener("load", onAboutBrowserLoad, true);
let tabMozilla = aWindow.gBrowser.addTab();
aWindow.gBrowser.selectedTab = tabMozilla;
// change the zoom on the mozilla page
win.FullZoom.enlarge();
// make sure the zoom level has been changed
isnot(win.ZoomManager.zoom, mozillaZoom, "Zoom level can be changed");
mozillaZoom = win.ZoomManager.zoom;
let mozillaBrowser = aWindow.gBrowser.getBrowserForTab(tabMozilla);
mozillaBrowser.addEventListener("load", function onMozillaBrowserLoad() {
mozillaBrowser.removeEventListener("load", onMozillaBrowserLoad, true);
let mozillaZoom = aWindow.ZoomManager.zoom;
// switch to about: tab
yield BrowserTestUtils.switchTab(win.gBrowser, tabAbout);
// change the zoom on the mozilla page
aWindow.FullZoom.enlarge();
// make sure the zoom level has been changed
isnot(aWindow.ZoomManager.zoom, mozillaZoom, "Zoom level can be changed");
mozillaZoom = aWindow.ZoomManager.zoom;
// switch back to mozilla tab
yield BrowserTestUtils.switchTab(win.gBrowser, tabMozilla);
// switch to about: tab
aWindow.gBrowser.selectedTab = tabAbout;
// make sure the zoom level has not changed
is(win.ZoomManager.zoom, mozillaZoom,
"Entering private browsing should not reset the zoom on a tab");
// switch back to mozilla tab
aWindow.gBrowser.selectedTab = tabMozilla;
// cleanup
win.FullZoom.reset();
yield Promise.all([ BrowserTestUtils.removeTab(tabMozilla),
BrowserTestUtils.removeTab(tabAbout) ]);
// make sure the zoom level has not changed
is(aWindow.ZoomManager.zoom, mozillaZoom,
"Entering private browsing should not reset the zoom on a tab");
// cleanup
aWindow.FullZoom.reset();
aWindow.gBrowser.removeTab(tabMozilla);
aWindow.gBrowser.removeTab(tabAbout);
aWindow.close();
aCallback();
}, true);
mozillaBrowser.contentWindow.location = "about:mozilla";
}, true);
aboutBrowser.contentWindow.location = "about:";
});
}
whenNewWindowLoaded({private: true}, function(privateWindow) {
testZoom(privateWindow, finish);
});
}
yield BrowserTestUtils.closeWindow(win);
});

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

@ -5,76 +5,60 @@
// This test makes sure that about:privatebrowsing does not appear zoomed in
// if there is already a zoom site pref for about:blank (bug 487656).
function test() {
add_task(function* test() {
// initialization
waitForExplicitFinish();
let windowsToClose = [];
let windowsToReset = [];
function doTestWhenReady(aIsZoomedWindow, aWindow, aCallback) {
function promiseLocationChange() {
return new Promise(resolve => {
Services.obs.addObserver(function onLocationChange(subj, topic, data) {
Services.obs.removeObserver(onLocationChange, topic);
resolve();
}, "browser-fullZoom:location-change", false);
});
}
function promiseTestReady(aIsZoomedWindow, aWindow) {
// Need to wait on two things, the ordering of which is not guaranteed:
// (1) the page load, and (2) FullZoom's update to the new page's zoom
// level. FullZoom broadcasts "browser-fullZoom:location-change" when its
// update is done. (See bug 856366 for details.)
let n = 0;
let browser = aWindow.gBrowser.selectedBrowser;
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
if (++n == 2)
doTest(aIsZoomedWindow, aWindow, aCallback);
}, true);
Services.obs.addObserver(function onLocationChange(subj, topic, data) {
Services.obs.removeObserver(onLocationChange, topic);
if (++n == 2)
doTest(aIsZoomedWindow, aWindow, aCallback);
}, "browser-fullZoom:location-change", false);
browser.loadURI("about:blank");
return BrowserTestUtils.loadURI(browser, "about:blank").then(() => {
return Promise.all([ BrowserTestUtils.browserLoaded(browser),
promiseLocationChange() ]);
}).then(() => doTest(aIsZoomedWindow, aWindow));
}
function doTest(aIsZoomedWindow, aWindow, aCallback) {
function doTest(aIsZoomedWindow, aWindow) {
if (aIsZoomedWindow) {
is(aWindow.ZoomManager.zoom, 1,
"Zoom level for freshly loaded about:blank should be 1");
// change the zoom on the blank page
aWindow.FullZoom.enlarge();
isnot(aWindow.ZoomManager.zoom, 1, "Zoom level for about:blank should be changed");
aCallback();
return;
}
// make sure the zoom level is set to 1
is(aWindow.ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
aCallback();
}
function finishTest() {
// cleanup
windowsToReset.forEach(function(win) {
win.FullZoom.reset();
});
windowsToClose.forEach(function(win) {
win.close();
});
finish();
}
function testOnWindow(options, callback) {
let win = whenNewWindowLoaded(options,
function(win) {
windowsToClose.push(win);
windowsToReset.push(win);
executeSoon(function() { callback(win); });
});
};
testOnWindow({}, function(win) {
doTestWhenReady(true, win, function() {
testOnWindow({private: true}, function(win) {
doTestWhenReady(false, win, finishTest);
});
return BrowserTestUtils.openNewBrowserWindow(options).then((win) => {
windowsToClose.push(win);
windowsToReset.push(win);
return win;
});
});
}
}
yield testOnWindow({}).then(win => promiseTestReady(true, win));
yield testOnWindow({private: true}).then(win => promiseTestReady(false, win));
// cleanup
windowsToReset.forEach((win) => win.FullZoom.reset());
yield Promise.all(windowsToClose.map(win => BrowserTestUtils.closeWindow(win)));
});

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

@ -746,5 +746,52 @@ this.BrowserTestUtils = {
seq: seq
});
});
}
},
/**
* Will poll a condition function until it returns true.
*
* @param condition
* A condition function that must return true or false. If the
* condition ever throws, this is also treated as a false.
* @param interval
* The time interval to poll the condition function. Defaults
* to 100ms.
* @param attempts
* The number of times to poll before giving up and rejecting
* if the condition has not yet returned true. Defaults to 50
* (~5 seconds for 100ms intervals)
* @return Promise
* Resolves when condition is true.
* Rejects if timeout is exceeded or condition ever throws.
*/
waitForCondition(condition, msg, interval=100, maxTries=50) {
return new Promise((resolve, reject) => {
let tries = 0;
let intervalID = setInterval(() => {
if (tries >= maxTries) {
clearInterval(intervalID);
msg += ` - timed out after ${maxTries} tries.`;
reject(msg);
return;
}
let conditionPassed = false;
try {
conditionPassed = condition();
} catch(e) {
msg += ` - threw exception: ${e}`;
clearInterval(intervalID);
reject(msg);
return;
}
if (conditionPassed) {
clearInterval(intervalID);
resolve();
}
tries++;
}, interval);
});
},
};

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

@ -1,32 +1,25 @@
function check_crash_list(tab, crashes) {
let doc = gBrowser.getBrowserForTab(tab).contentDocument;
let crashlinks = doc.getElementById("tbody").getElementsByTagName("a");
is(crashlinks.length, crashes.length, "about:crashes lists correct number of crash reports");
for(let i = 0; i < crashes.length; i++) {
is(crashlinks[i].firstChild.textContent, crashes[i].id, i + ": crash ID is correct");
}
cleanup_fake_appdir();
gBrowser.removeTab(tab);
finish();
}
function test() {
waitForExplicitFinish();
let appD = make_fake_appdir();
let crD = appD.clone();
crD.append("Crash Reports");
let crashes = add_fake_crashes(crD, 5);
// sanity check
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
let appDtest = dirSvc.get("UAppData", Components.interfaces.nsILocalFile);
ok(appD.equals(appDtest), "directory service provider registered ok");
let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
let browser = gBrowser.getBrowserForTab(tab);
browser.addEventListener("load", function() {
browser.removeEventListener("load", arguments.callee, true);
ok(true, "about:crashes loaded");
executeSoon(function() { check_crash_list(tab, crashes); });
}, true);
browser.loadURI("about:crashes", null, null);
}
add_task(function* test() {
let appD = make_fake_appdir();
let crD = appD.clone();
crD.append("Crash Reports");
let crashes = add_fake_crashes(crD, 5);
// sanity check
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
let appDtest = dirSvc.get("UAppData", Components.interfaces.nsILocalFile);
ok(appD.equals(appDtest), "directory service provider registered ok");
yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:crashes" }, function (browser) {
info("about:crashes loaded");
return ContentTask.spawn(browser, crashes, function (crashes) {
let doc = content.document;
let crashlinks = doc.getElementById("tbody").getElementsByTagName("a");
is(crashlinks.length, crashes.length, "about:crashes lists correct number of crash reports");
for(let i = 0; i < crashes.length; i++) {
is(crashlinks[i].firstChild.textContent, crashes[i].id, i + ": crash ID is correct");
}
});
});
cleanup_fake_appdir();
});