diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 02:24:04 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 02:24:04 +0000 |
commit | 59a6112447827f01c4e40ef3072819f821989570 (patch) | |
tree | be9f7a44a64e899dd2c27fb35d5c17bacd77b088 /chrome/test/pyautolib | |
parent | 94953a56eb19ddef86c0264ef9cd0ac1f0f18332 (diff) | |
download | chromium_src-59a6112447827f01c4e40ef3072819f821989570.zip chromium_src-59a6112447827f01c4e40ef3072819f821989570.tar.gz chromium_src-59a6112447827f01c4e40ef3072819f821989570.tar.bz2 |
Add generic "json dict" entry point for pyauto commands. Will prevent
the need to modify the automation proxy anymore. New pyauto commands
will only need to edit pyauto.py (to add a new SendJSONCommand() call)
and browser_proxy.cc (to implement the other side). Contrast with the
normal editing of ~8 files.
Also added WaitForAllDownloadsToComplete using new JSON path.
BUG=http://crbug.com/39274
Review URL: http://codereview.chromium.org/1547012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43436 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 9 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.cc | 13 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.h | 5 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 8 |
4 files changed, 34 insertions, 1 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 4d45d65..fe5f9ab 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -69,6 +69,7 @@ except ImportError: raise # Should go after sys.path is set appropriately +import simplejson as json # found in third_party import bookmark_model @@ -143,6 +144,13 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): """ return bookmark_model.BookmarkModel(self._GetBookmarksAsJSON()) + def WaitForAllDownloadsToComplete(self): + """Wait for all downloads to complete.""" + # Implementation detail: uses the generic "JSON command" model + # (experimental) + self._SendJSONRequest(0, json.dumps({'command': + 'WaitForAllDownloadsToComplete'})) + class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): """Base TestSuite for PyAuto UI tests.""" @@ -310,4 +318,3 @@ class Main(object): if __name__ == '__main__': Main() - diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index 4afc72e..84bdd18 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -274,3 +274,16 @@ scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) { return automation()->GetBrowserWindow(window_index); } + +std::string PyUITestBase::_SendJSONRequest(int window_index, + std::string& request) { + scoped_refptr<BrowserProxy> browser_proxy = + automation()->GetBrowserWindow(window_index); + EXPECT_TRUE(browser_proxy.get()); + std::string response; + if (browser_proxy.get()) { + EXPECT_TRUE(browser_proxy->SendJSONRequest(request, &response)); + } + return response; +} + diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h index 1ec6b57..1093fda 100644 --- a/chrome/test/pyautolib/pyautolib.h +++ b/chrome/test/pyautolib/pyautolib.h @@ -139,6 +139,11 @@ class PyUITestBase : public UITestBase { // Get a handle to browser window at the given index, or NULL on failure. scoped_refptr<BrowserProxy> GetBrowserWindow(int window_index); + // Meta-method. Experimental pattern of passing args and response as + // JSON dict to avoid future use of the SWIG interface and + // automation proxy additions. Returns response as JSON dict. + std::string _SendJSONRequest(int window_index, std::string& request); + 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 ed9de32..407aafc 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -309,5 +309,13 @@ class PyUITestBase { %feature("docstring", "Get a proxy to the browser window at the given " "zero-based index.") GetBrowserWindow; scoped_refptr<BrowserProxy> GetBrowserWindow(int window_index); + + // Meta-method + %feature("docstring", "Send a sync JSON request to Chrome. " + "Returns a JSON dict as a response. " + "Internal method.") + _SendJSONRequest; + std::string _SendJSONRequest(int window_index, std::string request); + }; |