OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 | 7 |
8 import pyauto_functional # Must be imported before pyauto | 8 import pyauto_functional # Must be imported before pyauto |
9 import pyauto | 9 import pyauto |
10 | 10 |
11 | 11 |
12 class CookiesTest(pyauto.PyUITest): | 12 class CookiesTest(pyauto.PyUITest): |
13 """Tests for Cookies.""" | 13 """Tests for Cookies.""" |
14 | 14 |
15 def testCookies(self): | 15 def _ClearCookiesAndCheck(self, url): |
| 16 self.ClearBrowsingData(['COOKIES'], 'EVERYTHING') |
| 17 cookie_data = self.GetCookie(pyauto.GURL(url)) |
| 18 self.assertEqual(0, len(cookie_data)) |
| 19 |
| 20 def _CookieCheckRegularWindow(self, url): |
| 21 """Check the cookie for the given URL in a regular window.""" |
| 22 self._ClearCookiesAndCheck(url) |
| 23 # Assert that the cookie data isn't empty after navigating to the url. |
| 24 self.NavigateToURL(url) |
| 25 cookie_data = self.GetCookie(pyauto.GURL(url)) |
| 26 self.assertNotEqual(0, len(cookie_data)) |
| 27 # Restart the browser and ensure the cookie data is the same. |
| 28 self.RestartBrowser(clear_profile=False) |
| 29 self.assertEqual(cookie_data, self.GetCookie(pyauto.GURL(url))) |
| 30 |
| 31 def _CookieCheckIncognitoWindow(self, url): |
| 32 """Check the cookie for the given URL in an incognito window.""" |
| 33 self._ClearCookiesAndCheck(url) |
| 34 # Navigate to the URL in an incognito window and verify no cookie is set. |
| 35 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 36 self.NavigateToURL(url, 1, 0) |
| 37 cookie_data = self.GetCookie(pyauto.GURL(url)) |
| 38 self.assertEqual(0, len(cookie_data)) |
| 39 |
| 40 def testSetCookies(self): |
16 """Test setting cookies and getting the value.""" | 41 """Test setting cookies and getting the value.""" |
17 cookie_url = pyauto.GURL(self.GetFileURLForPath( | 42 cookie_url = pyauto.GURL(self.GetFileURLForPath( |
18 os.path.join(self.DataDir(), 'title1.html'))) | 43 os.path.join(self.DataDir(), 'title1.html'))) |
19 cookie_val = 'foo=bar' | 44 cookie_val = 'foo=bar' |
20 self.SetCookie(cookie_url, cookie_val) | 45 self.SetCookie(cookie_url, cookie_val) |
21 self.assertEqual(cookie_val, self.GetCookie(cookie_url)) | 46 self.assertEqual(cookie_val, self.GetCookie(cookie_url)) |
22 | 47 |
| 48 def testCookiesHttp(self): |
| 49 """Test cookies set over HTTP for incognito and regular windows.""" |
| 50 http_url = 'http://www.google.com' |
| 51 self._CookieCheckRegularWindow(http_url) |
| 52 self._CookieCheckIncognitoWindow(http_url) |
| 53 |
| 54 def testCookiesHttps(self): |
| 55 """Test cookies set over HTTPS for incognito and regular windows.""" |
| 56 https_url = 'https://www.google.com' |
| 57 self._CookieCheckRegularWindow(https_url) |
| 58 self._CookieCheckIncognitoWindow(https_url) |
| 59 |
| 60 def testCookiesFile(self): |
| 61 """Test cookies set from an HTML file for incognito and regular windows.""" |
| 62 file_url = self.GetFileURLForPath( |
| 63 os.path.join(self.DataDir(), 'setcookie.html')) |
| 64 self._CookieCheckRegularWindow(file_url) |
| 65 self._CookieCheckIncognitoWindow(file_url) |
| 66 |
23 | 67 |
24 if __name__ == '__main__': | 68 if __name__ == '__main__': |
25 pyauto_functional.Main() | 69 pyauto_functional.Main() |
OLD | NEW |