Bug 1315105 - Part 3: Update close_dependent_tabs / grouped_shistory_crossproc test for new prerendering behavior, r=ehsan

MozReview-Commit-ID: Ic0CWUbLPuq

--HG--
extra : rebase_source : 3260db0a38e6020fa53259b98ad780d0f41f9ccc
This commit is contained in:
Michael Layzell 2016-12-20 19:39:50 +08:00
parent 0fa642800b
commit 40c2ca6442
2 changed files with 56 additions and 15 deletions

View File

@ -1,6 +1,7 @@
add_task(function* () {
yield SpecialPowers.pushPrefEnv({
set: [["browser.groupedhistory.enabled", true]]
set: [["browser.groupedhistory.enabled", true],
["dom.linkPrerender.enabled", true]]
});
// Wait for a process change and then fulfil the promise.
@ -14,27 +15,53 @@ add_task(function* () {
});
}
let tab2;
// Wait for given number tabs being closed.
function awaitTabClose(number) {
return new Promise(resolve => {
let seen = 0;
gBrowser.tabContainer.addEventListener("TabClose", function f() {
if (++seen == number) {
gBrowser.tabContainer.removeEventListener("TabClose", f);
resolve();
}
});
});
}
// Test 1: Create prerendered browser, and don't switch to it, then close the tab
let closed1 = awaitTabClose(2);
yield BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html,a" }, function* (browser1) {
// Set up the grouped SHEntry setup
tab2 = gBrowser.loadOneTab("data:text/html,b", {
referrerPolicy: Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT,
allowThirdPartyFixup: true,
relatedToCurrent: true,
isPrerendered: true,
});
});
// At this point tab2 should be closed
todo(!tab2.linkedBrowser, "The new tab should be closed");
yield BrowserTestUtils.removeTab(tab2); // XXX: Shouldn't be needed once the todo is fixed
let requestMade = new Promise(resolve => {
browser1.messageManager.addMessageListener("Prerender:Request", function f() {
browser1.messageManager.removeMessageListener("Prerender:Request", f);
ok(true, "Successfully received the prerender request");
resolve();
});
});
is(gBrowser.tabs.length, 2);
yield ContentTask.spawn(browser1, null, function() {
let link = content.document.createElement("link");
link.setAttribute("rel", "prerender");
link.setAttribute("href", "data:text/html,b");
content.document.body.appendChild(link);
});
yield requestMade;
is(gBrowser.tabs.length, 3);
});
yield closed1;
// At this point prerendered tab should be closed
is(gBrowser.tabs.length, 1, "The new tab and the prerendered 'tab' should be closed");
// Test 2: Create prerendered browser, switch to it, then close the tab
let closed2 = awaitTabClose(2);
yield BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html,a" }, function* (browser1) {
// Set up the grouped SHEntry setup
tab2 = gBrowser.loadOneTab("data:text/html,b", {
let tab2 = gBrowser.loadOneTab("data:text/html,b", {
referrerPolicy: Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT,
allowThirdPartyFixup: true,
relatedToCurrent: true,
@ -45,7 +72,8 @@ add_task(function* () {
tab2.linkedBrowser.frameLoader);
yield awaitProcessChange(browser1);
});
yield closed2;
// At this point tab2 should be closed
ok(!tab2.linkedBrowser, "The new tab should be closed");
// At this point prerendered tab should be closed
is(gBrowser.tabs.length, 1, "The new tab and the prerendered 'tab' should be closed");
});

View File

@ -14,6 +14,17 @@ add_task(function* () {
});
}
// Wait for the given tab being closed.
function awaitTabClose(tab) {
return new Promise(resolve => {
tab.addEventListener("TabClose", function f() {
tab.removeEventListener("TabClose", f);
ok(true, "The tab is being closed!\n");
resolve();
});
});
}
yield BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html,a" }, function* (browser1) {
// Set up the grouped SHEntry setup
let tab2 = gBrowser.loadOneTab("data:text/html,b", {
@ -28,6 +39,7 @@ add_task(function* () {
yield awaitProcessChange(browser1);
// Load a URI which will involve loading in the parent process
let tabClose = awaitTabClose(tab2);
browser1.loadURI("about:config", Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
yield BrowserTestUtils.browserLoaded(browser1);
let docshell = browser1.frameLoader.docShell.QueryInterface(Ci.nsIWebNavigation);
@ -37,5 +49,6 @@ add_task(function* () {
is(docshell.sessionHistory.count, 3, "Count is correct");
is(browser1.frameLoader.groupedSessionHistory, null,
"browser1's session history is now complete");
yield tabClose;
});
});