diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-13 17:33:05 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-13 17:33:05 +0000 |
commit | a9ff2c0716e6ad021e555de88d54e8e199afe0d7 (patch) | |
tree | e6231ae6bf359d5f2ad3d6f97e363616def731b7 | |
parent | 67d6d5f6f4d83d4c77a6dcfa686f41d864f1be79 (diff) | |
download | chromium_src-a9ff2c0716e6ad021e555de88d54e8e199afe0d7.zip chromium_src-a9ff2c0716e6ad021e555de88d54e8e199afe0d7.tar.gz chromium_src-a9ff2c0716e6ad021e555de88d54e8e199afe0d7.tar.bz2 |
Add hooks for fetching basic info from the browser.
This includes info like version string, executable name, path, and so on.
Review URL: http://codereview.chromium.org/2009013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47159 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 42 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 5 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 1 | ||||
-rw-r--r-- | chrome/test/functional/browser.py | 36 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 30 |
5 files changed, 114 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 93ad3d5..f73024f 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -71,6 +71,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/automation_constants.h" +#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/json_value_serializer.h" @@ -1591,6 +1592,45 @@ void AutomationProvider::RemoveBookmark(int handle, *success = false; } +// Sample json input: { "command": "GetBrowserInfo" } +// Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for +// sample json output. +void AutomationProvider::GetBrowserInfo(DictionaryValue* args, + IPC::Message* reply_message) { + std::string json_return; + bool reply_return = true; + + DictionaryValue* properties = new DictionaryValue; + properties->SetString(L"ChromeVersion", chrome::kChromeVersion); + properties->SetString(L"BrowserProcessExecutableName", + chrome::kBrowserProcessExecutableName); + properties->SetString(L"HelperProcessExecutableName", + chrome::kHelperProcessExecutableName); + properties->SetString(L"BrowserProcessExecutablePath", + chrome::kBrowserProcessExecutablePath); + properties->SetString(L"HelperProcessExecutablePath", + chrome::kHelperProcessExecutablePath); +#if defined(OS_WIN) + properties->SetString(L"command_line_string", + CommandLine::ForCurrentProcess()->command_line_string()); +#elif defined(OS_POSIX) + std::string command_line_string; + const std::vector<std::string>& argv = + CommandLine::ForCurrentProcess()->argv(); + for (uint i = 0; i < argv.size(); ++i) + command_line_string += argv[i] + " "; + properties->SetString(L"command_line_string", command_line_string); +#endif + + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->Set(L"properties", properties); + + base::JSONWriter::Write(return_value.get(), false, &json_return); + AutomationMsg_SendJSONRequest::WriteReplyParams( + reply_message, json_return, reply_return); + Send(reply_message); +} + // Sample json input: { "command": "GetHistoryInfo", // "search_text": "some text" } // Refer chrome/test/pyautolib/history_info.py for sample json output. @@ -1968,6 +2008,8 @@ void AutomationProvider::SendJSONRequest( handler_map["EnablePlugin"] = &AutomationProvider::EnablePlugin; handler_map["GetPluginsInfo"] = &AutomationProvider::GetPluginsInfo; + handler_map["GetBrowserInfo"] = &AutomationProvider::GetBrowserInfo; + handler_map["GetHistoryInfo"] = &AutomationProvider::GetHistoryInfo; handler_map["AddHistoryItem"] = &AutomationProvider::AddHistoryItem; diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 5662835..b4a7c76 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -334,6 +334,11 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, int64 id, bool* success); + // Get info about the chromium/chrome in use. + // This includes things like version, executable name, executable path. + // Uses the JSON interface for input/output. + void GetBrowserInfo(DictionaryValue* args, IPC::Message* reply_message); + // Get info about downloads. This includes only ones that have been // registered by the history system. // Uses the JSON interface for input/output. diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 146f039..e90655e 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -19,6 +19,7 @@ { 'all': [ 'bookmarks', + 'browser', 'downloads', 'history', 'navigation', diff --git a/chrome/test/functional/browser.py b/chrome/test/functional/browser.py new file mode 100644 index 0000000..7d2b08b --- /dev/null +++ b/chrome/test/functional/browser.py @@ -0,0 +1,36 @@ +#!/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 re + +import pyauto_functional # Must be imported before pyauto +import pyauto + + +class BrowserTest(pyauto.PyUITest): + """TestCase for Browser info.""" + + def Debug(self): + """Test method for experimentation. + + This method will not run automatically. + """ + import pprint + pp = pprint.PrettyPrinter(indent=2) + while True: + raw_input('Hit <enter> to dump info.. ') + properties = self.GetBrowserInfo() + self.assertTrue(properties) + pp.pprint(properties) + + def testGotVersion(self): + """Verify there's a valid version string.""" + version_string = self.GetBrowserInfo()['ChromeVersion'] + self.assertTrue(re.match("\d+\.\d+\.\d+.\.\d+", version_string)) + + +if __name__ == '__main__': + pyauto_functional.Main() + diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 700d156..21d4408 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -308,6 +308,36 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): self.assertTrue(self.WaitUntil( lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1)) + def GetBrowserInfo(self): + """Return info about the browser. + + This includes things like the version number, the executable name, + executable path, and so on. + + Returns: + a dictionary of properties about the browser + Sample: + { u'BrowserProcessExecutableName': u'Chromium', + u'BrowserProcessExecutablePath': u'Chromium.app/Contents/' + 'MacOS/Chromium', + u'ChromeVersion': u'6.0.401.0', + u'HelperProcessExecutableName': u'Chromium Helper', + u'HelperProcessExecutablePath': u'Chromium Helper.app/Contents/' + 'MacOS/Chromium Helper', + u'command_line_string': "command_line_string --with-flags" + } + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'GetBrowserInfo', + } + ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) + if ret_dict.has_key('error'): + raise JSONInterfaceError(ret_dict['error']) + return ret_dict['properties'] + def GetHistoryInfo(self, search_text=''): """Return info about browsing history. |