summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-03 16:27:01 +0000
committeralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-03 16:27:01 +0000
commit32a69cf04fe60cf9bfa6fe4e63a4dc0069b2d080 (patch)
treeb41acbb9ffae65e0993e478d25133784cd392b67 /chrome
parentc84741368416b492169d2f94ac39cdc3d5400f91 (diff)
downloadchromium_src-32a69cf04fe60cf9bfa6fe4e63a4dc0069b2d080.zip
chromium_src-32a69cf04fe60cf9bfa6fe4e63a4dc0069b2d080.tar.gz
chromium_src-32a69cf04fe60cf9bfa6fe4e63a4dc0069b2d080.tar.bz2
New PyAuto hooks for extensions.
Added two new hooks for extensions: GetExtensionsInfo returns information about all installed extensions and UninstallExtensionById uninstalls a given extension based on its id. Review URL: http://codereview.chromium.org/3053034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54761 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider.cc60
-rw-r--r--chrome/browser/automation/automation_provider.h12
-rw-r--r--chrome/test/functional/extensions.py23
-rw-r--r--chrome/test/pyautolib/pyauto.py40
4 files changed, 135 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index d2ff95c..bfe879f 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -2913,6 +2913,61 @@ void AutomationProvider::GetThemeInfo(Browser* browser,
AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
}
+// Sample json input: { "command": "GetExtensionsInfo" }
+// See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json
+// output.
+void AutomationProvider::GetExtensionsInfo(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ ExtensionsService* service = profile()->GetExtensionsService();
+ if (!service) {
+ reply.SendError("No extensions service.");
+ }
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ ListValue* extensions_values = new ListValue;
+ const ExtensionList* extensions = service->extensions();
+ for (ExtensionList::const_iterator it = extensions->begin();
+ it != extensions->end(); ++it) {
+ const Extension* extension = *it;
+ DictionaryValue* extension_value = new DictionaryValue;
+ extension_value->SetString(L"id", extension->id());
+ extension_value->SetString(L"version", extension->VersionString());
+ extension_value->SetString(L"name", extension->name());
+ extension_value->SetString(L"public_key", extension->public_key());
+ extension_value->SetString(L"description", extension->description());
+ extension_value->SetString(L"background_url",
+ extension->background_url().spec());
+ extension_value->SetString(L"options_url",
+ extension->options_url().spec());
+ extensions_values->Append(extension_value);
+ }
+ return_value->Set(L"extensions", extensions_values);
+ reply.SendSuccess(return_value.get());
+}
+
+// See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample
+// json input.
+// Sample json output: {}
+void AutomationProvider::UninstallExtensionById(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ std::string id;
+ if (!args->GetString(L"id", &id)) {
+ reply.SendError("Must include string id.");
+ return;
+ }
+ ExtensionsService* service = profile()->GetExtensionsService();
+ if (!service) {
+ reply.SendError("No extensions service.");
+ return;
+ }
+ ExtensionUnloadNotificationObserver observer;
+ service->UninstallExtension(id, false);
+ reply.SendSuccess(NULL);
+}
+
// Sample json input:
// { "command": "GetAutoFillProfile" }
// Refer to GetAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample
@@ -3243,6 +3298,11 @@ void AutomationProvider::SendJSONRequest(int handle,
// SetTheme() implemented using InstallExtension().
handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo;
+ // InstallExtension() present in pyauto.py.
+ handler_map["GetExtensionsInfo"] = &AutomationProvider::GetExtensionsInfo;
+ handler_map["UninstallExtensionById"] =
+ &AutomationProvider::UninstallExtensionById;
+
handler_map["SelectTranslateOption"] =
&AutomationProvider::SelectTranslateOption;
handler_map["GetTranslateInfo"] = &AutomationProvider::GetTranslateInfo;
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index ff1492d..fd3d2f5 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -507,6 +507,18 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
DictionaryValue* args,
IPC::Message* reply_message);
+ // Get info about all intalled extensions.
+ // Uses the JSON interface for input/output.
+ void GetExtensionsInfo(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Uninstalls the extension with the given id.
+ // Uses the JSON interface for input/output.
+ void UninstallExtensionById(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Returns information about translation for a given tab. Includes
// information about the translate bar if it is showing.
void GetTranslateInfo(Browser* browser,
diff --git a/chrome/test/functional/extensions.py b/chrome/test/functional/extensions.py
index 785f9af..69902e5 100644
--- a/chrome/test/functional/extensions.py
+++ b/chrome/test/functional/extensions.py
@@ -29,6 +29,22 @@ class ExtensionsTest(pyauto.PyUITest):
extensions_dir_ = 'extensions' # The directory of extensions
urls_file_ = 'urls.txt' # The file which holds a list of urls to visit
+ def Debug(self):
+ """Test method for experimentation.
+
+ This method is not run automatically.
+ """
+ while True:
+ raw_input('Interact with the browser and hit <enter> to dump history.. ')
+ print '*' * 20
+ extensions = self.GetExtensionsInfo()
+ import pprint
+ pp = pprint.PrettyPrinter(indent=2)
+ pp.pprint(extensions)
+
+ def _GetInstalledExtensionIds(self):
+ return [extension['id'] for extension in self.GetExtensionsInfo()]
+
def _ReturnCrashingExtensions(self, extensions, group_size, top_urls):
"""Install the given extensions in groups of group_size and return the
group of extensions that crashes (if any).
@@ -44,6 +60,7 @@ class ExtensionsTest(pyauto.PyUITest):
curr_extension = 0
num_extensions = len(extensions)
self.RestartBrowser()
+ orig_extension_ids = self._GetInstalledExtensionIds()
while curr_extension < num_extensions:
logging.debug('New group of %d extensions.' % group_size)
@@ -68,6 +85,12 @@ class ExtensionsTest(pyauto.PyUITest):
else:
if not num_browser_windows:
return _LogAndReturnCrashing()
+ else:
+ # Uninstall all extensions that aren't installed by default.
+ new_extension_ids = [id for id in self._GetInstalledExtensionIds()
+ if id not in orig_extension_ids]
+ for extension_id in new_extension_ids:
+ self.UninstallExtensionById(extension_id)
curr_extension = group_end
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 8a4bb60..3c3f979 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -720,6 +720,46 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
+ def GetExtensionsInfo(self):
+ """Returns information about all installed extensions.
+
+ Returns:
+ A list of dictionaries representing each of the installed extensions.
+ Example:
+ [ { u'background_url': u'',
+ u'description': u'Bookmark Manager',
+ u'id': u'eemcgdkfndhakfknompkggombfjjjeno',
+ u'name': u'Bookmark Manager',
+ u'options_url': u'',
+ u'version': u'0.1' },
+ { u'background_url': u'chrome-extension://\
+ lkdedmbpkaiahjjibfdmpoefffnbdkli/\
+ background.html',
+ u'description': u'Extension which lets you read your Facebook news \
+ feed and wall. You can also post status updates.',
+ u'id': u'lkdedmbpkaiahjjibfdmpoefffnbdkli',
+ u'name': u'Facebook for Google Chrome',
+ u'options_url': u'',
+ u'version': u'2.0.9' } ]
+ """
+ cmd_dict = { # Prepare command for the json interface
+ 'command': 'GetExtensionsInfo'
+ }
+ return self._GetResultFromJSONRequest(cmd_dict)['extensions']
+
+ def UninstallExtensionById(self, id):
+ """Uninstall the extension with the given id.
+
+ Args:
+ id: The string id of the extension. It can be retrieved through the
+ GetExtensionsInfo call above.
+ """
+ cmd_dict = { # Prepare command for the json interface
+ 'command': 'UninstallExtensionById',
+ 'id': id
+ }
+ self._GetResultFromJSONRequest(cmd_dict)
+
def SelectTranslateOption(self, option, tab_index=0, window_index=0):
"""Selects one of the options in the drop-down menu for the translate bar.