df45722b1001c49de5736b1efa92300a929db65b
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / cookies / add_cookie.py
1 from tests.support.fixtures import clear_all_cookies
2 from tests.support.fixtures import server_config
3
4 def test_add_domain_cookie(session, url):
5     session.url = url("/common/blank.html")
6     clear_all_cookies(session)
7     create_cookie_request = {
8         "cookie": {
9             "name": "hello",
10             "value": "world",
11             "domain": "web-platform.test",
12             "path": "/",
13             "httpOnly": False,
14             "secure": False
15         }
16     }
17     result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
18     assert result.status == 200
19     assert "value" in result.body
20     assert isinstance(result.body["value"], dict)
21
22     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
23     assert result.status == 200
24     assert "value" in result.body
25     assert isinstance(result.body["value"], list)
26     assert len(result.body["value"]) == 1
27     assert isinstance(result.body["value"][0], dict)
28
29     cookie = result.body["value"][0]
30     assert "name" in cookie
31     assert isinstance(cookie["name"], basestring)
32     assert "value" in cookie
33     assert isinstance(cookie["value"], basestring)
34     assert "domain" in cookie
35     assert isinstance(cookie["domain"], basestring)
36
37     assert cookie["name"] == "hello"
38     assert cookie["value"] == "world"
39     assert cookie["domain"] == ".web-platform.test"
40
41 def test_add_cookie_for_ip(session, url, server_config):
42     session.url = "http://127.0.0.1:%s/404" % (server_config["ports"]["http"][0])
43     clear_all_cookies(session)
44     create_cookie_request = {
45         "cookie": {
46             "name": "hello",
47             "value": "world",
48             "domain": "127.0.0.1",
49             "path": "/",
50             "httpOnly": False,
51             "secure": False
52         }
53     }
54     result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
55     assert result.status == 200
56     assert "value" in result.body
57     assert isinstance(result.body["value"], dict)
58
59     result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
60     assert result.status == 200
61     assert "value" in result.body
62     assert isinstance(result.body["value"], list)
63     assert len(result.body["value"]) == 1
64     assert isinstance(result.body["value"][0], dict)
65
66     cookie = result.body["value"][0]
67     assert "name" in cookie
68     assert isinstance(cookie["name"], basestring)
69     assert "value" in cookie
70     assert isinstance(cookie["value"], basestring)
71     assert "domain" in cookie
72     assert isinstance(cookie["domain"], basestring)
73
74     assert cookie["name"] == "hello"
75     assert cookie["value"] == "world"
76     assert cookie["domain"] == "127.0.0.1"