Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Recursive Loads</title>
<meta charset="utf-8">
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
const TEST_CASES = [
{ // too many recursive iframes
frameId: "recursiveFrame",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"about:blank",
],
},
{ // too many recursive iframes
frameId: "twoRecursiveIframes",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"about:blank",
],
},
{ // too many recursive iframes
frameId: "threeRecursiveIframes",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"about:blank",
],
},
{ // too many nested iframes
frameId: "sixRecursiveIframes",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
],
},
{ // too many recursive objects
frameId: "recursiveObject",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
],
},
{ // 3 nested srcdocs, should show all of them
frameId: "nestedSrcdoc",
expectedLocations: [
"about:srcdoc",
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"about:srcdoc",
"about:srcdoc",
],
},
{ // too many recursive dynamically created iframes
frameId: "dynamicrecursive",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"about:blank"
],
},
{ // navigating shouldn't be blocked by recursion check
frameId: "navigationIsNotRecursive",
expectedLocations: [
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"about:blank"
],
},
];
async function checkRecursiveLoad(level) {
let el = content.document.getElementById("static") || content.document.getElementById("dynamic");
let documentURI = await SpecialPowers.spawn(
el,
[],
() => this.content.document.documentURI
);
if (documentURI == "about:blank") {
// If we had too many recursive frames, the most inner iframe's uri will be about:blank
return [documentURI];
}
if (documentURI == "about:srcdoc" && level == 3) {
// Check that we have the correct most inner srcdoc iframe
let innerText = await SpecialPowers.spawn(
el,
[],
() => this.content.document.body.innerText
);
is(innerText, "Third nested srcdoc", "correct most inner srcdoc iframe");
}
let nestedIfrOrObjectURI = [];
try {
// Throws an error when we have too many nested frames/objects, because we
// claim to have no content window for the inner most frame/object.
nestedIfrOrObjectURI = await SpecialPowers.spawn(
el,
[level + 1],
checkRecursiveLoad
);
} catch (err) {
info(
`Tried to spawn another task in the iframe/object, but got err: ${err}, must have had too many nested iframes/objects\n`
);
}
return [documentURI, ...nestedIfrOrObjectURI];
}
add_task(async () => {
for (const testCase of TEST_CASES) {
let el = document.getElementById(testCase.frameId);
let loc = await SpecialPowers.spawn(
el,
[],
() => this.content.location.href
);
let locations = await SpecialPowers.spawn(el, [1], checkRecursiveLoad);
isDeeply(
[loc, ...locations],
testCase.expectedLocations,
"iframes/object loaded in correct order"
);
}
});
</script>
</pre>
<div>
<iframe style="height: 100vh; width:25%;" id="recursiveFrame" src="http://example.com/tests/docshell/test/navigation/frame_recursive.html"></iframe>
<iframe style="height: 100vh; width:25%;" id="twoRecursiveIframes" src="http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html"></iframe>
<iframe style="height: 100vh; width:25%;" id="threeRecursiveIframes" src="http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html"></iframe>
<iframe style="height: 100vh; width:25%;" id="sixRecursiveIframes" src="http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html"></iframe>
<object width="400" height="300" id="recursiveObject" data="http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html"></object>
<iframe id="nestedSrcdoc" srcdoc="Srcdoc that will embed an iframe &lt;iframe id=&quot;static&quot; src=&quot;http://example.com/tests/docshell/test/navigation/file_nested_srcdoc.html&quot;&gt;&lt;/iframe&gt;"></iframe>
<iframe style="height: 100vh; width:25%;" id="dynamicrecursive" src="http://example.com/tests/docshell/test/navigation/frame_recursive_dynamic.html"></iframe>
<iframe style="height: 100vh; width:25%;" id="navigationIsNotRecursive" src="http://example.com/tests/docshell/test/navigation/frame_recursive_target.html"></iframe>
</div>
</body>
</html>