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

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: path check 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
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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
20 #include "base/synchronization/waitable_event.h"
20 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
22 #include "base/values.h" 23 #include "base/values.h"
23 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_system.h" 25 #include "chrome/browser/extensions/extension_system.h"
25 #include "chrome/browser/extensions/test_extension_system.h" 26 #include "chrome/browser/extensions/test_extension_system.h"
26 #include "chrome/browser/media_galleries/media_file_system_context.h" 27 #include "chrome/browser/media_galleries/media_file_system_context.h"
27 #include "chrome/browser/media_galleries/media_file_system_registry.h" 28 #include "chrome/browser/media_galleries/media_file_system_registry.h"
28 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" 29 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h"
29 #include "chrome/browser/media_galleries/media_galleries_test_util.h" 30 #include "chrome/browser/media_galleries/media_galleries_test_util.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 #if defined OS_CHROMEOS 380 #if defined OS_CHROMEOS
380 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 381 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
381 chromeos::ScopedTestCrosSettings test_cros_settings_; 382 chromeos::ScopedTestCrosSettings test_cros_settings_;
382 chromeos::ScopedTestUserManager test_user_manager_; 383 chromeos::ScopedTestUserManager test_user_manager_;
383 #endif 384 #endif
384 385
385 // TODO(gbillock): Eliminate windows-specific code from this test. 386 // TODO(gbillock): Eliminate windows-specific code from this test.
386 #if defined(OS_WIN) 387 #if defined(OS_WIN)
387 scoped_ptr<test::TestStorageMonitorWin> monitor_; 388 scoped_ptr<test::TestStorageMonitorWin> monitor_;
388 #else 389 #else
389 chrome::test::TestStorageMonitor monitor_; 390 scoped_ptr<chrome::test::TestStorageMonitor> monitor_;
390 #endif 391 #endif
391 392
392 MockProfileSharedRenderProcessHostFactory rph_factory_; 393 MockProfileSharedRenderProcessHostFactory rph_factory_;
393 394
394 ScopedVector<ProfileState> profile_states_; 395 ScopedVector<ProfileState> profile_states_;
395 396
396 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); 397 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest);
397 }; 398 };
398 399
399 namespace { 400 namespace {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), 718 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(),
718 0, std::string(), false, false); 719 0, std::string(), false, false);
719 result.push_back(info); 720 result.push_back(info);
720 } 721 }
721 } 722 }
722 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); 723 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator);
723 return result; 724 return result;
724 } 725 }
725 726
726 void MediaFileSystemRegistryTest::SetUp() { 727 void MediaFileSystemRegistryTest::SetUp() {
727 #if defined(OS_WIN) 728 #if !defined(OS_WIN)
729 monitor_.reset(new test::TestStorageMonitor());
730 base::WaitableEvent wait_for_init(false, false);
731 monitor_->Initialize(base::Bind(&base::WaitableEvent::Signal,
732 base::Unretained(&wait_for_init)));
733 monitor_->MarkInitialized();
734 base::RunLoop().RunUntilIdle();
735 DCHECK(wait_for_init.IsSignaled());
Lei Zhang 2013/05/14 22:32:00 EXPECT_EQ in tests?
736 #else
728 test::TestPortableDeviceWatcherWin* portable_device_watcher = 737 test::TestPortableDeviceWatcherWin* portable_device_watcher =
729 new test::TestPortableDeviceWatcherWin; 738 new test::TestPortableDeviceWatcherWin;
730 test::TestVolumeMountWatcherWin* mount_watcher = 739 test::TestVolumeMountWatcherWin* mount_watcher =
731 new test::TestVolumeMountWatcherWin; 740 new test::TestVolumeMountWatcherWin;
732 portable_device_watcher->set_use_dummy_mtp_storage_info(true); 741 portable_device_watcher->set_use_dummy_mtp_storage_info(true);
733 monitor_.reset(new test::TestStorageMonitorWin( 742 monitor_.reset(new test::TestStorageMonitorWin(
734 mount_watcher, portable_device_watcher)); 743 mount_watcher, portable_device_watcher));
735 monitor_->Init(); 744 base::WaitableEvent wait_for_init(false, false);
745 wait_for_init.Reset();
746 monitor_->Initialize(base::Bind(&base::WaitableEvent::Signal,
747 base::Unretained(&wait_for_init)));
736 // TODO(gbillock): Replace this with the correct event notification 748 // TODO(gbillock): Replace this with the correct event notification
737 // on the storage monitor finishing the startup scan when that exists. 749 // on the storage monitor finishing the startup scan when that exists.
738 base::RunLoop().RunUntilIdle(); 750 base::RunLoop().RunUntilIdle();
739 mount_watcher->FlushWorkerPoolForTesting(); 751 mount_watcher->FlushWorkerPoolForTesting();
740 base::RunLoop().RunUntilIdle(); 752 base::RunLoop().RunUntilIdle();
741 mount_watcher->FlushWorkerPoolForTesting(); 753 mount_watcher->FlushWorkerPoolForTesting();
742 base::RunLoop().RunUntilIdle(); 754 base::RunLoop().RunUntilIdle();
755 DCHECK(wait_for_init.IsSignaled());
743 #endif 756 #endif
744 757
745 ChromeRenderViewHostTestHarness::SetUp(); 758 ChromeRenderViewHostTestHarness::SetUp();
746 DeleteContents(); 759 DeleteContents();
747 SetRenderProcessHostFactory(&rph_factory_); 760 SetRenderProcessHostFactory(&rph_factory_);
748 761
749 test_file_system_context_ = new TestMediaFileSystemContext( 762 test_file_system_context_ = new TestMediaFileSystemContext(
750 g_browser_process->media_file_system_registry()); 763 g_browser_process->media_file_system_registry());
751 764
752 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); 765 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 // Attach a device. 861 // Attach a device.
849 const std::string device_id = AttachDevice( 862 const std::string device_id = AttachDevice(
850 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 863 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM,
851 "removable_dcim_fake_id", 864 "removable_dcim_fake_id",
852 dcim_dir()); 865 dcim_dir());
853 EXPECT_EQ(gallery_count + 1, GetAutoAddedGalleries(profile_state).size()); 866 EXPECT_EQ(gallery_count + 1, GetAutoAddedGalleries(profile_state).size());
854 867
855 // Forget the device. 868 // Forget the device.
856 bool forget_gallery = false; 869 bool forget_gallery = false;
857 MediaGalleriesPreferences* prefs = 870 MediaGalleriesPreferences* prefs =
858 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); 871 GetProfileState(0)->GetMediaGalleriesPrefs();
859 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); 872 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries();
860 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); 873 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin();
861 it != galleries.end(); ++it) { 874 it != galleries.end(); ++it) {
862 if (it->second.device_id == device_id) { 875 if (it->second.device_id == device_id) {
863 prefs->ForgetGalleryById(it->first); 876 prefs->ForgetGalleryById(it->first);
864 forget_gallery = true; 877 forget_gallery = true;
865 break; 878 break;
866 } 879 }
867 } 880 }
868 MessageLoop::current()->RunUntilIdle(); 881 MessageLoop::current()->RunUntilIdle();
869 EXPECT_TRUE(forget_gallery); 882 EXPECT_TRUE(forget_gallery);
870 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); 883 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size());
871
872 // Call GetPreferences() and the gallery count should not change.
873 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile());
874 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size());
875 } 884 }
876 885
877 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { 886 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) {
878 FSInfoMap galleries_info; 887 FSInfoMap galleries_info;
879 InitForGalleriesInfoTest(&galleries_info); 888 InitForGalleriesInfoTest(&galleries_info);
880 889
881 for (FSInfoMap::const_iterator it = galleries_info.begin(); 890 for (FSInfoMap::const_iterator it = galleries_info.begin();
882 it != galleries_info.end(); 891 it != galleries_info.end();
883 ++it) { 892 ++it) {
884 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, 893 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name,
885 it->second.path, false, false); 894 it->second.path, false, false);
886 } 895 }
887 } 896 }
888 897
889 // TODO(gbillock): Put the platform-specific parts of this test in tests 898 // TODO(gbillock): Put the platform-specific parts of this test in tests
890 // for those classes, not here. This test, internally, ends up creating an 899 // for those classes, not here. This test, internally, ends up creating an
891 // MTP delegate. 900 // MTP delegate. (Probably ./win/mtp_device_delegate_impl_win_unittest)
892 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 901 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
893 #if !defined(OS_MACOSX) 902 #if !defined(OS_MACOSX)
894 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { 903 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) {
895 FSInfoMap galleries_info; 904 FSInfoMap galleries_info;
896 InitForGalleriesInfoTest(&galleries_info); 905 InitForGalleriesInfoTest(&galleries_info);
897 906
898 #if defined(OS_WIN) 907 #if defined(OS_WIN)
899 base::FilePath location( 908 base::FilePath location(
900 PortableDeviceWatcherWin::GetStoragePathFromStorageId( 909 PortableDeviceWatcherWin::GetStoragePathFromStorageId(
901 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); 910 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 pref_info_with_relpath.device_id = device_id; 985 pref_info_with_relpath.device_id = device_id;
977 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), 986 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(),
978 pref_info_with_relpath.AbsolutePath().value()); 987 pref_info_with_relpath.AbsolutePath().value());
979 988
980 DetachDevice(device_id); 989 DetachDevice(device_id);
981 EXPECT_TRUE(pref_info.AbsolutePath().empty()); 990 EXPECT_TRUE(pref_info.AbsolutePath().empty());
982 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); 991 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty());
983 } 992 }
984 993
985 } // namespace chrome 994 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698