Bug 1586119: Part 2 - Fix some more tests to almost work under Fission. r=mccr8

These still fail or timeout because of missing platform features, but at least
the tests will pass once those platform features are fixed after this.

Differential Revision: https://phabricator.services.mozilla.com/D48221

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kris Maglione 2019-10-04 21:50:34 +00:00
parent b8a4406b8e
commit 147f1b5141
9 changed files with 105 additions and 28 deletions

View File

@ -864,6 +864,13 @@ void BrowsingContext::Blur(ErrorResult& aError) {
}
}
Nullable<WindowProxyHolder> BrowsingContext::GetWindow() {
if (XRE_IsParentProcess() && !IsInProcess()) {
return nullptr;
}
return WindowProxyHolder(this);
}
Nullable<WindowProxyHolder> BrowsingContext::GetTop(ErrorResult& aError) {
if (mIsDiscarded) {
return nullptr;

View File

@ -305,6 +305,8 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
mWindowProxy = aWindowProxy;
}
Nullable<WindowProxyHolder> GetWindow();
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BrowsingContext)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(BrowsingContext)

View File

@ -224,3 +224,58 @@ function xpcWaitForFinishedFrames(callback, numFrames) {
var frameWaitInterval = setInterval(poll, 500);
}
function delay(msec) {
return new Promise(resolve => setTimeout(resolve, msec));
}
async function waitForFinishedFrames(numFrames) {
SimpleTest.requestFlakyTimeout("Polling");
var finishedWindows = new Set();
async function searchForFinishedFrames(win) {
try {
let { href, bodyText, readyState } = await SpecialPowers.spawn(
win,
[],
() => {
return {
href: this.content.location.href,
bodyText:
this.content.document.body &&
this.content.document.body.textContent.trim(),
readyState: this.content.document.readyState,
};
}
);
if (
(href.endsWith(target_url) || href.endsWith(target_popup_url)) &&
(bodyText == body || bodyText == popup_body) &&
readyState == "complete"
) {
finishedWindows.add(SpecialPowers.getBrowsingContextID(win));
}
} catch (e) {
// This may throw if a frame is not fully initialized, in which
// case we'll handle it in a later iteration.
}
for (let i = 0; i < win.frames.length; i++) {
await searchForFinishedFrames(win.frames[i]);
}
}
while (finishedWindows.size < numFrames) {
await delay(500);
for (let win of SpecialPowers.getGroupTopLevelWindows(window)) {
await searchForFinishedFrames(win);
}
}
if (finishedWindows.size > numFrames) {
throw new Error("Too many frames loaded.");
}
}

View File

@ -94,7 +94,7 @@ support-files = file_bug1379762-1.html
[test_sibling-matching-parent.html]
skip-if = fission # Times out.
[test_sibling-off-domain.html]
skip-if = fission # Times out.
fail-if = fission
[test_triggeringprincipal_frame_nav.html]
[test_triggeringprincipal_window_open.html]
[test_triggeringprincipal_parent_iframe_window_open.html]

View File

