Commit b15c73c0 authored by alyssad@chromium.org's avatar alyssad@chromium.org

New PyAuto tests for cookies.

Review URL: http://codereview.chromium.org/3050018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54011 0039d316-1c4b-4281-b951-d872f2087c98
parent 224526b1
<html>
<head>
<title>This page sets a cookie</title>
<script type="text/javascript">
function makeCookie()
{
expireAt = new Date;
expireAt.setMonth(expireAt.getMonth() + 3);
username = "Good";
document.cookie = "name=" + username + ";expires=" + expireAt.toGMTString()
}
</script>
</head>
<body onLoad="makeCookie()">
</body>
</html>
...@@ -12,7 +12,32 @@ import pyauto ...@@ -12,7 +12,32 @@ import pyauto
class CookiesTest(pyauto.PyUITest): class CookiesTest(pyauto.PyUITest):
"""Tests for Cookies.""" """Tests for Cookies."""
def testCookies(self): def _ClearCookiesAndCheck(self, url):
self.ClearBrowsingData(['COOKIES'], 'EVERYTHING')
cookie_data = self.GetCookie(pyauto.GURL(url))
self.assertEqual(0, len(cookie_data))
def _CookieCheckRegularWindow(self, url):
"""Check the cookie for the given URL in a regular window."""
self._ClearCookiesAndCheck(url)
# Assert that the cookie data isn't empty after navigating to the url.
self.NavigateToURL(url)
cookie_data = self.GetCookie(pyauto.GURL(url))
self.assertNotEqual(0, len(cookie_data))
# Restart the browser and ensure the cookie data is the same.
self.RestartBrowser(clear_profile=False)
self.assertEqual(cookie_data, self.GetCookie(pyauto.GURL(url)))
def _CookieCheckIncognitoWindow(self, url):
"""Check the cookie for the given URL in an incognito window."""
self._ClearCookiesAndCheck(url)
# Navigate to the URL in an incognito window and verify no cookie is set.
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
self.NavigateToURL(url, 1, 0)
cookie_data = self.GetCookie(pyauto.GURL(url))
self.assertEqual(0, len(cookie_data))
def testSetCookies(self):
"""Test setting cookies and getting the value.""" """Test setting cookies and getting the value."""
cookie_url = pyauto.GURL(self.GetFileURLForPath( cookie_url = pyauto.GURL(self.GetFileURLForPath(
os.path.join(self.DataDir(), 'title1.html'))) os.path.join(self.DataDir(), 'title1.html')))
...@@ -20,6 +45,25 @@ class CookiesTest(pyauto.PyUITest): ...@@ -20,6 +45,25 @@ class CookiesTest(pyauto.PyUITest):
self.SetCookie(cookie_url, cookie_val) self.SetCookie(cookie_url, cookie_val)
self.assertEqual(cookie_val, self.GetCookie(cookie_url)) self.assertEqual(cookie_val, self.GetCookie(cookie_url))
def testCookiesHttp(self):
"""Test cookies set over HTTP for incognito and regular windows."""
http_url = 'http://www.google.com'
self._CookieCheckRegularWindow(http_url)
self._CookieCheckIncognitoWindow(http_url)
def testCookiesHttps(self):
"""Test cookies set over HTTPS for incognito and regular windows."""
https_url = 'https://www.google.com'
self._CookieCheckRegularWindow(https_url)
self._CookieCheckIncognitoWindow(https_url)
def testCookiesFile(self):
"""Test cookies set from an HTML file for incognito and regular windows."""
file_url = self.GetFileURLForPath(
os.path.join(self.DataDir(), 'setcookie.html'))
self._CookieCheckRegularWindow(file_url)
self._CookieCheckIncognitoWindow(file_url)
if __name__ == '__main__': if __name__ == '__main__':
pyauto_functional.Main() pyauto_functional.Main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment