зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1734181 - Part 4: Add tests for the backbutton intervention behaviour. r=jjaschke,peterv,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D216828
This commit is contained in:
Родитель
52335f5a36
Коммит
184bda843d
|
@ -260,6 +260,8 @@ support-files = [
|
|||
"file_csp_uir_dummy.html",
|
||||
]
|
||||
|
||||
["browser_current_entry_always_in_history_menu.js"]
|
||||
|
||||
["browser_dataURI_unique_opaque_origin.js"]
|
||||
https_first_disabled = true
|
||||
|
||||
|
@ -305,6 +307,9 @@ support-files = ["overlink_test.html"]
|
|||
|
||||
["browser_platform_emulation.js"]
|
||||
|
||||
["browser_replace_state_during_navigation.js"]
|
||||
support-files = ["file_replace_state_during_navigation.html"]
|
||||
|
||||
["browser_search_notification.js"]
|
||||
|
||||
["browser_tab_replace_while_loading.js"]
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
|
||||
const TEST_URI = "https://example.com/";
|
||||
|
||||
add_setup(async function () {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.navigation.requireUserInteraction", true]],
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async () => {
|
||||
await BrowserTestUtils.withNewTab(TEST_URI, async browser => {
|
||||
// Navigate away, after causing a user interaction.
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
await followLink(TEST_URI + "2.html");
|
||||
|
||||
// Navigate again, without causing a user interaction.
|
||||
await SpecialPowers.spawn(browser, [], async function () {
|
||||
content.history.pushState({}, "", "https://example.com/3.html");
|
||||
});
|
||||
|
||||
// Wait for the session data to be flushed before continuing the test
|
||||
await new Promise(resolve =>
|
||||
SessionStore.getSessionHistory(gBrowser.selectedTab, resolve)
|
||||
);
|
||||
// The entry with no interaction shouldn't appear.
|
||||
await assertMenulist([TEST_URI + "3.html", TEST_URI]);
|
||||
|
||||
// Go back using history.back, which does not check for user interaction.
|
||||
await SpecialPowers.spawn(browser, [], async function () {
|
||||
content.history.back();
|
||||
});
|
||||
|
||||
// We are back on entry 2, so it should appear in the list.
|
||||
await assertMenulist([TEST_URI + "3.html", TEST_URI + "2.html", TEST_URI]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
|
||||
const TEST_URI =
|
||||
getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content",
|
||||
"https://example.com"
|
||||
) + "dummy_page.html";
|
||||
const TEST_URI_2 =
|
||||
getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content",
|
||||
"https://example.com"
|
||||
) + "file_replace_state_during_navigation.html";
|
||||
|
||||
add_setup(async function () {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.navigation.requireUserInteraction", true]],
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async () => {
|
||||
await BrowserTestUtils.withNewTab(TEST_URI, async browser => {
|
||||
// Add user interaction to the first page.
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("body", {}, browser);
|
||||
|
||||
// Follow link to the next page.
|
||||
await followLink(TEST_URI_2);
|
||||
|
||||
// Navigate, causing a hashchange event to fire and call history.replaceState
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#link", {}, browser);
|
||||
|
||||
await assertMenulist([
|
||||
TEST_URI_2 + "#1",
|
||||
TEST_URI_2 + "#inject",
|
||||
TEST_URI_2,
|
||||
TEST_URI,
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<script>
|
||||
window.addEventListener("hashchange", (event) => {
|
||||
history.replaceState(null, "", "#inject");
|
||||
history.pushState(null, "", "#" + event.newURL.split("#")[1]);
|
||||
});
|
||||
</script>
|
||||
<a id="link" href="#1">link</a>
|
|
@ -195,3 +195,51 @@ class SHListener {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function assertMenulist(entries) {
|
||||
// Wait for the session data to be flushed before continuing the test
|
||||
await new Promise(resolve =>
|
||||
SessionStore.getSessionHistory(gBrowser.selectedTab, resolve)
|
||||
);
|
||||
|
||||
let backButton = document.getElementById("back-button");
|
||||
let contextMenu = document.getElementById("backForwardMenu");
|
||||
|
||||
info("waiting for the history menu to open");
|
||||
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(
|
||||
contextMenu,
|
||||
"popupshown"
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(backButton, {
|
||||
type: "contextmenu",
|
||||
button: 2,
|
||||
});
|
||||
await popupShownPromise;
|
||||
|
||||
info("history menu opened");
|
||||
|
||||
let nodes = contextMenu.childNodes;
|
||||
|
||||
is(
|
||||
nodes.length,
|
||||
entries.length,
|
||||
"Has the expected number of contextMenu entries"
|
||||
);
|
||||
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
let node = nodes[i];
|
||||
is(
|
||||
node.getAttribute("uri"),
|
||||
entries[i],
|
||||
"contextMenu node has the correct uri"
|
||||
);
|
||||
}
|
||||
|
||||
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
|
||||
contextMenu,
|
||||
"popuphidden"
|
||||
);
|
||||
contextMenu.hidePopup();
|
||||
await popupHiddenPromise;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче