Skip to content

Commit

Permalink
Bug 1930930 [wpt PR 49138] - HTML: Consume user activation for window…
Browse files Browse the repository at this point in the history
….open (multi-global test), a=testonly

Automatic update from web-platform-tests
HTML: Consume user activation for window.open (multi-global test)

See whatwg/html#10547
--

wpt-commits: 5ec8ba6d68f27d49a056cbf940e3bc9a8324c538
wpt-pr: 49138

UltraBlame original commit: 3da7235374ed270a493d09f34f3c394c87b74de9
  • Loading branch information
marco-c committed Dec 1, 2024
1 parent 8eb3a36 commit e0566e7
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Current page used as a test helper</title>
<button id="focus-opener-button" onclick="opener.focus()">Focus opener</button>
<script>
'use strict';

onload = async () => {
await opener.opener.test_driver.click(document.getElementById("focus-opener-button"));
opener.postMessage("current page", "*");
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<title>Incumbent page used as a test helper</title>
<button id="focus-opener-button" onclick="opener.focus()">Focus opener</button>
<script>
'use strict';

function pageDone(expectedMessage) {
return new Promise(resolve => {
window.addEventListener('message', e => {
if (e.data === expectedMessage) {
resolve();
}
});
});
}

onload = async () => {
await opener.test_driver.bless("open current popup", null, window);
const currentDone = pageDone("current page");
const currentWin = window.open("current.html", "_blank");
await currentDone;
await opener.test_driver.bless("open relevant popup", null, window);
const relevantDone = pageDone("relevant page");
const relevantWin = window.open("relevant.html", "_blank");
await relevantDone;
window.openTestPopup = function() {
// This is the multi-global incarnation
return currentWin.open.call(relevantWin, "/resources/blank.html", "_blank");
};
opener.currentWin = currentWin;
opener.relevantWin = relevantWin;
await opener.test_driver.click(document.getElementById("focus-opener-button"));
opener.postMessage("incumbent page", "*");
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Relevant page used as a test helper</title>
<button id="focus-opener-button" onclick="opener.focus()">Focus opener</button>
<script>
'use strict';

onload = async () => {
await opener.opener.test_driver.click(document.getElementById("focus-opener-button"));
opener.postMessage("relevant page", "*");
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<title>window.open() and consuming user activation with multiple globals in play</title>
<link rel="help" href="https://html.spec.whatwg.org/#window-open-steps">
<link rel="help" href="https://html.spec.whatwg.org/#the-rules-for-choosing-a-navigable">
<!--
2. Let sourceDocument be the entry global object's associated Document.
10. Let targetNavigable and windowType be the result of applying the rules for choosing a navigable
given target, sourceDocument's node navigable, and noopener.
-->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<!-- This is the entry global -->

<script>
'use strict';

function pageDone(expectedMessage) {
return new Promise(resolve => {
window.addEventListener('message', e => {
if (e.data === expectedMessage) {
resolve();
}
});
});
}

promise_test(async function(t) {
await test_driver.bless("open incumbent popup");
const incumbentDone = pageDone("incumbent page");
const incumbentWin = window.open("support/incumbent.html", "_blank");
// incumbent.html opens two further popups and sets these properties (for this window):
// window.currentWin
// window.relevantWin
await incumbentDone;
await test_driver.bless("user activation in entry global");
const testWin = incumbentWin.openTestPopup();
t.add_cleanup(() => {
testWin.close();
relevantWin.close();
currentWin.close();
incumbentWin.close();
});
assert_false(navigator.userActivation.isActive, "User activation of the entry global should be consumed");
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>window.open() and consuming user activation</title>
<link rel="help" href="https://html.spec.whatwg.org/#the-rules-for-choosing-a-navigable">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
'use strict';

promise_test(async function(t) {
await test_driver.bless("user activation");
const testWin = window.open("/resources/blank.html", "_blank");
t.add_cleanup(() => {
testWin.close();
});
assert_false(navigator.userActivation.isActive, "User activation should be consumed");
});
</script>

0 comments on commit e0566e7

Please sign in to comment.