| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | |
| 18 #include "chrome/browser/extensions/browsertest_util.h" | 17 #include "chrome/browser/extensions/browsertest_util.h" |
| 19 #include "chrome/browser/extensions/component_loader.h" | 18 #include "chrome/browser/extensions/component_loader.h" |
| 20 #include "chrome/browser/extensions/crx_installer.h" | 19 #include "chrome/browser/extensions/crx_installer.h" |
| 21 #include "chrome/browser/extensions/extension_creator.h" | 20 #include "chrome/browser/extensions/extension_creator.h" |
| 22 #include "chrome/browser/extensions/extension_error_reporter.h" | 21 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 23 #include "chrome/browser/extensions/extension_install_prompt.h" | 22 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/extensions/extension_util.h" | 24 #include "chrome/browser/extensions/extension_util.h" |
| 26 #include "chrome/browser/extensions/unpacked_installer.h" | 25 #include "chrome/browser/extensions/unpacked_installer.h" |
| 27 #include "chrome/browser/extensions/updater/extension_cache_fake.h" | 26 #include "chrome/browser/extensions/updater/extension_cache_fake.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 30 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 33 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
| 34 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
| 36 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 37 #include "content/public/browser/navigation_controller.h" | 36 #include "content/public/browser/navigation_controller.h" |
| 38 #include "content/public/browser/navigation_entry.h" | 37 #include "content/public/browser/navigation_entry.h" |
| 39 #include "content/public/browser/notification_registrar.h" | 38 #include "content/public/browser/notification_registrar.h" |
| 40 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 41 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| 42 #include "content/public/test/browser_test_utils.h" | 41 #include "content/public/test/browser_test_utils.h" |
| 43 #include "extensions/browser/extension_host.h" | 42 #include "extensions/browser/extension_host.h" |
| 44 #include "extensions/browser/extension_prefs.h" | 43 #include "extensions/browser/extension_prefs.h" |
| 45 #include "extensions/browser/extension_system.h" | 44 #include "extensions/browser/extension_system.h" |
| 45 #include "extensions/browser/notification_types.h" |
| 46 #include "extensions/browser/uninstall_reason.h" | 46 #include "extensions/browser/uninstall_reason.h" |
| 47 #include "extensions/common/constants.h" | 47 #include "extensions/common/constants.h" |
| 48 #include "extensions/common/extension_set.h" | 48 #include "extensions/common/extension_set.h" |
| 49 #include "sync/api/string_ordinal.h" | 49 #include "sync/api/string_ordinal.h" |
| 50 | 50 |
| 51 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 52 #include "chromeos/chromeos_switches.h" | 52 #include "chromeos/chromeos_switches.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 using extensions::Extension; | 55 using extensions::Extension; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 const extensions::Extension* | 146 const extensions::Extension* |
| 147 ExtensionBrowserTest::LoadExtensionWithInstallParam( | 147 ExtensionBrowserTest::LoadExtensionWithInstallParam( |
| 148 const base::FilePath& path, | 148 const base::FilePath& path, |
| 149 int flags, | 149 int flags, |
| 150 const std::string& install_param) { | 150 const std::string& install_param) { |
| 151 ExtensionService* service = extensions::ExtensionSystem::Get( | 151 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 152 profile())->extension_service(); | 152 profile())->extension_service(); |
| 153 { | 153 { |
| 154 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 154 observer_->Watch(extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 155 content::NotificationService::AllSources()); | 155 content::NotificationService::AllSources()); |
| 156 | 156 |
| 157 scoped_refptr<extensions::UnpackedInstaller> installer( | 157 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 158 extensions::UnpackedInstaller::Create(service)); | 158 extensions::UnpackedInstaller::Create(service)); |
| 159 installer->set_prompt_for_plugins(false); | 159 installer->set_prompt_for_plugins(false); |
| 160 installer->set_require_modern_manifest_version( | 160 installer->set_require_modern_manifest_version( |
| 161 (flags & kFlagAllowOldManifestVersions) == 0); | 161 (flags & kFlagAllowOldManifestVersions) == 0); |
| 162 installer->Load(path); | 162 installer->Load(path); |
| 163 | 163 |
| 164 observer_->Wait(); | 164 observer_->Wait(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 190 } | 190 } |
| 191 | 191 |
| 192 const std::string extension_id = extension->id(); | 192 const std::string extension_id = extension->id(); |
| 193 | 193 |
| 194 if (!install_param.empty()) { | 194 if (!install_param.empty()) { |
| 195 extensions::ExtensionPrefs::Get(profile()) | 195 extensions::ExtensionPrefs::Get(profile()) |
| 196 ->SetInstallParam(extension_id, install_param); | 196 ->SetInstallParam(extension_id, install_param); |
| 197 // Re-enable the extension if needed. | 197 // Re-enable the extension if needed. |
| 198 if (service->extensions()->Contains(extension_id)) { | 198 if (service->extensions()->Contains(extension_id)) { |
| 199 content::WindowedNotificationObserver load_signal( | 199 content::WindowedNotificationObserver load_signal( |
| 200 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 200 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 201 content::Source<Profile>(profile())); | 201 content::Source<Profile>(profile())); |
| 202 // Reload the extension so that the | 202 // Reload the extension so that the |
| 203 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED | 203 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED |
| 204 // observers may access |install_param|. | 204 // observers may access |install_param|. |
| 205 service->ReloadExtension(extension_id); | 205 service->ReloadExtension(extension_id); |
| 206 load_signal.Wait(); | 206 load_signal.Wait(); |
| 207 extension = service->GetExtensionById(extension_id, false); | 207 extension = service->GetExtensionById(extension_id, false); |
| 208 CHECK(extension) << extension_id << " not found after reloading."; | 208 CHECK(extension) << extension_id << " not found after reloading."; |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Toggling incognito or file access will reload the extension, so wait for | 212 // Toggling incognito or file access will reload the extension, so wait for |
| 213 // the reload and grab the new extension instance. The default state is | 213 // the reload and grab the new extension instance. The default state is |
| 214 // incognito disabled and file access enabled, so we don't wait in those | 214 // incognito disabled and file access enabled, so we don't wait in those |
| 215 // cases. | 215 // cases. |
| 216 { | 216 { |
| 217 content::WindowedNotificationObserver load_signal( | 217 content::WindowedNotificationObserver load_signal( |
| 218 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 218 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 219 content::Source<Profile>(profile())); | 219 content::Source<Profile>(profile())); |
| 220 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); | 220 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); |
| 221 | 221 |
| 222 if (flags & kFlagEnableIncognito) { | 222 if (flags & kFlagEnableIncognito) { |
| 223 extensions::util::SetIsIncognitoEnabled(extension_id, profile(), true); | 223 extensions::util::SetIsIncognitoEnabled(extension_id, profile(), true); |
| 224 load_signal.Wait(); | 224 load_signal.Wait(); |
| 225 extension = service->GetExtensionById(extension_id, false); | 225 extension = service->GetExtensionById(extension_id, false); |
| 226 CHECK(extension) << extension_id << " not found after reloading."; | 226 CHECK(extension) << extension_id << " not found after reloading."; |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 { | 230 { |
| 231 content::WindowedNotificationObserver load_signal( | 231 content::WindowedNotificationObserver load_signal( |
| 232 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 232 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 233 content::Source<Profile>(profile())); | 233 content::Source<Profile>(profile())); |
| 234 CHECK(extensions::util::AllowFileAccess(extension_id, profile())); | 234 CHECK(extensions::util::AllowFileAccess(extension_id, profile())); |
| 235 if (!(flags & kFlagEnableFileAccess)) { | 235 if (!(flags & kFlagEnableFileAccess)) { |
| 236 extensions::util::SetAllowFileAccess(extension_id, profile(), false); | 236 extensions::util::SetAllowFileAccess(extension_id, profile(), false); |
| 237 load_signal.Wait(); | 237 load_signal.Wait(); |
| 238 extension = service->GetExtensionById(extension_id, false); | 238 extension = service->GetExtensionById(extension_id, false); |
| 239 CHECK(extension) << extension_id << " not found after reloading."; | 239 CHECK(extension) << extension_id << " not found after reloading."; |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 installer->set_creation_flags(creation_flags); | 488 installer->set_creation_flags(creation_flags); |
| 489 installer->set_install_source(install_source); | 489 installer->set_install_source(install_source); |
| 490 installer->set_install_immediately(install_immediately); | 490 installer->set_install_immediately(install_immediately); |
| 491 installer->set_is_ephemeral(is_ephemeral); | 491 installer->set_is_ephemeral(is_ephemeral); |
| 492 if (!installer->is_gallery_install()) { | 492 if (!installer->is_gallery_install()) { |
| 493 installer->set_off_store_install_allow_reason( | 493 installer->set_off_store_install_allow_reason( |
| 494 extensions::CrxInstaller::OffStoreInstallAllowedInTest); | 494 extensions::CrxInstaller::OffStoreInstallAllowedInTest); |
| 495 } | 495 } |
| 496 | 496 |
| 497 observer_->Watch( | 497 observer_->Watch( |
| 498 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 498 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 499 content::Source<extensions::CrxInstaller>(installer.get())); | 499 content::Source<extensions::CrxInstaller>(installer.get())); |
| 500 | 500 |
| 501 installer->InstallCrx(crx_path); | 501 installer->InstallCrx(crx_path); |
| 502 | 502 |
| 503 observer_->Wait(); | 503 observer_->Wait(); |
| 504 } | 504 } |
| 505 | 505 |
| 506 size_t num_after = service->extensions()->size(); | 506 size_t num_after = service->extensions()->size(); |
| 507 EXPECT_EQ(num_before + expected_change, num_after); | 507 EXPECT_EQ(num_before + expected_change, num_after); |
| 508 if (num_before + expected_change != num_after) { | 508 if (num_before + expected_change != num_after) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 524 | 524 |
| 525 return NULL; | 525 return NULL; |
| 526 } | 526 } |
| 527 | 527 |
| 528 if (!observer_->WaitForExtensionViewsToLoad()) | 528 if (!observer_->WaitForExtensionViewsToLoad()) |
| 529 return NULL; | 529 return NULL; |
| 530 return service->GetExtensionById(last_loaded_extension_id(), false); | 530 return service->GetExtensionById(last_loaded_extension_id(), false); |
| 531 } | 531 } |
| 532 | 532 |
| 533 void ExtensionBrowserTest::ReloadExtension(const std::string extension_id) { | 533 void ExtensionBrowserTest::ReloadExtension(const std::string extension_id) { |
| 534 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 534 observer_->Watch(extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 535 content::NotificationService::AllSources()); | 535 content::NotificationService::AllSources()); |
| 536 | 536 |
| 537 ExtensionService* service = | 537 ExtensionService* service = |
| 538 extensions::ExtensionSystem::Get(profile())->extension_service(); | 538 extensions::ExtensionSystem::Get(profile())->extension_service(); |
| 539 service->ReloadExtension(extension_id); | 539 service->ReloadExtension(extension_id); |
| 540 | 540 |
| 541 observer_->Wait(); | 541 observer_->Wait(); |
| 542 observer_->WaitForExtensionViewsToLoad(); | 542 observer_->WaitForExtensionViewsToLoad(); |
| 543 } | 543 } |
| 544 | 544 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 645 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| 646 profile(), extension_id, script); | 646 profile(), extension_id, script); |
| 647 } | 647 } |
| 648 | 648 |
| 649 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( | 649 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( |
| 650 const std::string& extension_id, | 650 const std::string& extension_id, |
| 651 const std::string& script) { | 651 const std::string& script) { |
| 652 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( | 652 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( |
| 653 profile(), extension_id, script); | 653 profile(), extension_id, script); |
| 654 } | 654 } |
| OLD | NEW |