@ -12,8 +12,8 @@
/* eslint-disable no-useless-concat */
/* global window0:true, window1:true, window2:true, window3:true */
var headerHTML = "<html><head>" +
"<script src='/tests/SimpleTest/EventUtils.js'></scr" + "ipt>" +
"<script src='NavigationUtils.js'></scr" + "ipt>" +
"<script src='/tests/SimpleTest/EventUtils.js'><\/script>" +
"<script src='NavigationUtils.js'><\/script>" +
"</head><body>";
var footerHTML = "</body></html>";
@ -22,7 +22,7 @@ function testChild0() {
window0 = window.open("", "window0", "width=10,height=10");
window0.document.open();
window0.document.write(headerHTML);
window0.document.write("<script>navigateByLocation(opener.frames[0])</scr" + "ipt>");
window0.document.write("<script>navigateByLocation(opener.frames[0])<\/script>");
window0.document.write(footerHTML);
window0.document.close();
}
@ -33,7 +33,7 @@ function testChild1() {
window1 = window.open("", "window1", "width=10,height=10");
window1.document.open();
window1.document.write(headerHTML);
window1.document.write("<script>navigateByOpen('child1');</scr" + "ipt>");
window1.document.write("<script>navigateByOpen('child1');<\/script>");
window1.document.write(footerHTML);
window1.document.close();
}
@ -44,7 +44,7 @@ function testChild2() {
window2 = window.open("", "window2", "width=10,height=10");
window2.document.open();
window2.document.write(headerHTML);
window2.document.write("<script>navigateByForm('child2');</scr" + "ipt>");
window2.document.write("<script>navigateByForm('child2');<\/script>");
window2.document.write(footerHTML);
window2.document.close();
}
@ -55,13 +55,15 @@ function testChild3() {
window3 = window.open("", "window3", "width=10,height=10");
window3.document.open();
window3.document.write(headerHTML);
window3.document.write("<script>navigateByHyperlink('child3');</scr" + "ipt>");
window3.document.write("<script>navigateByHyperlink('child3');<\/script>");
window3.document.write(footerHTML);
window3.document.close();
}
}
xpcWaitForFinishedFrames(async function() {
add_task(async function() {
await waitForFinishedFrames(4);
await isNavigated(frames[0], "Should be able to navigate on-domain opener's children by setting location.");
await isNavigated(frames[1], "Should be able to navigate on-domain opener's children by calling window.open.");
await isNavigated(frames[2], "Should be able to navigate on-domain opener's children by submitting form.");
@ -73,7 +75,6 @@ xpcWaitForFinishedFrames(async function() {
window3.close();
xpcCleanupWindows();
SimpleTest.finish();
}, 4);
</script>
@ -88,7 +89,6 @@ xpcWaitForFinishedFrames(async function() {
</div>
<pre id="test">
<script type="text/javascript">
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>

View File

@ -9,22 +9,22 @@
iframe { width: 90%; height: 50px; }
</style>
<script>
window.onload = function() {
window.onload = async function() {
document.getElementById("active").innerHTML =
'<iframe src="navigate.html#parent.frames[0],location"></iframe>' +
'<iframe src="navigate.html#child1,open"></iframe>' +
'<iframe src="navigate.html#child2,form"></iframe>' +
'<iframe src="navigate.html#child3,hyperlink"></iframe>';
xpcWaitForFinishedFrames(async function() {
await isNavigated(frames[0], "Should be able to navigate sibling with on-domain parent by setting location.");
await isNavigated(frames[1], "Should be able to navigate sibling with on-domain parent by calling window.open.");
await isNavigated(frames[2], "Should be able to navigate sibling with on-domain parent by submitting form.");
await isNavigated(frames[3], "Should be able to navigate sibling with on-domain parent by targeted hyperlink.");
await waitForFinishedFrames(4);
xpcCleanupWindows();
SimpleTest.finish();
}, 4);
await isNavigated(frames[0], "Should be able to navigate sibling with on-domain parent by setting location.");
await isNavigated(frames[1], "Should be able to navigate sibling with on-domain parent by calling window.open.");
await isNavigated(frames[2], "Should be able to navigate sibling with on-domain parent by submitting form.");
await isNavigated(frames[3], "Should be able to navigate sibling with on-domain parent by targeted hyperlink.");
xpcCleanupWindows();
SimpleTest.finish();
};
</script>
</head>

View File

@ -9,22 +9,22 @@
iframe { width: 90%; height: 50px; }
</style>
<script>
window.onload = function() {
window.onload = async function() {
document.getElementById("active").innerHTML =
'<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#parent.frames[0],location"></iframe>' +
'<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child1,open"></iframe>' +
'<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child2,form"></iframe>' +
'<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child3,hyperlink"></iframe>';
xpcWaitForFinishedFrames(function() {
isBlank(frames[0], "Should not be able to navigate off-domain sibling by setting location.");
isBlank(frames[1], "Should not be able to navigate off-domain sibling by calling window.open.");
isBlank(frames[2], "Should not be able to navigate off-domain sibling by submitting form.");
isBlank(frames[3], "Should not be able to navigate off-domain sibling by targeted hyperlink.");
await waitForFinishedFrames(4);
xpcCleanupWindows();
SimpleTest.finish();
}, 4);
isBlank(frames[0], "Should not be able to navigate off-domain sibling by setting location.");
isBlank(frames[1], "Should not be able to navigate off-domain sibling by calling window.open.");
isBlank(frames[2], "Should not be able to navigate off-domain sibling by submitting form.");
isBlank(frames[3], "Should not be able to navigate off-domain sibling by targeted hyperlink.");
xpcCleanupWindows();
SimpleTest.finish();
};
</script>
</head>

View File

@ -31,6 +31,8 @@ interface BrowsingContext {
readonly attribute BrowsingContext? opener;
readonly attribute BrowsingContextGroup group;
readonly attribute WindowProxy? window;
};
[Exposed=Window, ChromeOnly]

View File

@ -1613,6 +1613,17 @@ class SpecialPowersChild extends JSWindowActorChild {
return BrowsingContext.getFromWindow(target);
}
getBrowsingContextID(target) {
return this._browsingContextForTarget(target).id;
}
*getGroupTopLevelWindows(target) {
let { group } = this._browsingContextForTarget(target);
for (let bc of group.getToplevels()) {
yield bc.window;
}
}
/**
* Runs a task in the context of the given frame, and returns a
* promise which resolves to the return value of that task.