Fine-tune wpts for user-activation triggers to match spec proposal.

Proposed HTML PR: https://github.com/whatwg/html/pull/7248

Manually verified that these tests pass in Firefox.

Change-Id: I910158680a3741290ba9beef2c29050c11763be0
diff --git a/html/user-activation/activation-thru-contextmenu-event.html b/html/user-activation/activation-thru-contextmenu-event.html
deleted file mode 100644
index 7f84577..0000000
--- a/html/user-activation/activation-thru-contextmenu-event.html
+++ /dev/null
@@ -1,77 +0,0 @@
-<!DOCTYPE html>
-<html>
-  <head>
-    <title>User activation with 'contextmenu' event</title>
-    <meta name="timeout" content="long">
-    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
-    <link rel="author" title="Google" href="http://www.google.com "/>
-    <link rel="help" href="https://html.spec.whatwg.org/#triggered-by-user-activation">
-    <script src="/resources/testharness.js"></script>
-    <script src="/resources/testharnessreport.js"></script>
-    <script src="/resources/testdriver.js"></script>
-    <script src="/resources/testdriver-actions.js"></script>
-    <script src="/resources/testdriver-vendor.js"></script>
-    <style>
-      #target {
-        width: 250px;
-        height: 150px;
-        float: left;
-        background-color: green;
-      }
-
-      #done {
-        float: left;
-        padding: 20px;
-        margin: 10px;
-      }
-    </style>
-    <script type="text/javascript">
-      let activation_event_fired = false;
-
-      function run() {
-        let success = false;
-        let test_contextmenu = async_test("'contextmenu' can call vibrate.");
-        let actions_promise;
-        var target = document.getElementById("target");
-        var button = document.getElementById("done");
-
-        on_event(document.getElementById("done"), "click", () => {
-          test_contextmenu.step(() => {
-            assert_true(activation_event_fired, "activation event has fired");
-          });
-          // Make sure the test finishes after all the input actions are completed.
-          actions_promise.then(() => test_contextmenu.done());
-        });
-
-        on_event(document.getElementById("target"), "contextmenu", (e) => {
-            test_contextmenu.step(() => {
-              e.preventDefault();
-              assert_true(navigator.vibrate(200), "navigator.vibrate is successful");
-              activation_event_fired = true;
-            });
-        });
-
-        // Inject mouse inputs.
-        var actions = new test_driver.Actions();
-        actions_promise = actions
-            .pointerMove(0, 0, {origin: target})
-            .pointerDown({button: actions.ButtonType.RIGHT})
-            .pointerUp({button: actions.ButtonType.RIGHT})
-            .pointerMove(0, 0, {origin: button})
-            .pointerDown()
-            .pointerUp()
-            .send();
-      }
-    </script>
-  </head>
-  <body onload="run()">
-    <h1>User activation with 'contextmenu' event</h1>
-    <h4>Tests that a 'contextmenu' event is treated like a user activation.</h4>
-    <ol>
-      <li>Right-click or long-press on green.</li>
-      <li>Click or tap on Done.</li>
-    </ol>
-    <div id="target"></div>
-    <input type="button" id="done" value="Done" />
-  </body>
-</html>
diff --git a/html/user-activation/activation-trigger-click.html b/html/user-activation/activation-trigger-click.html
deleted file mode 100644
index abf685f..0000000
--- a/html/user-activation/activation-trigger-click.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <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 src="resources/utils.js"></script>
-</head>
-<body>
-  <h1>Test for click activation trigger</h1>
-  <p>Tests that a popup is allowed with user activation from a click event.</p>
-  <ol id="instructions">
-    <li>Click anywhere in the document.
-  </ol>
-  <script>
-    promise_test(async () => {
-        test_driver.click(document.body);
-        await getEvent('click');
-        let consumed = await consumeTransientActivation();
-        assert_true(consumed, "click event should result in activation");
-    }, "Activation through mouse event");
-  </script>
-</body>
-</html>
diff --git a/html/user-activation/activation-trigger-keyboard-enter.html b/html/user-activation/activation-trigger-keyboard-enter.html
new file mode 100644
index 0000000..fd51229
--- /dev/null
+++ b/html/user-activation/activation-trigger-keyboard-enter.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <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 src="resources/utils.js"></script>
+</head>
+<body>
+  <h1>Test for keyboard activation trigger for ENTER key</h1>
+  <p>Tests user activation from a ENTER keyboard event.</p>
+  <input type="text" autofocus />
+  <ol id="instructions">
+    <li>Press ENTER key.
+  </ol>
+  <script>
+    promise_test(async () => {
+        const ENTER_KEY = '\uE007';
+        test_driver.send_keys(document.body, ENTER_KEY);
+
+        let keydown_event = getEvent('keydown');
+        let keypress_event = getEvent('keypress');
+        let keyup_event = getEvent('keyup');
+
+        await keydown_event;
+        let consumed = await consumeTransientActivation();
+        assert_true(consumed,
+                    "ENTER keydown event should result in activation");
+
+        await keypress_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "ENTER keypress should have no activation after keydown consumption");
+
+        await keyup_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "ENTER keyup should have no activation after keydown consumption");
+    }, "Activation through ENTER keyboard event");
+  </script>
+</body>
+</html>
diff --git a/html/user-activation/activation-trigger-keyboard-escape.html b/html/user-activation/activation-trigger-keyboard-escape.html
new file mode 100644
index 0000000..76bdefb
--- /dev/null
+++ b/html/user-activation/activation-trigger-keyboard-escape.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <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 src="resources/utils.js"></script>
+</head>
+<body>
+  <h1>Test for keyboard activation trigger for ESCAPE key</h1>
+  <p>Tests missing user activation from a ESCAPE keyboard event.</p>
+  <input type="text" autofocus />
+  <ol id="instructions">
+    <li>Press ESCAPE key.
+  </ol>
+  <script>
+    promise_test(async () => {
+        const ESCAPE_KEY = '\uE00C';
+        test_driver.send_keys(document.body, ESCAPE_KEY);
+
+        let keydown_event = getEvent('keydown');
+        let keyup_event = getEvent('keyup');
+
+        await keydown_event;
+        let consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                    "ESCAPE keydown event should not result in activation");
+
+        await keyup_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "ESCAPE keyup should have no activation after keydown consumption");
+    }, "Activation through ESCAPE keyboard event");
+  </script>
+</body>
+</html>
diff --git a/html/user-activation/activation-trigger-keypress.html b/html/user-activation/activation-trigger-keypress.html
deleted file mode 100644
index cf3816f..0000000
--- a/html/user-activation/activation-trigger-keypress.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <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 src="resources/utils.js"></script>
-</head>
-<body>
-  <h1>Test for keypress activation trigger</h1>
-  <p>Tests that a popup is allowed with user activation from a keypress event.</p>
-  <input type="text" autofocus />
-  <ol id="instructions">
-    <li>Press ENTER key.
-  </ol>
-  <script>
-    promise_test(async () => {
-        const ENTER_KEY = '\uE007';
-        test_driver.send_keys(document.body, ENTER_KEY);
-
-        let keyup_event = getEvent('keyup');
-
-        await getEvent('keypress');
-        let consumed = await consumeTransientActivation();
-        assert_true(consumed,
-                    "ENTER keypress event should result in activation");
-
-        await keyup_event;
-        consumed = await consumeTransientActivation();
-        assert_false(consumed,
-                     "ENTER keyup should have no activation after keypress consumption");
-    }, "Activation through keyboard event");
-  </script>
-</body>
-</html>
diff --git a/html/user-activation/activation-trigger-mouse-left.html b/html/user-activation/activation-trigger-mouse-left.html
new file mode 100644
index 0000000..8bde4dd
--- /dev/null
+++ b/html/user-activation/activation-trigger-mouse-left.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <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 src="resources/utils.js"></script>
+</head>
+<body>
+  <h1>Test for click activation trigger</h1>
+  <p>Tests user activation from a mouse click.</p>
+  <ol id="instructions">
+    <li>Click anywhere in the document.
+  </ol>
+  <script>
+    promise_test(async () => {
+        test_driver.click(document.body);
+
+        let mousedown_event = getEvent('mousedown');
+        let mouseup_event = getEvent('mouseup');
+        let click_event = getEvent('click');
+
+        await mousedown_event;
+        let consumed = await consumeTransientActivation();
+        assert_true(consumed,
+                    "mousedown event should result in activation");
+
+        await mouseup_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "mouseup should have no activation after mousedown consumption");
+
+        await click_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "click should have no activation after mousedown consumption");
+    }, "Activation through left-click mouse event");
+  </script>
+</body>
+</html>
diff --git a/html/user-activation/activation-trigger-mouse-right.html b/html/user-activation/activation-trigger-mouse-right.html
new file mode 100644
index 0000000..a4734d0
--- /dev/null
+++ b/html/user-activation/activation-trigger-mouse-right.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <script src="/resources/testdriver.js"></script>
+  <script src="/resources/testdriver-actions.js"></script>
+  <script src="/resources/testdriver-vendor.js"></script>
+  <script src="resources/utils.js"></script>
+</head>
+<body>
+  <h1>Test for right-click activation trigger</h1>
+  <p>Tests user activation from a mouse right-click.</p>
+  <ol id="instructions">
+    <li>Right-click anywhere in the document.
+  </ol>
+  <script>
+    promise_test(async () => {
+        var actions = new test_driver.Actions();
+        actions_promise = actions
+            .pointerMove(0, 0, {origin: document.body})
+            .pointerDown({button: actions.ButtonType.RIGHT})
+            .pointerUp({button: actions.ButtonType.RIGHT})
+            .send();
+
+        // In most non-Windows platforms the right-click context-menu appears on mousedown, so
+        // mouseup and auxclick events are not received by the page if the menu is modal.  We
+        // are suppressing the context-menu to guarantee receiving those later events.
+        document.body.addEventListener("contextmenu", e => e.preventDefault());
+
+        let mousedown_event = getEvent('mousedown');
+        let mouseup_event = getEvent('mouseup');
+        let auxclick_event = getEvent('auxclick');
+        let contextmenu_event = getEvent('contextmenu');
+
+        await mousedown_event;
+        let consumed = await consumeTransientActivation();
+        assert_true(consumed,
+                    "mousedown event should result in activation");
+
+        await mouseup_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "mouseup should have no activation after mousedown consumption");
+
+        await auxclick_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "auxclick should have no activation after mousedown consumption");
+
+        await contextmenu_event;
+        consumed = await consumeTransientActivation();
+        assert_false(consumed,
+                     "contextmenu should have no activation after mousedown consumption");
+    }, "Activation through right-click mouse event");
+  </script>
+</body>
+</html>