Skip to content

Commit

Permalink
Test user clicks on <a>s
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed May 21, 2021
1 parent 97fc6b0 commit 31dccb1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
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,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
Expand Up @@ -2,6 +2,7 @@
<meta charset="utf-8">
<title>Subframe</title>

<body>
<script>
"use strict";
{{GET[code]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ window.insertIframe = (t, url) => {
const iframe = document.createElement("iframe");
iframe.src = url;
document.body.append(iframe);
t.add_cleanup(() => iframe.remove());

// Intentionally not including the following:
// t.add_cleanup(() => iframe.remove());
// Doing so breaks some of the testdriver.js tests with "cannot find window" errors.
return iframe;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Subframe</title>

<body>
<script>
"use strict";
{{GET[code]}}
</script>

<!-- This is necessary in cases involving user interaction because those happen async through the webdriver infrastructure -->
<img src="/common/slow.py">

0 comments on commit 31dccb1

Please sign in to comment.