diff options
author | dennisjeffrey@google.com <dennisjeffrey@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 17:28:19 +0000 |
---|---|---|
committer | dennisjeffrey@google.com <dennisjeffrey@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 17:28:19 +0000 |
commit | 42ecd8ab9d02965313bb54049713f24cb2a424c4 (patch) | |
tree | 9b79ea88ac45f408f1e0120f8e81dc59259e7eff | |
parent | edd45493720e09f4438ef286ffa8ce63379e89a5 (diff) | |
download | chromium_src-42ecd8ab9d02965313bb54049713f24cb2a424c4.zip chromium_src-42ecd8ab9d02965313bb54049713f24cb2a424c4.tar.gz chromium_src-42ecd8ab9d02965313bb54049713f24cb2a424c4.tar.bz2 |
Modify GetNTPInfo automation hook to return additional info about apps.
The following additional information is returned:
(1) Whether the app is a component extension.
(2) Whether the app is disabled.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/6689019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80644 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.cc | 65 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 28 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 34 |
3 files changed, 86 insertions, 41 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index a433e66..35f6c7b 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1684,6 +1684,32 @@ void PageSnapshotTaker::SendMessage(bool success) { delete this; } +namespace { + +// Returns a vector of dictionaries containing information about installed apps, +// as identified from a given list of extensions. The caller takes ownership +// of the created vector. +std::vector<DictionaryValue*>* GetAppInfoFromExtensions( + const ExtensionList* extensions, + ExtensionPrefs* ext_prefs) { + std::vector<DictionaryValue*>* apps_list = + new std::vector<DictionaryValue*>(); + for (ExtensionList::const_iterator ext = extensions->begin(); + ext != extensions->end(); ++ext) { + // Only return information about extensions that are actually apps. + if ((*ext)->is_app()) { + DictionaryValue* app_info = new DictionaryValue(); + AppLauncherHandler::CreateAppInfo(*ext, ext_prefs, app_info); + app_info->SetBoolean("is_component_extension", + (*ext)->location() == Extension::COMPONENT); + apps_list->push_back(app_info); + } + } + return apps_list; +} + +} // namespace + NTPInfoObserver::NTPInfoObserver( AutomationProvider* automation, IPC::Message* reply_message, @@ -1706,20 +1732,35 @@ NTPInfoObserver::NTPInfoObserver( return; } - // Get information about the apps in the new tab page. + // Collect information about the apps in the new tab page. ExtensionService* ext_service = automation_->profile()->GetExtensionService(); - const ExtensionList* extensions = ext_service->extensions(); - ListValue* apps_list = new ListValue(); - for (ExtensionList::const_iterator ext = extensions->begin(); - ext != extensions->end(); ++ext) { - // Only return information about extensions that are actually apps. - if ((*ext)->is_app()) { - DictionaryValue* app_info = new DictionaryValue(); - AppLauncherHandler::CreateAppInfo(*ext, ext_service->extension_prefs(), - app_info); - apps_list->Append(app_info); - } + if (!ext_service) { + AutomationJSONReply(automation_, reply_message_.release()) + .SendError("No ExtensionService."); + return; } + // Process enabled extensions. + ExtensionPrefs* ext_prefs = ext_service->extension_prefs(); + ListValue* apps_list = new ListValue(); + const ExtensionList* extensions = ext_service->extensions(); + std::vector<DictionaryValue*>* enabled_apps = GetAppInfoFromExtensions( + extensions, ext_prefs); + for (std::vector<DictionaryValue*>::const_iterator app = + enabled_apps->begin(); app != enabled_apps->end(); ++app) { + (*app)->SetBoolean("is_disabled", false); + apps_list->Append(*app); + } + delete enabled_apps; + // Process disabled extensions. + const ExtensionList* disabled_extensions = ext_service->disabled_extensions(); + std::vector<DictionaryValue*>* disabled_apps = GetAppInfoFromExtensions( + disabled_extensions, ext_prefs); + for (std::vector<DictionaryValue*>::const_iterator app = + disabled_apps->begin(); app != disabled_apps->end(); ++app) { + (*app)->SetBoolean("is_disabled", true); + apps_list->Append(*app); + } + delete disabled_apps; ntp_info_->Set("apps", apps_list); // Get the info that would be displayed in the recently closed section. diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index bd690b6..d3014f5 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -4032,9 +4032,9 @@ void TestingAutomationProvider::SignInToSync(Browser* browser, sync_waiter_->SetCredentials(username, password); } if (sync_waiter_->SetupSync()) { - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("success", true); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } else { reply.SendError("Signing in to sync was unsuccessful"); } @@ -4059,7 +4059,7 @@ void TestingAutomationProvider::GetSyncInfo(Browser* browser, IPC::Message* reply_message) { AutomationJSONReply reply(this, reply_message); DictionaryValue* sync_info = new DictionaryValue; - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); if (sync_waiter_.get() == NULL) { sync_waiter_.reset( ProfileSyncServiceHarness::CreateAndAttach(browser->profile())); @@ -4085,7 +4085,7 @@ void TestingAutomationProvider::GetSyncInfo(Browser* browser, sync_info->Set("synced datatypes", synced_datatype_list); } return_value->Set("sync_info", sync_info); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } // Sample json output: { "success": true } @@ -4157,9 +4157,9 @@ void TestingAutomationProvider::EnableSyncForDatatypes( ProfileSyncService::Status status = sync_waiter_->GetStatus(); if (status.summary == ProfileSyncService::Status::READY || status.summary == ProfileSyncService::Status::SYNCING) { - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("success", true); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } else { reply.SendError("Enabling sync for given datatypes was unsuccessful"); } @@ -4195,9 +4195,9 @@ void TestingAutomationProvider::DisableSyncForDatatypes( ProfileSyncService::Status status = sync_waiter_->GetStatus(); if (status.summary != ProfileSyncService::Status::READY && status.summary != ProfileSyncService::Status::SYNCING) { - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("success", true); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } else { reply.SendError("Disabling all sync datatypes was unsuccessful"); } @@ -4220,9 +4220,9 @@ void TestingAutomationProvider::DisableSyncForDatatypes( ProfileSyncService::Status status = sync_waiter_->GetStatus(); if (status.summary == ProfileSyncService::Status::READY || status.summary == ProfileSyncService::Status::SYNCING) { - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("success", true); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } else { reply.SendError("Disabling sync for given datatypes was unsuccessful"); } @@ -4741,13 +4741,13 @@ void TestingAutomationProvider::GetNTPThumbnailMode( const int shown_sections = ShownSectionsHandler::GetShownSections( browser->profile()->GetPrefs()); - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("apps", shown_sections & APPS ? true : false); return_value->SetBoolean("most_visited", shown_sections & THUMB ? true : false); AutomationJSONReply reply(this, reply_message); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } // Sample JSON input: { "command": "SetNTPThumbnailMode", "section": "apps", @@ -4806,7 +4806,7 @@ void TestingAutomationProvider::GetNTPMenuMode( const int shown_sections = ShownSectionsHandler::GetShownSections( browser->profile()->GetPrefs()); - DictionaryValue* return_value = new DictionaryValue; + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); return_value->SetBoolean("apps", shown_sections & MENU_APPS ? true : false); return_value->SetBoolean("most_visited", shown_sections & MENU_THUMB ? true : false); @@ -4814,7 +4814,7 @@ void TestingAutomationProvider::GetNTPMenuMode( shown_sections & MENU_RECENT ? true : false); AutomationJSONReply reply(this, reply_message); - reply.SendSuccess(return_value); + reply.SendSuccess(return_value.get()); } // Sample JSON input: { "command": "SetNTPMenuMode", "section": "apps", diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index a30b88c..46ff17c 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -2105,32 +2105,36 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): SAMPLE: [ { - u'description': u'Web Store', - u'options_url': u'', u'app_launch_index': 2, - u'name': u'Chrome Web Store', - u'launch_url': u'https://chrome.google.com/webstore', - u'icon_small': u'chrome://favicon/https://chrome.google.com/webstore', - u'launch_container': 2, + u'description': u'Web Store', u'icon_big': u'chrome://theme/IDR_APP_DEFAULT_ICON', + u'icon_small': u'chrome://favicon/https://chrome.google.com/webstore', u'id': u'ahfgeienlihckogmohjhadlkjgocpleb', - u'launch_type': 1 + u'is_component_extension': True, + u'is_disabled': False, + u'launch_container': 2, + u'launch_type': 1, + u'launch_url': u'https://chrome.google.com/webstore', + u'name': u'Chrome Web Store', + u'options_url': u'', }, { - u'description': u'A countdown app', - u'options_url': u'', u'app_launch_index': 1, - u'name': u'Countdown', - u'launch_url': (u'chrome-extension://aeabikdlfbfeihglecobdkdflahfgcpd/' - u'launchLocalPath.html'), + u'description': u'A countdown app', + u'icon_big': (u'chrome-extension://aeabikdlfbfeihglecobdkdflahfgcpd/' + u'countdown128.png'), u'icon_small': (u'chrome://favicon/chrome-extension://' u'aeabikdlfbfeihglecobdkdflahfgcpd/' u'launchLocalPath.html'), - u'launch_container': 2, - u'icon_big': (u'chrome-extension://aeabikdlfbfeihglecobdkdflahfgcpd/' - u'countdown128.png'), u'id': u'aeabikdlfbfeihglecobdkdflahfgcpd', + u'is_component_extension': False, + u'is_disabled': False, + u'launch_container': 2, u'launch_type': 1 + u'launch_url': (u'chrome-extension://aeabikdlfbfeihglecobdkdflahfgcpd/' + u'launchLocalPath.html'), + u'name': u'Countdown', + u'options_url': u'', } ] |