Skip to content

Commit

Permalink
Fix encoding name ; factor out common code into a separate support file.
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-wang committed Mar 9, 2018
1 parent 4c15431 commit bbffdc5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 76 deletions.
@@ -1,29 +1,13 @@
<!DOCTYPE html>
<meta charset="uft-8">
<meta charset="utf-8">
<title>iframe sandbox without allow_modals (alert)</title>
<link rel="author" title="Igalia" href="https://www.igalia.com/">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-iframe-sandbox">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-iframe-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe sandbox="allow-scripts"></iframe>
<script src="support/iframe_sandbox_block_modals.js"></script>
<script>
let modalName = "alert";
let expectedValue = undefined;

let timeOutForFailingToOpenModal = 500;
let startTime;
async_test(t => {
let iframe = document.querySelector("iframe");
iframe.onload = function() {
window.addEventListener("message", t.step_func_done(e => {
e.source.close();
assert_less_than(new Date().getTime() - startTime, timeOutForFailingToOpenModal, "Call to open modal dialog did not return immediately");
assert_equals(e.data, expectedValue, "Call to open modal dialog did not return expected value");
}));
startTime = new Date().getTime();
iframe.contentWindow.postMessage(modalName, "*");
}
iframe.src = "support/iframe-that-opens-modals.html";
}, "Frames without `allow-modals` should not be able to open modal dialogs");
runTest("alert", undefined);
</script>
@@ -1,29 +1,13 @@
<!DOCTYPE html>
<meta charset="uft-8">
<meta charset="utf-8">
<title>iframe sandbox without allow_modals (confirm)</title>
<link rel="author" title="Igalia" href="https://www.igalia.com/">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-iframe-sandbox">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-iframe-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe sandbox="allow-scripts"></iframe>
<script src="support/iframe_sandbox_block_modals.js"></script>
<script>
let modalName = "confirm";
let expectedValue = false;

let timeOutForFailingToOpenModal = 500;
let startTime;
async_test(t => {
let iframe = document.querySelector("iframe");
iframe.onload = function() {
window.addEventListener("message", t.step_func_done(e => {
e.source.close();
assert_less_than(new Date().getTime() - startTime, timeOutForFailingToOpenModal, "Call to open modal dialog did not return immediately");
assert_equals(e.data, expectedValue, "Call to open modal dialog did not return expected value");
}));
startTime = new Date().getTime();
iframe.contentWindow.postMessage(modalName, "*");
}
iframe.src = "support/iframe-that-opens-modals.html";
}, "Frames without `allow-modals` should not be able to open modal dialogs");
runTest("confirm", false);
</script>
@@ -1,29 +1,13 @@
<!DOCTYPE html>
<meta charset="uft-8">
<meta charset="utf-8">
<title>iframe sandbox without allow_modals (prompt)</title>
<link rel="author" title="Igalia" href="https://www.igalia.com/">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-iframe-sandbox">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-iframe-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe sandbox="allow-scripts"></iframe>
<script src="support/iframe_sandbox_block_modals.js"></script>
<script>
let modalName = "prompt";
let expectedValue = null;

let timeOutForFailingToOpenModal = 500;
let startTime;
async_test(t => {
let iframe = document.querySelector("iframe");
iframe.onload = function() {
window.addEventListener("message", t.step_func_done(e => {
e.source.close();
assert_less_than(new Date().getTime() - startTime, timeOutForFailingToOpenModal, "Call to open modal dialog did not return immediately");
assert_equals(e.data, expectedValue, "Call to open modal dialog did not return expected value");
}));
startTime = new Date().getTime();
iframe.contentWindow.postMessage(modalName, "*");
}
iframe.src = "support/iframe-that-opens-modals.html";
}, "Frames without `allow-modals` should not be able to open modal dialogs");
runTest("prompt", null);
</script>
@@ -1,29 +1,13 @@
<!DOCTYPE html>
<meta charset="uft-8">
<meta charset="utf-8">
<title>iframe sandbox without allow_modals (print)</title>
<link rel="author" title="Igalia" href="https://www.igalia.com/">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-iframe-sandbox">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-iframe-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe sandbox="allow-scripts"></iframe>
<script src="support/iframe_sandbox_block_modals.js"></script>
<script>
let modalName = "print";
let expectedValue = undefined;

let timeOutForFailingToOpenModal = 500;
let startTime;
async_test(t => {
let iframe = document.querySelector("iframe");
iframe.onload = function() {
window.addEventListener("message", t.step_func_done(e => {
e.source.close();
assert_less_than(new Date().getTime() - startTime, timeOutForFailingToOpenModal, "Call to open modal dialog did not return immediately");
assert_equals(e.data, expectedValue, "Call to open modal dialog did not return expected value");
}));
startTime = new Date().getTime();
iframe.contentWindow.postMessage(modalName, "*");
}
iframe.src = "support/iframe-that-opens-modals.html";
}, "Frames without `allow-modals` should not be able to open modal dialogs");
runTest("print", undefined);
</script>
@@ -0,0 +1,17 @@
function runTest(modalName, expectedValue) {
let timeOutForFailingToOpenModal = 500;
let startTime;
async_test(t => {
let iframe = document.querySelector("iframe");
iframe.onload = function() {
window.addEventListener("message", t.step_func_done(e => {
e.source.close();
assert_less_than(new Date().getTime() - startTime, timeOutForFailingToOpenModal, "Call to open modal dialog did not return immediately");
assert_equals(e.data, expectedValue, "Call to open modal dialog did not return expected value");
}));
startTime = new Date().getTime();
iframe.contentWindow.postMessage(modalName, "*");
}
iframe.src = "support/iframe-that-opens-modals.html";
}, "Frames without `allow-modals` should not be able to open modal dialogs");
}

0 comments on commit bbffdc5

Please sign in to comment.