OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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()); | |
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 Loading... | |
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 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); |
Lei Zhang
2013/05/14 04:12:22
Any chance we convert this test? The changes here
Greg Billock
2013/05/14 21:27:13
Yeah, I noticed this while converting these classe
Lei Zhang
2013/05/14 23:45:24
You gotta keep the GetPreferences() call for this
Greg Billock
2013/05/15 01:40:20
Done.
| |
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(); |
(...skipping 12 matching lines...) Expand all Loading... | |
881 for (FSInfoMap::const_iterator it = galleries_info.begin(); | 894 for (FSInfoMap::const_iterator it = galleries_info.begin(); |
882 it != galleries_info.end(); | 895 it != galleries_info.end(); |
883 ++it) { | 896 ++it) { |
884 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, | 897 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, |
885 it->second.path, false, false); | 898 it->second.path, false, false); |
886 } | 899 } |
887 } | 900 } |
888 | 901 |
889 // TODO(gbillock): Put the platform-specific parts of this test in tests | 902 // 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 | 903 // for those classes, not here. This test, internally, ends up creating an |
891 // MTP delegate. | 904 // MTP delegate. (Probably ./win/mtp_device_delegate_impl_win_unittest) |
892 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 905 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
893 #if !defined(OS_MACOSX) | 906 #if !defined(OS_MACOSX) |
894 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { | 907 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { |
895 FSInfoMap galleries_info; | 908 FSInfoMap galleries_info; |
896 InitForGalleriesInfoTest(&galleries_info); | 909 InitForGalleriesInfoTest(&galleries_info); |
897 | 910 |
898 #if defined(OS_WIN) | 911 #if defined(OS_WIN) |
899 base::FilePath location( | 912 base::FilePath location( |
900 PortableDeviceWatcherWin::GetStoragePathFromStorageId( | 913 PortableDeviceWatcherWin::GetStoragePathFromStorageId( |
901 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); | 914 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 pref_info_with_relpath.device_id = device_id; | 989 pref_info_with_relpath.device_id = device_id; |
977 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), | 990 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), |
978 pref_info_with_relpath.AbsolutePath().value()); | 991 pref_info_with_relpath.AbsolutePath().value()); |
979 | 992 |
980 DetachDevice(device_id); | 993 DetachDevice(device_id); |
981 EXPECT_TRUE(pref_info.AbsolutePath().empty()); | 994 EXPECT_TRUE(pref_info.AbsolutePath().empty()); |
982 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); | 995 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); |
983 } | 996 } |
984 | 997 |
985 } // namespace chrome | 998 } // namespace chrome |
OLD | NEW |