Bug 1407695 - Cover non session cookies in web platform tests; r=ato

MozReview-Commit-ID: 4cj00yy3U39

--HG--
extra : rebase_source : cb3e785f9eb591931e27df05addd97b5f62e7061
This commit is contained in:
Øyvind Strømmen 2017-10-19 21:12:21 +02:00
Родитель 79ce033bd8
Коммит 58ddeb8ae1
1 изменённых файлов: 30 добавлений и 1 удалений

Просмотреть файл

@ -1,5 +1,6 @@
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")
@ -31,6 +32,35 @@ def test_get_named_session_cookie(session, url):
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)
@ -65,4 +95,3 @@ def test_duplicated_cookie(session, url):
assert cookie["name"] == "hello"
assert cookie["value"] == "newworld"