654568fafb4bdc72a7bdaa017fe7f9815ab68f70
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / cookies / get_named_cookie.py
1 from tests.support.inline import inline
2 from tests.support.fixtures import clear_all_cookies
3
4 def test_get_named_cookie(session, url):
5     session.url = url("/common/blank.html")
6     session.execute_script("document.cookie = 'foo=bar'")
7
8     result = session.transport.send("GET", "session/%s/cookie/foo" % session.session_id)
9     assert result.status == 200
10     assert isinstance(result.body["value"], dict)
11
12     # table for cookie conversion
13     # https://w3c.github.io/webdriver/webdriver-spec.html#dfn-table-for-cookie-conversion
14     cookie = result.body["value"]
15     assert "name" in cookie
16     assert isinstance(cookie["name"], basestring)
17     assert "value" in cookie
18     assert isinstance(cookie["value"], basestring)
19     assert "path" in cookie
20     assert isinstance(cookie["path"], basestring)
21     assert "domain" in cookie
22     assert isinstance(cookie["domain"], basestring)
23     assert "secure" in cookie
24     assert isinstance(cookie["secure"], bool)
25     assert "httpOnly" in cookie
26     assert isinstance(cookie["httpOnly"], bool)
27     assert "expiry" in cookie
28     assert isinstance(cookie["expiry"], (int, long))
29
30     assert cookie["name"] == "foo"
31     assert cookie["value"] == "bar"
32
33 def test_duplicated_cookie(session, url):
34     session.url = url("/common/blank.html")
35     clear_all_cookies(session)
36     create_cookie_request = {
37         "cookie": {
38             "name": "hello",
39             "value": "world",
40             "domain": "web-platform.test",
41             "path": "/",
42             "httpOnly": False,
43             "secure": False
44         }
45     }
46     result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
47     assert result.status == 200
48     assert "value" in result.body
49     assert isinstance(result.body["value"], dict)
50
51     session.url = inline("<script>document.cookie = 'hello=newworld; domain=web-platform.test; path=/';</script>")
52     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
53     assert result.status == 200
54     assert "value" in result.body
55     assert isinstance(result.body["value"], list)
56     assert len(result.body["value"]) == 1
57     assert isinstance(result.body["value"][0], dict)
58
59     cookie = result.body["value"][0]
60     assert "name" in cookie
61     assert isinstance(cookie["name"], basestring)
62     assert "value" in cookie
63     assert isinstance(cookie["value"], basestring)
64
65     assert cookie["name"] == "hello"
66     assert cookie["value"] == "newworld"
67