Bug 1388365 - Test window rect state. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Tue, 08 Aug 2017 14:59:37 +0100
changeset 642719 e5aa430e0b46e00a1044aa1d592e0084252fb064
parent 642718 61311750a3609096a7bdce45cf1c9a5992fb283e
child 725081 f56066144dd7097c3939a08b23e725e10b61dc40
push id72846
push userbmo:ato@sny.no
push dateTue, 08 Aug 2017 17:43:46 +0000
reviewerswhimboo
bugs1388365
milestone57.0a1
Bug 1388365 - Test window rect state. r?whimboo MozReview-Commit-ID: 1MoA370SUeW
testing/web-platform/tests/webdriver/tests/maximize_window.py
testing/web-platform/tests/webdriver/tests/set_window_rect.py
--- a/testing/web-platform/tests/webdriver/tests/maximize_window.py
+++ b/testing/web-platform/tests/webdriver/tests/maximize_window.py
@@ -15,61 +15,68 @@ def test_maximize_no_browsing_context(se
 def test_handle_user_prompt(session):
     # Step 2
     session.url = alert_doc
     result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
     assert_error(result, "unexpected alert open")
 
 
 def test_maximize(session):
-    before = session.window.size
+    before_size = session.window.size
+    assert session.window.state == "normal"
 
     # step 4
     result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
     assert_success(result)
 
-    after = session.window.size
-    assert before != after
+    assert before_size != session.window.size
+    assert session.window.state == "maximized"
 
 
 def test_payload(session):
-    before = session.window.size
+    before_size = session.window.size
+    assert session.window.state == "normal"
 
     result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
 
     # step 5
     assert result.status == 200
     assert isinstance(result.body["value"], dict)
 
     rect = result.body["value"]
     assert "width" in rect
     assert "height" in rect
     assert "x" in rect
     assert "y" in rect
-    assert isinstance(rect["width"], float)
-    assert isinstance(rect["height"], float)
-    assert isinstance(rect["x"], float)
-    assert isinstance(rect["y"], float)
+    assert "state" in rect
+    assert isinstance(rect["width"], (int, float))
+    assert isinstance(rect["height"], (int, float))
+    assert isinstance(rect["x"], (int, float))
+    assert isinstance(rect["y"], (int, float))
+    assert isinstance(rect["state"], basestring)
 
-    after = session.window.size
-    assert before != after
+    assert before_size != session.window.size
+    assert session.window.state == "maximized"
 
 
 def test_maximize_when_resized_to_max_size(session):
     # Determine the largest available window size by first maximising
     # the window and getting the window rect dimensions.
     #
     # Then resize the window to the maximum available size.
     session.end()
+    assert session.window.state == "normal"
     available = session.window.maximize()
+    assert session.window.state == "maximized"
     session.end()
 
     session.window.size = (int(available["width"]), int(available["height"]))
 
     # In certain window managers a window extending to the full available
     # dimensions of the screen may not imply that the window is maximised,
     # since this is often a special state.  If a remote end expects a DOM
     # resize event, this may not fire if the window has already reached
     # its expected dimensions.
+    assert session.window.state == "normal"
     before = session.window.size
     session.window.maximize()
-    after = session.window.size
-    assert before == after
+    assert session.window.size == before
+    assert session.window.state == "maximized"
--- a/testing/web-platform/tests/webdriver/tests/set_window_rect.py
+++ b/testing/web-platform/tests/webdriver/tests/set_window_rect.py
@@ -97,172 +97,182 @@ def test_set_window_rect_invalid_params(
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     data)
 
     assert_error(result, "invalid argument")
 
 
 def test_set_window_fullscreen(session):
-    get_response = session.transport.send("GET", "session/%s/window/rect" % session.session_id)
-    original = get_response.body["value"]
+    original = session.window.rect
 
     # step 10
-    session.transport.send("POST",
-                           "session/%s/window/fullscreen" % session.session_id)
-    assert session.execute_script("return document.fullscreenElement != null")
+    session.window.fullscreen()
+    assert session.window.state == "fullscreen"
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"width": 400, "height": 400})
-    assert session.execute_script("return document.fullscreenElement == null")
     assert_success(result, {"x": original["x"],
                             "y": original["y"],
-                            "width": 400,
-                            "height": 400})
+                            "width": 400.0,
+                            "height": 400.0,
+                            "state": "normal"})
 
 
 def test_set_window_rect_window_minimized(session):
     # step 11
-    session.minimize()
+    session.window.minimize()
     assert session.execute_script("return document.hidden")
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"width": 400, "height": 400})
     assert not session.execute_script("return document.hidden")
     assert_success(result, {"width": 400, "height": 400})
 
 
 def test_set_window_height_width(session):
-    get_response = session.transport.send("GET", "session/%s/window/rect" % session.session_id)
-    original = get_response.body["value"]
+    original = session.window.rect
 
