Bug 1456996 - [wdspec] Get named cookie tests have to use a shared custom get_named_cookie command. r=maja_zf
authorHenrik Skupin <mail@hskupin.info>
Wed, 25 Apr 2018 23:20:47 +0200
changeset 471994 d1b7f7e210c6663614c8fd03494929ab90c833e8
parent 471993 2adfda24e3cd057e07f98e410453da7bd41ec489
child 471995 1f4ce46796fc2e003c0fa58391f39f3fdf35a944
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1456996
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 1456996 - [wdspec] Get named cookie tests have to use a shared custom get_named_cookie command. r=maja_zf MozReview-Commit-ID: 7r3Krzrv8Wr
testing/web-platform/tests/webdriver/tests/cookies/get_named_cookie.py
--- a/testing/web-platform/tests/webdriver/tests/cookies/get_named_cookie.py
+++ b/testing/web-platform/tests/webdriver/tests/cookies/get_named_cookie.py
@@ -1,24 +1,33 @@
-from tests.support.inline import inline
+from datetime import datetime, timedelta
+
+from tests.support.asserts import assert_success
 from tests.support.fixtures import clear_all_cookies
-from datetime import datetime, timedelta
+from tests.support.inline import inline
+
+
+def get_named_cookie(session, name):
+    return session.transport.send(
+        "GET", "session/{session_id}/cookie/{name}".format(
+            session_id=session.session_id,
+            name=name))
+
 
 def test_get_named_session_cookie(session, url):
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
     session.execute_script("document.cookie = 'foo=bar'")
 
-    result = session.transport.send("GET", "session/%s/cookie/foo" % session.session_id)
-    assert result.status == 200
-    assert isinstance(result.body["value"], dict)
+    result = get_named_cookie(session, "foo")
+    cookie = assert_success(result)
+    assert isinstance(cookie, dict)
 
     # table for cookie conversion
     # https://w3c.github.io/webdriver/webdriver-spec.html#dfn-table-for-cookie-conversion
-    cookie = result.body["value"]
     assert "name" in cookie
     assert isinstance(cookie["name"], basestring)
     assert "value" in cookie
     assert isinstance(cookie["value"], basestring)
     assert "path" in cookie
     assert isinstance(cookie["path"], basestring)
     assert "domain" in cookie
     assert isinstance(cookie["domain"], basestring)
@@ -27,44 +36,43 @@ def test_get_named_session_cookie(sessio
     assert "httpOnly" in cookie
     assert isinstance(cookie["httpOnly"], bool)
     if "expiry" in cookie:
         assert cookie.get("expiry") is None
 
     assert cookie["name"] == "foo"
     assert cookie["value"] == "bar"
 
+
 def test_get_named_cookie(session, url):
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
 
     # same formatting as Date.toUTCString() in javascript
     utc_string_format = "%a, %d %b %Y %H:%M:%S"
     a_year_from_now = (datetime.utcnow() + timedelta(days=365)).strftime(utc_string_format)
     session.execute_script("document.cookie = 'foo=bar;expires=%s'" % a_year_from_now)
 
-    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)
+    result = get_named_cookie(session, "foo")
+    cookie = assert_success(result)
+    assert isinstance(cookie, dict)
 
-    cookie = result.body["value"][0]
     assert "name" in cookie
     assert isinstance(cookie["name"], basestring)
     assert "value" in cookie
     assert isinstance(cookie["value"], basestring)
     assert "expiry" in cookie
     assert isinstance(cookie["expiry"], (int, long))
 
     assert cookie["name"] == "foo"
     assert cookie["value"] == "bar"
     # convert from seconds since epoch
-    assert datetime.utcfromtimestamp(cookie["expiry"]).strftime(utc_string_format) == a_year_from_now
+    assert datetime.utcfromtimestamp(
+        cookie["expiry"]).strftime(utc_string_format) == a_year_from_now
+
 
 def test_duplicated_cookie(session, url, server_config):
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
     create_cookie_request = {
         "cookie": {
             "name": "hello",
             "value": "world",
@@ -75,23 +83,20 @@ def test_duplicated_cookie(session, url,
         }
     }
     result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
     assert result.status == 200
     assert "value" in result.body
     assert result.body["value"] is None
 
     session.url = inline("<script>document.cookie = 'hello=newworld; domain=%s; path=/';</script>" % server_config["domains"][""])
-    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)
 
-    cookie = result.body["value"][0]
+    result = get_named_cookie(session, "hello")
+    cookie = assert_success(result)
+    assert isinstance(cookie, dict)
+
     assert "name" in cookie
     assert isinstance(cookie["name"], basestring)
     assert "value" in cookie
     assert isinstance(cookie["value"], basestring)
 
     assert cookie["name"] == "hello"
     assert cookie["value"] == "newworld"