зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1667027 - Fix more tests that uses legacySHistory. r=peterv
Differential Revision: https://phabricator.services.mozilla.com/D91277
This commit is contained in:
Родитель
8402c1cf3e
Коммит
06bea3d5db
|
@ -26,8 +26,14 @@ function test() {
|
|||
let browser = tab.linkedBrowser;
|
||||
|
||||
promiseTabState(tab, tabState).then(() => {
|
||||
let sessionHistory = browser.sessionHistory;
|
||||
let entry = sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
let entry;
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
let sessionHistory = browser.sessionHistory;
|
||||
entry = sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
} else {
|
||||
let sessionHistory = browser.browsingContext.sessionHistory;
|
||||
entry = sessionHistory.getEntryAtIndex(0);
|
||||
}
|
||||
|
||||
whenChildCount(entry, 1, function() {
|
||||
whenChildCount(entry, 2, function() {
|
||||
|
|
|
@ -26,14 +26,26 @@ function test() {
|
|||
let browser = tab.linkedBrowser;
|
||||
|
||||
promiseTabState(tab, tabState).then(() => {
|
||||
let sessionHistory = browser.sessionHistory;
|
||||
let entry = sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
let entry;
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
let sessionHistory = browser.sessionHistory;
|
||||
entry = sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
} else {
|
||||
let sessionHistory = browser.browsingContext.sessionHistory;
|
||||
entry = sessionHistory.getEntryAtIndex(0);
|
||||
}
|
||||
|
||||
whenChildCount(entry, 1, function() {
|
||||
whenChildCount(entry, 2, function() {
|
||||
promiseBrowserLoaded(browser).then(() => {
|
||||
let newSessionHistory = browser.sessionHistory;
|
||||
let newEntry = newSessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
let newEntry;
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
let newSessionHistory = browser.sessionHistory;
|
||||
newEntry = newSessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
} else {
|
||||
let newSessionHistory = browser.browsingContext.sessionHistory;
|
||||
newEntry = newSessionHistory.getEntryAtIndex(0);
|
||||
}
|
||||
|
||||
whenChildCount(newEntry, 0, function() {
|
||||
// Make sure that we reset the state.
|
||||
|
|
|
@ -4,20 +4,58 @@ add_task(async function duplicateTab() {
|
|||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
|
||||
let docshell = content.window.docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||
let shEntry = docshell.sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
is(shEntry.docshellID.toString(), docshell.historyID.toString());
|
||||
});
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
|
||||
let docshell = content.window.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
let shEntry = docshell.sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
is(shEntry.docshellID.toString(), docshell.historyID.toString());
|
||||
});
|
||||
} else {
|
||||
let historyID = await SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[],
|
||||
function() {
|
||||
let docshell = content.window.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
return docshell.historyID.toString();
|
||||
}
|
||||
);
|
||||
let shEntry = tab.linkedBrowser.browsingContext.sessionHistory.getEntryAtIndex(
|
||||
0
|
||||
);
|
||||
is(shEntry.docshellID.toString(), historyID.toString());
|
||||
}
|
||||
|
||||
let tab2 = gBrowser.duplicateTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
|
||||
|
||||
await SpecialPowers.spawn(tab2.linkedBrowser, [], function() {
|
||||
let docshell = content.window.docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||
let shEntry = docshell.sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
is(shEntry.docshellID.toString(), docshell.historyID.toString());
|
||||
});
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
await SpecialPowers.spawn(tab2.linkedBrowser, [], function() {
|
||||
let docshell = content.window.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
let shEntry = docshell.sessionHistory.legacySHistory.getEntryAtIndex(0);
|
||||
is(shEntry.docshellID.toString(), docshell.historyID.toString());
|
||||
});
|
||||
} else {
|
||||
let historyID = await SpecialPowers.spawn(
|
||||
tab2.linkedBrowser,
|
||||
[],
|
||||
function() {
|
||||
let docshell = content.window.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
return docshell.historyID.toString();
|
||||
}
|
||||
);
|
||||
let shEntry = tab2.linkedBrowser.browsingContext.sessionHistory.getEntryAtIndex(
|
||||
0
|
||||
);
|
||||
is(shEntry.docshellID.toString(), historyID.toString());
|
||||
}
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
BrowserTestUtils.removeTab(tab2);
|
||||
|
@ -29,15 +67,33 @@ add_task(async function contentToChromeNavigate() {
|
|||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
|
||||
let docshell = content.window.docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||
let sh = docshell.sessionHistory;
|
||||
is(sh.count, 1);
|
||||
is(
|
||||
sh.legacySHistory.getEntryAtIndex(0).docshellID.toString(),
|
||||
docshell.historyID.toString()
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
|
||||
let docshell = content.window.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
let sh = docshell.sessionHistory;
|
||||
is(sh.count, 1);
|
||||
is(
|
||||
sh.legacySHistory.getEntryAtIndex(0).docshellID.toString(),
|
||||
docshell.historyID.toString()
|
||||
);
|
||||
});
|
||||
} else {
|
||||
let historyID = await SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[],
|
||||
function() {
|
||||
let docshell = content.window.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
return docshell.historyID.toString();
|
||||
}
|
||||
);
|
||||
});
|
||||
let sh = tab.linkedBrowser.browsingContext.sessionHistory;
|
||||
is(sh.count, 1);
|
||||
is(sh.getEntryAtIndex(0).docshellID.toString(), historyID);
|
||||
}
|
||||
|
||||
// Force the browser to navigate to the chrome process.
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
|
||||
|
@ -54,17 +110,31 @@ add_task(async function contentToChromeNavigate() {
|
|||
let docShell = tab.linkedBrowser.frameLoader.docShell;
|
||||
|
||||
// 'cause we're in the chrome process, we can just directly poke at the shistory.
|
||||
let sh = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory;
|
||||
if (!Services.appinfo.sessionHistoryInParent) {
|
||||
let sh = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory;
|
||||
|
||||
is(sh.count, 2);
|
||||
is(
|
||||
sh.legacySHistory.getEntryAtIndex(0).docshellID.toString(),
|
||||
docShell.historyID.toString()
|
||||
);
|
||||
is(
|
||||
sh.legacySHistory.getEntryAtIndex(1).docshellID.toString(),
|
||||
docShell.historyID.toString()
|
||||
);
|
||||
is(sh.count, 2);
|
||||
is(
|
||||
sh.legacySHistory.getEntryAtIndex(0).docshellID.toString(),
|
||||
docShell.historyID.toString()
|
||||
);
|
||||
is(
|
||||
sh.legacySHistory.getEntryAtIndex(1).docshellID.toString(),
|
||||
docShell.historyID.toString()
|
||||
);
|
||||
} else {
|
||||
let sh = docShell.browsingContext.sessionHistory;
|
||||
|
||||
is(sh.count, 2);
|
||||
is(
|
||||
sh.getEntryAtIndex(0).docshellID.toString(),
|
||||
docShell.historyID.toString()
|
||||
);
|
||||
is(
|
||||
sh.getEntryAtIndex(1).docshellID.toString(),
|
||||
docShell.historyID.toString()
|
||||
);
|
||||
}
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -162,6 +162,7 @@ void CanonicalBrowsingContext::ReplacedBy(
|
|||
}
|
||||
aNewContext->mWebProgress = std::move(mWebProgress);
|
||||
aNewContext->mFields.SetWithoutSyncing<IDX_BrowserId>(GetBrowserId());
|
||||
aNewContext->mFields.SetWithoutSyncing<IDX_HistoryID>(GetHistoryID());
|
||||
|
||||
if (mSessionHistory) {
|
||||
mSessionHistory->SetBrowsingContext(aNewContext);
|
||||
|
|
|
@ -16,81 +16,101 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=509055
|
|||
<div id="content">
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 509055 **/
|
||||
/** Test for Bug 509055 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var gGen;
|
||||
var gGen;
|
||||
|
||||
function shortWait() {
|
||||
setTimeout(function() { gGen.next(); }, 0, false);
|
||||
}
|
||||
function shortWait() {
|
||||
setTimeout(function() { gGen.next(); }, 0, false);
|
||||
}
|
||||
|
||||
function onChildHashchange(e) {
|
||||
// gGen might be undefined when we refresh the page, so we have to check here
|
||||
dump("onChildHashchange() called.\n");
|
||||
if (gGen)
|
||||
gGen.next();
|
||||
}
|
||||
function onChildHashchange(e) {
|
||||
// gGen might be undefined when we refresh the page, so we have to check here
|
||||
dump("onChildHashchange() called.\n");
|
||||
if (gGen)
|
||||
gGen.next();
|
||||
}
|
||||
|
||||
function onChildLoad(e) {
|
||||
if (gGen)
|
||||
gGen.next();
|
||||
}
|
||||
function onChildLoad(e) {
|
||||
if (gGen)
|
||||
gGen.next();
|
||||
}
|
||||
|
||||
function* runTest() {
|
||||
var popup = window.open("file_bug509055.html", "popup 0",
|
||||
"height=200,width=200,location=yes," +
|
||||
"menubar=yes,status=yes,toolbar=yes,dependent=yes");
|
||||
popup.hashchangeCallback = onChildHashchange;
|
||||
popup.onload = onChildLoad;
|
||||
dump("Waiting for initial load.\n");
|
||||
yield undefined;
|
||||
async function* runTest() {
|
||||
var popup = window.open("file_bug509055.html", "popup 0",
|
||||
"height=200,width=200,location=yes," +
|
||||
"menubar=yes,status=yes,toolbar=yes,dependent=yes");
|
||||
popup.hashchangeCallback = onChildHashchange;
|
||||
popup.onload = onChildLoad;
|
||||
dump("Waiting for initial load.\n");
|
||||
yield undefined;
|
||||
|
||||
// Without this wait, the change to location.hash below doesn't create a
|
||||
// SHEntry or enable the back button.
|
||||
shortWait();
|
||||
dump("Got initial load. Spinning event loop.\n");
|
||||
yield undefined;
|
||||
// Without this wait, the change to location.hash below doesn't create a
|
||||
// SHEntry or enable the back button.
|
||||
shortWait();
|
||||
dump("Got initial load. Spinning event loop.\n");
|
||||
yield undefined;
|
||||
|
||||
popup.location.hash = "#1";
|
||||
dump("Waiting for hashchange.\n");
|
||||
yield undefined;
|
||||
popup.location.hash = "#1";
|
||||
dump("Waiting for hashchange.\n");
|
||||
yield undefined;
|
||||
|
||||
popup.history.back();
|
||||
dump("Waiting for second hashchange.\n");
|
||||
yield undefined; // wait for hashchange
|
||||
popup.history.back();
|
||||
dump("Waiting for second hashchange.\n");
|
||||
yield undefined; // wait for hashchange
|
||||
|
||||
popup.document.title = "Changed";
|
||||
popup.document.title = "Changed";
|
||||
|
||||
// Wait for listeners to be notified of the title change.
|
||||
shortWait();
|
||||
dump("Got second hashchange. Spinning event loop.\n");
|
||||
yield undefined;
|
||||
// Wait for listeners to be notified of the title change.
|
||||
shortWait();
|
||||
dump("Got second hashchange. Spinning event loop.\n");
|
||||
yield undefined;
|
||||
|
||||
var sh = SpecialPowers.wrap(popup)
|
||||
.docShell
|
||||
.QueryInterface(SpecialPowers.Ci.nsIWebNavigation)
|
||||
.sessionHistory;
|
||||
let sheTitle = "";
|
||||
if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
|
||||
var sh = SpecialPowers.wrap(popup)
|
||||
.docShell
|
||||
.QueryInterface(SpecialPowers.Ci.nsIWebNavigation)
|
||||
.sessionHistory;
|
||||
|
||||
// Get the title of the inner popup's current SHEntry
|
||||
var sheTitle = sh.legacySHistory.getEntryAtIndex(sh.index).title;
|
||||
is(sheTitle, "Changed", "SHEntry's title should change when we change.");
|
||||
// Get the title of the inner popup's current SHEntry
|
||||
sheTitle = sh.legacySHistory.getEntryAtIndex(sh.index).title;
|
||||
} else {
|
||||
let chromeScript = SpecialPowers.loadChromeScript(() => {
|
||||
// eslint-disable-next-line no-undef
|
||||
addMessageListener("getTitle", browsingContext => {
|
||||
// eslint-disable-next-line no-shadow
|
||||
let sh = browsingContext.sessionHistory;
|
||||
let title = sh.getEntryAtIndex(sh.index).title;
|
||||
// eslint-disable-next-line no-undef
|
||||
sendAsyncMessage("title", title);
|
||||
});
|
||||
});
|
||||
|
||||
popup.close();
|
||||
let p = chromeScript.promiseOneMessage("title");
|
||||
let browsingContext = SpecialPowers.wrap(popup)
|
||||
.docShell.browsingContext;
|
||||
chromeScript.sendAsyncMessage("getTitle", browsingContext);
|
||||
sheTitle = await p;
|
||||
chromeScript.destroy();
|
||||
}
|
||||
is(sheTitle, "Changed", "SHEntry's title should change when we change.");
|
||||
|
||||
SimpleTest.executeSoon(SimpleTest.finish);
|
||||
}
|
||||
popup.close();
|
||||
|
||||
window.addEventListener("load", function() {
|
||||
gGen = runTest();
|
||||
gGen.next();
|
||||
});
|
||||
SimpleTest.executeSoon(SimpleTest.finish);
|
||||
}
|
||||
|
||||
</script>
|
||||
window.addEventListener("load", function() {
|
||||
gGen = runTest();
|
||||
gGen.next();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -82,29 +82,6 @@ function page2PageShow() {
|
|||
}
|
||||
}
|
||||
|
||||
function dumpSHistory(theWindow) {
|
||||
let sh = SpecialPowers.wrap(theWindow).docShell
|
||||
.QueryInterface(SpecialPowers.Ci.nsIWebNavigation)
|
||||
.sessionHistory;
|
||||
if (!sh) {
|
||||
dump(" window has no shistory.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
dump(" count: " + sh.count + "\n");
|
||||
dump(" index: " + sh.index + "\n");
|
||||
dump(" requestedIndex: " + sh.legacySHistory.requestedIndex + "\n");
|
||||
|
||||
for (let i = 0; i < sh.count; i++) {
|
||||
let shentry = sh.legacySHistory.getEntryAtIndex(i);
|
||||
dump(" " + i + ": " + shentry.URI.spec + "\n");
|
||||
for (let j = 0; j < shentry.childCount; j++) {
|
||||
let child = shentry.GetChildAt(j);
|
||||
dump(" child " + j + ": " + child.URI.spec + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var popup = window.open("file_bug590573_1.html");
|
||||
|
||||
var gTestContinuation = null;
|
||||
|
@ -113,8 +90,6 @@ function pageLoad() {
|
|||
loads++;
|
||||
dump("pageLoad(loads=" + loads + ", page location=" + popup.location + ")\n");
|
||||
|
||||
dumpSHistory(window);
|
||||
|
||||
if (!gTestContinuation) {
|
||||
gTestContinuation = testBody();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче