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

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: Provisional push for gbillock 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 content::MockRenderProcessHost* single_rph_; 277 content::MockRenderProcessHost* single_rph_;
278 content::MockRenderProcessHost* shared_rph_; 278 content::MockRenderProcessHost* shared_rph_;
279 279
280 DISALLOW_COPY_AND_ASSIGN(ProfileState); 280 DISALLOW_COPY_AND_ASSIGN(ProfileState);
281 }; 281 };
282 282
283 } // namespace 283 } // namespace
284 284
285 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { 285 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness {
286 public: 286 public:
287 MediaFileSystemRegistryTest();
288 virtual ~MediaFileSystemRegistryTest() {}
289
290 void CreateProfileState(size_t profile_count); 287 void CreateProfileState(size_t profile_count);
291 288
292 ProfileState* GetProfileState(size_t i); 289 ProfileState* GetProfileState(size_t i);
293 290
294 base::FilePath empty_dir() { 291 base::FilePath empty_dir() {
295 return empty_dir_; 292 return empty_dir_;
296 } 293 }
297 294
298 base::FilePath dcim_dir() { 295 base::FilePath dcim_dir() {
299 return dcim_dir_; 296 return dcim_dir_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return test_file_system_context_->GetMediaFileSystemRegistry(); 346 return test_file_system_context_->GetMediaFileSystemRegistry();
350 } 347 }
351 348
352 protected: 349 protected:
353 virtual void SetUp() OVERRIDE; 350 virtual void SetUp() OVERRIDE;
354 virtual void TearDown() OVERRIDE; 351 virtual void TearDown() OVERRIDE;
355 352
356 private: 353 private:
357 // This makes sure that at least one default gallery exists on the file 354 // This makes sure that at least one default gallery exists on the file
358 // system. 355 // system.
359 EnsureMediaDirectoriesExists media_directories_; 356 scoped_ptr<EnsureMediaDirectoriesExists> media_directories_;
360 357
361 // Some test gallery directories. 358 // Some test gallery directories.
362 base::ScopedTempDir galleries_dir_; 359 scoped_ptr<base::ScopedTempDir> galleries_dir_;
363 // An empty directory in |galleries_dir_| 360 // An empty directory in |galleries_dir_|
364 base::FilePath empty_dir_; 361 base::FilePath empty_dir_;
365 // A directory in |galleries_dir_| with a DCIM directory in it. 362 // A directory in |galleries_dir_| with a DCIM directory in it.
366 base::FilePath dcim_dir_; 363 base::FilePath dcim_dir_;
367 364
368 // MediaFileSystemRegistry owns this. 365 // MediaFileSystemRegistry owns this.
369 TestMediaFileSystemContext* test_file_system_context_; 366 TestMediaFileSystemContext* test_file_system_context_;
370 367
371 // Needed for extension service & friends to work. 368 // Needed for extension service & friends to work.
372 content::TestBrowserThread ui_thread_;
373 content::TestBrowserThread file_thread_;
374 369
375 #if defined OS_CHROMEOS 370 #if defined OS_CHROMEOS
376 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 371 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
377 chromeos::ScopedTestCrosSettings test_cros_settings_; 372 chromeos::ScopedTestCrosSettings test_cros_settings_;
378 chromeos::ScopedTestUserManager test_user_manager_; 373 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
379 #endif 374 #endif
380 375
381 // TODO(gbillock): Eliminate windows-specific code from this test. 376 // TODO(gbillock): Eliminate windows-specific code from this test.
382 #if defined(OS_WIN) 377 #if defined(OS_WIN)
383 scoped_ptr<test::TestStorageMonitorWin> monitor_; 378 scoped_ptr<test::TestStorageMonitorWin> monitor_;
384 #else 379 #else
385 chrome::test::TestStorageMonitor monitor_; 380 chrome::test::TestStorageMonitor monitor_;
386 #endif 381 #endif
387 382
388 MockProfileSharedRenderProcessHostFactory rph_factory_; 383 scoped_ptr<MockProfileSharedRenderProcessHostFactory> rph_factory_;
389 384
390 ScopedVector<ProfileState> profile_states_; 385 ScopedVector<ProfileState> profile_states_;
391
392 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest);
393 }; 386 };
394 387
395 namespace { 388 namespace {
396 389
397 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, 390 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a,
398 const MediaFileSystemInfo& b) { 391 const MediaFileSystemInfo& b) {
399 CHECK_NE(a.name, b.name); // Name must be unique. 392 CHECK_NE(a.name, b.name); // Name must be unique.
400 return a.name < b.name; 393 return a.name < b.name;
401 } 394 }
402 395
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 num_comparisons_ = 0; 563 num_comparisons_ = 0;
571 return result; 564 return result;
572 } 565 }
573 566
574 } // namespace 567 } // namespace
575 568
576 ///////////////////////////////// 569 /////////////////////////////////
577 // MediaFileSystemRegistryTest // 570 // MediaFileSystemRegistryTest //
578 ///////////////////////////////// 571 /////////////////////////////////
579 572
580 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest()
581 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()),
582 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) {
583 }
584
585 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { 573 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) {
586 for (size_t i = 0; i < profile_count; ++i) { 574 for (size_t i = 0; i < profile_count; ++i) {
587 ProfileState* state = new ProfileState(&rph_factory_); 575 ProfileState* state = new ProfileState(rph_factory_.get());
588 profile_states_.push_back(state); 576 profile_states_.push_back(state);
589 } 577 }
590 } 578 }
591 579
592 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { 580 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) {
593 return profile_states_[i]; 581 return profile_states_[i];
594 } 582 }
595 583
596 std::string MediaFileSystemRegistryTest::AddUserGallery( 584 std::string MediaFileSystemRegistryTest::AddUserGallery(
597 StorageInfo::Type type, 585 StorageInfo::Type type,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), 701 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(),
714 0, std::string(), false, false); 702 0, std::string(), false, false);
715 result.push_back(info); 703 result.push_back(info);
716 } 704 }
717 } 705 }
718 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); 706 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator);
719 return result; 707 return result;
720 } 708 }
721 709
722 void MediaFileSystemRegistryTest::SetUp() { 710 void MediaFileSystemRegistryTest::SetUp() {
711 ChromeRenderViewHostTestHarness::CreateThreadBundle();
712 media_directories_.reset(new EnsureMediaDirectoriesExists());
713 galleries_dir_.reset(new base::ScopedTempDir());
714 rph_factory_.reset(new MockProfileSharedRenderProcessHostFactory());
723 #if defined(OS_WIN) 715 #if defined(OS_WIN)
724 test::TestPortableDeviceWatcherWin* portable_device_watcher = 716 test::TestPortableDeviceWatcherWin* portable_device_watcher =
725 new test::TestPortableDeviceWatcherWin; 717 new test::TestPortableDeviceWatcherWin;
726 test::TestVolumeMountWatcherWin* mount_watcher = 718 test::TestVolumeMountWatcherWin* mount_watcher =
727 new test::TestVolumeMountWatcherWin; 719 new test::TestVolumeMountWatcherWin;
728 portable_device_watcher->set_use_dummy_mtp_storage_info(true); 720 portable_device_watcher->set_use_dummy_mtp_storage_info(true);
729 monitor_.reset(new test::TestStorageMonitorWin( 721 monitor_.reset(new test::TestStorageMonitorWin(
730 mount_watcher, portable_device_watcher)); 722 mount_watcher, portable_device_watcher));
731 monitor_->Init(); 723 monitor_->Init();
732 // TODO(gbillock): Replace this with the correct event notification 724 // TODO(gbillock): Replace this with the correct event notification
733 // on the storage monitor finishing the startup scan when that exists. 725 // on the storage monitor finishing the startup scan when that exists.
734 base::RunLoop().RunUntilIdle(); 726 base::RunLoop().RunUntilIdle();
Greg Billock 2013/05/22 00:05:25 Moved to monitor_->Initialize(run_loop.QuitClosure
awong 2013/05/22 20:08:36 Done.
735 mount_watcher->FlushWorkerPoolForTesting(); 727 mount_watcher->FlushWorkerPoolForTesting();
736 base::RunLoop().RunUntilIdle(); 728 base::RunLoop().RunUntilIdle();
737 mount_watcher->FlushWorkerPoolForTesting(); 729 mount_watcher->FlushWorkerPoolForTesting();
738 base::RunLoop().RunUntilIdle(); 730 base::RunLoop().RunUntilIdle();
739 #endif 731 #endif
732 ChromeRenderViewHostTestHarness::SetUp();
Greg Billock 2013/05/22 00:05:25 You moved this up to line 715 right?
awong 2013/05/22 20:08:36 Good point. Fixed.
740 733
741 ChromeRenderViewHostTestHarness::SetUp();
742 DeleteContents(); 734 DeleteContents();
743 SetRenderProcessHostFactory(&rph_factory_); 735 SetRenderProcessHostFactory(rph_factory_.get());
744 736
745 test_file_system_context_ = new TestMediaFileSystemContext( 737 test_file_system_context_ = new TestMediaFileSystemContext(
746 g_browser_process->media_file_system_registry()); 738 g_browser_process->media_file_system_registry());
747 739
748 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); 740 #if defined OS_CHROMEOS
749 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); 741 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
742 #endif
743
744 ASSERT_TRUE(galleries_dir_->CreateUniqueTempDir());
745 empty_dir_ = galleries_dir_->path().AppendASCII("empty");
750 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); 746 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_));
751 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim"); 747 dcim_dir_ = galleries_dir_->path().AppendASCII("with_dcim");
752 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_)); 748 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_));
753 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); 749 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName)));
754 } 750 }
755 751
756 void MediaFileSystemRegistryTest::TearDown() { 752 void MediaFileSystemRegistryTest::TearDown() {
757 profile_states_.clear(); 753 profile_states_.clear();
758 ChromeRenderViewHostTestHarness::TearDown();
759 MediaFileSystemRegistry* registry = 754 MediaFileSystemRegistry* registry =
760 g_browser_process->media_file_system_registry(); 755 g_browser_process->media_file_system_registry();
761 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests()); 756 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests());
762 BrowserThread::GetBlockingPool()->FlushForTesting(); 757 #if defined OS_CHROMEOS
763 MessageLoop::current()->RunUntilIdle(); 758 test_user_manager_.reset();
759 #endif
760
761 #if defined(OS_WIN)
762 monitor_.reset();
763 #endif
764 ChromeRenderViewHostTestHarness::TearDown();
764 } 765 }
765 766
766 /////////// 767 ///////////
767 // Tests // 768 // Tests //
768 /////////// 769 ///////////
769 770
770 TEST_F(MediaFileSystemRegistryTest, Basic) { 771 TEST_F(MediaFileSystemRegistryTest, Basic) {
771 CreateProfileState(1); 772 CreateProfileState(1);
772 AssertAllAutoAddedGalleries(); 773 AssertAllAutoAddedGalleries();
773 774
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 pref_info_with_relpath.device_id = device_id; 971 pref_info_with_relpath.device_id = device_id;
971 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), 972 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(),
972 pref_info_with_relpath.AbsolutePath().value()); 973 pref_info_with_relpath.AbsolutePath().value());
973 974
974 DetachDevice(device_id); 975 DetachDevice(device_id);
975 EXPECT_TRUE(pref_info.AbsolutePath().empty()); 976 EXPECT_TRUE(pref_info.AbsolutePath().empty());
976 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); 977 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty());
977 } 978 }
978 979
979 } // namespace chrome 980 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698