Bug 1485580 - [wdspec] Improve timeouts tests for "Set Timeout" and "New Session". r=jgraham
authorHenrik Skupin <mail@hskupin.info>
Fri, 24 Aug 2018 10:24:52 +0200
changeset 481605 1fd335726c0088e8ffe303beff533442c973b083
parent 481604 289a5cd12a3839fa13ed1b3517b7a1fd2d3d4fea
child 481606 4bc3167b02408d6af7f7bff52a0e77864254321d
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersjgraham
bugs1485580
milestone63.0a1
Bug 1485580 - [wdspec] Improve timeouts tests for "Set Timeout" and "New Session". r=jgraham
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/new_session/invalid_capabilities.py
testing/web-platform/tests/webdriver/tests/new_session/support/create.py
testing/web-platform/tests/webdriver/tests/set_timeouts/set.py
testing/web-platform/tests/webdriver/tests/set_timeouts/user_prompts.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -423109,16 +423109,24 @@
     ]
    ],
    "webdriver/tests/set_timeouts/set.py": [
     [
      "/webdriver/tests/set_timeouts/set.py",
      {}
     ]
    ],
+   "webdriver/tests/set_timeouts/user_prompts.py": [
+    [
+     "/webdriver/tests/set_timeouts/user_prompts.py",
+     {
+      "timeout": "long"
+     }
+    ]
+   ],
    "webdriver/tests/set_window_rect/set.py": [
     [
      "/webdriver/tests/set_window_rect/set.py",
      {
       "timeout": "long"
      }
     ]
    ],
@@ -648589,17 +648597,17 @@
    "f00f6042b085dc09876f67ae650ff62ceb3eb76a",
    "wdspec"
   ],
   "webdriver/tests/new_session/default_values.py": [
    "61816812eb1e79e4cc96190e09e597a878bdebee",
    "wdspec"
   ],
   "webdriver/tests/new_session/invalid_capabilities.py": [
-   "83f93ea22f7ed28fa28ab05d36387df828716026",
+   "f31ce3b8b6fd5f8e4a9ff4d0137debdb7dacdea4",
    "wdspec"
   ],
   "webdriver/tests/new_session/merge.py": [
    "857d289fcaf054492e17ba730c6f530d55fe2640",
    "wdspec"
   ],
   "webdriver/tests/new_session/page_load_strategy.py": [
    "69288ef43335605e4c9d21cfa56bd2806f6e92b0",
@@ -648613,17 +648621,17 @@
    "3e8520718237e6d74fe368d68c4a7bf2ead08c9e",
    "wdspec"
   ],
   "webdriver/tests/new_session/support/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/new_session/support/create.py": [
-   "85ae1cd4ea85e0a1e0d712b1a7803d6066ab8739",
+   "475fe5a424fe609f0a7e55164e56378e229e4885",
    "support"
   ],
   "webdriver/tests/new_session/timeouts.py": [
    "c5adb9396819beb03d4627ef9890958fb687b58d",
    "wdspec"
   ],
   "webdriver/tests/page_source/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
