| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 #if defined OS_CHROMEOS | 386 #if defined OS_CHROMEOS |
| 386 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 387 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 387 chromeos::ScopedTestCrosSettings test_cros_settings_; | 388 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 388 chromeos::ScopedTestUserManager test_user_manager_; | 389 chromeos::ScopedTestUserManager test_user_manager_; |
| 389 #endif | 390 #endif |
| 390 | 391 |
| 391 // TODO(gbillock): Eliminate windows-specific code from this test. | 392 // TODO(gbillock): Eliminate windows-specific code from this test. |
| 392 #if defined(OS_WIN) | 393 #if defined(OS_WIN) |
| 393 scoped_ptr<test::TestStorageMonitorWin> monitor_; | 394 scoped_ptr<test::TestStorageMonitorWin> monitor_; |
| 394 #else | 395 #else |
| 395 chrome::test::TestStorageMonitor monitor_; | 396 scoped_ptr<chrome::test::TestStorageMonitor> monitor_; |
| 396 #endif | 397 #endif |
| 397 | 398 |
| 398 MockProfileSharedRenderProcessHostFactory rph_factory_; | 399 MockProfileSharedRenderProcessHostFactory rph_factory_; |
| 399 | 400 |
| 400 ScopedVector<ProfileState> profile_states_; | 401 ScopedVector<ProfileState> profile_states_; |
| 401 | 402 |
| 402 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); | 403 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); |
| 403 }; | 404 }; |
| 404 | 405 |
| 405 namespace { | 406 namespace { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 554 } |
| 554 | 555 |
| 555 Profile* ProfileState::profile() { | 556 Profile* ProfileState::profile() { |
| 556 return profile_.get(); | 557 return profile_.get(); |
| 557 } | 558 } |
| 558 | 559 |
| 559 void ProfileState::CompareResults( | 560 void ProfileState::CompareResults( |
| 560 const std::string& test, | 561 const std::string& test, |
| 561 const std::vector<MediaFileSystemInfo>& expected, | 562 const std::vector<MediaFileSystemInfo>& expected, |
| 562 const std::vector<MediaFileSystemInfo>& actual) { | 563 const std::vector<MediaFileSystemInfo>& actual) { |
| 564 LOG(INFO) << "CompareResults " << expected.size() << " vs " << actual.size(); |
| 563 // Order isn't important, so sort the results. Assume that expected | 565 // Order isn't important, so sort the results. Assume that expected |
| 564 // is already sorted. | 566 // is already sorted. |
| 565 std::vector<MediaFileSystemInfo> sorted(actual); | 567 std::vector<MediaFileSystemInfo> sorted(actual); |
| 566 std::sort(sorted.begin(), sorted.end(), MediaFileSystemInfoComparator); | 568 std::sort(sorted.begin(), sorted.end(), MediaFileSystemInfoComparator); |
| 567 | 569 |
| 568 num_comparisons_++; | 570 num_comparisons_++; |
| 569 ASSERT_EQ(expected.size(), actual.size()) << test; | 571 ASSERT_EQ(expected.size(), actual.size()) << test; |
| 570 for (size_t i = 0; i < expected.size() && i < actual.size(); ++i) { | 572 for (size_t i = 0; i < expected.size() && i < actual.size(); ++i) { |
| 571 EXPECT_EQ(expected[i].path, actual[i].path) << test; | 573 EXPECT_EQ(expected[i].path, actual[i].path) << test; |
| 572 EXPECT_FALSE(actual[i].fsid.empty()) << test; | 574 EXPECT_FALSE(actual[i].fsid.empty()) << test; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), | 726 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), |
| 725 0, std::string(), false, false); | 727 0, std::string(), false, false); |
| 726 result.push_back(info); | 728 result.push_back(info); |
| 727 } | 729 } |
| 728 } | 730 } |
| 729 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); | 731 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); |
| 730 return result; | 732 return result; |
| 731 } | 733 } |
| 732 | 734 |
| 733 void MediaFileSystemRegistryTest::SetUp() { | 735 void MediaFileSystemRegistryTest::SetUp() { |
| 734 #if defined(OS_WIN) | 736 #if !defined(OS_WIN) |
| 737 monitor_.reset(new test::TestStorageMonitor()); |
| 738 base::WaitableEvent wait_for_init(false, false); |
| 739 monitor_->Initialize(base::Bind(&base::WaitableEvent::Signal, |
| 740 base::Unretained(&wait_for_init))); |
| 741 monitor_->MarkInitialized(); |
| 742 base::RunLoop().RunUntilIdle(); |
| 743 DCHECK(wait_for_init.IsSignaled()); |
| 744 #else |
| 735 test::TestPortableDeviceWatcherWin* portable_device_watcher = | 745 test::TestPortableDeviceWatcherWin* portable_device_watcher = |
| 736 new test::TestPortableDeviceWatcherWin; | 746 new test::TestPortableDeviceWatcherWin; |
| 737 test::TestVolumeMountWatcherWin* mount_watcher = | 747 test::TestVolumeMountWatcherWin* mount_watcher = |
| 738 new test::TestVolumeMountWatcherWin; | 748 new test::TestVolumeMountWatcherWin; |
| 739 portable_device_watcher->set_use_dummy_mtp_storage_info(true); | 749 portable_device_watcher->set_use_dummy_mtp_storage_info(true); |
| 740 monitor_.reset(new test::TestStorageMonitorWin( | 750 monitor_.reset(new test::TestStorageMonitorWin( |
| 741 mount_watcher, portable_device_watcher)); | 751 mount_watcher, portable_device_watcher)); |
| 742 monitor_->Init(); | 752 base::WaitableEvent wait_for_init(false, false); |
| 753 wait_for_init.Reset(); |
| 754 monitor_->Initialize(base::Bind(&base::WaitableEvent::Signal, |
| 755 base::Unretained(&wait_for_init))); |
| 743 // TODO(gbillock): Replace this with the correct event notification | 756 // TODO(gbillock): Replace this with the correct event notification |
| 744 // on the storage monitor finishing the startup scan when that exists. | 757 // on the storage monitor finishing the startup scan when that exists. |
| 745 base::RunLoop().RunUntilIdle(); | 758 base::RunLoop().RunUntilIdle(); |
| 746 mount_watcher->FlushWorkerPoolForTesting(); | 759 mount_watcher->FlushWorkerPoolForTesting(); |
| 747 base::RunLoop().RunUntilIdle(); | 760 base::RunLoop().RunUntilIdle(); |
| 748 mount_watcher->FlushWorkerPoolForTesting(); | 761 mount_watcher->FlushWorkerPoolForTesting(); |
| 749 base::RunLoop().RunUntilIdle(); | 762 base::RunLoop().RunUntilIdle(); |
| 763 DCHECK(wait_for_init.IsSignaled()); |
| 750 #endif | 764 #endif |
| 751 | 765 |
| 752 ChromeRenderViewHostTestHarness::SetUp(); | 766 ChromeRenderViewHostTestHarness::SetUp(); |
| 753 DeleteContents(); | 767 DeleteContents(); |
| 754 SetRenderProcessHostFactory(&rph_factory_); | 768 SetRenderProcessHostFactory(&rph_factory_); |
| 755 | 769 |
| 756 test_file_system_context_ = new TestMediaFileSystemContext( | 770 test_file_system_context_ = new TestMediaFileSystemContext( |
| 757 g_browser_process->media_file_system_registry()); | 771 g_browser_process->media_file_system_registry()); |
| 758 (new extensions::BackgroundManifestHandler)->Register(); | 772 (new extensions::BackgroundManifestHandler)->Register(); |
| 759 (new extensions::IncognitoHandler)->Register(); | 773 (new extensions::IncognitoHandler)->Register(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 for (FSInfoMap::const_iterator it = galleries_info.begin(); | 905 for (FSInfoMap::const_iterator it = galleries_info.begin(); |
| 892 it != galleries_info.end(); | 906 it != galleries_info.end(); |
| 893 ++it) { | 907 ++it) { |
| 894 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, | 908 CheckGalleryInfo(it->second, test_file_system_context(), &it->second.name, |
| 895 it->second.path, false, false); | 909 it->second.path, false, false); |
| 896 } | 910 } |
| 897 } | 911 } |
| 898 | 912 |
| 899 // TODO(gbillock): Put the platform-specific parts of this test in tests | 913 // 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 | 914 // for those classes, not here. This test, internally, ends up creating an |
| 901 // MTP delegate. | 915 // MTP delegate. (Probably ./win/mtp_device_delegate_impl_win_unittest) |
| 902 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 916 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 903 #if !defined(OS_MACOSX) | 917 #if !defined(OS_MACOSX) |
| 904 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { | 918 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { |
| 905 FSInfoMap galleries_info; | 919 FSInfoMap galleries_info; |
| 906 InitForGalleriesInfoTest(&galleries_info); | 920 InitForGalleriesInfoTest(&galleries_info); |
| 907 | 921 |
| 908 #if defined(OS_WIN) | 922 #if defined(OS_WIN) |
| 909 base::FilePath location( | 923 base::FilePath location( |
| 910 PortableDeviceWatcherWin::GetStoragePathFromStorageId( | 924 PortableDeviceWatcherWin::GetStoragePathFromStorageId( |
| 911 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); | 925 test::TestPortableDeviceWatcherWin::kStorageUniqueIdA)); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 pref_info_with_relpath.device_id = device_id; | 1000 pref_info_with_relpath.device_id = device_id; |
| 987 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), | 1001 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), |
| 988 pref_info_with_relpath.AbsolutePath().value()); | 1002 pref_info_with_relpath.AbsolutePath().value()); |
| 989 | 1003 |
| 990 DetachDevice(device_id); | 1004 DetachDevice(device_id); |
| 991 EXPECT_TRUE(pref_info.AbsolutePath().empty()); | 1005 EXPECT_TRUE(pref_info.AbsolutePath().empty()); |
| 992 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); | 1006 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); |
| 993 } | 1007 } |
| 994 | 1008 |
| 995 } // namespace chrome | 1009 } // namespace chrome |
| OLD | NEW |