Bug 1392368 - Correct types and bounds checks for Set Window Rect. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Tue, 22 Aug 2017 15:16:06 +0100
changeset 653178 dfcdc8b25a057ad5668077de728c7639ac711d7a
parent 653177 4d43bc688bea5e8c54d4abbc5950c322b80be070
child 653179 6c6b6ace9e08b25b99984e7df55de2317fa854a2
push id76248
push userbmo:ato@sny.no
push dateFri, 25 Aug 2017 16:27:14 +0000
reviewersautomatedtester
bugs1392368
milestone57.0a1
Bug 1392368 - Correct types and bounds checks for Set Window Rect. r?automatedtester This patch splits types and bounds checks into two tests for clarity and reduces unnecessary fields for readability. It also covers a few missing eventualities and edge cases. MozReview-Commit-ID: GTBw0fZOgwY
testing/web-platform/tests/webdriver/tests/set_window_rect.py
--- a/testing/web-platform/tests/webdriver/tests/set_window_rect.py
+++ b/testing/web-platform/tests/webdriver/tests/set_window_rect.py
@@ -130,32 +130,75 @@ def test_handle_prompt_missing_value(ses
     create_dialog("prompt", text="dismiss #3", result_var="dismiss3")
 
     result = set_window_rect(session, {"x": int(original["x"]),
                                        "y": int(original["y"])})
     assert_error(result, "unexpected alert open")
     assert_dialog_handled(session, "dismiss #3")
 
 
-@pytest.mark.parametrize("data", [
-    {"height": None, "width": None, "x": "a", "y": "b"},
-    {"height": "a", "width": "b", "x": None, "y": None},
-    {"height": None, "width": None, "x": 10.1, "y": 10.1},
-    {"height": 10.1, "width": 10.1, "x": None, "y": None},
-    {"height": True, "width": False, "x": None, "y": None},
-    {"height": None, "width": None, "x": True, "y": False},
-    {"height": [], "width": [], "x": None, "y": None},
-    {"height": None, "width": None, "x": [], "y": []},
-    {"height": [], "width": [], "x": [], "y": []},
-    {"height": {}, "width": {}, "x": None, "y": None},
-    {"height": None, "width": None, "x": {}, "y": {}},
+@pytest.mark.parametrize("rect", [
+    {"width": "a"},
+    {"height": "b"},
+    {"width": "a", "height": "b"},
+    {"x": "a"},
+    {"y": "b"},
+    {"x": "a", "y": "b"},
+    {"width": "a", "height": "b", "x": "a", "y": "b"},
+
+    {"width": True},
+    {"height": False},
+    {"width": True, "height": False},
+    {"x": True},
+    {"y": False},
+    {"x": True, "y": False},
+    {"width": True, "height": False, "x": True, "y": False},
+
+    {"width": []},
+    {"height": []},
+    {"width": [], "height": []},
+    {"x": []},
+    {"y": []},
+    {"x": [], "y": []},
+    {"width": [], "height": [], "x": [], "y": []},
+
+    {"height": {}},
+    {"width": {}},
+    {"height": {}, "width": {}},
+    {"x": {}},
+    {"y": {}},
+    {"x": {}, "y": {}},
+    {"width": {}, "height": {}, "x": {}, "y": {}},
 ])
-def test_invalid_params(session, data):
-    # step 8-9
-    response = set_window_rect(session, data)
+def test_invalid_types(session, rect):
+    """
+    8. If width or height is neither null nor a Number from 0 to 2^64 -
+    1, return error with error code invalid argument.
+
+    9. If x or y is neither null nor a Number from -(263) to 263 - 1,
+    return error with error code invalid argument.
+    """
+    response = set_window_rect(session, rect)
+    assert_error(response, "invalid argument")
+
+
+@pytest.mark.parametrize("rect", [
+    {"width": -1},
+    {"height": -2},
+    {"width": -1, "height": -2},
+])
+def test_out_of_bounds(session, rect):
+    """
+    8. If width or height is neither null nor a Number from 0 to 2^64 -
+    1, return error with error code invalid argument.
+
+    9. If x or y is neither null nor a Number from -(263) to 263 - 1,
+    return error with error code invalid argument.
+    """
+    response = set_window_rect(session, rect)
     assert_error(response, "invalid argument")
 
 
 def test_fully_exit_fullscreen(session):
     """
     10. Fully exit fullscreen.
 
     [...]
@@ -163,17 +206,16 @@ def test_fully_exit_fullscreen(session):
     To fully exit fullscreen a document document, run these steps:
 
       1. If document's fullscreen element is null, terminate these steps.
 
       2. Unfullscreen elements whose fullscreen flag is set, within
       document's top layer, except for document's fullscreen element.
 
       3. Exit fullscreen document.
-
     """
 
     session.window.fullscreen()
     assert session.execute_script("return window.fullScreen") is True
 
     response = set_window_rect(session, {"width": 400, "height": 400})
     value = assert_success(response)
     assert value["width"] == 400