Bug 1407695 - Cover non session cookies in web platform tests; r?ato draft
authorØyvind Strømmen <insula.ventus@gmail.com>
Thu, 19 Oct 2017 21:12:21 +0200
changeset 684963 089cea45dbba2c159730ff76fd82cfd9b8767063
parent 684962 7ac87dd6a33fea1707c9337ce82d6f48ce77f272
child 737011 d21bd8a8a7e486006469c22225306e5540e35223
push id85780
push userbmo:insula.ventus@gmail.com
push dateMon, 23 Oct 2017 20:39:02 +0000
reviewersato
bugs1407695
milestone58.0a1
Bug 1407695 - Cover non session cookies in web platform tests; r?ato MozReview-Commit-ID: 9NTHTBpmyhi
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,10 +1,11 @@
 from tests.support.inline import inline
 from tests.support.fixtures import clear_all_cookies
+from datetime import datetime, timedelta
 
 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
@@ -26,16 +27,45 @@ def test_get_named_session_cookie(sessio
     assert "httpOnly" in cookie
     assert isinstance(cookie["httpOnly"], bool)
     assert "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)
+
+    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
+
 def test_duplicated_cookie(session, url):
     session.url = url("/common/blank.html")
     clear_all_cookies(session)
     create_cookie_request = {
         "cookie": {
             "name": "hello",
             "value": "world",
             "domain": "web-platform.test",
@@ -60,9 +90,8 @@ def test_duplicated_cookie(session, url)
     cookie = result.body["value"][0]
     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"
-