Skip to content

Commit

Permalink
Add consume_user_activation() to testdriver.js
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed Nov 28, 2022
1 parent 4435c35 commit 81aa4c0
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
6 changes: 3 additions & 3 deletions html/user-activation/activation-trigger-keyboard-enter.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ <h1>Test for keyboard activation trigger for ENTER key</h1>
await test_driver.send_keys(document.body, ENTER_KEY);

await keydown_event;
let consumed = await consumeTransientActivation();
let consumed = await test_driver.consume_user_activation();
assert_true(consumed,
"ENTER keydown event should result in activation");

await keypress_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"ENTER keypress should have no activation after keydown consumption");

await keyup_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"ENTER keyup should have no activation after keydown consumption");
}, "Activation through ENTER keyboard event");
Expand Down
4 changes: 2 additions & 2 deletions html/user-activation/activation-trigger-keyboard-escape.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ <h1>Test for keyboard activation trigger for ESCAPE key</h1>
await test_driver.send_keys(document.body, ESCAPE_KEY);

await keydown_event;
let consumed = await consumeTransientActivation();
let consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"ESCAPE keydown event should not result in activation");

await keyup_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"ESCAPE keyup should have no activation after keydown consumption");
}, "Activation through ESCAPE keyboard event");
Expand Down
6 changes: 3 additions & 3 deletions html/user-activation/activation-trigger-mouse-left.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ <h1>Test for click activation trigger</h1>
await test_driver.click(document.body);

await mousedown_event;
let consumed = await consumeTransientActivation();
let consumed = await test_driver.consume_user_activation();
assert_true(consumed,
"mousedown event should result in activation");

await mouseup_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"mouseup should have no activation after mousedown consumption");

await click_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"click should have no activation after mousedown consumption");
}, "Activation through left-click mouse event");
Expand Down
8 changes: 4 additions & 4 deletions html/user-activation/activation-trigger-mouse-right.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ <h1>Test for right-click activation trigger</h1>
let contextmenu_event = getEvent('contextmenu');

await mousedown_event;
let consumed = await consumeTransientActivation();
let consumed = await test_driver.consume_user_activation();
assert_true(consumed,
"mousedown event should result in activation");

await mouseup_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"mouseup should have no activation after mousedown consumption");

await auxclick_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"auxclick should have no activation after mousedown consumption");

await contextmenu_event;
consumed = await consumeTransientActivation();
consumed = await test_driver.consume_user_activation();
assert_false(consumed,
"contextmenu should have no activation after mousedown consumption");
}, "Activation through right-click mouse event");
Expand Down
6 changes: 3 additions & 3 deletions html/user-activation/activation-trigger-pointerevent.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ <h1>Test for pointerevent click activation trigger</h1>
let click_event = getEvent('click');

await pointerdown_event;
let consumed_pointerdown = await consumeTransientActivation();
let consumed_pointerdown = await test_driver.consume_user_activation();
await pointerup_event;
let consumed_pointerup = await consumeTransientActivation();
let consumed_pointerup = await test_driver.consume_user_activation();
await click_event;
let consumed_click = await consumeTransientActivation();
let consumed_click = await test_driver.consume_user_activation();

if (pointer_type === "mouse") {
assert_true(consumed_pointerdown,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!DOCTYPE html>
<html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<head>
<script>
window.top.postMessage(JSON.stringify({
Expand All @@ -8,8 +10,8 @@
"hasBeenActive": navigator.userActivation.hasBeenActive
}), "*");

window.addEventListener("click", event => {
window.open().close();
window.addEventListener("click", async event => {
await test_driver.consume_user_activation();

window.top.postMessage(JSON.stringify({
"type": "child-crossorigin-report",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!DOCTYPE html>
<html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<head>
<script>
window.top.postMessage(JSON.stringify({
Expand All @@ -8,8 +10,8 @@
"hasBeenActive": navigator.userActivation.hasBeenActive
}), "*");

window.addEventListener("click", event => {
window.open().close();
window.addEventListener("click", async event => {
await test_driver.consume_user_activation();

window.top.postMessage(JSON.stringify({
"type": "child-sameorigin-report",
Expand Down
28 changes: 28 additions & 0 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,28 @@
set_spc_transaction_mode: function(mode, context=null) {
return window.test_driver_internal.set_spc_transaction_mode(mode, context);
},

/**
* Consumes the user activation
*
* Matches the `Consume User Activation of Window
* <https://w3c.github.io/permissions/#consume-user-activation-of-window>`
* WebDriver command.
*
* Which corresponds to these steps in HTML:
* https://html.spec.whatwg.org/#consume-user-activation
*
* @example
* await test_driver.consume_user_activation();
* await test_driver.consume_user_activation(iframe.contentWindow);
*
* @param {WindowProxy?} [context=null] - Browsing context in which to run the
* call.
* @returns {Promise<boolean>} fulfilled when user activation is consumed.
*/
consume_user_activation(context=null) {
return window.test_driver_internal.consume_user_activation(context);
},
};

window.test_driver_internal = {
Expand Down Expand Up @@ -774,5 +796,11 @@
return Promise.reject(new Error("unimplemented"));
},

async consume_user_activation () {
if (this.in_automation) {
throw new Error('Not implemented');
}
},

};
})();

0 comments on commit 81aa4c0

Please sign in to comment.