@@ -648653,17 +648661,21 @@
    "edc37d6edb483c232401676f6c11ab7512774605",
    "wdspec"
   ],
   "webdriver/tests/set_timeouts/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/set_timeouts/set.py": [
-   "e603e217ec7d73bf7bc59f1d2e8687a89c818c47",
+   "a78ab2e68e82ba28c15748bb98239b3d232dc9f1",
+   "wdspec"
+  ],
+  "webdriver/tests/set_timeouts/user_prompts.py": [
+   "a98d87e9b2e2ca252a3ed7cf215a20bd1c299818",
    "wdspec"
   ],
   "webdriver/tests/set_window_rect/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/set_window_rect/set.py": [
    "928fd622efc22f520f4c6a9f783f60ec270146e2",
--- a/testing/web-platform/tests/webdriver/tests/new_session/invalid_capabilities.py
+++ b/testing/web-platform/tests/webdriver/tests/new_session/invalid_capabilities.py
@@ -1,12 +1,14 @@
 import pytest
 
+from conftest import product, flatten
+
+from tests.new_session.support.create import invalid_data, invalid_extensions
 from tests.support.asserts import assert_error
-from conftest import product, flatten
 
 
 @pytest.mark.parametrize("value", [None, 1, "{}", []])
 def test_invalid_capabilites(new_session, value):
     response, _ = new_session({"capabilities": value})
     assert_error(response, "invalid argument")
 
 
@@ -21,78 +23,30 @@ def test_invalid_always_match(new_sessio
 @pytest.mark.parametrize("value", [None, 1, "[]", {}])
 def test_invalid_first_match(new_session, add_browser_capabilities, value):
     capabilities = {"alwaysMatch": add_browser_capabilities({}), "firstMatch": value}
 
     response, _ = new_session({"capabilities": capabilities})
     assert_error(response, "invalid argument")
 
 
-invalid_data = [
-    ("acceptInsecureCerts", [1, [], {}, "false"]),
-    ("browserName", [1, [], {}, False]),
-    ("browserVersion", [1, [], {}, False]),
-    ("platformName", [1, [], {}, False]),
-    ("pageLoadStrategy", [1, [], {}, False, "invalid", "NONE", "Eager", "eagerblah", "interactive",
-                          " eager", "eager "]),
-    ("proxy", [1, [], "{}", {"proxyType": "SYSTEM"}, {"proxyType": "systemSomething"},
-               {"proxy type": "pac"}, {"proxy-Type": "system"}, {"proxy_type": "system"},
-               {"proxytype": "system"}, {"PROXYTYPE": "system"}, {"proxyType": None},
-               {"proxyType": 1}, {"proxyType": []}, {"proxyType": {"value": "system"}},
-               {" proxyType": "system"}, {"proxyType ": "system"}, {"proxyType ": " system"},
-               {"proxyType": "system "}]),
-    ("timeouts", [1, [], "{}", False, {"pageLOAD": 10}, {"page load": 10},
-                  {"page load": 10}, {"pageLoad": "10"}, {"pageLoad": {"value": 10}},
-                  {"invalid": 10}, {"pageLoad": -1}, {"pageLoad": 2**64},
-                  {"pageLoad": None}, {"pageLoad": 1.1}, {"pageLoad": 10, "invalid": 10},
-                  {" pageLoad": 10}, {"pageLoad ": 10}]),
-    ("unhandledPromptBehavior", [1, [], {}, False, "DISMISS", "dismissABC", "Accept",
-                                 " dismiss", "dismiss "])
-]
-
-
 @pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
                                   lambda key, value: {"firstMatch": [{key: value}]}])
 @pytest.mark.parametrize("key,value", flatten(product(*item) for item in invalid_data))
 def test_invalid_values(new_session, add_browser_capabilities, body, key, value):
     capabilities = body(key, value)
     if "alwaysMatch" in capabilities:
         capabilities["alwaysMatch"] = add_browser_capabilities(capabilities["alwaysMatch"])
     else:
         capabilities["firstMatch"][0] = add_browser_capabilities(capabilities["firstMatch"][0])
 
     response, _ = new_session({"capabilities": capabilities})
     assert_error(response, "invalid argument")
 
 
-invalid_extensions = [
-    "firefox",
-    "firefox_binary",
-    "firefoxOptions",
-    "chromeOptions",
-    "automaticInspection",
-    "automaticProfiling",
-    "platform",
-    "version",
-    "browser",
-    "platformVersion",
-    "javascriptEnabled",
-    "nativeEvents",
-    "seleniumProtocol",
-    "profile",
-    "trustAllSSLCertificates",
-    "initialBrowserUrl",
-    "requireWindowFocus",
-    "logFile",
-    "logLevel",
-    "safari.options",
-    "ensureCleanSession",
-]
-
-
 @pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
                                   lambda key, value: {"firstMatch": [{key: value}]}])
 @pytest.mark.parametrize("key", invalid_extensions)
 def test_invalid_extensions(new_session, add_browser_capabilities, body, key):
     capabilities = body(key, {})
     if "alwaysMatch" in capabilities:
         capabilities["alwaysMatch"] = add_browser_capabilities(capabilities["alwaysMatch"])
     else:
