summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 20:22:17 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 20:22:17 +0000
commitb172783e9129bb9c8c34130d16e3b777f7fca3ea (patch)
tree3724aabfe509af020deb55013dd7bd9d41b0271c /chrome/test
parentb84194157dcf0044df4634ebd279d05a5107bb7e (diff)
downloadchromium_src-b172783e9129bb9c8c34130d16e3b777f7fca3ea.zip
chromium_src-b172783e9129bb9c8c34130d16e3b777f7fca3ea.tar.gz
chromium_src-b172783e9129bb9c8c34130d16e3b777f7fca3ea.tar.bz2
Expose BrowserProxy and TabProxy methods directly to PyAuto
- Swig scoped_refptr so as to make BrowserProxy and TabProxy objects directly visible and callable, although the use of scoped_refptr is transparent to pyauto user - Fix a crash in BookmarkModel.FindByID() while operating on leaf nodes - Expose methods to set preferences - Expose methods to handle http auth prompts - Add a pyauto test to verify the restore-on-start preference - Fix path so that pydoc continues to work on pyauto.py Review URL: http://codereview.chromium.org/1536001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42990 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/functional/prefs.py38
-rw-r--r--chrome/test/pyautolib/argc_argv.i30
-rw-r--r--chrome/test/pyautolib/bookmark_model.py2
-rw-r--r--chrome/test/pyautolib/pyauto.py1
-rw-r--r--chrome/test/pyautolib/pyautolib.cc3
-rw-r--r--chrome/test/pyautolib/pyautolib.h3
-rw-r--r--chrome/test/pyautolib/pyautolib.i147
7 files changed, 195 insertions, 29 deletions
diff --git a/chrome/test/functional/prefs.py b/chrome/test/functional/prefs.py
new file mode 100644
index 0000000..c02332b
--- /dev/null
+++ b/chrome/test/functional/prefs.py
@@ -0,0 +1,38 @@
+#!/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 logging
+
+import pyauto_functional # Must be imported before pyauto
+import pyauto
+
+
+class PrefsTest(pyauto.PyUITest):
+ """TestCase for Preferences."""
+
+ def testSessionRestore(self):
+ url1 = 'http://www.google.com/'
+ url2 = 'http://news.google.com/'
+ self.NavigateToURL(url1)
+ self.AppendTab(pyauto.GURL(url2))
+ num_tabs = self.GetTabCount()
+ # Set pref to restore session on startup
+ browser = self.GetBrowserWindow(0)
+ browser.SetIntPreference(pyauto.kRestoreOnStartup, 1)
+ logging.debug('Setting %s to 1' % pyauto.kRestoreOnStartup)
+ self.CloseBrowserAndServer() # Close browser
+ self.set_clear_profile(False) # Do not clear profile on next startup
+ self.LaunchBrowserAndServer() # Reopen browser
+ self.assertEqual(num_tabs, self.GetTabCount())
+ self.ActivateTab(0)
+ self.assertEqual(url1, self.GetActiveTabURL().spec())
+ self.ActivateTab(1)
+ self.assertEqual(url2, self.GetActiveTabURL().spec())
+ self.set_clear_profile(True) # Restore the flag to clear profile next
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()
+
diff --git a/chrome/test/pyautolib/argc_argv.i b/chrome/test/pyautolib/argc_argv.i
new file mode 100644
index 0000000..b705006
--- /dev/null
+++ b/chrome/test/pyautolib/argc_argv.i
@@ -0,0 +1,30 @@
+// 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.
+//
+// Make functions using (int argc, char** argv) usable as (sys.argv) from python
+
+%typemap(in) (int argc, char **argv) {
+ int i;
+ if (!PyList_Check($input)) {
+ PyErr_SetString(PyExc_ValueError, "Expecting a list");
+ return NULL;
+ }
+ $1 = PyList_Size($input);
+ $2 = (char **) malloc(($1+1)*sizeof(char *));
+ for (i = 0; i < $1; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+ if (!PyString_Check(s)) {
+ free($2);
+ PyErr_SetString(PyExc_ValueError, "List items must be strings");
+ return NULL;
+ }
+ $2[i] = PyString_AsString(s);
+ }
+ $2[i] = 0;
+}
+
+%typemap(freearg) (int argc, char **argv) {
+ if ($2) free($2);
+}
+
diff --git a/chrome/test/pyautolib/bookmark_model.py b/chrome/test/pyautolib/bookmark_model.py
index e201ccf..f67c969 100644
--- a/chrome/test/pyautolib/bookmark_model.py
+++ b/chrome/test/pyautolib/bookmark_model.py
@@ -69,7 +69,7 @@ class BookmarkModel(object):
for node in nodes:
if node['id'] == id:
return node
- for child in node['children']:
+ for child in node.get('children', []):
found_node = self.FindByID(id, [child])
if found_node:
return found_node
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 0e29411..4d45d65 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -53,6 +53,7 @@ def _LocateBinDirs():
}
deps_dirs = [ os.path.join(script_dir, os.pardir,
os.pardir, os.pardir, 'third_party'),
+ script_dir,
]
sys.path += bin_dirs.get(sys.platform, []) + deps_dirs
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index a26b8eb..4afc72e 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -270,4 +270,7 @@ bool PyUITestBase::RemoveBookmark(std::wstring& id) {
return browser_proxy->RemoveBookmark(StringToInt64(WideToUTF16(id)));
}
+scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) {
+ return automation()->GetBrowserWindow(window_index);
+}
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 2d14834..1ec6b57 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -136,6 +136,9 @@ class PyUITestBase : public UITestBase {
// Finally, bookmark deletion:
bool RemoveBookmark(std::wstring& id);
+ // Get a handle to browser window at the given index, or NULL on failure.
+ scoped_refptr<BrowserProxy> GetBrowserWindow(int window_index);
+
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 009832a..ed9de32 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -17,40 +17,39 @@
%module(docstring="Python interface to Automtion Proxy.") pyautolib
%feature("autodoc", "1");
-%include "std_string.i"
-%include "std_wstring.i"
+%include <std_wstring.i>
+%include <std_string.i>
+
+%include "chrome/test/pyautolib/argc_argv.i"
+
+// Headers that can be swigged directly.
+%include "chrome/app/chrome_dll_resource.h"
+%include "chrome/common/pref_names.h"
+%include "chrome/test/automation/automation_constants.h"
%{
+#include "chrome/common/pref_names.h"
+#include "chrome/test/automation/automation_constants.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/pyautolib/pyautolib.h"
%}
-// Make functions using (int argc, char** argv) usable as (sys.argv) from python
-%typemap(in) (int argc, char **argv) {
- int i;
- if (!PyList_Check($input)) {
- PyErr_SetString(PyExc_ValueError, "Expecting a list");
- return NULL;
- }
- $1 = PyList_Size($input);
- $2 = (char **) malloc(($1+1)*sizeof(char *));
- for (i = 0; i < $1; i++) {
- PyObject *s = PyList_GetItem($input,i);
- if (!PyString_Check(s)) {
- free($2);
- PyErr_SetString(PyExc_ValueError, "List items must be strings");
- return NULL;
- }
- $2[i] = PyString_AsString(s);
- }
- $2[i] = 0;
-}
-
-%typemap(freearg) (int argc, char **argv) {
- if ($2) free($2);
-}
+// scoped_refptr
+template <class T>
+class scoped_refptr {
+ public:
+ scoped_refptr();
+ scoped_refptr(T* p);
+ ~scoped_refptr();
-%include "chrome/app/chrome_dll_resource.h"
+ T* get() const;
+ T* operator->() const;
+};
+%template(scoped_refptr__BrowserProxy) scoped_refptr<BrowserProxy>;
+%template(scoped_refptr__TabProxy) scoped_refptr<TabProxy>;
+// GURL
%feature("docstring", "Represent a URL. Call spec() to get the string.") GURL;
class GURL {
public:
@@ -60,6 +59,7 @@ class GURL {
const std::string& spec() const;
};
+// FilePath
%feature("docstring",
"Represent a file path. Call value() to get the string.") FilePath;
class FilePath {
@@ -71,12 +71,86 @@ class FilePath {
typedef std::string StringType;
#endif // SWIGWIN
const StringType& value() const;
- %feature("docstring", "Construct an empty FilePath or from a string.")
+ %feature("docstring", "Construct an empty FilePath from a string.")
FilePath;
FilePath();
explicit FilePath(const StringType& path);
};
+// BrowserProxy
+%feature("docstring", "Proxy handle to a browser window.") BrowserProxy;
+%nodefaultctor BrowserProxy;
+%nodefaultdtor BrowserProxy;
+class BrowserProxy {
+ public:
+ %feature("docstring", "Activate the tab at the given zero-based index")
+ ActivateTab;
+ bool ActivateTab(int tab_index);
+
+ %feature("docstring", "Get proxy to the tab at the given zero-based index")
+ GetTab;
+ scoped_refptr<TabProxy> GetTab(int tab_index) const;
+
+ // Prefs
+ %feature("docstring", "Sets the int value of the specified preference. "
+ "Refer chrome/common/pref_names.h for the list of prefs.")
+ SetIntPreference;
+ bool SetIntPreference(const std::wstring& name, int value);
+ %feature("docstring", "Sets the string value of the specified preference. "
+ "Refer chrome/common/pref_names.h for the list of prefs.")
+ SetStringPreference;
+ bool SetStringPreference(const std::wstring& name, const std::wstring& value);
+ %feature("docstring", "Sets the boolean value of the specified preference. "
+ "Refer chrome/common/pref_names.h for the list of prefs.")
+ SetBooleanPreference;
+ bool SetBooleanPreference(const std::wstring& name, bool value);
+};
+
+// TabProxy
+%feature("docstring", "Proxy handle to a tab.") TabProxy;
+%nodefaultctor TabProxy;
+%nodefaultdtor TabProxy;
+class TabProxy {
+ public:
+ // Navigation
+ %feature("docstring", "Navigates to a given GURL. "
+ "Blocks until the navigation completes. ") NavigateToURL;
+ AutomationMsg_NavigationResponseValues NavigateToURL(const GURL& url);
+ %feature("docstring", "Equivalent to hitting the Back button. "
+ "Blocks until navigation completes.") GoBack;
+ AutomationMsg_NavigationResponseValues GoBack();
+ %feature("docstring", "Equivalent to hitting the Forward button. "
+ "Blocks until navigation completes.") GoForward;
+ AutomationMsg_NavigationResponseValues GoForward();
+ %feature("docstring", "Equivalent to hitting the Reload button. "
+ "Blocks until navigation completes.") Reload;
+ AutomationMsg_NavigationResponseValues Reload();
+ %feature("docstring", "Closes the tab. Supply True to wait "
+ "until the tab has closed, else it'll wait only until the call "
+ "has been initiated. Be careful while closing the last tab "
+ "since it might close the browser.") Close;
+ bool Close();
+ bool Close(bool wait_until_closed);
+
+ // HTTP Auth
+ %feature("docstring",
+ "Checks if this tab has a login prompt waiting for auth. This will be "
+ "true if a navigation results in a login prompt, and if an attempted "
+ "login fails. "
+ "Note that this is only valid if you've done a navigation on this same "
+ "object; different TabProxy objects can refer to the same Tab. Calls "
+ "that can set this are NavigateToURL, GoBack, and GoForward. ")
+ NeedsAuth;
+ bool NeedsAuth() const;
+ %feature("docstring", "Supply authentication to a login prompt. "
+ "Blocks until navigation completes or another login prompt appears "
+ "in the case of failed auth.") SetAuth;
+ bool SetAuth(const std::wstring& username, const std::wstring& password);
+ %feature("docstring", "Cancel authentication to a login prompt. ")
+ CancelAuth;
+ bool CancelAuth();
+};
+
class PyUITestSuiteBase {
public:
%feature("docstring", "Create the suite.") PyUITestSuiteBase;
@@ -102,6 +176,19 @@ class PyUITestBase {
"Closes all windows and destroys the browser.") TearDown;
virtual void TearDown();
+ %feature("docstring", "Launches the browser and IPC testing server.")
+ LaunchBrowserAndServer;
+ void LaunchBrowserAndServer();
+ %feature("docstring", "Closes the browser and IPC testing server.")
+ CloseBrowserAndServer;
+ void CloseBrowserAndServer();
+
+ %feature("docstring", "If False, sets the flag so that the profile is "
+ "not cleared on next startup. Useful for persisting profile "
+ "across restarts. By default the state is True, to clear profile.")
+ set_clear_profile;
+ void set_clear_profile(bool clear_profile);
+
// Navigation Methods
%feature("docstring", "Navigate to the given url in the given tab and given "
"window (or active tab in first window if indexes not given). "
@@ -218,5 +305,9 @@ class PyUITestBase {
%feature("docstring", "Install an extension from the given file. Returns "
"True if successfully installed and loaded.") InstallExtension;
bool InstallExtension(const FilePath& crx_file);
+
+ %feature("docstring", "Get a proxy to the browser window at the given "
+ "zero-based index.") GetBrowserWindow;
+ scoped_refptr<BrowserProxy> GetBrowserWindow(int window_index);
};