summaryrefslogtreecommitdiffstats
path: root/dom/base/test/useractivation/test_useractivation_key_events.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/test/useractivation/test_useractivation_key_events.html')
-rw-r--r--dom/base/test/useractivation/test_useractivation_key_events.html91
1 files changed, 91 insertions, 0 deletions
diff --git a/dom/base/test/useractivation/test_useractivation_key_events.html b/dom/base/test/useractivation/test_useractivation_key_events.html
new file mode 100644
index 0000000000..d97906c22b
--- /dev/null
+++ b/dom/base/test/useractivation/test_useractivation_key_events.html
@@ -0,0 +1,91 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>User activation test: key events</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script>
+
+function synthesizeKeyAndWait(aKey, aEvent) {
+ let promise = new Promise(aResolve => {
+ document.addEventListener("keydown", function(e) {
+ e.preventDefault();
+ aResolve();
+ }, { once: true });
+ });
+ synthesizeKey(aKey, aEvent, window);
+ return promise;
+}
+
+add_task(async function TestPrintableKey() {
+ let tests = [ 'a', 'b', 'c', 'A', 'B', '1', '2', '3' ];
+
+ for (let key of tests) {
+ SpecialPowers.wrap(document).clearUserGestureActivation();
+ await synthesizeKeyAndWait(key, {});
+ ok(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
+ `check has-been-user-activated for ${key}`);
+ ok(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
+ `check has-valid-transient-user-activation for ${key}`);
+ }
+});
+
+add_task(async function TestNonPrintableKey() {
+ let tests = [ [ "KEY_Alt", false],
+ [ "KEY_Backspace", false],
+ [ "KEY_Escape" , false ],
+ [ "KEY_Tab" , false ],
+ // Treat as user input
+ [ "KEY_Enter", true],
+ [ " ", true] ];
+
+ for (let [key, expectedResult] of tests) {
+ SpecialPowers.wrap(document).clearUserGestureActivation();
+ await synthesizeKeyAndWait(key, {});
+ is(SpecialPowers.wrap(document).hasBeenUserGestureActivated, expectedResult,
+ `check has-been-user-activated for "${key}"`);
+ is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, expectedResult,
+ `check has-valid-transient-user-activation for "${key}"`);
+ }
+});
+
+add_task(async function TestModifier() {
+ let tests = [ [ 'a', { altKey: true }, false],
+ [ 'a', { ctrlKey: true }, false],
+ [ 'a', { metaKey: true }, false],
+ [ 'a', { osKey: true }, false],
+ [ 'c', { altKey: true }, false ],
+ [ 'c', { osKey: true }, false ],
+ [ 'v', { altKey: true }, false ],
+ [ 'v', { osKey: true }, false ],
+ [ 'x', { altKey: true }, false ],
+ [ 'x', { osKey: true }, false ],
+ // Treat as user input
+ [ 'a', { altGraphKey: true }, true ],
+ [ 'a', { fnKey: true }, true ],
+ [ 'a', { shiftKey: true }, true ],
+ [ 'c', { accelKey: true }, true ],
+ [ 'v', { accelKey: true }, true ],
+ [ 'x', { accelKey: true }, true ] ];
+
+ for (let [key, event, expectedResult] of tests) {
+ SpecialPowers.wrap(document).clearUserGestureActivation();
+ await synthesizeKeyAndWait(key, event);
+ is(SpecialPowers.wrap(document).hasBeenUserGestureActivated, expectedResult,
+ `check has-been-user-activated for ${key} with ${JSON.stringify(event)}`);
+ is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, expectedResult,
+ `check has-valid-transient-user-activation for ${key} with ${JSON.stringify(event)}`);
+ }
+});
+
+add_task(async function endTests() {
+ // Reset the activation flag in order not to interfere following test in the
+ // verify mode which would run the test using same document couple times.
+ SpecialPowers.wrap(document).clearUserGestureActivation();
+});
+
+</script>
+</body>