summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-15 20:36:41 +0000
committeralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-15 20:36:41 +0000
commit731b4677ab26acf1f6813f5320ef0bec38d325b6 (patch)
tree789ec6c8bb9d2e618a94cdd7fa299b6bf39ba7c6 /chrome
parentb5e5774975c5291cff7dc3df1c2f482d2a10b389 (diff)
downloadchromium_src-731b4677ab26acf1f6813f5320ef0bec38d325b6.zip
chromium_src-731b4677ab26acf1f6813f5320ef0bec38d325b6.tar.gz
chromium_src-731b4677ab26acf1f6813f5320ef0bec38d325b6.tar.bz2
Expose cookie get/set to pyauto
Review URL: http://codereview.chromium.org/2903008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52522 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/test/functional/PYAUTO_TESTS1
-rw-r--r--chrome/test/functional/cookies.py25
-rw-r--r--chrome/test/pyautolib/pyautolib.cc32
-rw-r--r--chrome/test/pyautolib/pyautolib.h7
-rw-r--r--chrome/test/pyautolib/pyautolib.i13
5 files changed, 78 insertions, 0 deletions
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS
index 5029b06..afb3885 100644
--- a/chrome/test/functional/PYAUTO_TESTS
+++ b/chrome/test/functional/PYAUTO_TESTS
@@ -28,6 +28,7 @@
'browsing_data',
'codesign',
'content',
+ 'cookies',
'downloads',
'history',
'navigation',
diff --git a/chrome/test/functional/cookies.py b/chrome/test/functional/cookies.py
new file mode 100644
index 0000000..5a3a60b
--- /dev/null
+++ b/chrome/test/functional/cookies.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+
+import pyauto_functional # Must be imported before pyauto
+import pyauto
+
+
+class CookiesTest(pyauto.PyUITest):
+ """Tests for Cookies."""
+
+ def testCookies(self):
+ """Test setting cookies and getting the value."""
+ cookie_url = pyauto.GURL(self.GetFileURLForPath(
+ os.path.join(self.DataDir(), 'title1.html')))
+ cookie_val = 'foo=bar'
+ self.SetCookie(cookie_url, cookie_val)
+ self.assertEqual(cookie_val, self.GetCookie(cookie_url))
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 0ae5b55..4a24a18 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -298,3 +298,35 @@ std::string PyUITestBase::_SendJSONRequest(int window_index,
bool PyUITestBase::ResetToDefaultTheme() {
return automation()->ResetToDefaultTheme();
}
+
+bool PyUITestBase::SetCookie(const GURL& cookie_url,
+ const std::string& value,
+ int window_index,
+ int tab_index) {
+ scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
+ EXPECT_TRUE(browser_proxy.get());
+ if (!browser_proxy.get())
+ return false;
+ scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
+ EXPECT_TRUE(tab_proxy.get());
+ if (!tab_proxy.get())
+ return false;
+ return tab_proxy->SetCookie(cookie_url, value);
+}
+
+std::string PyUITestBase::GetCookie(const GURL& cookie_url,
+ int window_index,
+ int tab_index) {
+ std::string cookie_val;
+ scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
+ EXPECT_TRUE(browser_proxy.get());
+ // TODO(phadjan.jr): figure out a way to unambiguously report error.
+ if (!browser_proxy.get())
+ return cookie_val;
+ scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
+ EXPECT_TRUE(tab_proxy.get());
+ if (!tab_proxy.get())
+ return cookie_val;
+ EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val));
+ return cookie_val;
+}
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 6c6fc35..e2a35f1 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -150,6 +150,13 @@ class PyUITestBase : public UITestBase {
// Resets to the default theme. Returns true on success.
bool ResetToDefaultTheme();
+ // Sets a cookie value for a url. Returns true on success.
+ bool SetCookie(const GURL& cookie_url, const std::string& value,
+ int window_index=0, int tab_index=0);
+ // Gets a cookie value for the given url.
+ std::string GetCookie(const GURL& cookie_url, int window_index=0,
+ int tab_index=0);
+
private:
// Enables PostTask to main thread.
// Should be shared across multiple instances of PyUITestBase so that this
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index 889f989..a1c4d64 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -313,6 +313,19 @@ class PyUITestBase {
"Returns True on success.") AppendTab;
bool AppendTab(const GURL& tab_url, int window_index=0);
+ %feature("docstring", "Set the value of the cookie at cookie_url to value "
+ "for the given window index and tab index. "
+ "Returns True on success.") SetCookie;
+ bool SetCookie(const GURL& cookie_url, const std::string& value,
+ int window_index=0, int tab_index=0);
+
+ %feature("docstring", "Get the value of the cokie at cookie_url for the "
+ "given window index and tab index. "
+ "Returns empty string on error or if there is no value for the "
+ "cookie.") GetCookieVal;
+ std::string GetCookie(const GURL& cookie_url, int window_index=0,
+ int tab_index=0);
+
// Misc methods
%feature("docstring", "Determine if the browser is running. "
"Returns False if user closed the window or if the browser died")