Bug 1100223 - Add test to ensure loadURI() on pending tabs works as expected r=Gijs

This commit is contained in:
Tim Taubert 2015-02-22 14:18:19 +01:00
parent 97dc6bc886
commit 030a3dea86
5 changed files with 59 additions and 20 deletions

View File

@ -89,6 +89,7 @@ skip-if = buildapp == 'mulet'
[browser_merge_closed_tabs.js]
[browser_pageStyle.js]
[browser_privatetabs.js]
[browser_replace_load.js]
[browser_restore_redirect.js]
[browser_scrollPositions.js]
[browser_sessionHistory.js]

View File

@ -60,12 +60,3 @@ add_task(function* test() {
// Clean up.
gBrowser.removeTab(tab);
});
function promiseTabRestoring(tab) {
return new Promise(resolve => {
tab.addEventListener("SSTabRestoring", function onRestoring() {
tab.removeEventListener("SSTabRestoring", onRestoring);
resolve();
});
});
}

View File

@ -42,14 +42,3 @@ add_task(function test_label_and_icon() {
// Cleanup.
gBrowser.removeTab(tab);
});
function promiseTabRestoring(tab) {
let deferred = Promise.defer();
tab.addEventListener("SSTabRestoring", function onRestoring() {
tab.removeEventListener("SSTabRestoring", onRestoring);
deferred.resolve();
});
return deferred.promise;
}

View File

@ -0,0 +1,54 @@
"use strict";
const STATE = {
entries: [{url: "about:robots"}, {url: "about:mozilla"}],
selected: 2
};
/**
* Bug 1100223. Calling browser.loadURI() while a tab is loading causes
* sessionstore to override the desired target URL. This test ensures that
* calling loadURI() on a pending tab causes the tab to no longer be marked
* as pending and correctly finish the instructed load while keeping the
* restored history around.
*/
add_task(function* () {
yield testSwitchToTab("about:mozilla#fooobar", {ignoreFragment: true});
yield testSwitchToTab("about:mozilla?foo=bar", {replaceQueryString: true});
});
let testSwitchToTab = Task.async(function* (url, options) {
// Create a background tab.
let tab = gBrowser.addTab("about:blank");
let browser = tab.linkedBrowser;
yield promiseBrowserLoaded(browser);
// The tab shouldn't be restored right away.
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
// Prepare the tab state.
let promise = promiseTabRestoring(tab);
ss.setTabState(tab, JSON.stringify(STATE));
ok(tab.hasAttribute("pending"), "tab is pending");
yield promise;
// Switch-to-tab with a similar URI.
switchToTabHavingURI(url, false, options);
ok(!tab.hasAttribute("pending"), "tab is no longer pending");
// Wait until the tab is restored.
yield promiseTabRestored(tab);
is(browser.currentURI.spec, url, "correct URL loaded");
// Check that we didn't lose any history entries.
let count = yield ContentTask.spawn(browser, null, function* () {
let Ci = Components.interfaces;
let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
let history = webNavigation.sessionHistory.QueryInterface(Ci.nsISHistoryInternal);
return history && history.count;
});
is(count, 3, "three history entries");
// Cleanup.
gBrowser.removeTab(tab);
});

View File

@ -502,6 +502,10 @@ function promiseTabRestored(tab) {
return promiseEvent(tab, "SSTabRestored");
}
function promiseTabRestoring(tab) {
return promiseEvent(tab, "SSTabRestoring");
}
function sendMessage(browser, name, data = {}) {
browser.messageManager.sendAsyncMessage(name, data);
return promiseContentMessage(browser, name);