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

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: Fix merge 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 280
280 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { 281 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness {
281 public: 282 public:
282 MediaFileSystemRegistryTest(); 283 MediaFileSystemRegistryTest();
283 virtual ~MediaFileSystemRegistryTest() {} 284 virtual ~MediaFileSystemRegistryTest() {}
284 285
285 void CreateProfileState(size_t profile_count); 286 void CreateProfileState(size_t profile_count);
286 287
287 ProfileState* GetProfileState(size_t i); 288 ProfileState* GetProfileState(size_t i);
288 289
290 MediaGalleriesPreferences* GetPreferences(Profile* profile);
291
289 base::FilePath empty_dir() { 292 base::FilePath empty_dir() {
290 return empty_dir_; 293 return empty_dir_;
291 } 294 }
292 295
293 base::FilePath dcim_dir() { 296 base::FilePath dcim_dir() {
294 return dcim_dir_; 297 return dcim_dir_;
295 } 298 }
296 299
297 TestMediaFileSystemContext* test_file_system_context() { 300 TestMediaFileSystemContext* test_file_system_context() {
298 return test_file_system_context_; 301 return test_file_system_context_;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 for (size_t i = 0; i < profile_count; ++i) { 587 for (size_t i = 0; i < profile_count; ++i) {
585 ProfileState* state = new ProfileState(&rph_factory_); 588 ProfileState* state = new ProfileState(&rph_factory_);
586 profile_states_.push_back(state); 589 profile_states_.push_back(state);
587 } 590 }
588 } 591 }
589 592
590 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { 593 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) {
591 return profile_states_[i]; 594 return profile_states_[i];
592 } 595 }
593 596
597 MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences(
598 Profile* profile) {
599 return registry()->GetPreferences(profile);
600 }
601
594 std::string MediaFileSystemRegistryTest::AddUserGallery( 602 std::string MediaFileSystemRegistryTest::AddUserGallery(
595 StorageInfo::Type type, 603 StorageInfo::Type type,
596 const std::string& unique_id, 604 const std::string& unique_id,
597 const base::FilePath& path) { 605 const base::FilePath& path) {
598 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); 606 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id);
599 string16 name = path.LossyDisplayName(); 607 string16 name = path.LossyDisplayName();
600 DCHECK(!StorageInfo::IsMediaDevice(device_id)); 608 DCHECK(!StorageInfo::IsMediaDevice(device_id));
601 609
602 for (size_t i = 0; i < profile_states_.size(); ++i) { 610 for (size_t i = 0; i < profile_states_.size(); ++i) {
603 profile_states_[i]->GetMediaGalleriesPrefs()->AddGalleryWithName( 611 profile_states_[i]->GetMediaGalleriesPrefs()->AddGalleryWithName(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 740
733 void MediaFileSystemRegistryTest::SetUp() { 741 void MediaFileSystemRegistryTest::SetUp() {
734 #if defined(OS_WIN) 742 #if defined(OS_WIN)
735 test::TestPortableDeviceWatcherWin* portable_device_watcher = 743 test::TestPortableDeviceWatcherWin* portable_device_watcher =
736 new test::TestPortableDeviceWatcherWin; 744 new test::TestPortableDeviceWatcherWin;
737 test::TestVolumeMountWatcherWin* mount_watcher = 745 test::TestVolumeMountWatcherWin* mount_watcher =
738 new test::TestVolumeMountWatcherWin; 746 new test::TestVolumeMountWatcherWin;
739 portable_device_watcher->set_use_dummy_mtp_storage_info(true); 747 portable_device_watcher->set_use_dummy_mtp_storage_info(true);
740 monitor_.reset(new test::TestStorageMonitorWin( 748 monitor_.reset(new test::TestStorageMonitorWin(
741 mount_watcher, portable_device_watcher)); 749 mount_watcher, portable_device_watcher));
742 monitor_->Init(); 750 monitor_->Initialize(base::Bind(&base::DoNothing));
743 // TODO(gbillock): Replace this with the correct event notification 751 // TODO(gbillock): Replace this with the correct event notification
744 // on the storage monitor finishing the startup scan when that exists. 752 // on the storage monitor finishing the startup scan when that exists.
745 base::RunLoop().RunUntilIdle(); 753 base::RunLoop().RunUntilIdle();
746 mount_watcher->FlushWorkerPoolForTesting(); 754 mount_watcher->FlushWorkerPoolForTesting();
747 base::RunLoop().RunUntilIdle(); 755 base::RunLoop().RunUntilIdle();
748 mount_watcher->FlushWorkerPoolForTesting(); 756 mount_watcher->FlushWorkerPoolForTesting();
749 base::RunLoop().RunUntilIdle(); 757 base::RunLoop().RunUntilIdle();
750 #else 758 #else
751 monitor_.reset(new test::TestStorageMonitor()); 759 monitor_.reset(new test::TestStorageMonitor());
752 monitor_->Init(); 760 monitor_->Initialize(base::Bind(&base::DoNothing));
761 monitor_->MarkInitialized();
762 base::RunLoop().RunUntilIdle();
753 #endif 763 #endif
754 764
755 ChromeRenderViewHostTestHarness::SetUp(); 765 ChromeRenderViewHostTestHarness::SetUp();
756 DeleteContents(); 766 DeleteContents();
757 SetRenderProcessHostFactory(&rph_factory_); 767 SetRenderProcessHostFactory(&rph_factory_);
758 768
759 test_file_system_context_ = new TestMediaFileSystemContext( 769 test_file_system_context_ = new TestMediaFileSystemContext(
760 g_browser_process->media_file_system_registry()); 770 g_browser_process->media_file_system_registry());
761 771
762 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); 772 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 867
858 // Attach a device. 868 // Attach a device.
859 const std::string device_id = AttachDevice( 869 const std::string device_id = AttachDevice(
860 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, 870 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM,
861 "removable_dcim_fake_id", 871 "removable_dcim_fake_id",
862 dcim_dir()); 872 dcim_dir());
863 EXPECT_EQ(gallery_count + 1, GetAutoAddedGalleries(profile_state).size()); 873 EXPECT_EQ(gallery_count + 1, GetAutoAddedGalleries(profile_state).size());
864 874
865 // Forget the device. 875 // Forget the device.
866 bool forget_gallery = false; 876 bool forget_gallery = false;
867 MediaGalleriesPreferences* prefs = 877 MediaGalleriesPreferences* prefs = GetPreferences(profile_state->profile());
868 registry()->GetPreferences(profile_state->profile());
869 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); 878 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries();
870 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); 879 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin();
871 it != galleries.end(); ++it) { 880 it != galleries.end(); ++it) {
872 if (it->second.device_id == device_id) { 881 if (it->second.device_id == device_id) {
873 prefs->ForgetGalleryById(it->first); 882 prefs->ForgetGalleryById(it->first);
874 forget_gallery = true; 883 forget_gallery = true;
875 break; 884 break;
876 } 885 }
877 } 886 }
878 base::MessageLoop::current()->RunUntilIdle(); 887 base::MessageLoop::current()->RunUntilIdle();
879 EXPECT_TRUE(forget_gallery); 888 EXPECT_TRUE(forget_gallery);
880 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); 889 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size());
881 890
882 // Call GetPreferences() and the gallery count should not change. 891 // Call GetPreferences() and the gallery count should not change.
883 registry()->GetPreferences(profile_state->profile()); 892 prefs = GetPreferences(profile_state->profile());
884 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); 893 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size());
885 } 894 }
886 895
887 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { 896 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) {
888 FSInfoMap galleries_info; 897 FSInfoMap galleries_info;
889 InitForGalleriesInfoTest(&galleries_info); 898 InitForGalleriesInfoTest(&galleries_info);
890 899
891 for (FSInfoMap::const_iterator it = galleries_info.begin(); 900 for (FSInfoMap::const_iterator it = galleries_info.begin();
892 it != galleries_info.end(); 901 it != galleries_info.end();
893 ++it) { 902 ++it) {
894 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, 903 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name,
895 it->second.path, false, false); 904 it->second.path, false, false);
896 } 905 }
897 } 906 }
898 907
899 // TODO(gbillock): Put the platform-specific parts of this test in tests 908 // TODO(gbillock): Put the platform-specific parts of this test in tests
900 // for those classes, not here. This test, internally, ends up creating an 909 // for those classes, not here. This test, internally, ends up creating an
901 // MTP delegate. 910 // MTP delegate. (Probably ./win/mtp_device_delegate_impl_win_unittest)
902 #if !defined(OS_MACOSX) 911 #if !defined(OS_MACOSX)
903 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { 912 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) {
904 FSInfoMap galleries_info; 913 FSInfoMap galleries_info;
905 InitForGalleriesInfoTest(&galleries_info); 914 InitForGalleriesInfoTest(&galleries_info);
906 915
907 #if defined(OS_WIN) 916 #if defined(OS_WIN)
908 base::FilePath location( 917 base::FilePath location(
909 PortableDeviceWatcherWin::GetStoragePathFromStorageId( 918 PortableDeviceWatcherWin::GetStoragePathFromStorageId(
910 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); 919 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA));
911 #else 920 #else
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 pref_info_with_relpath.device_id = device_id; 993 pref_info_with_relpath.device_id = device_id;
985 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), 994 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(),
986 pref_info_with_relpath.AbsolutePath().value()); 995 pref_info_with_relpath.AbsolutePath().value());
987 996
988 DetachDevice(device_id); 997 DetachDevice(device_id);
989 EXPECT_TRUE(pref_info.AbsolutePath().empty()); 998 EXPECT_TRUE(pref_info.AbsolutePath().empty());
990 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); 999 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty());
991 } 1000 }
992 1001
993 } // namespace chrome 1002 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698