summaryrefslogtreecommitdiffstats
path: root/chrome/test/pyautolib
diff options
context:
space:
mode:
authordpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 01:01:50 +0000
committerdpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 01:01:50 +0000
commit7ad1cac85e099546dc5ff4424d5c37cbc0fe473e (patch)
tree9b0336a6d292dc4d1d59619c7d6dcb396691b825 /chrome/test/pyautolib
parent0661468753c74324ba7e9373805be4ef3849e151 (diff)
downloadchromium_src-7ad1cac85e099546dc5ff4424d5c37cbc0fe473e.zip
chromium_src-7ad1cac85e099546dc5ff4424d5c37cbc0fe473e.tar.gz
chromium_src-7ad1cac85e099546dc5ff4424d5c37cbc0fe473e.tar.bz2
Add ExecuteJavascript() method to PyUITestBase
This allows us to evaluate JavaScript expressions in the renderer and read values out of the DOM of the page, which is useful for testing things like the PasswordManager. R=nirimesh@chromium.org, jrg@chromium.org, alyssad@chromium.org TEST=chrome/test/functional/test_execute_javascript.py BUG=none Review URL: http://codereview.chromium.org/3012039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55013 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r--chrome/test/pyautolib/pyauto.py8
-rw-r--r--chrome/test/pyautolib/pyautolib.cc30
-rw-r--r--chrome/test/pyautolib/pyautolib.h19
-rw-r--r--chrome/test/pyautolib/pyautolib.i17
4 files changed, 72 insertions, 2 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 89b3c28..bca01d2 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1447,8 +1447,12 @@ class Main(object):
# TODO(nirnimesh): Figure out a way to control this from here on Win too.
if PyUITest.IsPosix():
chrome_flags += ' --enable-crash-reporter'
- if chrome_flags:
- suite_args.append('--extra-chrome-flags=%s' % chrome_flags)
+
+ # We add this so that pyauto can execute javascript in the renderer and
+ # read values back out.
+ chrome_flags += ' --dom-automation'
+
+ suite_args.append('--extra-chrome-flags=%s' % chrome_flags)
pyauto_suite = PyUITestSuite(suite_args)
loaded_tests = self._LoadTests(self._args)
pyauto_suite.addTests(loaded_tests)
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 76c32fe..804c30a 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -297,6 +297,36 @@ std::string PyUITestBase::_SendJSONRequest(int window_index,
return response;
}
+std::wstring PyUITestBase::ExecuteJavascript(const std::wstring& script,
+ int window_index,
+ int tab_index,
+ const std::wstring& frame_xpath) {
+ scoped_refptr<BrowserProxy> browser_proxy =
+ automation()->GetBrowserWindow(window_index);
+ EXPECT_TRUE(browser_proxy.get());
+ std::wstring response;
+ if (!browser_proxy.get())
+ return response;
+ scoped_refptr<TabProxy> tab_proxy =
+ browser_proxy->GetTab(tab_index);
+ EXPECT_TRUE(tab_proxy.get());
+ if (!tab_proxy.get())
+ return response;
+
+ EXPECT_TRUE(tab_proxy->ExecuteAndExtractString(frame_xpath, script,
+ &response));
+ return response;
+}
+
+std::wstring PyUITestBase::GetDOMValue(const std::wstring& expr,
+ int window_index,
+ int tab_index,
+ const std::wstring& frame_xpath) {
+ std::wstring script = std::wstring(L"window.domAutomationController.send(") +
+ expr + std::wstring(L")");
+ return ExecuteJavascript(script, window_index, tab_index, frame_xpath);
+}
+
bool PyUITestBase::ResetToDefaultTheme() {
return automation()->ResetToDefaultTheme();
}
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 2901fed..e3c4c5c 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -148,6 +148,25 @@ class PyUITestBase : public UITestBase {
// automation proxy additions. Returns response as JSON dict.
std::string _SendJSONRequest(int window_index, std::string& request);
+ // Execute javascript in a given tab, and return the response. This is
+ // a low-level method intended for use mostly by GetDOMValue(). Note that
+ // any complicated manipulation of the page should be done by something
+ // like WebDriver, not PyAuto. Also note that in order for the script to
+ // return a value to the calling code, it invoke
+ // window.domAutomationController.send(), passing in the intended return
+ // value.
+ std::wstring ExecuteJavascript(const std::wstring& script,
+ int window_index = 0,
+ int tab_index = 0,
+ const std::wstring& frame_xpath = L"");
+
+ // Evaluate a Javascript expression and return the result as a string. This
+ // method is intended largely to read values out of the frame DOM.
+ std::wstring GetDOMValue(const std::wstring& expr,
+ int window_index = 0,
+ int tab_index = 0,
+ const std::wstring& frame_xpath = L"");
+
// Resets to the default theme. Returns true on success.
bool ResetToDefaultTheme();
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index a1c4d64..b5fd1a5 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -154,6 +154,7 @@ class TabProxy {
%feature("docstring", "Cancel authentication to a login prompt. ")
CancelAuth;
bool CancelAuth();
+
};
class PyUITestSuiteBase {
@@ -347,6 +348,22 @@ class PyUITestBase {
_SendJSONRequest;
std::string _SendJSONRequest(int window_index, std::string request);
+ %feature("docstring", "Execute a string of javascript in the specified "
+ "(window, tab, frame) and return a string.") ExecuteJavascript;
+ std::wstring ExecuteJavascript(const std::wstring& script,
+ int window_index=0,
+ int tab_index=0,
+ const std::wstring& frame_xpath="");
+
+ %feature("docstring", "Evaluate a javascript expression in the specified "
+ "(window, tab, frame) and return the specified DOM value "
+ "as a string. This is a wrapper around "
+ "window.domAutomationController.send().") GetDOMValue;
+ std::wstring GetDOMValue(const std::wstring& expr,
+ int window_index=0,
+ int tab_index=0,
+ const std::wstring& frame_xpath="");
+
%feature("docstring", "Resets to the default theme. "
"Returns true on success.") ResetToDefaultTheme;
bool ResetToDefaultTheme();