| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 | 220 |
| 221 EXPECT_EQ(0u, extension->install_warnings().size()) | 221 EXPECT_EQ(0u, extension->install_warnings().size()) |
| 222 << install_warnings_message; | 222 << install_warnings_message; |
| 223 return NULL; | 223 return NULL; |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 const std::string extension_id = extension->id(); | 227 const std::string extension_id = extension->id(); |
| 228 | 228 |
| 229 // If this is an incognito test (e.g. where the test fixture appended the |
| 230 // --incognito flag), we need to use the original profile when we wait for |
| 231 // notifications. |
| 232 Profile* original_profile = profile()->GetOriginalProfile(); |
| 233 |
| 229 if (!install_param.empty()) { | 234 if (!install_param.empty()) { |
| 230 extensions::ExtensionPrefs::Get(profile()) | 235 extensions::ExtensionPrefs::Get(original_profile) |
| 231 ->SetInstallParam(extension_id, install_param); | 236 ->SetInstallParam(extension_id, install_param); |
| 232 // Re-enable the extension if needed. | 237 // Re-enable the extension if needed. |
| 233 if (registry->enabled_extensions().Contains(extension_id)) { | 238 if (registry->enabled_extensions().Contains(extension_id)) { |
| 234 content::WindowedNotificationObserver load_signal( | 239 content::WindowedNotificationObserver load_signal( |
| 235 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 240 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 236 content::Source<Profile>(profile())); | 241 content::Source<Profile>(original_profile)); |
| 237 // Reload the extension so that the | 242 // Reload the extension so that the |
| 238 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED | 243 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED |
| 239 // observers may access |install_param|. | 244 // observers may access |install_param|. |
| 240 service->ReloadExtension(extension_id); | 245 service->ReloadExtension(extension_id); |
| 241 load_signal.Wait(); | 246 load_signal.Wait(); |
| 242 extension = service->GetExtensionById(extension_id, false); | 247 extension = service->GetExtensionById(extension_id, false); |
| 243 CHECK(extension) << extension_id << " not found after reloading."; | 248 CHECK(extension) << extension_id << " not found after reloading."; |
| 244 } | 249 } |
| 245 } | 250 } |
| 246 | 251 |
| 247 // Toggling incognito or file access will reload the extension, so wait for | 252 // Toggling incognito or file access will reload the extension, so wait for |
| 248 // the reload and grab the new extension instance. The default state is | 253 // the reload and grab the new extension instance. The default state is |
| 249 // incognito disabled and file access enabled, so we don't wait in those | 254 // incognito disabled and file access enabled, so we don't wait in those |
| 250 // cases. | 255 // cases. |
| 251 { | 256 { |
| 252 content::WindowedNotificationObserver load_signal( | 257 content::WindowedNotificationObserver load_signal( |
| 253 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 258 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 254 content::Source<Profile>(profile())); | 259 content::Source<Profile>(original_profile)); |
| 255 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())) | 260 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, original_profile)) |
| 256 << extension_id << " is enabled in incognito, but shouldn't be"; | 261 << extension_id << " is enabled in incognito, but shouldn't be"; |
| 257 | 262 |
| 258 if (flags & kFlagEnableIncognito) { | 263 if (flags & kFlagEnableIncognito) { |
| 259 extensions::util::SetIsIncognitoEnabled(extension_id, profile(), true); | 264 extensions::util::SetIsIncognitoEnabled(extension_id, original_profile, |
| 265 true); |
| 260 load_signal.Wait(); | 266 load_signal.Wait(); |
| 261 extension = service->GetExtensionById(extension_id, false); | 267 extension = service->GetExtensionById(extension_id, false); |
| 262 CHECK(extension) << extension_id << " not found after reloading."; | 268 CHECK(extension) << extension_id << " not found after reloading."; |
| 263 } | 269 } |
| 264 } | 270 } |
| 265 | 271 |
| 266 { | 272 { |
| 267 content::WindowedNotificationObserver load_signal( | 273 content::WindowedNotificationObserver load_signal( |
| 268 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 274 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 269 content::Source<Profile>(profile())); | 275 content::Source<Profile>(original_profile)); |
| 270 CHECK(extensions::util::AllowFileAccess(extension_id, profile())); | 276 CHECK(extensions::util::AllowFileAccess(extension_id, original_profile)); |
| 271 if (!(flags & kFlagEnableFileAccess)) { | 277 if (!(flags & kFlagEnableFileAccess)) { |
| 272 extensions::util::SetAllowFileAccess(extension_id, profile(), false); | 278 extensions::util::SetAllowFileAccess(extension_id, original_profile, |
| 279 false); |
| 273 load_signal.Wait(); | 280 load_signal.Wait(); |
| 274 extension = service->GetExtensionById(extension_id, false); | 281 extension = service->GetExtensionById(extension_id, false); |
| 275 CHECK(extension) << extension_id << " not found after reloading."; | 282 CHECK(extension) << extension_id << " not found after reloading."; |
| 276 } | 283 } |
| 277 } | 284 } |
| 278 | 285 |
| 279 if (!observer_->WaitForExtensionViewsToLoad()) | 286 if (!observer_->WaitForExtensionViewsToLoad()) |
| 280 return NULL; | 287 return NULL; |
| 281 | 288 |
| 282 return extension; | 289 return extension; |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 645 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| 639 profile(), extension_id, script); | 646 profile(), extension_id, script); |
| 640 } | 647 } |
| 641 | 648 |
| 642 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( | 649 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( |
| 643 const std::string& extension_id, | 650 const std::string& extension_id, |
| 644 const std::string& script) { | 651 const std::string& script) { |
| 645 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( | 652 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( |
| 646 profile(), extension_id, script); | 653 profile(), extension_id, script); |
| 647 } | 654 } |
| OLD | NEW |