--- a/testing/web-platform/tests/webdriver/tests/new_session/support/create.py
+++ b/testing/web-platform/tests/webdriver/tests/new_session/support/create.py
@@ -1,15 +1,130 @@
 # Note that we can only test things here all implementations must support
 valid_data = [
-    ("acceptInsecureCerts", [False, None]),
-    ("browserName", [None]),
-    ("browserVersion", [None]),
-    ("platformName", [None]),
-    ("pageLoadStrategy", ["none", "eager", "normal", None]),
-    ("proxy", [None]),
-    ("timeouts", [{"script": 0, "pageLoad": 2.0, "implicit": 2**53 - 1},
-                  {"script": 50, "pageLoad": 25},
-                  {"script": 500},
-                  {}]),
-    ("unhandledPromptBehavior", ["dismiss", "accept", None]),
-    ("test:extension", [True, "abc", 123, [], {"key": "value"}, None]),
+    ("acceptInsecureCerts", [
+        False, None,
+    ]),
+    ("browserName", [
+        None,
+    ]),
+    ("browserVersion", [
+        None,
+    ]),
+    ("platformName", [
+        None,
+    ]),
+    ("pageLoadStrategy", [
+        None,
+        "none",
+        "eager",
+        "normal",
+    ]),
+    ("proxy", [
+        None,
+    ]),
+    ("timeouts", [
+        None, {},
+        {"script": 0, "pageLoad": 2.0, "implicit": 2**53 - 1},
+        {"script": 50, "pageLoad": 25},
+        {"script": 500},
+    ]),
+    ("unhandledPromptBehavior", [
+        "dismiss",
+        "accept",
+        None,
+    ]),
+    ("test:extension", [
+        None, False, "abc", 123, [],
+        {"key": "value"},
+    ]),
 ]
