Bug 1337133 - Set up fixtures for mouse actions in wdspec tests. r=ato, a=test-only
authorMaja Frydrychowicz <mjzffr@gmail.com>
Mon, 27 Feb 2017 08:26:32 -0500
changeset 376538 4750fbf396d0077c4dd851c213fc5349f5dd05cf
parent 376537 3d937ea641e711039144921a1209b9a94331e579
child 376539 8910e502db34694c2056dafe5f2a97b3884d192a
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1337133
milestone53.0a2
Bug 1337133 - Set up fixtures for mouse actions in wdspec tests. r=ato, a=test-only MozReview-Commit-ID: zzIQgSgEPb
testing/web-platform/tests/webdriver/actions/conftest.py
testing/web-platform/tests/webdriver/actions/key.py
testing/web-platform/tests/webdriver/actions/mouse.py
testing/web-platform/tests/webdriver/actions/sequence.py
testing/web-platform/tests/webdriver/actions/support/refine.py
testing/web-platform/tests/webdriver/actions/support/test_actions_wdspec.html
--- a/testing/web-platform/tests/webdriver/actions/conftest.py
+++ b/testing/web-platform/tests/webdriver/actions/conftest.py
@@ -1,16 +1,24 @@
 import pytest
 
 
 @pytest.fixture
 def key_chain(session):
     return session.actions.sequence("key", "keyboard_id")
 
 
+@pytest.fixture
+def mouse_chain(session):
+    return session.actions.sequence(
+        "pointer",
+        "pointer_id",
+        {"pointerType": "mouse"})
+
+
 @pytest.fixture(autouse=True)
 def release_actions(session, request):
     # release all actions after each test
     # equivalent to a teardown_function, but with access to session fixture
     request.addfinalizer(session.actions.release)
 
 
 @pytest.fixture
--- a/testing/web-platform/tests/webdriver/actions/key.py
+++ b/testing/web-platform/tests/webdriver/actions/key.py
@@ -1,26 +1,12 @@
 import pytest
 
 from support.keys import Keys
-from support.refine import get_keys, filter_dict
-
-
-def get_events(session):
-    """Return list of key events recorded in the test_keys_page fixture."""
-    events = session.execute_script("return allEvents.events;") or []
-    # `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
-    # test_keys_wdspec.html), so this converts them back into unicode literals.
-    for e in events:
-        # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char)
-        if e["key"].startswith(u"U+"):
-            key = e["key"]
-            hex_suffix = key[key.index("+") + 1:]
-            e["key"] = unichr(int(hex_suffix, 16))
-    return events
+from support.refine import get_keys, filter_dict, get_events
 
 
 def test_lone_keyup_sends_no_events(session, key_reporter, key_chain):
     key_chain.key_up("a").perform()
     assert len(get_keys(key_reporter)) == 0
     assert len(get_events(session)) == 0
     session.actions.release()
     assert len(get_keys(key_reporter)) == 0
--- a/testing/web-platform/tests/webdriver/actions/mouse.py
+++ b/testing/web-platform/tests/webdriver/actions/mouse.py
@@ -1,4 +1,8 @@
-import pytest
+from support.refine import get_events
+
 
-def test_nothing():
-    assert True
+#def test_nothing(session, test_actions_page, mouse_chain):
+#    mouse_chain \
+#        .pointer_down(1) \
+#        .perform()
+#    assert True
--- a/testing/web-platform/tests/webdriver/actions/sequence.py
+++ b/testing/web-platform/tests/webdriver/actions/sequence.py
@@ -1,23 +1,9 @@
-from support.refine import get_keys, filter_dict
-
-
-def get_events(session):
-    """Return list of key events recorded in the test_keys_page fixture."""
-    events = session.execute_script("return allEvents.events;") or []
-    # `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
-    # test_keys_wdspec.html), so this converts them back into unicode literals.
-    for e in events:
-        # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char)
-        if e["key"].startswith(u"U+"):
-            key = e["key"]
-            hex_suffix = key[key.index("+") + 1:]
-            e["key"] = unichr(int(hex_suffix, 16))
-    return events
+from support.refine import get_keys, filter_dict, get_events
 
 
 def test_no_actions_send_no_events(session, key_reporter, key_chain):
     key_chain.perform()
     assert len(get_keys(key_reporter)) == 0
     assert len(get_events(session)) == 0
 
 
