| 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" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 const extensions::Extension* | 145 const extensions::Extension* |
| 146 ExtensionBrowserTest::LoadExtensionWithInstallParam( | 146 ExtensionBrowserTest::LoadExtensionWithInstallParam( |
| 147 const base::FilePath& path, | 147 const base::FilePath& path, |
| 148 int flags, | 148 int flags, |
| 149 const std::string& install_param) { | 149 const std::string& install_param) { |
| 150 ExtensionService* service = extensions::ExtensionSystem::Get( | 150 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 151 profile())->extension_service(); | 151 profile())->extension_service(); |
| 152 { | 152 { |
| 153 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED, | 153 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 154 content::NotificationService::AllSources()); | 154 content::NotificationService::AllSources()); |
| 155 | 155 |
| 156 scoped_refptr<extensions::UnpackedInstaller> installer( | 156 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 157 extensions::UnpackedInstaller::Create(service)); | 157 extensions::UnpackedInstaller::Create(service)); |
| 158 installer->set_prompt_for_plugins(false); | 158 installer->set_prompt_for_plugins(false); |
| 159 installer->set_require_modern_manifest_version( | 159 installer->set_require_modern_manifest_version( |
| 160 (flags & kFlagAllowOldManifestVersions) == 0); | 160 (flags & kFlagAllowOldManifestVersions) == 0); |
| 161 installer->Load(path); | 161 installer->Load(path); |
| 162 | 162 |
| 163 observer_->Wait(); | 163 observer_->Wait(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 189 } | 189 } |
| 190 | 190 |
| 191 const std::string extension_id = extension->id(); | 191 const std::string extension_id = extension->id(); |
| 192 | 192 |
| 193 if (!install_param.empty()) { | 193 if (!install_param.empty()) { |
| 194 extensions::ExtensionPrefs::Get(profile()) | 194 extensions::ExtensionPrefs::Get(profile()) |
| 195 ->SetInstallParam(extension_id, install_param); | 195 ->SetInstallParam(extension_id, install_param); |
| 196 // Re-enable the extension if needed. | 196 // Re-enable the extension if needed. |
| 197 if (service->extensions()->Contains(extension_id)) { | 197 if (service->extensions()->Contains(extension_id)) { |
| 198 content::WindowedNotificationObserver load_signal( | 198 content::WindowedNotificationObserver load_signal( |
| 199 chrome::NOTIFICATION_EXTENSION_LOADED, | 199 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 200 content::Source<Profile>(profile())); | 200 content::Source<Profile>(profile())); |
| 201 // Reload the extension so that the NOTIFICATION_EXTENSION_LOADED | 201 // Reload the extension so that the |
| 202 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED |
| 202 // observers may access |install_param|. | 203 // observers may access |install_param|. |
| 203 service->ReloadExtension(extension_id); | 204 service->ReloadExtension(extension_id); |
| 204 load_signal.Wait(); | 205 load_signal.Wait(); |
| 205 extension = service->GetExtensionById(extension_id, false); | 206 extension = service->GetExtensionById(extension_id, false); |
| 206 CHECK(extension) << extension_id << " not found after reloading."; | 207 CHECK(extension) << extension_id << " not found after reloading."; |
| 207 } | 208 } |
| 208 } | 209 } |
| 209 | 210 |
| 210 // Toggling incognito or file access will reload the extension, so wait for | 211 // Toggling incognito or file access will reload the extension, so wait for |
| 211 // the reload and grab the new extension instance. The default state is | 212 // the reload and grab the new extension instance. The default state is |
| 212 // incognito disabled and file access enabled, so we don't wait in those | 213 // incognito disabled and file access enabled, so we don't wait in those |
| 213 // cases. | 214 // cases. |
| 214 { | 215 { |
| 215 content::WindowedNotificationObserver load_signal( | 216 content::WindowedNotificationObserver load_signal( |
| 216 chrome::NOTIFICATION_EXTENSION_LOADED, | 217 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 217 content::Source<Profile>(profile())); | 218 content::Source<Profile>(profile())); |
| 218 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); | 219 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); |
| 219 | 220 |
| 220 if (flags & kFlagEnableIncognito) { | 221 if (flags & kFlagEnableIncognito) { |
| 221 extensions::util::SetIsIncognitoEnabled(extension_id, profile(), true); | 222 extensions::util::SetIsIncognitoEnabled(extension_id, profile(), true); |
| 222 load_signal.Wait(); | 223 load_signal.Wait(); |
| 223 extension = service->GetExtensionById(extension_id, false); | 224 extension = service->GetExtensionById(extension_id, false); |
| 224 CHECK(extension) << extension_id << " not found after reloading."; | 225 CHECK(extension) << extension_id << " not found after reloading."; |
| 225 } | 226 } |
| 226 } | 227 } |
| 227 | 228 |
| 228 { | 229 { |
| 229 content::WindowedNotificationObserver load_signal( | 230 content::WindowedNotificationObserver load_signal( |
| 230 chrome::NOTIFICATION_EXTENSION_LOADED, | 231 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 231 content::Source<Profile>(profile())); | 232 content::Source<Profile>(profile())); |
| 232 CHECK(extensions::util::AllowFileAccess(extension_id, profile())); | 233 CHECK(extensions::util::AllowFileAccess(extension_id, profile())); |
| 233 if (!(flags & kFlagEnableFileAccess)) { | 234 if (!(flags & kFlagEnableFileAccess)) { |
| 234 extensions::util::SetAllowFileAccess(extension_id, profile(), false); | 235 extensions::util::SetAllowFileAccess(extension_id, profile(), false); |
| 235 load_signal.Wait(); | 236 load_signal.Wait(); |
| 236 extension = service->GetExtensionById(extension_id, false); | 237 extension = service->GetExtensionById(extension_id, false); |
| 237 CHECK(extension) << extension_id << " not found after reloading."; | 238 CHECK(extension) << extension_id << " not found after reloading."; |
| 238 } | 239 } |
| 239 } | 240 } |
| 240 | 241 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 498 |
| 498 return NULL; | 499 return NULL; |
| 499 } | 500 } |
| 500 | 501 |
| 501 if (!observer_->WaitForExtensionViewsToLoad()) | 502 if (!observer_->WaitForExtensionViewsToLoad()) |
| 502 return NULL; | 503 return NULL; |
| 503 return service->GetExtensionById(last_loaded_extension_id(), false); | 504 return service->GetExtensionById(last_loaded_extension_id(), false); |
| 504 } | 505 } |
| 505 | 506 |
| 506 void ExtensionBrowserTest::ReloadExtension(const std::string extension_id) { | 507 void ExtensionBrowserTest::ReloadExtension(const std::string extension_id) { |
| 507 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED, | 508 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 508 content::NotificationService::AllSources()); | 509 content::NotificationService::AllSources()); |
| 509 | 510 |
| 510 ExtensionService* service = | 511 ExtensionService* service = |
| 511 extensions::ExtensionSystem::Get(profile())->extension_service(); | 512 extensions::ExtensionSystem::Get(profile())->extension_service(); |
| 512 service->ReloadExtension(extension_id); | 513 service->ReloadExtension(extension_id); |
| 513 | 514 |
| 514 observer_->Wait(); | 515 observer_->Wait(); |
| 515 observer_->WaitForExtensionViewsToLoad(); | 516 observer_->WaitForExtensionViewsToLoad(); |
| 516 } | 517 } |
| 517 | 518 |
| 518 void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { | 519 void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 616 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| 616 profile(), extension_id, script); | 617 profile(), extension_id, script); |
| 617 } | 618 } |
| 618 | 619 |
| 619 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( | 620 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( |
| 620 const std::string& extension_id, | 621 const std::string& extension_id, |
| 621 const std::string& script) { | 622 const std::string& script) { |
| 622 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( | 623 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( |
| 623 profile(), extension_id, script); | 624 profile(), extension_id, script); |
| 624 } | 625 } |
| OLD | NEW |