Skip to content

Commit

Permalink
Test replace vs. push before/during load and pageshow
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic authored Jun 24, 2021
1 parent 861f0cb commit c1bb1fd
Show file tree
Hide file tree
Showing 45 changed files with 1,628 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
document.body.append(a);
a.click();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "aElement.click() during the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onpageshow = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
document.body.append(a);
a.click();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "aElement.click() during the pageshow event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
document.currentScript.before(a);
a.click();
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoad(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "aElement.click() before the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
a.id = "the-anchor";
a.textContent = "needs to have content to be clickable";
document.body.append(a);
parent.test_driver.click(a);
};
`;

const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "User click on <a> during the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onpageshow = () => {
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
a.id = "the-anchor";
a.textContent = "needs to have content to be clickable";
document.body.append(a);
parent.test_driver.click(a);
};
`;

const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "User click on <a> during the pageshow event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
const a = document.createElement("a");
a.href = "/common/blank.html?thereplacement";
a.id = "the-anchor";
a.textContent = "needs to have content to be clickable";
document.currentScript.before(a);
parent.test_driver.click(a);
`;

const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoad(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load");
}, "User click on <a> before the load event must NOT replace");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
document.body.append(form);
form.requestSubmit();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace during the load event, triggered by formElement.submit()");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onpageshow = () => {
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
document.body.append(form);
form.requestSubmit();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace during the pageshow event, triggered by formElement.submit()");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
document.currentScript.before(form);
form.requestSubmit();
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoad(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace before load, triggered by formElement.requestSubmit()");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<body>
<script>
"use strict";
promise_test(async t => {
const sentinelIframe = await setupSentinelIframe(t);
const startingHistoryLength = history.length;

const code = `
window.onload = () => {
const form = document.createElement("form");
form.action = "/common/blank.html";
const input = document.createElement("input");
input.type = "hidden";
input.name = "thereplacement";
form.append(input);
const button = document.createElement("button");
button.type = "submit";
form.append(button);
document.body.append(form);
button.click();
};
`;

const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
const afterReplacementURL = "/common/blank.html?thereplacement=";
const iframe = insertIframe(t, startURL);

assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");

await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");

await checkSentinelIframe(t, sentinelIframe);
assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
}, "Replace during load, triggered by submitButton.click()");
</script>
Loading

0 comments on commit c1bb1fd

Please sign in to comment.