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

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

Issue 14556015: [Media Galleries] Lazily initialize the storage monitor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Harden async boundary in WebUI Created 7 years, 6 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
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/bind_helpers.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "base/message_loop.h" 17 #include "base/message_loop.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/stringprintf.h" 20 #include "base/stringprintf.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 285
285 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { 286 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness {
286 public: 287 public:
287 MediaFileSystemRegistryTest(); 288 MediaFileSystemRegistryTest();
288 virtual ~MediaFileSystemRegistryTest() {} 289 virtual ~MediaFileSystemRegistryTest() {}
289 290
290 void CreateProfileState(size_t profile_count); 291 void CreateProfileState(size_t profile_count);
291 292
292 ProfileState* GetProfileState(size_t i); 293 ProfileState* GetProfileState(size_t i);
293 294
295 MediaGalleriesPreferences* GetPreferences(Profile* profile);
296
294 base::FilePath empty_dir() { 297 base::FilePath empty_dir() {
295 return empty_dir_; 298 return empty_dir_;
296 } 299 }
297 300
298 base::FilePath dcim_dir() { 301 base::FilePath dcim_dir() {
299 return dcim_dir_; 302 return dcim_dir_;
300 } 303 }
301 304
302 TestMediaFileSystemContext* test_file_system_context() { 305 TestMediaFileSystemContext* test_file_system_context() {
303 return test_file_system_context_; 306 return test_file_system_context_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 #if defined OS_CHROMEOS 378 #if defined OS_CHROMEOS
376 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 379 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
377 chromeos::ScopedTestCrosSettings test_cros_settings_; 380 chromeos::ScopedTestCrosSettings test_cros_settings_;
378 chromeos::ScopedTestUserManager test_user_manager_; 381 chromeos::ScopedTestUserManager test_user_manager_;
379 #endif 382 #endif
380 383
381 // TODO(gbillock): Eliminate windows-specific code from this test. 384 // TODO(gbillock): Eliminate windows-specific code from this test.
382 #if defined(OS_WIN) 385 #if defined(OS_WIN)
383 scoped_ptr<test::TestStorageMonitorWin> monitor_; 386 scoped_ptr<test::TestStorageMonitorWin> monitor_;
384 #else 387 #else
385 chrome::test::TestStorageMonitor monitor_; 388 scoped_ptr<chrome::test::TestStorageMonitor> monitor_;
386 #endif 389 #endif
387 390
388 MockProfileSharedRenderProcessHostFactory rph_factory_; 391 MockProfileSharedRenderProcessHostFactory rph_factory_;
389 392
390 ScopedVector<ProfileState> profile_states_; 393 ScopedVector<ProfileState> profile_states_;
391 394
392 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); 395 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest);
393 }; 396 };
394 397
395 namespace { 398 namespace {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 for (size_t i = 0; i < profile_count; ++i) { 589 for (size_t i = 0; i < profile_count; ++i) {
587 ProfileState* state = new ProfileState(&rph_factory_); 590 ProfileState* state = new ProfileState(&rph_factory_);
588 profile_states_.push_back(state); 591 profile_states_.push_back(state);
589 } 592 }
590 } 593 }
591 594
592 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { 595 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) {
593 return profile_states_[i]; 596 return profile_states_[i];
594 } 597 }
595 598
599 MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences(
600 Profile* profile) {
601 return GetMediaFileSystemRegistry()->GetPreferences(profile);
602 }
603
596 std::string MediaFileSystemRegistryTest::AddUserGallery( 604 std::string MediaFileSystemRegistryTest::AddUserGallery(
597 StorageInfo::Type type, 605 StorageInfo::Type type,
598 const std::string& unique_id, 606 const std::string& unique_id,
599 const base::FilePath& path) { 607 const base::FilePath& path) {
600 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); 608 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id);
601 string16 name = path.LossyDisplayName(); 609 string16 name = path.LossyDisplayName();
602 DCHECK(!StorageInfo::IsMediaDevice(device_id)); 610 DCHECK(!StorageInfo::IsMediaDevice(device_id));
603 611
604 for (size_t i = 0; i < profile_states_.size(); ++i) { 612 for (size_t i = 0; i < profile_states_.size(); ++i) {
605 profile_states_[i]->GetMediaGalleriesPrefs()->AddGalleryWithName( 613 profile_states_[i]->GetMediaGalleriesPrefs()->AddGalleryWithName(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), 721 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(),
714 0, std::string(), false, false); 722 0, std::string(), false, false);
715 result.push_back(info); 723 result.push_back(info);
716 } 724 }
717 } 725 }
718 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); 726 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator);
719 return result; 727 return result;
720 } 728 }
721 729
722 void MediaFileSystemRegistryTest::SetUp() { 730 void MediaFileSystemRegistryTest::SetUp() {
723 #if defined(OS_WIN) 731 #if !defined(OS_WIN)
Lei Zhang 2013/06/03 06:01:35 style nit: #if defined(OS_WIN) ... #else ... #endi
Greg Billock 2013/06/03 15:30:57 Done.
732 monitor_.reset(new test::TestStorageMonitor());
733 monitor_->Initialize(base::Bind(&base::DoNothing));
734 monitor_->MarkInitialized();
735 base::RunLoop().RunUntilIdle();
736 #else
724 test::TestPortableDeviceWatcherWin* portable_device_watcher = 737 test::TestPortableDeviceWatcherWin* portable_device_watcher =
725 new test::TestPortableDeviceWatcherWin; 738 new test::TestPortableDeviceWatcherWin;
726 test::TestVolumeMountWatcherWin* mount_watcher = 739 test::TestVolumeMountWatcherWin* mount_watcher =
727 new test::TestVolumeMountWatcherWin; 740 new test::TestVolumeMountWatcherWin;
728 portable_device_watcher->set_use_dummy_mtp_storage_info(true); 741 portable_device_watcher->set_use_dummy_mtp_storage_info(true);
729 monitor_.reset(new test::TestStorageMonitorWin( 742 monitor_.reset(new test::TestStorageMonitorWin(
730 mount_watcher, portable_device_watcher)); 743 mount_watcher, portable_device_watcher));
731 monitor_->Init(); 744 monitor_->Initialize(base::Bind(&base::DoNothing));
732 // TODO(gbillock): Replace this with the correct event notification 745 // TODO(gbillock): Replace this with the correct event notification
733 // on the storage monitor finishing the startup scan when that exists. 746 // on the storage monitor finishing the startup scan when that exists.
734 base::RunLoop().RunUntilIdle(); 747 base::RunLoop().RunUntilIdle();
735 mount_watcher->FlushWorkerPoolForTesting(); 748 mount_watcher->FlushWorkerPoolForTesting();
736 base::RunLoop().RunUntilIdle(); 749 base::RunLoop().RunUntilIdle();
737 mount_watcher->FlushWorkerPoolForTesting(); 750 mount_watcher->FlushWorkerPoolForTesting();
738 base::RunLoop().RunUntilIdle(); 751 base::RunLoop().RunUntilIdle();
739 #endif 752 #endif
740 753
741 ChromeRenderViewHostTestHarness::SetUp(); 754 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 856
844 // Attach a device. 857 // Attach a device.
845 const std::string device_id = AttachDevice( 858 const std::string device_id = AttachDevice(
846 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, 859 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM,
847 "removable_dcim_fake_id", 860 "removable_dcim_fake_id",
848 dcim_dir()); 861 dcim_dir());
849 EXPECT_EQ(gallery_count + 1, GetAutoAddedGalleries(profile_state).size()); 862 EXPECT_EQ(gallery_count + 1, GetAutoAddedGalleries(profile_state).size());
850 863
851 // Forget the device. 864 // Forget the device.
852 bool forget_gallery = false; 865 bool forget_gallery = false;
853 MediaGalleriesPreferences* prefs = 866 MediaGalleriesPreferences* prefs = GetPreferences(profile_state->profile());
854 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile());
855 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); 867 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries();
856 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); 868 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin();
857 it != galleries.end(); ++it) { 869 it != galleries.end(); ++it) {
858 if (it->second.device_id == device_id) { 870 if (it->second.device_id == device_id) {
859 prefs->ForgetGalleryById(it->first); 871 prefs->ForgetGalleryById(it->first);
860 forget_gallery = true; 872 forget_gallery = true;
861 break; 873 break;
862 } 874 }
863 } 875 }
864 base::MessageLoop::current()->RunUntilIdle(); 876 base::MessageLoop::current()->RunUntilIdle();
865 EXPECT_TRUE(forget_gallery); 877 EXPECT_TRUE(forget_gallery);
866 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); 878 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size());
867 879
868 // Call GetPreferences() and the gallery count should not change. 880 // Call GetPreferences() and the gallery count should not change.
869 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); 881 prefs = GetPreferences(profile_state->profile());
870 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); 882 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size());
871 } 883 }
872 884
873 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { 885 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) {
874 FSInfoMap galleries_info; 886 FSInfoMap galleries_info;
875 InitForGalleriesInfoTest(&galleries_info); 887 InitForGalleriesInfoTest(&galleries_info);
876 888
877 for (FSInfoMap::const_iterator it = galleries_info.begin(); 889 for (FSInfoMap::const_iterator it = galleries_info.begin();
878 it != galleries_info.end(); 890 it != galleries_info.end();
879 ++it) { 891 ++it) {
880 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, 892 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name,
881 it->second.path, false, false); 893 it->second.path, false, false);
882 } 894 }
883 } 895 }
884 896
885 // TODO(gbillock): Put the platform-specific parts of this test in tests 897 // TODO(gbillock): Put the platform-specific parts of this test in tests
886 // for those classes, not here. This test, internally, ends up creating an 898 // for those classes, not here. This test, internally, ends up creating an
887 // MTP delegate. 899 // MTP delegate. (Probably ./win/mtp_device_delegate_impl_win_unittest)
888 #if !defined(OS_MACOSX) 900 #if !defined(OS_MACOSX)
889 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { 901 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) {
890 FSInfoMap galleries_info; 902 FSInfoMap galleries_info;
891 InitForGalleriesInfoTest(&galleries_info); 903 InitForGalleriesInfoTest(&galleries_info);
892 904
893 #if defined(OS_WIN) 905 #if defined(OS_WIN)
894 base::FilePath location( 906 base::FilePath location(
895 PortableDeviceWatcherWin::GetStoragePathFromStorageId( 907 PortableDeviceWatcherWin::GetStoragePathFromStorageId(
896 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); 908 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA));
897 #else 909 #else
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 pref_info_with_relpath.device_id = device_id; 982 pref_info_with_relpath.device_id = device_id;
971 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), 983 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(),
972 pref_info_with_relpath.AbsolutePath().value()); 984 pref_info_with_relpath.AbsolutePath().value());
973 985
974 DetachDevice(device_id); 986 DetachDevice(device_id);
975 EXPECT_TRUE(pref_info.AbsolutePath().empty()); 987 EXPECT_TRUE(pref_info.AbsolutePath().empty());
976 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); 988 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty());
977 } 989 }
978 990
979 } // namespace chrome 991 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698