-    # Step 12
-    _max = session.execute_script("""
+    # step 12
+    max = session.execute_script("""
         return {
           width: window.screen.availWidth,
           height: window.screen.availHeight,
         }""")
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
-                                    {"width": _max["width"] - 100,
-                                     "height": _max["height"] - 100})
+                                    {"width": max["width"] - 100,
+                                     "height": max["height"] - 100})
 
-    # Step 14
-    assert_success(result, {"x": original["x"], "y": original["y"],
-                            "width": _max["width"] - 100,
-                            "height": _max["height"] - 100})
+    # step 14
+    assert_success(result, {"x": original["x"],
+                            "y": original["y"],
+                            "width": max["width"] - 100,
+                            "height": max["height"] - 100,
+                            "state": "normal"})
 
 
 def test_set_window_height_width_larger_than_max(session):
-    # Step 12
-    _max = session.execute_script("""
+    # step 12
+    max = session.execute_script("""
         return {
           width: window.screen.availWidth,
           height: window.screen.availHeight,
         }""")
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
-                                    {"width": _max["width"] + 100,
-                                     "height": _max["width"] + 100})
+                                    {"width": max["width"] + 100,
+                                     "height": max["width"] + 100})
 
     # Step 14
     assert result.status == 200
-    assert result.body["value"]["width"] >= _max["width"]
-    assert result.body["value"]["height"] >= _max["height"]
+    rect = result.body["value"]
+    assert rect["width"] >= max["width"]
+    assert rect["height"] >= max["height"]
+    assert rect["state"] == "normal"
 
 
 def test_set_window_height_width_as_current(session):
-    # Step 12
-    get_response = session.transport.send("GET", "session/%s/window/rect" % session.session_id)
-    original = get_response.body["value"]
+    # step 12
+    original = session.window.rect
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"width": int(original["width"]),
                                      "height": int(original["height"])})
 
-    # Step 14
+    # step 14
     assert_success(result, {"x": original["x"],
                             "y": original["y"],
                             "width": original["width"],
-                            "height": original["height"]})
+                            "height": original["height"],
+                            "state": original["state"]})
 
 
 def test_set_window_rect_x_y(session):
-    # Step 13
-    get_response = session.transport.send("GET", "session/%s/window/rect" % session.session_id)
-    original = get_response.body["value"]
+    # step 13
+    original = session.window.rect
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"x": int(original["x"]) + 10,
                                      "y": int(original["y"]) + 10})
-    # Step 14
+    # step 14
     assert_success(result, {"x": original["x"] + 10,
                             "y": original["y"] + 10,
                             "width": original["width"],
-                            "height": original["height"]})
+                            "height": original["height"],
+                            "state": original["state"]})
 
 
 def test_set_window_rect_negative_x_y(session):
-    get_response = session.transport.send("GET", "session/%s/window/rect" % session.session_id)
-    original = get_response.body["value"]
+    original = session.window.rect
 
-    # Step 13
+    # step 13
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"x": - 8,
                                      "y": - 8})
 
+    # step 14
+
     os = session.capabilities["platformName"]
-    # Step 14
+    # certain WMs prohibit windows from being moved off-screen
     if os == "linux":
-        # certain WMs prohibit windows from being moved off-screen
-        assert_success(result, {"x": 0, "y": 0,
-                                "width": original["width"],
-                                "height": original["height"]})
+        rect = assert_success(result)
+        assert rect["x"] <= 0
+        assert rect["y"] <= 0
+        assert rect["width"] == original["width"]
+        assert rect["height"] == original["height"]
+        assert rect["state"] == original["state"]
 
     # On macOS, windows can only be moved off the screen on the
     # horizontal axis.  The system menu bar also blocks windows from
     # being moved to (0,0).
     elif os == "darwin":
-        assert_success(result, {"x": -8, "y": 23,
+        assert_success(result, {"x": -8,
+                                "y": 23,
                                 "width": original["width"],
-                                "height": original["height"]})
+                                "height": original["height"],
+                                "state": original["state"]})
 
     # It turns out that Windows is the only platform on which the
     # window can be reliably positioned off-screen.
     elif os == "windows_nt":
-        assert_success(result, {"x": -8, "y": -8,
+        assert_success(result, {"x": -8,
+                                "y": -8,
                                 "width": original["width"],
-                                "height": original["height"]})
-
+                                "height": original["height"],
+                                "state": original["state"]})
 
 
 def test_set_window_x_y_as_current(session):
-    # Step 13
-    get_response = session.transport.send("GET", "session/%s/window/rect" % session.session_id)
-    original = get_response.body["value"]
+    # step 13
+    original = session.window.rect
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"x": int(original["x"]),
                                      "y": int(original["y"])})
-    # Step 14
+    # step 14
     assert_success(result, {"x": original["x"],
                             "y": original["y"],
                             "width": original["width"],
-                            "height": original["height"]})
+                            "height": original["height"],
+                            "state": original["state"]})
 
 def test_set_window_rect_payload(session):
     # step 14
     result = session.transport.send("POST",
                                     "session/%s/window/rect" % session.session_id,
                                     {"x": 400,
                                      "y": 400})
 
     assert result.status == 200
     assert isinstance(result.body["value"], dict)
-    assert "width" in result.body["value"]
-    assert "height" in result.body["value"]
-    assert "x" in result.body["value"]
-    assert "y" in result.body["value"]
-    assert isinstance(result.body["value"]["width"], (int, float))
-    assert isinstance(result.body["value"]["height"], (int, float))
-    assert isinstance(result.body["value"]["x"], (int, float))
-    assert isinstance(result.body["value"]["y"], (int, float))
+    rect = result.body["value"]
+    assert "width" in rect
+    assert "height" in rect
+    assert "x" in rect
+    assert "y" in rect
+    assert "state" in rect
+    assert isinstance(rect["width"], (int, float))
+    assert isinstance(rect["height"], (int, float))
+    assert isinstance(rect["x"], (int, float))
+    assert isinstance(rect["y"], (int, float))
+    assert isinstance(rect["state"], basestring)