--- a/testing/web-platform/tests/webdriver/actions/support/refine.py
+++ b/testing/web-platform/tests/webdriver/actions/support/refine.py
@@ -1,8 +1,22 @@
+def get_events(session):
+    """Return list of key events recorded in the test_keys_page fixture."""
+    events = session.execute_script("return allEvents.events;") or []
+    # `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
+    # test_keys_wdspec.html), so this converts them back into unicode literals.
+    for e in events:
+        # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char)
+        if "key" in e and e["key"].startswith(u"U+"):
+            key = e["key"]
+            hex_suffix = key[key.index("+") + 1:]
+            e["key"] = unichr(int(hex_suffix, 16))
+    return events
+
+
 def get_keys(input_el):
     """Get printable characters entered into `input_el`.
 
     :param input_el: HTML input element.
     """
     rv = input_el.property("value")
     if rv is None:
         return ""
--- a/testing/web-platform/tests/webdriver/actions/support/test_actions_wdspec.html
+++ b/testing/web-platform/tests/webdriver/actions/support/test_actions_wdspec.html
@@ -1,13 +1,22 @@
-
 <!doctype html>
 <meta charset=utf-8>
 <head>
     <title>Test Actions</title>
+    <style>
+      div { padding:0px; margin: 0px; }
+      #resultContainer { width: 600px; height: 60px; }
+      #outer { width: 100px; height: 50px; background-color: #ccc; }
+      #trackPointer {
+        width: 5px;
+        height: 5px;
+        border: solid 1px red;
+        position: fixed; }
+    </style>
     <script>
         var allEvents = {events: []};
         function displayMessage(message) {
             document.getElementById("events").innerHTML = "<p>" + message + "</p>";
         }
 
         function appendMessage(message) {
             document.getElementById("events").innerHTML += "<p>" + message + "</p>";
@@ -28,43 +37,95 @@
             var surrogate = highSurrogate || (charCode >= 0xDC00 && charCode <= 0xDFFF);
             if (surrogate) {
               key = "U+" + charCode.toString(16);
             }
           }
           return key;
         }
 
-        function recordEvent(event) {
+        function recordKeyboardEvent(event) {
           var key = escapeSurrogateHalf(event.key);
           allEvents.events.push({
             "code": event.code,
             "key": key,
             "which": event.which,
             "location": event.location,
             "ctrl": event.ctrlKey,
             "meta": event.metaKey,
             "shift": event.shiftKey,
             "repeat": event.repeat,
             "type": event.type
           });
-          appendMessage(`${event.type}(code:${event.code}, key:${key}, which:${event.which})`);
+          appendMessage(`${event.type}(` +
+              `code: ${event.code}, ` +
+              `key: ${key}, ` +
+              `which: ${event.which})`);
+        }
+
+        function recordPointerEvent(event) {
+          allEvents.events.push({
+            "type": event.type,
+            "button": event.button,
+            "buttons": event.buttons,
+            "pageX": event.pageX,
+            "pageY": event.pageY,
+            "target": event.target.id
+          });
+          appendMessage(`${event.type}(` +
+              `button: ${event.button}, ` +
+              `pageX: ${event.pageX}, ` +
+              `pageY: ${event.pageY}, ` +
+              `button: ${event.button}, ` +
+              `buttons: ${event.buttons}, ` +
+              `target id: ${event.target.id})`);
+        }
+
+        function recordFirstPointerMove(event) {
+          recordPointerEvent(event);
+          window.removeEventListener("mousemove", recordFirstPointerMove);
         }
 
         function resetEvents() {
             allEvents.events.length = 0;
             displayMessage("");
         }
+
+        document.addEventListener("DOMContentLoaded", () => {
+          var keyReporter = document.getElementById("keys");
+          ["keyup", "keypress", "keydown"].forEach((e) => {
+            keyReporter.addEventListener(e, recordKeyboardEvent);
+          });
+          var outer = document.getElementById("outer");
+          ["click", "dblclick", "mousedown",
+              "mouseup", "contextmenu"].forEach((e) => {
+            outer.addEventListener(e, recordPointerEvent);
+          });
+          window.addEventListener("mousemove", recordFirstPointerMove);
+          //visual cue for mousemove
+          var pointer = document.getElementById("trackPointer");
+          window.addEventListener("mousemove", (e) => {
+            setTimeout(() => {
+              let offset = 15;
+              pointer.style.top = e.pageY + offset + "px";
+              pointer.style.left = e.pageX + offset + "px";
+            }, 30);
+          });
+        });
     </script>
 </head>
 <body>
+  <div id="trackPointer"></div>
   <div>
     <h2>KeyReporter</h2>
-    <input type="text" id="keys" size="80"
-           onkeyup="recordEvent(event)"
-           onkeypress="recordEvent(event)"
-           onkeydown="recordEvent(event)">
+    <input type="text" id="keys" size="80">
   </div>
-  <div id="resultContainer" style="width:300;height:60">
+  <div>
+    <h2>ClickReporter</h2>
+    <div id="outer">
+    </div>
+  </div>
+  <div id="resultContainer">
     <h2>Events</h2>
     <div id="events"></div>
   </div>
 </body>
+</html>