| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "chrome/browser/browser_window.h" | 13 #include "chrome/browser/browser_window.h" |
| 14 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
| 15 #include "chrome/browser/extensions/extension_error_reporter.h" | 15 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 16 #include "chrome/browser/extensions/extension_host.h" | 16 #include "chrome/browser/extensions/extension_host.h" |
| 17 #include "chrome/browser/extensions/extension_install_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
| 18 #include "chrome/browser/extensions/extensions_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/omnibox/location_bar.h" | 21 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/notification_registrar.h" | 24 #include "chrome/common/notification_registrar.h" |
| 25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/notification_type.h" | 26 #include "chrome/common/notification_type.h" |
| 27 #include "chrome/test/ui_test_utils.h" | 27 #include "chrome/test/ui_test_utils.h" |
| 28 | 28 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 EnableDOMAutomation(); | 39 EnableDOMAutomation(); |
| 40 | 40 |
| 41 // This enables it for extension hosts. | 41 // This enables it for extension hosts. |
| 42 ExtensionHost::EnableDOMAutomation(); | 42 ExtensionHost::EnableDOMAutomation(); |
| 43 | 43 |
| 44 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 44 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 45 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); | 45 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); |
| 46 | 46 |
| 47 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 48 // This makes sure that we create the Default profile first, with no | 48 // This makes sure that we create the Default profile first, with no |
| 49 // ExtensionsService and then the real profile with one, as we do when | 49 // ExtensionService and then the real profile with one, as we do when |
| 50 // running on chromeos. | 50 // running on chromeos. |
| 51 command_line->AppendSwitchASCII(switches::kLoginUser, | 51 command_line->AppendSwitchASCII(switches::kLoginUser, |
| 52 "TestUser@gmail.com"); | 52 "TestUser@gmail.com"); |
| 53 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 53 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 54 command_line->AppendSwitch(switches::kNoFirstRun); | 54 command_line->AppendSwitch(switches::kNoFirstRun); |
| 55 #endif | 55 #endif |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path, | 58 bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path, |
| 59 bool incognito_enabled) { | 59 bool incognito_enabled) { |
| 60 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 60 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 61 { | 61 { |
| 62 NotificationRegistrar registrar; | 62 NotificationRegistrar registrar; |
| 63 registrar.Add(this, NotificationType::EXTENSION_LOADED, | 63 registrar.Add(this, NotificationType::EXTENSION_LOADED, |
| 64 NotificationService::AllSources()); | 64 NotificationService::AllSources()); |
| 65 service->LoadExtension(path); | 65 service->LoadExtension(path); |
| 66 ui_test_utils::RunMessageLoop(); | 66 ui_test_utils::RunMessageLoop(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Find the extension by iterating backwards since it is likely last. | 69 // Find the extension by iterating backwards since it is likely last. |
| 70 FilePath extension_path = path; | 70 FilePath extension_path = path; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 virtual void OnInstallSuccess(const Extension* extension) {} | 118 virtual void OnInstallSuccess(const Extension* extension) {} |
| 119 | 119 |
| 120 virtual void OnInstallFailure(const std::string& error) {} | 120 virtual void OnInstallFailure(const std::string& error) {} |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, | 123 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, |
| 124 const FilePath& path, | 124 const FilePath& path, |
| 125 InstallUIType ui_type, | 125 InstallUIType ui_type, |
| 126 int expected_change) { | 126 int expected_change) { |
| 127 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 127 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 128 service->set_show_extensions_prompts(false); | 128 service->set_show_extensions_prompts(false); |
| 129 size_t num_before = service->extensions()->size(); | 129 size_t num_before = service->extensions()->size(); |
| 130 | 130 |
| 131 { | 131 { |
| 132 NotificationRegistrar registrar; | 132 NotificationRegistrar registrar; |
| 133 registrar.Add(this, NotificationType::EXTENSION_LOADED, | 133 registrar.Add(this, NotificationType::EXTENSION_LOADED, |
| 134 NotificationService::AllSources()); | 134 NotificationService::AllSources()); |
| 135 registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 135 registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
| 136 NotificationService::AllSources()); | 136 NotificationService::AllSources()); |
| 137 registrar.Add(this, NotificationType::EXTENSION_INSTALL_ERROR, | 137 registrar.Add(this, NotificationType::EXTENSION_INSTALL_ERROR, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 167 iter != errors->end(); ++iter) | 167 iter != errors->end(); ++iter) |
| 168 VLOG(1) << *iter; | 168 VLOG(1) << *iter; |
| 169 | 169 |
| 170 return false; | 170 return false; |
| 171 } | 171 } |
| 172 | 172 |
| 173 return WaitForExtensionHostsToLoad(); | 173 return WaitForExtensionHostsToLoad(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { | 176 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { |
| 177 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 177 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 178 service->ReloadExtension(extension_id); | 178 service->ReloadExtension(extension_id); |
| 179 ui_test_utils::RegisterAndWait(this, | 179 ui_test_utils::RegisterAndWait(this, |
| 180 NotificationType::EXTENSION_LOADED, | 180 NotificationType::EXTENSION_LOADED, |
| 181 NotificationService::AllSources()); | 181 NotificationService::AllSources()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { | 184 void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { |
| 185 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 185 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 186 service->UnloadExtension(extension_id); | 186 service->UnloadExtension(extension_id); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) { | 189 void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) { |
| 190 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 190 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 191 service->UninstallExtension(extension_id, false); | 191 service->UninstallExtension(extension_id, false); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void ExtensionBrowserTest::DisableExtension(const std::string& extension_id) { | 194 void ExtensionBrowserTest::DisableExtension(const std::string& extension_id) { |
| 195 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 195 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 196 service->DisableExtension(extension_id); | 196 service->DisableExtension(extension_id); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { | 199 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { |
| 200 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 200 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 201 service->EnableExtension(extension_id); | 201 service->EnableExtension(extension_id); |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool ExtensionBrowserTest::WaitForPageActionCountChangeTo(int count) { | 204 bool ExtensionBrowserTest::WaitForPageActionCountChangeTo(int count) { |
| 205 LocationBarTesting* location_bar = | 205 LocationBarTesting* location_bar = |
| 206 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | 206 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 207 if (location_bar->PageActionCount() != count) { | 207 if (location_bar->PageActionCount() != count) { |
| 208 target_page_action_count_ = count; | 208 target_page_action_count_ = count; |
| 209 ui_test_utils::RegisterAndWait(this, | 209 ui_test_utils::RegisterAndWait(this, |
| 210 NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 210 NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 265 } |
| 266 | 266 |
| 267 void ExtensionBrowserTest::WaitForExtensionLoad() { | 267 void ExtensionBrowserTest::WaitForExtensionLoad() { |
| 268 ui_test_utils::RegisterAndWait(this, NotificationType::EXTENSION_LOADED, | 268 ui_test_utils::RegisterAndWait(this, NotificationType::EXTENSION_LOADED, |
| 269 NotificationService::AllSources()); | 269 NotificationService::AllSources()); |
| 270 WaitForExtensionHostsToLoad(); | 270 WaitForExtensionHostsToLoad(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 bool ExtensionBrowserTest::WaitForExtensionCrash( | 273 bool ExtensionBrowserTest::WaitForExtensionCrash( |
| 274 const std::string& extension_id) { | 274 const std::string& extension_id) { |
| 275 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 275 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 276 | 276 |
| 277 if (!service->GetExtensionById(extension_id, true)) { | 277 if (!service->GetExtensionById(extension_id, true)) { |
| 278 // The extension is already unloaded, presumably due to a crash. | 278 // The extension is already unloaded, presumably due to a crash. |
| 279 return true; | 279 return true; |
| 280 } | 280 } |
| 281 ui_test_utils::RegisterAndWait(this, | 281 ui_test_utils::RegisterAndWait(this, |
| 282 NotificationType::EXTENSION_PROCESS_TERMINATED, | 282 NotificationType::EXTENSION_PROCESS_TERMINATED, |
| 283 NotificationService::AllSources()); | 283 NotificationService::AllSources()); |
| 284 return (service->GetExtensionById(extension_id, true) == NULL); | 284 return (service->GetExtensionById(extension_id, true) == NULL); |
| 285 } | 285 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 MessageLoopForUI::current()->Quit(); | 350 MessageLoopForUI::current()->Quit(); |
| 351 } | 351 } |
| 352 break; | 352 break; |
| 353 } | 353 } |
| 354 | 354 |
| 355 default: | 355 default: |
| 356 NOTREACHED(); | 356 NOTREACHED(); |
| 357 break; | 357 break; |
| 358 } | 358 } |
| 359 } | 359 } |
| OLD | NEW |