Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 413 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
414 }; 414 };
415 415
416 ExtensionServiceTestBase::ExtensionServiceInitParams:: 416 ExtensionServiceTestBase::ExtensionServiceInitParams::
417 ExtensionServiceInitParams() 417 ExtensionServiceInitParams()
418 : autoupdate_enabled(false), is_first_run(true) { 418 : autoupdate_enabled(false), is_first_run(true) {
419 } 419 }
420 420
421 // Our message loop may be used in tests which require it to be an IO loop. 421 // Our message loop may be used in tests which require it to be an IO loop.
422 ExtensionServiceTestBase::ExtensionServiceTestBase() 422 ExtensionServiceTestBase::ExtensionServiceTestBase()
423 : loop_(MessageLoop::TYPE_IO), 423 : loop_(base::MessageLoop::TYPE_IO),
424 service_(NULL), 424 service_(NULL),
425 management_policy_(NULL), 425 management_policy_(NULL),
426 expected_extensions_count_(0), 426 expected_extensions_count_(0),
427 ui_thread_(BrowserThread::UI, &loop_), 427 ui_thread_(BrowserThread::UI, &loop_),
428 db_thread_(BrowserThread::DB, &loop_), 428 db_thread_(BrowserThread::DB, &loop_),
429 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), 429 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_),
430 file_thread_(BrowserThread::FILE, &loop_), 430 file_thread_(BrowserThread::FILE, &loop_),
431 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), 431 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_),
432 io_thread_(BrowserThread::IO, &loop_) { 432 io_thread_(BrowserThread::IO, &loop_) {
433 base::FilePath test_data_dir; 433 base::FilePath test_data_dir;
434 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 434 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
435 ADD_FAILURE(); 435 ADD_FAILURE();
436 return; 436 return;
437 } 437 }
438 data_dir_ = test_data_dir.AppendASCII("extensions"); 438 data_dir_ = test_data_dir.AppendASCII("extensions");
439 } 439 }
440 440
441 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 441 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
442 // Drop our reference to ExtensionService and TestingProfile, so that they 442 // Drop our reference to ExtensionService and TestingProfile, so that they
443 // can be destroyed while BrowserThreads and MessageLoop are still around 443 // can be destroyed while BrowserThreads and MessageLoop are still around
444 // (they are used in the destruction process). 444 // (they are used in the destruction process).
445 service_ = NULL; 445 service_ = NULL;
446 MessageLoop::current()->RunUntilIdle(); 446 base::MessageLoop::current()->RunUntilIdle();
447 profile_.reset(NULL); 447 profile_.reset(NULL);
448 MessageLoop::current()->RunUntilIdle(); 448 base::MessageLoop::current()->RunUntilIdle();
449 } 449 }
450 450
451 void ExtensionServiceTestBase::InitializeExtensionService( 451 void ExtensionServiceTestBase::InitializeExtensionService(
452 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { 452 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
453 TestingProfile::Builder profile_builder; 453 TestingProfile::Builder profile_builder;
454 // Create a PrefService that only contains user defined preference values. 454 // Create a PrefService that only contains user defined preference values.
455 PrefServiceMockBuilder builder; 455 PrefServiceMockBuilder builder;
456 builder.WithUserFilePrefs( 456 builder.WithUserFilePrefs(
457 params.pref_file, loop_.message_loop_proxy()); 457 params.pref_file, loop_.message_loop_proxy());
458 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable); 458 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable);
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 // If packing succeeded, we make sure that the package names match our 1115 // If packing succeeded, we make sure that the package names match our
1116 // expectations. 1116 // expectations.
1117 void PackExtensionTestClient::OnPackSuccess( 1117 void PackExtensionTestClient::OnPackSuccess(
1118 const base::FilePath& crx_path, 1118 const base::FilePath& crx_path,
1119 const base::FilePath& private_key_path) { 1119 const base::FilePath& private_key_path) {
1120 // We got the notification and processed it; we don't expect any further tasks 1120 // We got the notification and processed it; we don't expect any further tasks
1121 // to be posted to the current thread, so we should stop blocking and continue 1121 // to be posted to the current thread, so we should stop blocking and continue
1122 // on with the rest of the test. 1122 // on with the rest of the test.
1123 // This call to |Quit()| matches the call to |Run()| in the 1123 // This call to |Quit()| matches the call to |Run()| in the
1124 // |PackPunctuatedExtension| test. 1124 // |PackPunctuatedExtension| test.
1125 MessageLoop::current()->Quit(); 1125 base::MessageLoop::current()->Quit();
1126 EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); 1126 EXPECT_EQ(expected_crx_path_.value(), crx_path.value());
1127 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); 1127 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value());
1128 ASSERT_TRUE(file_util::PathExists(private_key_path)); 1128 ASSERT_TRUE(file_util::PathExists(private_key_path));
1129 } 1129 }
1130 1130
1131 // The tests are designed so that we never expect to see a packing error. 1131 // The tests are designed so that we never expect to see a packing error.
1132 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, 1132 void PackExtensionTestClient::OnPackFailure(const std::string& error_message,
1133 ExtensionCreator::ErrorType type) { 1133 ExtensionCreator::ErrorType type) {
1134 if (type == ExtensionCreator::kCRXExists) 1134 if (type == ExtensionCreator::kCRXExists)
1135 FAIL() << "Packing should not fail."; 1135 FAIL() << "Packing should not fail.";
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 new extensions::PackExtensionJob(&pack_client, output_dir, 2014 new extensions::PackExtensionJob(&pack_client, output_dir,
2015 base::FilePath(), 2015 base::FilePath(),
2016 ExtensionCreator::kOverwriteCRX)); 2016 ExtensionCreator::kOverwriteCRX));
2017 packer->Start(); 2017 packer->Start();
2018 2018
2019 // The packer will post a notification task to the current thread's message 2019 // The packer will post a notification task to the current thread's message
2020 // loop when it is finished. We manually run the loop here so that we 2020 // loop when it is finished. We manually run the loop here so that we
2021 // block and catch the notification; otherwise, the process would exit. 2021 // block and catch the notification; otherwise, the process would exit.
2022 // This call to |Run()| is matched by a call to |Quit()| in the 2022 // This call to |Run()| is matched by a call to |Quit()| in the
2023 // |PackExtensionTestClient|'s notification handling code. 2023 // |PackExtensionTestClient|'s notification handling code.
2024 MessageLoop::current()->Run(); 2024 base::MessageLoop::current()->Run();
2025 2025
2026 if (HasFatalFailure()) 2026 if (HasFatalFailure())
2027 return; 2027 return;
2028 2028
2029 InstallCRX(expected_crx_path, INSTALL_NEW); 2029 InstallCRX(expected_crx_path, INSTALL_NEW);
2030 } 2030 }
2031 } 2031 }
2032 2032
2033 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { 2033 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) {
2034 InitializeEmptyExtensionService(); 2034 InitializeEmptyExtensionService();
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 .AppendASCII("v2_bad_requirements"); 3798 .AppendASCII("v2_bad_requirements");
3799 extensions::UnpackedInstaller::Create(service_)->Load(path); 3799 extensions::UnpackedInstaller::Create(service_)->Load(path);
3800 loop_.RunUntilIdle(); 3800 loop_.RunUntilIdle();
3801 EXPECT_EQ(1u, GetErrors().size()); 3801 EXPECT_EQ(1u, GetErrors().size());
3802 EXPECT_EQ(0u, service_->extensions()->size()); 3802 EXPECT_EQ(0u, service_->extensions()->size());
3803 } 3803 }
3804 3804
3805 class ExtensionCookieCallback { 3805 class ExtensionCookieCallback {
3806 public: 3806 public:
3807 ExtensionCookieCallback() 3807 ExtensionCookieCallback()
3808 : result_(false), 3808 : result_(false), weak_factory_(base::MessageLoop::current()) {}
brettw 2013/04/28 04:26:27 In other cases you were a bit too aggressive putti
3809 weak_factory_(MessageLoop::current()) {}
3810 3809
3811 void SetCookieCallback(bool result) { 3810 void SetCookieCallback(bool result) {
3812 MessageLoop::current()->PostTask( 3811 base::MessageLoop::current()->PostTask(
3813 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); 3812 FROM_HERE,
brettw 2013/04/28 04:26:27 Old way was fine, below also.
3813 base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr()));
3814 result_ = result; 3814 result_ = result;
3815 } 3815 }
3816 3816
3817 void GetAllCookiesCallback(const net::CookieList& list) { 3817 void GetAllCookiesCallback(const net::CookieList& list) {
3818 MessageLoop::current()->PostTask( 3818 base::MessageLoop::current()->PostTask(
3819 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); 3819 FROM_HERE,
3820 base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr()));
3820 list_ = list; 3821 list_ = list;
3821 } 3822 }
3822 net::CookieList list_; 3823 net::CookieList list_;
3823 bool result_; 3824 bool result_;
3824 base::WeakPtrFactory<MessageLoop> weak_factory_; 3825 base::WeakPtrFactory<base::MessageLoop> weak_factory_;
3825 }; 3826 };
3826 3827
3827 // Verifies extension state is removed upon uninstall. 3828 // Verifies extension state is removed upon uninstall.
3828 TEST_F(ExtensionServiceTest, ClearExtensionData) { 3829 TEST_F(ExtensionServiceTest, ClearExtensionData) {
3829 InitializeEmptyExtensionService(); 3830 InitializeEmptyExtensionService();
3830 ExtensionCookieCallback callback; 3831 ExtensionCookieCallback callback;
3831 3832
3832 // Load a test extension. 3833 // Load a test extension.
3833 base::FilePath path = data_dir_; 3834 base::FilePath path = data_dir_;
3834 path = path.AppendASCII("good.crx"); 3835 path = path.AppendASCII("good.crx");
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
4631 // 4632 //
4632 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are 4633 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are
4633 // enabled or not. 4634 // enabled or not.
4634 TEST(ExtensionServiceTestSimple, Enabledness) { 4635 TEST(ExtensionServiceTestSimple, Enabledness) {
4635 // Make sure the PluginService singleton is destroyed at the end of the test. 4636 // Make sure the PluginService singleton is destroyed at the end of the test.
4636 base::ShadowingAtExitManager at_exit_manager; 4637 base::ShadowingAtExitManager at_exit_manager;
4637 4638
4638 ExtensionErrorReporter::Init(false); // no noisy errors 4639 ExtensionErrorReporter::Init(false); // no noisy errors
4639 ExtensionsReadyRecorder recorder; 4640 ExtensionsReadyRecorder recorder;
4640 scoped_ptr<TestingProfile> profile(new TestingProfile()); 4641 scoped_ptr<TestingProfile> profile(new TestingProfile());
4641 MessageLoop loop; 4642 base::MessageLoop loop;
4642 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); 4643 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop);
4643 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); 4644 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop);
4644 #if defined OS_CHROMEOS 4645 #if defined OS_CHROMEOS
4645 chromeos::ScopedTestDeviceSettingsService device_settings_service; 4646 chromeos::ScopedTestDeviceSettingsService device_settings_service;
4646 chromeos::ScopedTestCrosSettings cros_settings; 4647 chromeos::ScopedTestCrosSettings cros_settings;
4647 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( 4648 scoped_ptr<chromeos::ScopedTestUserManager> user_manager(
4648 new chromeos::ScopedTestUserManager); 4649 new chromeos::ScopedTestUserManager);
4649 #endif 4650 #endif
4650 scoped_ptr<CommandLine> command_line; 4651 scoped_ptr<CommandLine> command_line;
4651 base::FilePath install_dir = profile->GetPath() 4652 base::FilePath install_dir = profile->GetPath()
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
5955 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 5956 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
5956 AddMockExternalProvider(provider); 5957 AddMockExternalProvider(provider);
5957 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 5958 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
5958 5959
5959 service_->CheckForExternalUpdates(); 5960 service_->CheckForExternalUpdates();
5960 loop_.RunUntilIdle(); 5961 loop_.RunUntilIdle();
5961 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5962 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5962 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 5963 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_));
5963 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 5964 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore));
5964 } 5965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698