| 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_path.h" | 10 #include "base/file_path.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // ExtensionService and then the real profile with one, as we do when | 72 // ExtensionService and then the real profile with one, as we do when |
| 73 // running on chromeos. | 73 // running on chromeos. |
| 74 command_line->AppendSwitchASCII(switches::kLoginUser, | 74 command_line->AppendSwitchASCII(switches::kLoginUser, |
| 75 "TestUser@gmail.com"); | 75 "TestUser@gmail.com"); |
| 76 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 76 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 77 #endif | 77 #endif |
| 78 } | 78 } |
| 79 | 79 |
| 80 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( | 80 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( |
| 81 const FilePath& path, int flags) { | 81 const FilePath& path, int flags) { |
| 82 ExtensionService* service = browser()->profile()->GetExtensionService(); | 82 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 83 browser()->profile())->extension_service(); |
| 83 { | 84 { |
| 84 content::NotificationRegistrar registrar; | 85 content::NotificationRegistrar registrar; |
| 85 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 86 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 86 content::NotificationService::AllSources()); | 87 content::NotificationService::AllSources()); |
| 87 scoped_refptr<extensions::UnpackedInstaller> installer( | 88 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 88 extensions::UnpackedInstaller::Create(service)); | 89 extensions::UnpackedInstaller::Create(service)); |
| 89 installer->set_prompt_for_plugins(false); | 90 installer->set_prompt_for_plugins(false); |
| 90 installer->set_require_modern_manifest_version( | 91 installer->set_require_modern_manifest_version( |
| 91 (flags & kFlagAllowOldManifestVersions) == 0); | 92 (flags & kFlagAllowOldManifestVersions) == 0); |
| 92 installer->Load(path); | 93 installer->Load(path); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 178 } |
| 178 | 179 |
| 179 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( | 180 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( |
| 180 const FilePath& path) { | 181 const FilePath& path) { |
| 181 return LoadExtensionWithFlags(path, | 182 return LoadExtensionWithFlags(path, |
| 182 kFlagEnableFileAccess | kFlagEnableIncognito); | 183 kFlagEnableFileAccess | kFlagEnableIncognito); |
| 183 } | 184 } |
| 184 | 185 |
| 185 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( | 186 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( |
| 186 const FilePath& path) { | 187 const FilePath& path) { |
| 187 ExtensionService* service = browser()->profile()->GetExtensionService(); | 188 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 189 browser()->profile())->extension_service(); |
| 188 | 190 |
| 189 std::string manifest; | 191 std::string manifest; |
| 190 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), | 192 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), |
| 191 &manifest)) | 193 &manifest)) |
| 192 return NULL; | 194 return NULL; |
| 193 | 195 |
| 194 std::string extension_id = service->component_loader()->Add(manifest, path); | 196 std::string extension_id = service->component_loader()->Add(manifest, path); |
| 195 const Extension* extension = service->extensions()->GetByID(extension_id); | 197 const Extension* extension = service->extensions()->GetByID(extension_id); |
| 196 if (!extension) | 198 if (!extension) |
| 197 return NULL; | 199 return NULL; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 | 400 |
| 399 return NULL; | 401 return NULL; |
| 400 } | 402 } |
| 401 | 403 |
| 402 if (!WaitForExtensionViewsToLoad()) | 404 if (!WaitForExtensionViewsToLoad()) |
| 403 return NULL; | 405 return NULL; |
| 404 return service->GetExtensionById(last_loaded_extension_id_, false); | 406 return service->GetExtensionById(last_loaded_extension_id_, false); |
| 405 } | 407 } |
| 406 | 408 |
| 407 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { | 409 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { |
| 408 ExtensionService* service = browser()->profile()->GetExtensionService(); | 410 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 411 browser()->profile())->extension_service(); |
| 409 service->ReloadExtension(extension_id); | 412 service->ReloadExtension(extension_id); |
| 410 ui_test_utils::RegisterAndWait(this, | 413 ui_test_utils::RegisterAndWait(this, |
| 411 chrome::NOTIFICATION_EXTENSION_LOADED, | 414 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 412 content::NotificationService::AllSources()); | 415 content::NotificationService::AllSources()); |
| 413 } | 416 } |
| 414 | 417 |
| 415 void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { | 418 void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { |
| 416 ExtensionService* service = browser()->profile()->GetExtensionService(); | 419 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 420 browser()->profile())->extension_service(); |
| 417 service->UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_DISABLE); | 421 service->UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_DISABLE); |
| 418 } | 422 } |
| 419 | 423 |
| 420 void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) { | 424 void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) { |
| 421 ExtensionService* service = browser()->profile()->GetExtensionService(); | 425 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 426 browser()->profile())->extension_service(); |
| 422 service->UninstallExtension(extension_id, false, NULL); | 427 service->UninstallExtension(extension_id, false, NULL); |
| 423 } | 428 } |
| 424 | 429 |
| 425 void ExtensionBrowserTest::DisableExtension(const std::string& extension_id) { | 430 void ExtensionBrowserTest::DisableExtension(const std::string& extension_id) { |
| 426 ExtensionService* service = browser()->profile()->GetExtensionService(); | 431 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 432 browser()->profile())->extension_service(); |
| 427 service->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); | 433 service->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); |
| 428 } | 434 } |
| 429 | 435 |
| 430 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { | 436 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { |
| 431 ExtensionService* service = browser()->profile()->GetExtensionService(); | 437 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 438 browser()->profile())->extension_service(); |
| 432 service->EnableExtension(extension_id); | 439 service->EnableExtension(extension_id); |
| 433 } | 440 } |
| 434 | 441 |
| 435 bool ExtensionBrowserTest::WaitForPageActionCountChangeTo(int count) { | 442 bool ExtensionBrowserTest::WaitForPageActionCountChangeTo(int count) { |
| 436 LocationBarTesting* location_bar = | 443 LocationBarTesting* location_bar = |
| 437 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | 444 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 438 if (location_bar->PageActionCount() != count) { | 445 if (location_bar->PageActionCount() != count) { |
| 439 target_page_action_count_ = count; | 446 target_page_action_count_ = count; |
| 440 ui_test_utils::RegisterAndWait(this, | 447 ui_test_utils::RegisterAndWait(this, |
| 441 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 448 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 bool ExtensionBrowserTest::WaitForExtensionLoadError() { | 515 bool ExtensionBrowserTest::WaitForExtensionLoadError() { |
| 509 int before = extension_load_errors_observed_; | 516 int before = extension_load_errors_observed_; |
| 510 ui_test_utils::RegisterAndWait(this, | 517 ui_test_utils::RegisterAndWait(this, |
| 511 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 518 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 512 content::NotificationService::AllSources()); | 519 content::NotificationService::AllSources()); |
| 513 return extension_load_errors_observed_ != before; | 520 return extension_load_errors_observed_ != before; |
| 514 } | 521 } |
| 515 | 522 |
| 516 bool ExtensionBrowserTest::WaitForExtensionCrash( | 523 bool ExtensionBrowserTest::WaitForExtensionCrash( |
| 517 const std::string& extension_id) { | 524 const std::string& extension_id) { |
| 518 ExtensionService* service = browser()->profile()->GetExtensionService(); | 525 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 526 browser()->profile())->extension_service(); |
| 519 | 527 |
| 520 if (!service->GetExtensionById(extension_id, true)) { | 528 if (!service->GetExtensionById(extension_id, true)) { |
| 521 // The extension is already unloaded, presumably due to a crash. | 529 // The extension is already unloaded, presumably due to a crash. |
| 522 return true; | 530 return true; |
| 523 } | 531 } |
| 524 ui_test_utils::RegisterAndWait( | 532 ui_test_utils::RegisterAndWait( |
| 525 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 533 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 526 content::NotificationService::AllSources()); | 534 content::NotificationService::AllSources()); |
| 527 return (service->GetExtensionById(extension_id, true) == NULL); | 535 return (service->GetExtensionById(extension_id, true) == NULL); |
| 528 } | 536 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 case content::NOTIFICATION_LOAD_STOP: | 688 case content::NOTIFICATION_LOAD_STOP: |
| 681 VLOG(1) << "Got LOAD_STOP notification."; | 689 VLOG(1) << "Got LOAD_STOP notification."; |
| 682 MessageLoopForUI::current()->Quit(); | 690 MessageLoopForUI::current()->Quit(); |
| 683 break; | 691 break; |
| 684 | 692 |
| 685 default: | 693 default: |
| 686 NOTREACHED(); | 694 NOTREACHED(); |
| 687 break; | 695 break; |
| 688 } | 696 } |
| 689 } | 697 } |
| OLD | NEW |