mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 17:25:36 +00:00
Bug 1640221, remove content.js frame script from session store tests. Replace with BrowserTestUtils functions and SpecialPowers.spawn, r=mikedeboer
Differential Revision: https://phabricator.services.mozilla.com/D76514
This commit is contained in:
parent
e38a47a505
commit
e302160291
@ -11,7 +11,6 @@
|
||||
skip-if = os == 'linux' && !e10s
|
||||
support-files =
|
||||
head.js
|
||||
content.js
|
||||
content-forms.js
|
||||
browser_formdata_sample.html
|
||||
browser_formdata_xpath_sample.html
|
||||
|
@ -42,7 +42,7 @@ add_task(async function test_add_interesting_window() {
|
||||
let tab = newWin.gBrowser.selectedTab;
|
||||
await promiseOnHistoryReplaceEntry(tab);
|
||||
} else {
|
||||
await promiseContentMessage(browser, "ss-test:OnHistoryReplaceEntry");
|
||||
await promiseOnHistoryReplaceEntryInChild(browser);
|
||||
}
|
||||
// Clear out the userTypedValue so that the new window looks like
|
||||
// it's really not worth restoring.
|
||||
|
@ -87,7 +87,7 @@ add_task(async function() {
|
||||
ok(!entries[0].children, "no children collected");
|
||||
|
||||
// Navigate the subframe.
|
||||
browser.messageManager.sendAsyncMessage("ss-test:click", { id: "lnk" });
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#lnk", {}, browser);
|
||||
await promiseBrowserLoaded(browser, false /* don't ignore subframes */);
|
||||
|
||||
await TabStateFlusher.flush(browser);
|
||||
|
@ -44,23 +44,13 @@ add_task(async function check_js_redirect() {
|
||||
],
|
||||
};
|
||||
|
||||
let loadPromise = new Promise(resolve => {
|
||||
function listener(msg) {
|
||||
if (msg.data.url.endsWith("restore_redirect_target.html")) {
|
||||
window.messageManager.removeMessageListener(
|
||||
"ss-test:loadEvent",
|
||||
listener
|
||||
);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
window.messageManager.addMessageListener("ss-test:loadEvent", listener);
|
||||
});
|
||||
|
||||
// Open a new tab to restore into.
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
|
||||
let browser = tab.linkedBrowser;
|
||||
let loadPromise = BrowserTestUtils.browserLoaded(browser, true, url =>
|
||||
url.endsWith("restore_redirect_target.html")
|
||||
);
|
||||
|
||||
await promiseTabState(tab, state);
|
||||
|
||||
info("Restored tab");
|
||||
|
@ -19,6 +19,15 @@ const SCROLL2_STR = SCROLL2_X + "," + SCROLL2_Y;
|
||||
|
||||
requestLongerTimeout(2);
|
||||
|
||||
function getScrollPosition(bc) {
|
||||
return SpecialPowers.spawn(bc, [], () => {
|
||||
let x = {},
|
||||
y = {};
|
||||
content.windowUtils.getVisualViewportOffset(x, y);
|
||||
return { x: x.value, y: y.value };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that we properly serialize and restore scroll positions
|
||||
* for an average page without any frames.
|
||||
@ -29,10 +38,7 @@ add_task(async function test_scroll() {
|
||||
await promiseBrowserLoaded(browser);
|
||||
|
||||
// Scroll down a little.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: SCROLL_X,
|
||||
y: SCROLL_Y,
|
||||
});
|
||||
await setScrollPosition(browser, SCROLL_X, SCROLL_Y);
|
||||
await checkScroll(tab, { scroll: SCROLL_STR }, "scroll is fine");
|
||||
|
||||
// Duplicate and check that the scroll position is restored.
|
||||
@ -40,7 +46,7 @@ add_task(async function test_scroll() {
|
||||
let browser2 = tab2.linkedBrowser;
|
||||
await promiseTabRestored(tab2);
|
||||
|
||||
let scroll = await sendMessage(browser2, "ss-test:getScrollPosition");
|
||||
let scroll = await getScrollPosition(browser2);
|
||||
is(
|
||||
JSON.stringify(scroll),
|
||||
JSON.stringify({ x: SCROLL_X, y: SCROLL_Y }),
|
||||
@ -64,7 +70,7 @@ add_task(async function test_scroll() {
|
||||
// Scroll back to the top and check that the position has been reset. We
|
||||
// expect the scroll position to be "null" here because there is no data to
|
||||
// be stored if the frame is in its default scroll position.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", { x: 0, y: 0 });
|
||||
await setScrollPosition(browser, 0, 0);
|
||||
await checkScroll(tab, null, "no scroll stored");
|
||||
|
||||
// Cleanup.
|
||||
@ -82,11 +88,11 @@ add_task(async function test_scroll_nested() {
|
||||
await promiseBrowserLoaded(browser);
|
||||
|
||||
// Scroll the first child frame down a little.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: SCROLL_X,
|
||||
y: SCROLL_Y,
|
||||
frame: 0,
|
||||
});
|
||||
await setScrollPosition(
|
||||
browser.browsingContext.children[0],
|
||||
SCROLL_X,
|
||||
SCROLL_Y
|
||||
);
|
||||
await checkScroll(
|
||||
tab,
|
||||
{ children: [{ scroll: SCROLL_STR }] },
|
||||
@ -94,11 +100,11 @@ add_task(async function test_scroll_nested() {
|
||||
);
|
||||
|
||||
// Scroll the second child frame down a little.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: SCROLL2_X,
|
||||
y: SCROLL2_Y,
|
||||
frame: 1,
|
||||
});
|
||||
await setScrollPosition(
|
||||
browser.browsingContext.children[1],
|
||||
SCROLL2_X,
|
||||
SCROLL2_Y
|
||||
);
|
||||
await checkScroll(
|
||||
tab,
|
||||
{ children: [{ scroll: SCROLL_STR }, { scroll: SCROLL2_STR }] },
|
||||
@ -110,18 +116,14 @@ add_task(async function test_scroll_nested() {
|
||||
let browser2 = tab2.linkedBrowser;
|
||||
await promiseTabRestored(tab2);
|
||||
|
||||
let scroll = await sendMessage(browser2, "ss-test:getScrollPosition", {
|
||||
frame: 0,
|
||||
});
|
||||
let scroll = await getScrollPosition(browser2.browsingContext.children[0]);
|
||||
is(
|
||||
JSON.stringify(scroll),
|
||||
JSON.stringify({ x: SCROLL_X, y: SCROLL_Y }),
|
||||
"scroll position #1 has been duplicated correctly"
|
||||
);
|
||||
|
||||
scroll = await sendMessage(browser2, "ss-test:getScrollPosition", {
|
||||
frame: 1,
|
||||
});
|
||||
scroll = await getScrollPosition(browser2.browsingContext.children[1]);
|
||||
is(
|
||||
JSON.stringify(scroll),
|
||||
JSON.stringify({ x: SCROLL2_X, y: SCROLL2_Y }),
|
||||
@ -130,11 +132,7 @@ add_task(async function test_scroll_nested() {
|
||||
|
||||
// Check that resetting one frame's scroll position removes it from the
|
||||
// serialized value.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
frame: 0,
|
||||
});
|
||||
await setScrollPosition(browser.browsingContext.children[0], 0, 0);
|
||||
await checkScroll(
|
||||
tab,
|
||||
{ children: [null, { scroll: SCROLL2_STR }] },
|
||||
@ -142,11 +140,7 @@ add_task(async function test_scroll_nested() {
|
||||
);
|
||||
|
||||
// Check the resetting all frames' scroll positions nulls the stored value.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
frame: 1,
|
||||
});
|
||||
await setScrollPosition(browser.browsingContext.children[1], 0, 0);
|
||||
await checkScroll(tab, null, "no scroll stored");
|
||||
|
||||
// Cleanup.
|
||||
@ -169,10 +163,7 @@ add_task(async function test_scroll_background_tabs() {
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
// Scroll down a little.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: SCROLL_X,
|
||||
y: SCROLL_Y,
|
||||
});
|
||||
await setScrollPosition(browser, SCROLL_X, SCROLL_Y);
|
||||
await checkScroll(
|
||||
tab,
|
||||
{ scroll: SCROLL_STR },
|
||||
@ -184,10 +175,7 @@ add_task(async function test_scroll_background_tabs() {
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
// Scroll down a little.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: SCROLL2_X,
|
||||
y: SCROLL2_Y,
|
||||
});
|
||||
await setScrollPosition(browser, SCROLL2_X, SCROLL2_Y);
|
||||
await checkScroll(
|
||||
tab,
|
||||
{ scroll: SCROLL2_STR },
|
||||
|
@ -30,10 +30,7 @@ add_task(async function test_scroll_background_about_reader_tabs() {
|
||||
]);
|
||||
|
||||
// Scroll down a little.
|
||||
await sendMessage(browser, "ss-test:setScrollPosition", {
|
||||
x: 0,
|
||||
y: SCROLL_READER_MODE_Y,
|
||||
});
|
||||
await setScrollPosition(browser, 0, SCROLL_READER_MODE_Y);
|
||||
await checkScroll(tab, { scroll: SCROLL_READER_MODE_STR }, "scroll is fine");
|
||||
|
||||
// Close the window
|
||||
|
@ -14,11 +14,14 @@ add_task(async function test_load_start() {
|
||||
let browser = tab.linkedBrowser;
|
||||
await promiseBrowserLoaded(browser);
|
||||
|
||||
const PAGE = "http://example.com/";
|
||||
|
||||
// Load a new URI.
|
||||
await BrowserTestUtils.loadURI(browser, "about:mozilla");
|
||||
let historyReplacePromise = promiseOnHistoryReplaceEntryInChild(browser);
|
||||
await BrowserTestUtils.loadURI(browser, PAGE);
|
||||
|
||||
// Remove the tab before it has finished loading.
|
||||
await promiseContentMessage(browser, "ss-test:OnHistoryReplaceEntry");
|
||||
await historyReplacePromise;
|
||||
await promiseRemoveTabAndSessionState(tab);
|
||||
|
||||
// Undo close the tab.
|
||||
@ -27,7 +30,7 @@ add_task(async function test_load_start() {
|
||||
await promiseTabRestored(tab);
|
||||
|
||||
// Check that the correct URL was restored.
|
||||
is(browser.currentURI.spec, "about:mozilla", "url is correct");
|
||||
is(browser.currentURI.spec, PAGE, "url is correct");
|
||||
|
||||
// Cleanup.
|
||||
gBrowser.removeTab(tab);
|
||||
@ -53,8 +56,13 @@ add_task(async function test_hashchange() {
|
||||
is(entries.length, 1, "there is one shistory entry");
|
||||
|
||||
// Click the link and wait for a hashchange event.
|
||||
browser.messageManager.sendAsyncMessage("ss-test:click", { id: "a" });
|
||||
await promiseContentMessage(browser, "ss-test:hashchange");
|
||||
let eventPromise = BrowserTestUtils.waitForContentEvent(
|
||||
browser,
|
||||
"hashchange",
|
||||
true
|
||||
);
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#a", {}, browser);
|
||||
await eventPromise;
|
||||
|
||||
// Check that we now have two shistory entries.
|
||||
await TabStateFlusher.flush(browser);
|
||||
@ -122,7 +130,7 @@ add_task(async function test_subframes() {
|
||||
is(entries[0].children.length, 1, "the entry has one child");
|
||||
|
||||
// Navigate the subframe.
|
||||
browser.messageManager.sendAsyncMessage("ss-test:click", { id: "a1" });
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#a1", {}, browser);
|
||||
await promiseBrowserLoaded(browser, false /* don't ignore subframes */);
|
||||
|
||||
// Check shistory.
|
||||
@ -136,8 +144,13 @@ add_task(async function test_subframes() {
|
||||
await promiseBrowserLoaded(browser, false /* don't ignore subframes */);
|
||||
|
||||
// Navigate the subframe again.
|
||||
browser.messageManager.sendAsyncMessage("ss-test:click", { id: "a2" });
|
||||
await promiseContentMessage(browser, "ss-test:hashchange");
|
||||
let eventPromise = BrowserTestUtils.waitForContentEvent(
|
||||
browser,
|
||||
"hashchange",
|
||||
true
|
||||
);
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#a2", {}, browser);
|
||||
await eventPromise;
|
||||
|
||||
// Check shistory.
|
||||
await TabStateFlusher.flush(browser);
|
||||
|
@ -1,161 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/* eslint-env mozilla/frame-script */
|
||||
|
||||
"use strict";
|
||||
|
||||
function executeSoon(callback) {
|
||||
Services.tm.dispatchToMainThread(callback);
|
||||
}
|
||||
|
||||
var historyListener = {
|
||||
OnHistoryNewEntry() {
|
||||
sendAsyncMessage("ss-test:OnHistoryNewEntry");
|
||||
},
|
||||
|
||||
OnHistoryGotoIndex() {
|
||||
sendAsyncMessage("ss-test:OnHistoryGotoIndex");
|
||||
},
|
||||
|
||||
OnHistoryPurge() {
|
||||
sendAsyncMessage("ss-test:OnHistoryPurge");
|
||||
},
|
||||
|
||||
OnHistoryReload() {
|
||||
sendAsyncMessage("ss-test:OnHistoryReload");
|
||||
return true;
|
||||
},
|
||||
|
||||
OnHistoryReplaceEntry() {
|
||||
sendAsyncMessage("ss-test:OnHistoryReplaceEntry");
|
||||
},
|
||||
|
||||
QueryInterface: ChromeUtils.generateQI([
|
||||
Ci.nsISHistoryListener,
|
||||
Ci.nsISupportsWeakReference,
|
||||
]),
|
||||
};
|
||||
|
||||
var { sessionHistory } = docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||
if (sessionHistory) {
|
||||
sessionHistory.legacySHistory.addSHistoryListener(historyListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* This frame script is only loaded for sessionstore mochitests. It enables us
|
||||
* to modify and query docShell data when running with multiple processes.
|
||||
*/
|
||||
|
||||
addEventListener(
|
||||
"hashchange",
|
||||
function() {
|
||||
sendAsyncMessage("ss-test:hashchange");
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
addMessageListener("ss-test:getStyleSheets", function(msg) {
|
||||
let sheets = content.document.styleSheets;
|
||||
let titles = Array.from(sheets, ss => [ss.title, ss.disabled]);
|
||||
sendSyncMessage("ss-test:getStyleSheets", titles);
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:enableStyleSheetsForSet", function(msg) {
|
||||
let sheets = content.document.styleSheets;
|
||||
let change = false;
|
||||
for (let i = 0; i < sheets.length; i++) {
|
||||
if (sheets[i].disabled != !msg.data.includes(sheets[i].title)) {
|
||||
change = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
function observer() {
|
||||
Services.obs.removeObserver(
|
||||
observer,
|
||||
"style-sheet-applicable-state-changed"
|
||||
);
|
||||
|
||||
// It's possible our observer will run before the one in
|
||||
// content-sessionStore.js. Therefore, we run ours a little
|
||||
// later.
|
||||
executeSoon(() => sendAsyncMessage("ss-test:enableStyleSheetsForSet"));
|
||||
}
|
||||
if (change) {
|
||||
// We don't want to reply until content-sessionStore.js has seen
|
||||
// the change.
|
||||
Services.obs.addObserver(observer, "style-sheet-applicable-state-changed");
|
||||
|
||||
content.document.enableStyleSheetsForSet(msg.data);
|
||||
} else {
|
||||
sendAsyncMessage("ss-test:enableStyleSheetsForSet");
|
||||
}
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:enableSubDocumentStyleSheetsForSet", function(msg) {
|
||||
let iframe = content.document.getElementById(msg.data.id);
|
||||
iframe.contentDocument.enableStyleSheetsForSet(msg.data.set);
|
||||
sendAsyncMessage("ss-test:enableSubDocumentStyleSheetsForSet");
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:getAuthorStyleDisabled", function(msg) {
|
||||
let { authorStyleDisabled } = docShell.contentViewer;
|
||||
sendSyncMessage("ss-test:getAuthorStyleDisabled", authorStyleDisabled);
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:setAuthorStyleDisabled", function(msg) {
|
||||
let markupDocumentViewer = docShell.contentViewer;
|
||||
markupDocumentViewer.authorStyleDisabled = msg.data;
|
||||
sendSyncMessage("ss-test:setAuthorStyleDisabled");
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:getScrollPosition", function(msg) {
|
||||
let frame = content;
|
||||
if (msg.data.hasOwnProperty("frame")) {
|
||||
frame = content.frames[msg.data.frame];
|
||||
}
|
||||
let x = {},
|
||||
y = {};
|
||||
frame.windowUtils.getVisualViewportOffset(x, y);
|
||||
sendAsyncMessage("ss-test:getScrollPosition", { x: x.value, y: y.value });
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:setScrollPosition", function(msg) {
|
||||
let frame = content;
|
||||
let { x, y } = msg.data;
|
||||
if (msg.data.hasOwnProperty("frame")) {
|
||||
frame = content.frames[msg.data.frame];
|
||||
}
|
||||
frame.scrollTo(x, y);
|
||||
|
||||
frame.addEventListener(
|
||||
"mozvisualscroll",
|
||||
function onScroll(event) {
|
||||
if (frame.document.ownerGlobal.visualViewport == event.target) {
|
||||
frame.removeEventListener("mozvisualscroll", onScroll, {
|
||||
mozSystemGroup: true,
|
||||
});
|
||||
sendAsyncMessage("ss-test:setScrollPosition");
|
||||
}
|
||||
},
|
||||
{ mozSystemGroup: true }
|
||||
);
|
||||
});
|
||||
|
||||
addMessageListener("ss-test:click", function({ data }) {
|
||||
content.document.getElementById(data.id).click();
|
||||
sendAsyncMessage("ss-test:click");
|
||||
});
|
||||
|
||||
addEventListener(
|
||||
"load",
|
||||
function(event) {
|
||||
let subframe = event.target != content.document;
|
||||
sendAsyncMessage("ss-test:loadEvent", {
|
||||
subframe,
|
||||
url: event.target.documentURI,
|
||||
});
|
||||
},
|
||||
true
|
||||
);
|
@ -15,7 +15,7 @@ const HTTPROOT = ROOT.replace(
|
||||
"chrome://mochitests/content/",
|
||||
"http://example.com/"
|
||||
);
|
||||
const FRAME_SCRIPTS = [ROOT + "content.js", ROOT + "content-forms.js"];
|
||||
const FRAME_SCRIPTS = [ROOT + "content-forms.js"];
|
||||
|
||||
for (let script of FRAME_SCRIPTS) {
|
||||
Services.mm.loadFrameScript(script, true);
|
||||
@ -662,6 +662,26 @@ function popPrefs() {
|
||||
return SpecialPowers.popPrefEnv();
|
||||
}
|
||||
|
||||
function setScrollPosition(bc, x, y) {
|
||||
return SpecialPowers.spawn(bc, [x, y], (childX, childY) => {
|
||||
return new Promise(resolve => {
|
||||
content.addEventListener(
|
||||
"mozvisualscroll",
|
||||
function onScroll(event) {
|
||||
if (content.document.ownerGlobal.visualViewport == event.target) {
|
||||
content.removeEventListener("mozvisualscroll", onScroll, {
|
||||
mozSystemGroup: true,
|
||||
});
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
{ mozSystemGroup: true }
|
||||
);
|
||||
content.scrollTo(childX, childY);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function checkScroll(tab, expected, msg) {
|
||||
let browser = tab.linkedBrowser;
|
||||
await TabStateFlusher.flush(browser);
|
||||
@ -676,3 +696,34 @@ function whenDomWindowClosedHandled(aCallback) {
|
||||
aCallback();
|
||||
}, "sessionstore-debug-domwindowclosed-handled");
|
||||
}
|
||||
|
||||
function promiseOnHistoryReplaceEntryInChild(browser) {
|
||||
return SpecialPowers.spawn(browser, [], () => {
|
||||
return new Promise(resolve => {
|
||||
var historyListener = {
|
||||
OnHistoryNewEntry() {},
|
||||
OnHistoryGotoIndex() {},
|
||||
OnHistoryPurge() {},
|
||||
OnHistoryReload() {
|
||||
return true;
|
||||
},
|
||||
|
||||
OnHistoryReplaceEntry() {
|
||||
resolve();
|
||||
},
|
||||
|
||||
QueryInterface: ChromeUtils.generateQI([
|
||||
Ci.nsISHistoryListener,
|
||||
Ci.nsISupportsWeakReference,
|
||||
]),
|
||||
};
|
||||
|
||||
var { sessionHistory } = this.docShell.QueryInterface(
|
||||
Ci.nsIWebNavigation
|
||||
);
|
||||
if (sessionHistory) {
|
||||
sessionHistory.legacySHistory.addSHistoryListener(historyListener);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user