Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11028)

Unified Diff: chrome/test/functional/cookies.py

Issue 9584012: Clean up cookie pyauto tests to actually test what the comments say (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/cookies.py
diff --git a/chrome/test/functional/cookies.py b/chrome/test/functional/cookies.py
index 890a2cd4baa42ea11f7f26ccc7038fb81639c182..1078a0a374dd1dc0facd110affd116db2f3a4eb4 100755
--- a/chrome/test/functional/cookies.py
+++ b/chrome/test/functional/cookies.py
@@ -12,27 +12,48 @@ import pyauto
class CookiesTest(pyauto.PyUITest):
"""Tests for Cookies."""
- def _CookieCheckIncognitoWindow(self, url):
+ def __init__(self, methodName='runTest'):
+ super(CookiesTest, self).__init__(methodName)
+ self.test_host = os.environ.get('COOKIES_TEST_HOST', 'www.google.com')
+
+ def _CookieCheckIncognitoWindow(self, url, cookies_enabled=True):
"""Check the cookie for the given URL in an incognito window."""
# Navigate to the URL in an incognito window and verify no cookie is set.
+ self.assertFalse(self.GetCookie(pyauto.GURL(url)),
+ msg='Cannot run with pre-existing cookies')
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+ self.assertFalse(self.GetCookie(pyauto.GURL(url), 1),
+ msg='Fresh incognito window should not have cookies')
self.NavigateToURL(url, 1, 0)
+ if cookies_enabled:
+ self.assertTrue(self.GetCookie(pyauto.GURL(url), 1),
+ msg='Cookies not set in incognito window')
+ else:
+ self.assertFalse(self.GetCookie(pyauto.GURL(url), 1),
+ msg='Cookies not blocked in incognito window')
self.assertFalse(self.GetCookie(pyauto.GURL(url)),
- msg='Unable to get cookie in incognito window.')
+ msg='Incognito mode cookies leaking to regular profile')
+ self.CloseBrowserWindow(1);
+ self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+ self.assertFalse(self.GetCookie(pyauto.GURL(url), 1),
+ msg='Cookies persisting between incognito sessions')
+ self.CloseBrowserWindow(1);
def testSetCookies(self):
"""Test setting cookies and getting the value."""
cookie_url = pyauto.GURL(self.GetFileURLForDataPath('title1.html'))
cookie_val = 'foo=bar'
+ self.assertFalse(self.GetCookie(cookie_url),
+ msg='There should be no cookies for %s' % cookie_url)
self.SetCookie(cookie_url, cookie_val)
self.assertEqual(cookie_val, self.GetCookie(cookie_url),
msg='Could not find the cookie value foo=bar')
def testCookiesHttp(self):
"""Test cookies set over HTTP for incognito and regular windows."""
- http_url = 'http://www.google.com'
+ http_url = 'http://%s' % self.test_host
self.assertFalse(self.GetCookie(pyauto.GURL(http_url)),
- msg='No cookies found after navigating to %s' % http_url)
+ msg='There should be no cookies for %s' % http_url)
# Incognito window
self._CookieCheckIncognitoWindow(http_url)
# Regular window
@@ -41,30 +62,32 @@ class CookiesTest(pyauto.PyUITest):
self.assertTrue(cookie_data,
msg='Cookie did not exist after loading %s' % http_url)
# Restart and verify that the cookie persists.
- self.assertEqual(cookie_data, self.GetCookie(pyauto.GURL(http_url)),
- msg='Cookie did not persist after restarting session.')
+ self.RestartBrowser(clear_profile=False)
Nirnimesh 2012/03/02 19:23:27 Hmm.. I guess I am to blame for this mischief. tha
+ self.assertTrue(self.GetCookie(pyauto.GURL(http_url)),
+ msg='Cookie did not persist after restarting session.')
def testCookiesHttps(self):
"""Test cookies set over HTTPS for incognito and regular windows."""
- https_url = 'https://www.google.com'
+ https_url = 'https://%s' % self.test_host
self.assertFalse(self.GetCookie(pyauto.GURL(https_url)),
- msg='No cookies found after navigating to %s' % https_url)
+ msg='There should be no cookies for %s' % https_url)
# Incognito window
self._CookieCheckIncognitoWindow(https_url)
# Regular window
self.NavigateToURL(https_url)
cookie_data = self.GetCookie(pyauto.GURL(https_url))
self.assertTrue(cookie_data,
- msg='Unable to get cookie after navigating to page')
+ msg='Cookie did not exist after loading %s' % https_url)
# Restart and verify that the cookie persists.
- self.assertEqual(cookie_data, self.GetCookie(pyauto.GURL(https_url)),
- msg='Cookie did not persist after restarting session.')
+ self.RestartBrowser(clear_profile=False)
+ self.assertTrue(cookie_data, self.GetCookie(pyauto.GURL(https_url)),
+ msg='Cookie did not persist after restarting session.')
def testCookiesFile(self):
"""Test cookies set from file:// url for incognito and regular windows."""
file_url = self.GetFileURLForDataPath('setcookie.html')
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
- msg='Did not find cookie for file url %s' % file_url)
+ msg='There should be no cookie for file url %s' % file_url)
# Incognito window
self._CookieCheckIncognitoWindow(file_url)
# Regular window
@@ -79,30 +102,39 @@ class CookiesTest(pyauto.PyUITest):
def testBlockCookies(self):
"""Verify that cookies are being blocked."""
file_url = self.GetFileURLForDataPath('setcookie.html')
+ http_url = 'http://%s' % self.test_host
+ https_url = 'https://%s' % self.test_host
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
- msg='Did not find cookie for url %s' % file_url)
+ msg='There should be no cookie for file url %s' % file_url)
# Set the preference to block all cookies.
self.SetPrefs(pyauto.kDefaultContentSettings, {u'cookies': 2})
# Regular window
- self.NavigateToURL('http://www.google.com')
- self.AppendTab(pyauto.GURL('https://www.google.com'))
+ self.NavigateToURL(http_url)
+ self.AppendTab(pyauto.GURL(https_url))
self.AppendTab(pyauto.GURL(file_url))
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
msg='Cookies are not blocked.')
+ self.assertFalse(self.GetCookie(pyauto.GURL(http_url)),
+ msg='Cookies are not blocked.')
+ self.assertFalse(self.GetCookie(pyauto.GURL(https_url)),
+ msg='Cookies are not blocked.')
# Incognito window
- self._CookieCheckIncognitoWindow('http://www.google.com')
- self.GetBrowserWindow(1).GetTab(0).Close(True)
+ self._CookieCheckIncognitoWindow(http_url, cookies_enabled=False)
# Restart and verify that cookie setting persists and there are no cookies.
self.SetPrefs(pyauto.kRestoreOnStartup, 1)
self.RestartBrowser(clear_profile=False)
self.assertEquals({u'cookies': 2},
- self.GetPrefsInfo().Prefs(pyauto.kDefaultContentSettings))
+ self.GetPrefsInfo().Prefs(pyauto.kDefaultContentSettings),
+ msg='Cookie setting did not persist after restarting session.')
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
- msg='Cookie setting did not persist after restarting '
- 'session.')
+ msg='Cookies are not blocked.')
+ self.assertFalse(self.GetCookie(pyauto.GURL(http_url)),
+ msg='Cookies are not blocked.')
+ self.assertFalse(self.GetCookie(pyauto.GURL(https_url)),
+ msg='Cookies are not blocked.')
def testClearCookiesOnEndingSession(self):
"""Verify that cookies are cleared when the browsing session is closed."""
@@ -126,6 +158,7 @@ class CookiesTest(pyauto.PyUITest):
"""Verify that cookies can be allowed and set using exceptions for
particular website(s) when all others are blocked."""
file_url = self.GetFileURLForDataPath('setcookie.html')
+ http_url = 'http://%s' % self.test_host
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
msg='Unable to set cookie.')
@@ -139,26 +172,27 @@ class CookiesTest(pyauto.PyUITest):
# Creating an exception to allow cookies from http://www.google.com.
self.SetPrefs(pyauto.kContentSettingsPatternPairs,
- {'[*.]google.com,*': { 'cookies': 1}})
+ {'[*.]%s,*' % self.test_host: { 'cookies': 1}})
# Navigate to google.com and check if cookies are set.
- self.NavigateToURL('http://www.google.com')
- self.assertTrue(self.GetCookie(pyauto.GURL('http://www.google.com')),
+ self.NavigateToURL(http_url)
+ self.assertTrue(self.GetCookie(pyauto.GURL(http_url)),
msg='Cookies are not set for the exception.')
def testBlockCookiesUsingExceptions(self):
"""Verify that cookies can be blocked for a specific website
using exceptions."""
file_url = self.GetFileURLForDataPath('setcookie.html')
+ http_url = 'http://%s' % self.test_host
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
msg='Unable to set cookie.')
# Create an exception to block cookies from http://www.google.com
self.SetPrefs(pyauto.kContentSettingsPatternPairs,
- {'[*.]google.com,*': { 'cookies': 2}})
+ {'[*.]%s,*' % self.test_host: { 'cookies': 2}})
# Navigate to google.com and check if cookies are blocked.
- self.NavigateToURL('http://www.google.com')
- self.assertFalse(self.GetCookie(pyauto.GURL('http://www.google.com')),
+ self.NavigateToURL(http_url)
+ self.assertFalse(self.GetCookie(pyauto.GURL(http_url)),
msg='Cookies are being set for the exception.')
# Check if cookies are being set for other websites/webpages.
@@ -170,6 +204,7 @@ class CookiesTest(pyauto.PyUITest):
"""Verify that cookies can be allowed and set using exceptions for
particular website(s) only for a session when all others are blocked."""
file_url = self.GetFileURLForPath('setcookie.html')
+ http_url = 'http://%s' % self.test_host
self.assertFalse(self.GetCookie(pyauto.GURL(file_url)),
msg='Unable to set cookie.')
@@ -183,17 +218,16 @@ class CookiesTest(pyauto.PyUITest):
# Creating an exception to allow cookies for a session for google.com.
self.SetPrefs(pyauto.kContentSettingsPatternPairs,
- {'[*.]google.com,*': { 'cookies': 4}})
+ {'[*.]%s,*' % self.test_host: { 'cookies': 4}})
# Navigate to google.com and check if cookies are set.
- self.NavigateToURL('http://www.google.com')
- self.assertTrue(self.GetCookie(pyauto.GURL('http://www.google.com')),
+ self.NavigateToURL(http_url)
+ self.assertTrue(self.GetCookie(pyauto.GURL(http_url)),
msg='Cookies are not set for the exception.')
# Restart the browser to check that the cookie doesn't persist.
self.RestartBrowser(clear_profile=False)
- self.assertFalse(self.GetCookie(pyauto.GURL('http://www.google.com')),
+ self.assertFalse(self.GetCookie(pyauto.GURL(http_url)),
msg='Cookie persisted after restarting session.')
-
if __name__ == '__main__':
pyauto_functional.Main()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698