Bug 1456799 - [wdspec] Add cookie tests have to use a shared custom add_cookie command. r=maja_zf
authorHenrik Skupin <mail@hskupin.info>
Wed, 25 Apr 2018 16:33:59 +0200
changeset 469108 9d55d0203a2b08980505d172982f516726e009bd
parent 469107 281208264c7493ff293b8c362e4d87e54dab6696
child 469109 c07b1375c1c4c9337ff81ab53757b5130f558a14
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1456799
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1456799 - [wdspec] Add cookie tests have to use a shared custom add_cookie command. r=maja_zf MozReview-Commit-ID: 8t8iMByRjcQ
testing/web-platform/tests/webdriver/tests/cookies/add_cookie.py
--- a/testing/web-platform/tests/webdriver/tests/cookies/add_cookie.py
+++ b/testing/web-platform/tests/webdriver/tests/cookies/add_cookie.py
@@ -1,28 +1,33 @@
 from tests.support.asserts import assert_success
 from tests.support.fixtures import clear_all_cookies
 from datetime import datetime, timedelta
 
 
+def add_cookie(session, cookie):
+    return session.transport.send(
+        "POST", "session/{session_id}/cookie".format(**vars(session)),
+        {"cookie": cookie})
+
+
 def test_add_domain_cookie(session, url, server_config):
+    new_cookie = {
+        "name": "hello",
+        "value": "world",
+        "domain": server_config["browser_host"],
+        "path": "/",
+        "httpOnly": False,
+        "secure": False
+    }
+
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
-    create_cookie_request = {
-        "cookie": {
-            "name": "hello",
-            "value": "world",
-            "domain": server_config["browser_host"],
-            "path": "/",
-            "httpOnly": False,
-            "secure": False
-        }
-    }
-    result = session.transport.send(
-        "POST", "session/%s/cookie" % session.session_id, create_cookie_request)
+
+    result = add_cookie(session, new_cookie)
     assert_success(result)
 
     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
     assert result.status == 200
     assert "value" in result.body
     assert isinstance(result.body["value"], list)
     assert len(result.body["value"]) == 1
     assert isinstance(result.body["value"][0], dict)
@@ -37,31 +42,29 @@ def test_add_domain_cookie(session, url,
 
     assert cookie["name"] == "hello"
     assert cookie["value"] == "world"
     assert cookie["domain"] == server_config["browser_host"] or \
         cookie["domain"] == ".%s" % server_config["browser_host"]
 
 
 def test_add_cookie_for_ip(session, url, server_config, configuration):
+    new_cookie = {
+        "name": "hello",
+        "value": "world",
+        "domain": "127.0.0.1",
+        "path": "/",
+        "httpOnly": False,
+        "secure": False
+    }
+
     session.url = "http://127.0.0.1:%s/common/blank.html" % (server_config["ports"]["http"][0])
     clear_all_cookies(session)
-    create_cookie_request = {
-        "cookie": {
-            "name": "hello",
-            "value": "world",
-            "domain": "127.0.0.1",
-            "path": "/",
-            "httpOnly": False,
-            "secure": False
-        }
-    }
 
-    result = session.transport.send(
-        "POST", "session/%s/cookie" % session.session_id, create_cookie_request)
+    result = add_cookie(session, new_cookie)
     assert_success(result)
 
     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
     assert result.status == 200
     assert "value" in result.body
     assert isinstance(result.body["value"], list)
     assert len(result.body["value"]) == 1
     assert isinstance(result.body["value"][0], dict)
@@ -75,29 +78,29 @@ def test_add_cookie_for_ip(session, url,
     assert isinstance(cookie["domain"], basestring)
 
     assert cookie["name"] == "hello"
     assert cookie["value"] == "world"
     assert cookie["domain"] == "127.0.0.1"
 
 
 def test_add_non_session_cookie(session, url):
-    session.url = url("/common/blank.html")
-    clear_all_cookies(session)
     a_year_from_now = int(
         (datetime.utcnow() + timedelta(days=365) - datetime.utcfromtimestamp(0)).total_seconds())
-    create_cookie_request = {
-        "cookie": {
-            "name": "hello",
-            "value": "world",
-            "expiry": a_year_from_now
-        }
+
+    new_cookie = {
+        "name": "hello",
+        "value": "world",
+        "expiry": a_year_from_now
     }
-    result = session.transport.send(
-        "POST", "session/%s/cookie" % session.session_id, create_cookie_request)
+
+    session.url = url("/common/blank.html")
+    clear_all_cookies(session)
+
+    result = add_cookie(session, new_cookie)
     assert_success(result)
 
     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
     assert result.status == 200
     assert "value" in result.body
     assert isinstance(result.body["value"], list)
     assert len(result.body["value"]) == 1
     assert isinstance(result.body["value"][0], dict)
@@ -111,26 +114,25 @@ def test_add_non_session_cookie(session,
     assert isinstance(cookie["expiry"], int)
 
     assert cookie["name"] == "hello"
     assert cookie["value"] == "world"
     assert cookie["expiry"] == a_year_from_now
 
 
 def test_add_session_cookie(session, url):
+    new_cookie = {
+        "name": "hello",
+        "value": "world"
+    }
+
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
-    create_cookie_request = {
-        "cookie": {
-            "name": "hello",
-            "value": "world"
-        }
-    }
-    result = session.transport.send(
-        "POST", "session/%s/cookie" % session.session_id, create_cookie_request)
+
+    result = add_cookie(session, new_cookie)
     assert_success(result)
 
     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
     assert result.status == 200
     assert "value" in result.body
     assert isinstance(result.body["value"], list)
     assert len(result.body["value"]) == 1
     assert isinstance(result.body["value"][0], dict)
@@ -143,27 +145,26 @@ def test_add_session_cookie(session, url
     if "expiry" in cookie:
         assert cookie.get("expiry") is None
 
     assert cookie["name"] == "hello"
     assert cookie["value"] == "world"
 
 
 def test_add_session_cookie_with_leading_dot_character_in_domain(session, url, server_config):
+    new_cookie = {
+        "name": "hello",
+        "value": "world",
+        "domain": ".%s" % server_config["browser_host"]
+    }
+
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
-    create_cookie_request = {
-        "cookie": {
-            "name": "hello",
-            "value": "world",
-            "domain": ".%s" % server_config["browser_host"]
-        }
-    }
-    result = session.transport.send(
-        "POST", "session/%s/cookie" % session.session_id, create_cookie_request)
+
+    result = add_cookie(session, new_cookie)
     assert_success(result)
 
     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
     assert result.status == 200
     assert "value" in result.body
     assert isinstance(result.body["value"], list)
     assert len(result.body["value"]) == 1
     assert isinstance(result.body["value"][0], dict)