Bug 1345653 - Test pointer move with element origin and click with navigation; r?ato draft
authorMaja Frydrychowicz <mjzffr@gmail.com>
Tue, 04 Apr 2017 00:30:00 -0400
changeset 555734 c77c39790c4b9fe9d98fc2e68cb9939ddc5be7b0
parent 555733 ea313bd053b15644a71f2d0460193380157d8c18
child 622679 41cfd8a55181d9481ef2d980391d95783515d957
push id52315
push userbmo:mjzffr@gmail.com
push dateTue, 04 Apr 2017 18:59:07 +0000
reviewersato
bugs1345653
milestone55.0a1
Bug 1345653 - Test pointer move with element origin and click with navigation; r?ato Verify that there is no hang when we use pointer actions to perform a click that results in navigation and document unload. MozReview-Commit-ID: EO5FClnxML5
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/actions/mouse.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -208145,17 +208145,17 @@
    "78b6434a88021b7f56e5a7bf3e858fc9558a7c19",
    "wdspec"
   ],
   "webdriver/actions/key.py": [
    "918bcadf034657dfcb679fd92c8a11efe34bfedf",
    "wdspec"
   ],
   "webdriver/actions/mouse.py": [
-   "640ae3074200938ad63f77627d6645efa8c5716e",
+   "86b27e994042b37b4889175a10a02c30a24d3c7e",
    "wdspec"
   ],
   "webdriver/actions/sequence.py": [
    "d80f382863e52ff223db735a2a551197e570774f",
    "wdspec"
   ],
   "webdriver/actions/special_keys.py": [
    "b2d6c2fa8852c6299b6bd214f67007efebe3029a",
--- a/testing/web-platform/tests/webdriver/actions/mouse.py
+++ b/testing/web-platform/tests/webdriver/actions/mouse.py
@@ -1,31 +1,77 @@
+import urllib
+
 from support.refine import get_events, filter_dict
 
 
+# TODO use support.inline module once available from upstream
+def inline(doc):
+    return "data:text/html;charset=utf-8,%s" % urllib.quote(doc)
+
+
+def link_doc(dest):
+    content = "<a href=\"{}\" id=\"link\">destination</a>".format(dest)
+    return inline(content)
+
+
 def test_click_at_coordinates(session, test_actions_page, mouse_chain):
     div_point = {
         "x": 82,
         "y": 187,
     }
-    button = 0
     mouse_chain \
         .pointer_move(div_point["x"], div_point["y"], duration=1000) \
-        .pointer_down(button) \
-        .pointer_up(button) \
+        .click() \
         .perform()
     events = get_events(session)
     assert len(events) == 4
     for e in events:
         if e["type"] != "mousemove":
             assert e["pageX"] == div_point["x"]
             assert e["pageY"] == div_point["y"]
             assert e["target"] == "outer"
         if e["type"] != "mousedown":
             assert e["buttons"] == 0
-        assert e["button"] == button
+        assert e["button"] == 0
     expected = [
         {"type": "mousedown", "buttons": 1},
         {"type": "mouseup",  "buttons": 0},
         {"type": "click", "buttons": 0},
     ]
     filtered_events = [filter_dict(e, expected[0]) for e in events]
     assert expected == filtered_events[1:]
+
+
+def test_click_element_center(session, test_actions_page, mouse_chain):
+    outer = session.find.css("#outer", all=False)
+    outer_rect = outer.rect
+    center_x = outer_rect["width"] / 2 + outer_rect["x"]
+    center_y = outer_rect["height"] / 2 + outer_rect["y"]
+    mouse_chain.click(element=outer).perform()
+    events = get_events(session)
+    assert len(events) == 4
+    event_types = [e["type"] for e in events]
+    assert ["mousemove", "mousedown", "mouseup", "click"] == event_types
+    for e in events:
+        if e["type"] != "mousemove":
+            # TODO use pytest.approx once we upgrade to pytest > 3.0
+            assert abs(e["pageX"] - center_x) < 1
+            assert abs(e["pageY"] - center_y) < 1
+            assert e["target"] == "outer"
+
+
+def test_click_navigation(session, url):
+    destination = url("/webdriver/actions/support/test_actions_wdspec.html")
+    start = link_doc(destination)
+
+    def click(link):
+        mouse_chain = session.actions.sequence(
+            "pointer", "pointer_id", {"pointerType": "mouse"})
+        mouse_chain.click(element=link).pause(300).perform()
+
+    session.url = start
+    click(session.find.css("#link", all=False))
+    assert session.url == destination
+    # repeat steps to check behaviour after document unload
+    session.url = start
+    click(session.find.css("#link", all=False))
+    assert session.url == destination