summaryrefslogtreecommitdiffstats
path: root/chrome/test/pyautolib
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 15:25:27 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 15:25:27 +0000
commit0f164be78650c2e735641600562f810d1a214769 (patch)
treefdfb4224b157e8be2baa18cbea80baf2c64cfd9a /chrome/test/pyautolib
parent616381f0a55322de447465573e39612e5af18b31 (diff)
downloadchromium_src-0f164be78650c2e735641600562f810d1a214769.zip
chromium_src-0f164be78650c2e735641600562f810d1a214769.tar.gz
chromium_src-0f164be78650c2e735641600562f810d1a214769.tar.bz2
Add pyauto tests and helper files for system-level testing of Web SQL Databases.
BUG=59379 TEST=none Review URL: http://codereview.chromium.org/4223001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r--chrome/test/pyautolib/pyauto.py34
-rw-r--r--chrome/test/pyautolib/pyautolib.cc6
-rw-r--r--chrome/test/pyautolib/pyautolib.h4
-rw-r--r--chrome/test/pyautolib/pyautolib.i5
4 files changed, 49 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 60b4728..a152c7e 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1596,6 +1596,40 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ def CallJavascriptFunc(self, function, args=[], tab_index=0, windex=0):
+ """Executes a script which calls a given javascript function.
+
+ The invoked javascript function must send a result back via the
+ domAutomationController.send function, or this function will never return.
+
+ Defaults to first tab in first window.
+
+ Args:
+ function: name of the function
+ args: list of all the arguments to pass into the called function. These
+ should be able to be converted to a string using the |str| function.
+ tab_index: index of the tab within the given window
+ windex: index of the window
+
+ Returns:
+ a string that was sent back via the domAutomationController.send method
+ """
+ # Convert the given arguments for evaluation in a javascript statement.
+ converted_args = []
+ for arg in args:
+ # If it is a string argument, we need to quote and escape it properly.
+ if type(arg) == type('string') or type(arg) == type(u'unicode'):
+ # We must convert all " in the string to \", so that we don't try
+ # to evaluate invalid javascript like ""arg"".
+ converted_arg = '"' + arg.replace('"', '\\"') + '"'
+ else:
+ # Convert it to a string so that we can use |join| later.
+ converted_arg = str(arg)
+ converted_args += [converted_arg]
+ js = '%s(%s)' % (function, ', '.join(converted_args))
+ logging.debug('Executing javascript: ', js)
+ return self.ExecuteJavascript(js, windex, tab_index)
+
class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite):
"""Base TestSuite for PyAuto UI tests."""
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index e1007df..6d35548 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -80,6 +80,12 @@ void PyUITestBase::NavigateToURL(
UITestBase::NavigateToURL(url, window_index, tab_index);
}
+void PyUITestBase::ReloadActiveTab(int window_index) {
+ scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
+ ASSERT_TRUE(tab_proxy.get());
+ ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->Reload());
+}
+
bool PyUITestBase::AppendTab(const GURL& tab_url, int window_index) {
scoped_refptr<BrowserProxy> browser_proxy =
automation()->GetBrowserWindow(window_index);
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index c40b97e..00f1c28 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -58,6 +58,10 @@ class PyUITestBase : public UITestBase {
// Blocks until page loaded.
void NavigateToURL(const char* url_string, int window_index, int tab_index);
+ // Reloads the active tab in the given window.
+ // Blocks until page reloaded.
+ void ReloadActiveTab(int window_index = 0);
+
// Get the URL of the active tab.
GURL GetActiveTabURL(int window_index = 0);
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index 875d530..1a46ee0 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -221,6 +221,11 @@ class PyUITestBase {
void NavigateToURL(const char* url_string);
void NavigateToURL(const char* url_string, int window_index, int tab_index);
+ %feature("docstring", "Reload the active tab in the given window (or first "
+ "window if index not given). Blocks until page has reloaded.")
+ ReloadActiveTab;
+ void ReloadActiveTab(int window_index = 0);
+
// BrowserProxy methods
%feature("docstring", "Apply the accelerator with given id "
"(IDC_BACK, IDC_NEWTAB ...) to the given or first window. "