Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<title>Test that submitting a target=_blank form consumes userActivation</title>
<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>
<div id=log></div>
<form action=resources/endpoint.html target=_blank>
<input type=hidden name=channelname>
<button>Submit</button>
</form>
<script>
function waitForNewWindow(aChannelName) {
return new Promise(resolve => {
let channel = new BroadcastChannel(aChannelName);
channel.addEventListener("message", () => {
assert_true(true, "new window is opened");
channel.postMessage("close");
resolve();
}, {once: true});
});
}
function testFormSubmission(aChannelName, aSubmitFun, aMsg) {
promise_test(async () => {
document.querySelector("input").value = aChannelName;
await test_driver.bless('transient activation');
assert_true(navigator.userActivation.isActive, 'should have user activation');
let newWindowPromise = waitForNewWindow(aChannelName);
aSubmitFun();
await newWindowPromise;
assert_false(navigator.userActivation.isActive, 'navigator.userActivation.isActive after opening a new window');
}, aMsg);
}
testFormSubmission(`${Date.now()}_script_submit`, () => {
document.querySelector("form").submit();
}, `<form target=_blank>.submit()`);
testFormSubmission(`${Date.now()}_script_requestSubmit`, () => {
document.querySelector("form").requestSubmit();
}, `<form target=_blank>.requestSubmit()`);
testFormSubmission(`${Date.now()}_click_submit`, () => {
test_driver.click(document.querySelector("button"));
}, `<form target=_blank> click submit`);
</script>