Chromium Code Reviews| 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 _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): | 15 def _CookieCheckIncognitoWindow(self, url): |
| 32 """Check the cookie for the given URL in an incognito window.""" | 16 """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. | 17 # Navigate to the URL in an incognito window and verify no cookie is set. |
| 35 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 18 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 36 self.NavigateToURL(url, 1, 0) | 19 self.NavigateToURL(url, 1, 0) |
| 37 cookie_data = self.GetCookie(pyauto.GURL(url)) | 20 self.assertFalse(self.GetCookie(pyauto.GURL(url))) |
| 38 self.assertEqual(0, len(cookie_data)) | |
| 39 | 21 |
| 40 def testSetCookies(self): | 22 def testSetCookies(self): |
| 41 """Test setting cookies and getting the value.""" | 23 """Test setting cookies and getting the value.""" |
| 42 cookie_url = pyauto.GURL(self.GetFileURLForPath( | 24 cookie_url = pyauto.GURL(self.GetFileURLForPath( |
| 43 os.path.join(self.DataDir(), 'title1.html'))) | 25 os.path.join(self.DataDir(), 'title1.html'))) |
| 44 cookie_val = 'foo=bar' | 26 cookie_val = 'foo=bar' |
| 45 self.SetCookie(cookie_url, cookie_val) | 27 self.SetCookie(cookie_url, cookie_val) |
| 46 self.assertEqual(cookie_val, self.GetCookie(cookie_url)) | 28 self.assertEqual(cookie_val, self.GetCookie(cookie_url)) |
| 47 | 29 |
| 48 def testCookiesHttp(self): | 30 def testCookiesHttp(self): |
| 49 """Test cookies set over HTTP for incognito and regular windows.""" | 31 """Test cookies set over HTTP for incognito and regular windows.""" |
| 50 http_url = 'http://www.google.com' | 32 http_url = 'http://www.google.com' |
| 51 self._CookieCheckRegularWindow(http_url) | 33 self.assertFalse(self.GetCookie(pyauto.GURL(http_url))) |
| 52 self._CookieCheckIncognitoWindow(http_url) | 34 self._CookieCheckIncognitoWindow(http_url) |
|
Alyssa
2010/09/02 00:33:08
nit: Maybe comment above this call # Incognito win
| |
| 35 # Regular window | |
| 36 self.NavigateToURL(http_url) | |
| 37 cookie_data = self.GetCookie(pyauto.GURL(http_url)) | |
| 38 self.assertTrue(cookie_data) | |
| 39 # Restart and verify that the cookie persists. | |
| 40 self.assertEqual(cookie_data, self.GetCookie(pyauto.GURL(http_url))) | |
| 53 | 41 |
| 54 def testCookiesHttps(self): | 42 def testCookiesHttps(self): |
| 55 """Test cookies set over HTTPS for incognito and regular windows.""" | 43 """Test cookies set over HTTPS for incognito and regular windows.""" |
| 56 https_url = 'https://www.google.com' | 44 https_url = 'https://www.google.com' |
| 57 self._CookieCheckRegularWindow(https_url) | 45 self.assertFalse(self.GetCookie(pyauto.GURL(https_url))) |
| 58 self._CookieCheckIncognitoWindow(https_url) | 46 self._CookieCheckIncognitoWindow(https_url) |
| 47 # Regular window | |
| 48 self.NavigateToURL(https_url) | |
| 49 cookie_data = self.GetCookie(pyauto.GURL(https_url)) | |
| 50 self.assertTrue(cookie_data) | |
| 51 # Restart and verify that the cookie persists. | |
| 52 self.assertEqual(cookie_data, self.GetCookie(pyauto.GURL(https_url))) | |
| 59 | 53 |
| 60 def testCookiesFile(self): | 54 def testCookiesFile(self): |
| 61 """Test cookies set from an HTML file for incognito and regular windows.""" | 55 """Test cookies set from file:// url for incognito and regular windows.""" |
| 62 file_url = self.GetFileURLForPath( | 56 file_url = self.GetFileURLForPath( |
| 63 os.path.join(self.DataDir(), 'setcookie.html')) | 57 os.path.join(self.DataDir(), 'setcookie.html')) |
| 64 self._CookieCheckRegularWindow(file_url) | 58 self.assertFalse(self.GetCookie(pyauto.GURL(file_url))) |
| 65 self._CookieCheckIncognitoWindow(file_url) | 59 self._CookieCheckIncognitoWindow(file_url) |
| 60 # Regular window | |
| 61 self.NavigateToURL(file_url) | |
| 62 self.assertEqual('name=Good', self.GetCookie(pyauto.GURL(file_url))) | |
| 63 # Restart and verify that cookie persists | |
| 64 self.RestartBrowser(clear_profile=False) | |
| 65 self.assertEqual('name=Good', self.GetCookie(pyauto.GURL(file_url))) | |
| 66 | 66 |
| 67 | 67 |
| 68 if __name__ == '__main__': | 68 if __name__ == '__main__': |
| 69 pyauto_functional.Main() | 69 pyauto_functional.Main() |
| OLD | NEW |