OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 411 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
412 }; | 412 }; |
413 | 413 |
414 ExtensionServiceTestBase::ExtensionServiceInitParams:: | 414 ExtensionServiceTestBase::ExtensionServiceInitParams:: |
415 ExtensionServiceInitParams() | 415 ExtensionServiceInitParams() |
416 : autoupdate_enabled(false), is_first_run(true) { | 416 : autoupdate_enabled(false), is_first_run(true) { |
417 } | 417 } |
418 | 418 |
419 // Our message loop may be used in tests which require it to be an IO loop. | 419 // Our message loop may be used in tests which require it to be an IO loop. |
420 ExtensionServiceTestBase::ExtensionServiceTestBase() | 420 ExtensionServiceTestBase::ExtensionServiceTestBase() |
421 : loop_(MessageLoop::TYPE_IO), | 421 : loop_(base::MessageLoop::TYPE_IO), |
422 service_(NULL), | 422 service_(NULL), |
423 management_policy_(NULL), | 423 management_policy_(NULL), |
424 expected_extensions_count_(0), | 424 expected_extensions_count_(0), |
425 ui_thread_(BrowserThread::UI, &loop_), | 425 ui_thread_(BrowserThread::UI, &loop_), |
426 db_thread_(BrowserThread::DB, &loop_), | 426 db_thread_(BrowserThread::DB, &loop_), |
427 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), | 427 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), |
428 file_thread_(BrowserThread::FILE, &loop_), | 428 file_thread_(BrowserThread::FILE, &loop_), |
429 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), | 429 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), |
430 io_thread_(BrowserThread::IO, &loop_) { | 430 io_thread_(BrowserThread::IO, &loop_) { |
431 base::FilePath test_data_dir; | 431 base::FilePath test_data_dir; |
432 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 432 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
433 ADD_FAILURE(); | 433 ADD_FAILURE(); |
434 return; | 434 return; |
435 } | 435 } |
436 data_dir_ = test_data_dir.AppendASCII("extensions"); | 436 data_dir_ = test_data_dir.AppendASCII("extensions"); |
437 } | 437 } |
438 | 438 |
439 ExtensionServiceTestBase::~ExtensionServiceTestBase() { | 439 ExtensionServiceTestBase::~ExtensionServiceTestBase() { |
440 // Drop our reference to ExtensionService and TestingProfile, so that they | 440 // Drop our reference to ExtensionService and TestingProfile, so that they |
441 // can be destroyed while BrowserThreads and MessageLoop are still around | 441 // can be destroyed while BrowserThreads and MessageLoop are still around |
442 // (they are used in the destruction process). | 442 // (they are used in the destruction process). |
443 service_ = NULL; | 443 service_ = NULL; |
444 MessageLoop::current()->RunUntilIdle(); | 444 base::MessageLoop::current()->RunUntilIdle(); |
445 profile_.reset(NULL); | 445 profile_.reset(NULL); |
446 MessageLoop::current()->RunUntilIdle(); | 446 base::MessageLoop::current()->RunUntilIdle(); |
447 } | 447 } |
448 | 448 |
449 void ExtensionServiceTestBase::InitializeExtensionService( | 449 void ExtensionServiceTestBase::InitializeExtensionService( |
450 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { | 450 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { |
451 TestingProfile::Builder profile_builder; | 451 TestingProfile::Builder profile_builder; |
452 // Create a PrefService that only contains user defined preference values. | 452 // Create a PrefService that only contains user defined preference values. |
453 PrefServiceMockBuilder builder; | 453 PrefServiceMockBuilder builder; |
454 builder.WithUserFilePrefs( | 454 builder.WithUserFilePrefs( |
455 params.pref_file, loop_.message_loop_proxy()); | 455 params.pref_file, loop_.message_loop_proxy()); |
456 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | 456 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 // If packing succeeded, we make sure that the package names match our | 1119 // If packing succeeded, we make sure that the package names match our |
1120 // expectations. | 1120 // expectations. |
1121 void PackExtensionTestClient::OnPackSuccess( | 1121 void PackExtensionTestClient::OnPackSuccess( |
1122 const base::FilePath& crx_path, | 1122 const base::FilePath& crx_path, |
1123 const base::FilePath& private_key_path) { | 1123 const base::FilePath& private_key_path) { |
1124 // We got the notification and processed it; we don't expect any further tasks | 1124 // We got the notification and processed it; we don't expect any further tasks |
1125 // to be posted to the current thread, so we should stop blocking and continue | 1125 // to be posted to the current thread, so we should stop blocking and continue |
1126 // on with the rest of the test. | 1126 // on with the rest of the test. |
1127 // This call to |Quit()| matches the call to |Run()| in the | 1127 // This call to |Quit()| matches the call to |Run()| in the |
1128 // |PackPunctuatedExtension| test. | 1128 // |PackPunctuatedExtension| test. |
1129 MessageLoop::current()->Quit(); | 1129 base::MessageLoop::current()->Quit(); |
1130 EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); | 1130 EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); |
1131 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); | 1131 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); |
1132 ASSERT_TRUE(file_util::PathExists(private_key_path)); | 1132 ASSERT_TRUE(file_util::PathExists(private_key_path)); |
1133 } | 1133 } |
1134 | 1134 |
1135 // The tests are designed so that we never expect to see a packing error. | 1135 // The tests are designed so that we never expect to see a packing error. |
1136 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, | 1136 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
1137 ExtensionCreator::ErrorType type) { | 1137 ExtensionCreator::ErrorType type) { |
1138 if (type == ExtensionCreator::kCRXExists) | 1138 if (type == ExtensionCreator::kCRXExists) |
1139 FAIL() << "Packing should not fail."; | 1139 FAIL() << "Packing should not fail."; |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2020 new extensions::PackExtensionJob(&pack_client, output_dir, | 2020 new extensions::PackExtensionJob(&pack_client, output_dir, |
2021 base::FilePath(), | 2021 base::FilePath(), |
2022 ExtensionCreator::kOverwriteCRX)); | 2022 ExtensionCreator::kOverwriteCRX)); |
2023 packer->Start(); | 2023 packer->Start(); |
2024 | 2024 |
2025 // The packer will post a notification task to the current thread's message | 2025 // The packer will post a notification task to the current thread's message |
2026 // loop when it is finished. We manually run the loop here so that we | 2026 // loop when it is finished. We manually run the loop here so that we |
2027 // block and catch the notification; otherwise, the process would exit. | 2027 // block and catch the notification; otherwise, the process would exit. |
2028 // This call to |Run()| is matched by a call to |Quit()| in the | 2028 // This call to |Run()| is matched by a call to |Quit()| in the |
2029 // |PackExtensionTestClient|'s notification handling code. | 2029 // |PackExtensionTestClient|'s notification handling code. |
2030 MessageLoop::current()->Run(); | 2030 base::MessageLoop::current()->Run(); |
2031 | 2031 |
2032 if (HasFatalFailure()) | 2032 if (HasFatalFailure()) |
2033 return; | 2033 return; |
2034 | 2034 |
2035 InstallCRX(expected_crx_path, INSTALL_NEW); | 2035 InstallCRX(expected_crx_path, INSTALL_NEW); |
2036 } | 2036 } |
2037 } | 2037 } |
2038 | 2038 |
2039 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { | 2039 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { |
2040 InitializeEmptyExtensionService(); | 2040 InitializeEmptyExtensionService(); |
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3805 extensions::UnpackedInstaller::Create(service_)->Load(path); | 3805 extensions::UnpackedInstaller::Create(service_)->Load(path); |
3806 loop_.RunUntilIdle(); | 3806 loop_.RunUntilIdle(); |
3807 EXPECT_EQ(1u, GetErrors().size()); | 3807 EXPECT_EQ(1u, GetErrors().size()); |
3808 EXPECT_EQ(0u, service_->extensions()->size()); | 3808 EXPECT_EQ(0u, service_->extensions()->size()); |
3809 } | 3809 } |
3810 | 3810 |
3811 class ExtensionCookieCallback { | 3811 class ExtensionCookieCallback { |
3812 public: | 3812 public: |
3813 ExtensionCookieCallback() | 3813 ExtensionCookieCallback() |
3814 : result_(false), | 3814 : result_(false), |
3815 weak_factory_(MessageLoop::current()) {} | 3815 weak_factory_(base::MessageLoop::current()) {} |
3816 | 3816 |
3817 void SetCookieCallback(bool result) { | 3817 void SetCookieCallback(bool result) { |
3818 MessageLoop::current()->PostTask( | 3818 base::MessageLoop::current()->PostTask(FROM_HERE, |
3819 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); | 3819 base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
3820 result_ = result; | 3820 result_ = result; |
3821 } | 3821 } |
3822 | 3822 |
3823 void GetAllCookiesCallback(const net::CookieList& list) { | 3823 void GetAllCookiesCallback(const net::CookieList& list) { |
3824 MessageLoop::current()->PostTask( | 3824 base::MessageLoop::current()->PostTask(FROM_HERE, |
3825 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); | 3825 base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
3826 list_ = list; | 3826 list_ = list; |
3827 } | 3827 } |
3828 net::CookieList list_; | 3828 net::CookieList list_; |
3829 bool result_; | 3829 bool result_; |
3830 base::WeakPtrFactory<MessageLoop> weak_factory_; | 3830 base::WeakPtrFactory<base::MessageLoop> weak_factory_; |
3831 }; | 3831 }; |
3832 | 3832 |
3833 // Verifies extension state is removed upon uninstall. | 3833 // Verifies extension state is removed upon uninstall. |
3834 TEST_F(ExtensionServiceTest, ClearExtensionData) { | 3834 TEST_F(ExtensionServiceTest, ClearExtensionData) { |
3835 InitializeEmptyExtensionService(); | 3835 InitializeEmptyExtensionService(); |
3836 ExtensionCookieCallback callback; | 3836 ExtensionCookieCallback callback; |
3837 | 3837 |
3838 // Load a test extension. | 3838 // Load a test extension. |
3839 base::FilePath path = data_dir_; | 3839 base::FilePath path = data_dir_; |
3840 path = path.AppendASCII("good.crx"); | 3840 path = path.AppendASCII("good.crx"); |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4636 // | 4636 // |
4637 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are | 4637 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are |
4638 // enabled or not. | 4638 // enabled or not. |
4639 TEST(ExtensionServiceTestSimple, Enabledness) { | 4639 TEST(ExtensionServiceTestSimple, Enabledness) { |
4640 // Make sure the PluginService singleton is destroyed at the end of the test. | 4640 // Make sure the PluginService singleton is destroyed at the end of the test. |
4641 base::ShadowingAtExitManager at_exit_manager; | 4641 base::ShadowingAtExitManager at_exit_manager; |
4642 | 4642 |
4643 ExtensionErrorReporter::Init(false); // no noisy errors | 4643 ExtensionErrorReporter::Init(false); // no noisy errors |
4644 ExtensionsReadyRecorder recorder; | 4644 ExtensionsReadyRecorder recorder; |
4645 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 4645 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
4646 MessageLoop loop; | 4646 base::MessageLoop loop; |
4647 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); | 4647 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); |
4648 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); | 4648 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); |
4649 #if defined OS_CHROMEOS | 4649 #if defined OS_CHROMEOS |
4650 chromeos::ScopedTestDeviceSettingsService device_settings_service; | 4650 chromeos::ScopedTestDeviceSettingsService device_settings_service; |
4651 chromeos::ScopedTestCrosSettings cros_settings; | 4651 chromeos::ScopedTestCrosSettings cros_settings; |
4652 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( | 4652 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( |
4653 new chromeos::ScopedTestUserManager); | 4653 new chromeos::ScopedTestUserManager); |
4654 #endif | 4654 #endif |
4655 scoped_ptr<CommandLine> command_line; | 4655 scoped_ptr<CommandLine> command_line; |
4656 base::FilePath install_dir = profile->GetPath() | 4656 base::FilePath install_dir = profile->GetPath() |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5960 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 5960 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
5961 AddMockExternalProvider(provider); | 5961 AddMockExternalProvider(provider); |
5962 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 5962 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
5963 | 5963 |
5964 service_->CheckForExternalUpdates(); | 5964 service_->CheckForExternalUpdates(); |
5965 loop_.RunUntilIdle(); | 5965 loop_.RunUntilIdle(); |
5966 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 5966 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
5967 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 5967 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
5968 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 5968 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
5969 } | 5969 } |
OLD | NEW |