-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test <meta> refresh behavior when moving between documents
Tests for whatwg/html#2198.
- Loading branch information
Showing
4 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...element/pragma-directives/attr-meta-http-equiv-refresh/allow-scripts-flag-changing-1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Meta refresh is blocked by the allow-scripts sandbox flag at its creation time, not when refresh comes due</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh"> | ||
|
||
<div id="log"></div> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const sourceIFrame = document.createElement("iframe"); | ||
sourceIFrame.setAttribute("sandbox", "allow-same-origin"); | ||
|
||
const destIFrame = document.createElement("iframe"); | ||
|
||
let sourceLoadCount = 0; | ||
let destLoadCount = 0; | ||
|
||
sourceIFrame.onload = () => { | ||
++sourceLoadCount; | ||
|
||
if (sourceLoadCount === 2) { | ||
assert_unreached("The iframe from which the meta came from must not refresh"); | ||
} | ||
|
||
maybeStartTest(); | ||
}; | ||
|
||
destIFrame.onload = () => { | ||
++destLoadCount; | ||
|
||
if (destLoadCount === 2) { | ||
assert_unreached("The iframe into which the meta was moved must not refresh"); | ||
} | ||
|
||
maybeStartTest(); | ||
}; | ||
|
||
function maybeStartTest() { | ||
if (sourceLoadCount === 1 && destLoadCount === 1) { | ||
// Test that no refreshes occur within 3 seconds | ||
step_timeout(done, 3000); | ||
|
||
const meta = sourceIFrame.contentDocument.querySelector("meta"); | ||
destIFrame.contentDocument.body.appendChild(meta); | ||
} | ||
} | ||
|
||
sourceIFrame.src = "support/refresh.sub.html?input=" + encodeURIComponent("1; url=foo"); | ||
destIFrame.src = "support/ufoo"; | ||
|
||
document.body.appendChild(sourceIFrame); | ||
document.body.appendChild(destIFrame); | ||
</script> |
54 changes: 54 additions & 0 deletions
54
...element/pragma-directives/attr-meta-http-equiv-refresh/allow-scripts-flag-changing-2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Meta refresh of the original iframe is not blocked if moved into a sandboxed iframe</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh"> | ||
|
||
<div id="log"></div> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const sourceIFrame = document.createElement("iframe"); | ||
|
||
const destIFrame = document.createElement("iframe"); | ||
destIFrame.setAttribute("sandbox", "allow-same-origin"); | ||
|
||
let sourceLoadCount = 0; | ||
let destLoadCount = 0; | ||
|
||
sourceIFrame.onload = () => { | ||
++sourceLoadCount; | ||
|
||
if (sourceLoadCount === 2) { | ||
assert_equals(sourceIFrame.contentDocument.body.textContent.trim(), "foo"); | ||
done(); | ||
} | ||
|
||
maybeStartTest(); | ||
}; | ||
|
||
destIFrame.onload = () => { | ||
++destLoadCount; | ||
|
||
if (destLoadCount === 2) { | ||
assert_unreached("The iframe into which the meta was moved must not refresh"); | ||
} | ||
|
||
maybeStartTest(); | ||
}; | ||
|
||
function maybeStartTest() { | ||
if (sourceLoadCount === 1 && destLoadCount === 1) { | ||
const meta = sourceIFrame.contentDocument.querySelector("meta"); | ||
destIFrame.contentDocument.body.appendChild(meta); | ||
} | ||
} | ||
|
||
sourceIFrame.src = "support/refresh.sub.html?input=" + encodeURIComponent("1; url=foo"); | ||
destIFrame.src = "support/ufoo"; | ||
|
||
document.body.appendChild(sourceIFrame); | ||
document.body.appendChild(destIFrame); | ||
</script> |
30 changes: 30 additions & 0 deletions
30
...adata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/dynamic-append.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Meta refresh applies even when dynamically appended</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#pragma-directives"> | ||
|
||
<div id="log"></div> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const iframe = document.createElement("iframe"); | ||
let loadCount = 0; | ||
|
||
iframe.onload = () => { | ||
++loadCount; | ||
const iDocument = iframe.contentDocument; | ||
|
||
if (loadCount === 1) { | ||
iDocument.body.innerHTML = `<meta http-equiv="refresh" content="1; url=foo">`; | ||
} else if (loadCount === 2) { | ||
assert_equals(iDocument.body.textContent.trim(), "foo"); | ||
done(); | ||
} | ||
}; | ||
|
||
iframe.src = "support/ufoo"; | ||
document.body.appendChild(iframe); | ||
</script> |
51 changes: 51 additions & 0 deletions
51
...ata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/moving-documents.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>When moving between documents, must refresh the original document</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh"> | ||
|
||
<div id="log"></div> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const sourceIFrame = document.createElement("iframe"); | ||
const destIFrame = document.createElement("iframe"); | ||
let sourceLoadCount = 0; | ||
let destLoadCount = 0; | ||
|
||
sourceIFrame.onload = () => { | ||
++sourceLoadCount; | ||
|
||
if (sourceLoadCount === 2) { | ||
assert_equals(sourceIFrame.contentDocument.body.textContent.trim(), "foo"); | ||
done(); | ||
} | ||
|
||
maybeStartTest(); | ||
}; | ||
|
||
destIFrame.onload = () => { | ||
++destLoadCount; | ||
|
||
if (destLoadCount === 2) { | ||
assert_unreached("The iframe into which the meta was moved must not refresh"); | ||
} | ||
|
||
maybeStartTest(); | ||
}; | ||
|
||
function maybeStartTest() { | ||
if (sourceLoadCount === 1 && destLoadCount === 1) { | ||
const meta = sourceIFrame.contentDocument.querySelector("meta"); | ||
destIFrame.contentDocument.body.appendChild(meta); | ||
} | ||
} | ||
|
||
sourceIFrame.src = "support/refresh.sub.html?input=" + encodeURIComponent("1; url=foo"); | ||
destIFrame.src = "support/ufoo"; | ||
|
||
document.body.appendChild(sourceIFrame); | ||
document.body.appendChild(destIFrame); | ||
</script> |