+
+invalid_data = [
+    ("acceptInsecureCerts", [
+        1, [], {}, "false",
+    ]),
+    ("browserName", [
+        1, [], {}, False,
+    ]),
+    ("browserVersion", [
+        1, [], {}, False,
+    ]),
+    ("platformName", [
+        1, [], {}, False,
+    ]),
+    ("pageLoadStrategy", [
+        1, [], {}, False,
+        "invalid",
+        "NONE",
+        "Eager",
+        "eagerblah",
+        "interactive",
+        " eager",
+        "eager "]),
+    ("proxy", [
+        1, [], "{}",
+        {"proxyType": "SYSTEM"},
+        {"proxyType": "systemSomething"},
+        {"proxy type": "pac"},
+        {"proxy-Type": "system"},
+        {"proxy_type": "system"},
+        {"proxytype": "system"},
+        {"PROXYTYPE": "system"},
+        {"proxyType": None},
+        {"proxyType": 1},
+        {"proxyType": []},
+        {"proxyType": {"value": "system"}},
+        {" proxyType": "system"},
+        {"proxyType ": "system"},
+        {"proxyType ": " system"},
+        {"proxyType": "system "},
+    ]),
+    ("timeouts", [
+        1, [], "{}", False,
+        {"invalid": 10},
+        {"PAGELOAD": 10},
+        {"page load": 10},
+        {" pageLoad": 10},
+        {"pageLoad ": 10},
+        {"pageLoad": None},
+        {"pageLoad": False},
+        {"pageLoad": []},
+        {"pageLoad": "10"},
+        {"pageLoad": 2.5},
+        {"pageLoad": -1},
+        {"pageLoad": 2**53},
+        {"pageLoad": {"value": 10}},
+        {"pageLoad": 10, "invalid": 10},
+    ]),
+    ("unhandledPromptBehavior", [
+        1, [], {}, False,
+        "DISMISS",
+        "dismissABC",
+        "Accept",
+        " dismiss",
+        "dismiss ",
+    ])
+]
+
+invalid_extensions = [
+    "firefox",
+    "firefox_binary",
+    "firefoxOptions",
+    "chromeOptions",
+    "automaticInspection",
+    "automaticProfiling",
+    "platform",
+    "version",
+    "browser",
+    "platformVersion",
+    "javascriptEnabled",
+    "nativeEvents",
+    "seleniumProtocol",
+    "profile",
+    "trustAllSSLCertificates",
+    "initialBrowserUrl",
+    "requireWindowFocus",
+    "logFile",
+    "logLevel",
+    "safari.options",
+    "ensureCleanSession",
+]
--- a/testing/web-platform/tests/webdriver/tests/set_timeouts/set.py
+++ b/testing/web-platform/tests/webdriver/tests/set_timeouts/set.py
@@ -1,8 +1,10 @@
+import pytest
+
 from webdriver.transport import Response
 
 from tests.support.asserts import assert_error, assert_success
 
 
 def set_timeouts(session, timeouts):
     return session.transport.send(
         "POST", "session/{session_id}/timeouts".format(**vars(session)),
@@ -11,19 +13,65 @@ def set_timeouts(session, timeouts):
 
 def test_null_parameter_value(session, http):
     path = "/session/{session_id}/timeouts".format(**vars(session))
     with http.post(path, None) as response:
         assert_error(Response.from_http(response), "invalid argument")
 
 
 def test_null_response_value(session):
-    response = set_timeouts(session, {"implicit": 1000})
+    timeouts = {"implicit": 10, "pageLoad": 10, "script": 10}
+    response = set_timeouts(session, timeouts)
     value = assert_success(response)
     assert value is None
 
-    response = set_timeouts(session, {"pageLoad": 1000})
-    value = assert_success(response)
-    assert value is None
+
+@pytest.mark.parametrize("value", [1, "{}", False, []])
+def test_parameters_invalid(session, value):
+    response = set_timeouts(session, value)
+    assert_error(response, "invalid argument")
+
+
+def test_parameters_empty_no_change(session):
+    original = session.timeouts._get()
+
+    response = set_timeouts(session, {})
+    assert_success(response)
+
+    assert session.timeouts._get() == original
+
+
+def test_key_invalid(session):
+    response = set_timeouts(session, {"foo": 1000})
+    assert_error(response, "invalid argument")
+
 
-    response = set_timeouts(session, {"script": 1000})
-    value = assert_success(response)
-    assert value is None
+@pytest.mark.parametrize("typ", ["implicit", "pageLoad", "script"])
+@pytest.mark.parametrize("value", [0, 2.0, 2**53 - 1])
+def test_positive_integer(session, typ, value):
+    response = set_timeouts(session, {typ: value})
+    assert_success(response)
+
+    assert session.timeouts._get(typ) == value
+
+
+@pytest.mark.parametrize("typ", ["implicit", "pageLoad", "script"])
+@pytest.mark.parametrize("value", [None, [], {}, False, "10"])
+def test_value_invalid_types(session, typ, value):
+    response = set_timeouts(session, {typ: value})
+    assert_error(response, "invalid argument")
+
+
+@pytest.mark.parametrize("typ", ["implicit", "pageLoad", "script"])
+@pytest.mark.parametrize("value", [-1, 2.5, 2**53])
+def test_value_positive_integer(session, typ, value):
+    response = set_timeouts(session, {typ: value})
+    assert_error(response, "invalid argument")
+
+
+def test_set_all_fields(session):
+    timeouts = {"implicit": 10, "pageLoad": 20, "script": 30}
+    response = set_timeouts(session, timeouts)
+    assert_success(response)
+
+    assert session.timeouts.implicit == 10
+    assert session.timeouts.page_load == 20
+    assert session.timeouts.script == 30
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/set_timeouts/user_prompts.py
@@ -0,0 +1,62 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import assert_success
+
+
+def set_timeouts(session, timeouts):
+    return session.transport.send(
+        "POST", "session/{session_id}/timeouts".format(**vars(session)),
+        timeouts)
+
+
+@pytest.fixture
+def check_user_prompt_not_closed(session, create_dialog):
+    def check_user_prompt_not_closed(dialog_type):
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = set_timeouts(session, {"script": 100})
+        assert_success(response)
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+        assert session.timeouts.script == 100
+
+    return check_user_prompt_not_closed
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_accept(check_user_prompt_not_closed, dialog_type):
+    check_user_prompt_not_closed(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_accept_and_notify(check_user_prompt_not_closed, dialog_type):
+    check_user_prompt_not_closed(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_dismiss(check_user_prompt_not_closed, dialog_type):
+    check_user_prompt_not_closed(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_dismiss_and_notify(check_user_prompt_not_closed, dialog_type):
+    check_user_prompt_not_closed(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed, dialog_type):
+    check_user_prompt_not_closed(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_default(check_user_prompt_not_closed, dialog_type):
+    check_user_prompt_not_closed(dialog_type)