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

Side by Side Diff: chrome/browser/media_galleries/media_file_system_registry_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 7 years, 7 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) 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 // MediaFileSystemRegistry unit tests. 5 // MediaFileSystemRegistry unit tests.
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 content::MockRenderProcessHost* single_rph_; 281 content::MockRenderProcessHost* single_rph_;
282 content::MockRenderProcessHost* shared_rph_; 282 content::MockRenderProcessHost* shared_rph_;
283 283
284 DISALLOW_COPY_AND_ASSIGN(ProfileState); 284 DISALLOW_COPY_AND_ASSIGN(ProfileState);
285 }; 285 };
286 286
287 } // namespace 287 } // namespace
288 288
289 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { 289 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness {
290 public: 290 public:
291 MediaFileSystemRegistryTest();
292 virtual ~MediaFileSystemRegistryTest() {}
293
294 void CreateProfileState(size_t profile_count); 291 void CreateProfileState(size_t profile_count);
295 292
296 ProfileState* GetProfileState(size_t i); 293 ProfileState* GetProfileState(size_t i);
297 294
298 base::FilePath empty_dir() { 295 base::FilePath empty_dir() {
299 return empty_dir_; 296 return empty_dir_;
300 } 297 }
301 298
302 base::FilePath dcim_dir() { 299 base::FilePath dcim_dir() {
303 return dcim_dir_; 300 return dcim_dir_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 base::ScopedTempDir galleries_dir_; 363 base::ScopedTempDir galleries_dir_;
367 // An empty directory in |galleries_dir_| 364 // An empty directory in |galleries_dir_|
368 base::FilePath empty_dir_; 365 base::FilePath empty_dir_;
369 // A directory in |galleries_dir_| with a DCIM directory in it. 366 // A directory in |galleries_dir_| with a DCIM directory in it.
370 base::FilePath dcim_dir_; 367 base::FilePath dcim_dir_;
371 368
372 // MediaFileSystemRegistry owns this. 369 // MediaFileSystemRegistry owns this.
373 TestMediaFileSystemContext* test_file_system_context_; 370 TestMediaFileSystemContext* test_file_system_context_;
374 371
375 // Needed for extension service & friends to work. 372 // Needed for extension service & friends to work.
376 content::TestBrowserThread ui_thread_;
377 content::TestBrowserThread file_thread_;
378 373
379 #if defined OS_CHROMEOS 374 #if defined OS_CHROMEOS
380 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 375 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
381 chromeos::ScopedTestCrosSettings test_cros_settings_; 376 chromeos::ScopedTestCrosSettings test_cros_settings_;
382 chromeos::ScopedTestUserManager test_user_manager_; 377 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
383 #endif 378 #endif
384 379
385 // TODO(gbillock): Eliminate windows-specific code from this test. 380 // TODO(gbillock): Eliminate windows-specific code from this test.
386 #if defined(OS_WIN) 381 #if defined(OS_WIN)
387 scoped_ptr<test::TestStorageMonitorWin> monitor_; 382 scoped_ptr<test::TestStorageMonitorWin> monitor_;
388 #else 383 #else
389 chrome::test::TestStorageMonitor monitor_; 384 chrome::test::TestStorageMonitor monitor_;
390 #endif 385 #endif
391 386
392 MockProfileSharedRenderProcessHostFactory rph_factory_; 387 MockProfileSharedRenderProcessHostFactory rph_factory_;
393 388
394 ScopedVector<ProfileState> profile_states_; 389 ScopedVector<ProfileState> profile_states_;
395
396 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest);
397 }; 390 };
398 391
399 namespace { 392 namespace {
400 393
401 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, 394 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a,
402 const MediaFileSystemInfo& b) { 395 const MediaFileSystemInfo& b) {
403 CHECK_NE(a.name, b.name); // Name must be unique. 396 CHECK_NE(a.name, b.name); // Name must be unique.
404 return a.name < b.name; 397 return a.name < b.name;
405 } 398 }
406 399
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 num_comparisons_ = 0; 567 num_comparisons_ = 0;
575 return result; 568 return result;
576 } 569 }
577 570
578 } // namespace 571 } // namespace
579 572
580 ///////////////////////////////// 573 /////////////////////////////////
581 // MediaFileSystemRegistryTest // 574 // MediaFileSystemRegistryTest //
582 ///////////////////////////////// 575 /////////////////////////////////
583 576
584 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest()
585 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()),
586 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) {
587 }
588
589 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { 577 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) {
590 for (size_t i = 0; i < profile_count; ++i) { 578 for (size_t i = 0; i < profile_count; ++i) {
591 ProfileState* state = new ProfileState(&rph_factory_); 579 ProfileState* state = new ProfileState(&rph_factory_);
592 profile_states_.push_back(state); 580 profile_states_.push_back(state);
593 } 581 }
594 } 582 }
595 583
596 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { 584 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) {
597 return profile_states_[i]; 585 return profile_states_[i];
598 } 586 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 base::RunLoop().RunUntilIdle(); 730 base::RunLoop().RunUntilIdle();
743 #endif 731 #endif
744 732
745 ChromeRenderViewHostTestHarness::SetUp(); 733 ChromeRenderViewHostTestHarness::SetUp();
746 DeleteContents(); 734 DeleteContents();
747 SetRenderProcessHostFactory(&rph_factory_); 735 SetRenderProcessHostFactory(&rph_factory_);
748 736
749 test_file_system_context_ = new TestMediaFileSystemContext( 737 test_file_system_context_ = new TestMediaFileSystemContext(
750 g_browser_process->media_file_system_registry()); 738 g_browser_process->media_file_system_registry());
751 739
740 #if defined OS_CHROMEOS
741 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
742 #endif
743
752 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); 744 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir());
753 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); 745 empty_dir_ = galleries_dir_.path().AppendASCII("empty");
754 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); 746 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_));
755 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim"); 747 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim");
756 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_)); 748 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_));
757 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); 749 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName)));
758 } 750 }
759 751
760 void MediaFileSystemRegistryTest::TearDown() { 752 void MediaFileSystemRegistryTest::TearDown() {
761 profile_states_.clear(); 753 profile_states_.clear();
762 ChromeRenderViewHostTestHarness::TearDown();
763 MediaFileSystemRegistry* registry = 754 MediaFileSystemRegistry* registry =
764 g_browser_process->media_file_system_registry(); 755 g_browser_process->media_file_system_registry();
765 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests()); 756 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests());
766 BrowserThread::GetBlockingPool()->FlushForTesting(); 757 #if defined OS_CHROMEOS
767 MessageLoop::current()->RunUntilIdle(); 758 test_user_manager_.reset();
759 #endif
760 ChromeRenderViewHostTestHarness::TearDown();
768 } 761 }
769 762
770 /////////// 763 ///////////
771 // Tests // 764 // Tests //
772 /////////// 765 ///////////
773 766
774 TEST_F(MediaFileSystemRegistryTest, Basic) { 767 TEST_F(MediaFileSystemRegistryTest, Basic) {
775 CreateProfileState(1); 768 CreateProfileState(1);
776 AssertAllAutoAddedGalleries(); 769 AssertAllAutoAddedGalleries();
777 770
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 pref_info_with_relpath.device_id = device_id; 969 pref_info_with_relpath.device_id = device_id;
977 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), 970 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(),
978 pref_info_with_relpath.AbsolutePath().value()); 971 pref_info_with_relpath.AbsolutePath().value());
979 972
980 DetachDevice(device_id); 973 DetachDevice(device_id);
981 EXPECT_TRUE(pref_info.AbsolutePath().empty()); 974 EXPECT_TRUE(pref_info.AbsolutePath().empty());
982 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); 975 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty());
983 } 976 }
984 977
985 } // namespace chrome 978 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698