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" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 content::MockRenderProcessHost* single_rph_; | 277 content::MockRenderProcessHost* single_rph_; |
278 content::MockRenderProcessHost* shared_rph_; | 278 content::MockRenderProcessHost* shared_rph_; |
279 | 279 |
280 DISALLOW_COPY_AND_ASSIGN(ProfileState); | 280 DISALLOW_COPY_AND_ASSIGN(ProfileState); |
281 }; | 281 }; |
282 | 282 |
283 } // namespace | 283 } // namespace |
284 | 284 |
285 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { | 285 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { |
286 public: | 286 public: |
287 MediaFileSystemRegistryTest(); | |
288 virtual ~MediaFileSystemRegistryTest() {} | |
289 | |
290 void CreateProfileState(size_t profile_count); | 287 void CreateProfileState(size_t profile_count); |
291 | 288 |
292 ProfileState* GetProfileState(size_t i); | 289 ProfileState* GetProfileState(size_t i); |
293 | 290 |
294 base::FilePath empty_dir() { | 291 base::FilePath empty_dir() { |
295 return empty_dir_; | 292 return empty_dir_; |
296 } | 293 } |
297 | 294 |
298 base::FilePath dcim_dir() { | 295 base::FilePath dcim_dir() { |
299 return dcim_dir_; | 296 return dcim_dir_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 base::ScopedTempDir galleries_dir_; | 359 base::ScopedTempDir galleries_dir_; |
363 // An empty directory in |galleries_dir_| | 360 // An empty directory in |galleries_dir_| |
364 base::FilePath empty_dir_; | 361 base::FilePath empty_dir_; |
365 // A directory in |galleries_dir_| with a DCIM directory in it. | 362 // A directory in |galleries_dir_| with a DCIM directory in it. |
366 base::FilePath dcim_dir_; | 363 base::FilePath dcim_dir_; |
367 | 364 |
368 // MediaFileSystemRegistry owns this. | 365 // MediaFileSystemRegistry owns this. |
369 TestMediaFileSystemContext* test_file_system_context_; | 366 TestMediaFileSystemContext* test_file_system_context_; |
370 | 367 |
371 // Needed for extension service & friends to work. | 368 // Needed for extension service & friends to work. |
372 content::TestBrowserThread ui_thread_; | |
373 content::TestBrowserThread file_thread_; | |
374 | 369 |
375 #if defined OS_CHROMEOS | 370 #if defined OS_CHROMEOS |
376 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 371 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
377 chromeos::ScopedTestCrosSettings test_cros_settings_; | 372 chromeos::ScopedTestCrosSettings test_cros_settings_; |
378 chromeos::ScopedTestUserManager test_user_manager_; | 373 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
379 #endif | 374 #endif |
380 | 375 |
381 // TODO(gbillock): Eliminate windows-specific code from this test. | 376 // TODO(gbillock): Eliminate windows-specific code from this test. |
382 #if defined(OS_WIN) | 377 #if defined(OS_WIN) |
383 scoped_ptr<test::TestStorageMonitorWin> monitor_; | 378 scoped_ptr<test::TestStorageMonitorWin> monitor_; |
384 #else | 379 #else |
385 chrome::test::TestStorageMonitor monitor_; | 380 chrome::test::TestStorageMonitor monitor_; |
386 #endif | 381 #endif |
387 | 382 |
388 MockProfileSharedRenderProcessHostFactory rph_factory_; | 383 MockProfileSharedRenderProcessHostFactory rph_factory_; |
389 | 384 |
390 ScopedVector<ProfileState> profile_states_; | 385 ScopedVector<ProfileState> profile_states_; |
391 | |
392 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); | |
393 }; | 386 }; |
394 | 387 |
395 namespace { | 388 namespace { |
396 | 389 |
397 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, | 390 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, |
398 const MediaFileSystemInfo& b) { | 391 const MediaFileSystemInfo& b) { |
399 CHECK_NE(a.name, b.name); // Name must be unique. | 392 CHECK_NE(a.name, b.name); // Name must be unique. |
400 return a.name < b.name; | 393 return a.name < b.name; |
401 } | 394 } |
402 | 395 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 num_comparisons_ = 0; | 563 num_comparisons_ = 0; |
571 return result; | 564 return result; |
572 } | 565 } |
573 | 566 |
574 } // namespace | 567 } // namespace |
575 | 568 |
576 ///////////////////////////////// | 569 ///////////////////////////////// |
577 // MediaFileSystemRegistryTest // | 570 // MediaFileSystemRegistryTest // |
578 ///////////////////////////////// | 571 ///////////////////////////////// |
579 | 572 |
580 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() | |
581 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), | |
582 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { | |
583 } | |
584 | |
585 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 573 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
586 for (size_t i = 0; i < profile_count; ++i) { | 574 for (size_t i = 0; i < profile_count; ++i) { |
587 ProfileState* state = new ProfileState(&rph_factory_); | 575 ProfileState* state = new ProfileState(&rph_factory_); |
588 profile_states_.push_back(state); | 576 profile_states_.push_back(state); |
589 } | 577 } |
590 } | 578 } |
591 | 579 |
592 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { | 580 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
593 return profile_states_[i]; | 581 return profile_states_[i]; |
594 } | 582 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), | 701 MediaFileSystemInfo info(path.LossyDisplayName(), path, std::string(), |
714 0, std::string(), false, false); | 702 0, std::string(), false, false); |
715 result.push_back(info); | 703 result.push_back(info); |
716 } | 704 } |
717 } | 705 } |
718 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); | 706 std::sort(result.begin(), result.end(), MediaFileSystemInfoComparator); |
719 return result; | 707 return result; |
720 } | 708 } |
721 | 709 |
722 void MediaFileSystemRegistryTest::SetUp() { | 710 void MediaFileSystemRegistryTest::SetUp() { |
| 711 ChromeRenderViewHostTestHarness::SetUp(); |
723 #if defined(OS_WIN) | 712 #if defined(OS_WIN) |
724 test::TestPortableDeviceWatcherWin* portable_device_watcher = | 713 test::TestPortableDeviceWatcherWin* portable_device_watcher = |
725 new test::TestPortableDeviceWatcherWin; | 714 new test::TestPortableDeviceWatcherWin; |
726 test::TestVolumeMountWatcherWin* mount_watcher = | 715 test::TestVolumeMountWatcherWin* mount_watcher = |
727 new test::TestVolumeMountWatcherWin; | 716 new test::TestVolumeMountWatcherWin; |
728 portable_device_watcher->set_use_dummy_mtp_storage_info(true); | 717 portable_device_watcher->set_use_dummy_mtp_storage_info(true); |
729 monitor_.reset(new test::TestStorageMonitorWin( | 718 monitor_.reset(new test::TestStorageMonitorWin( |
730 mount_watcher, portable_device_watcher)); | 719 mount_watcher, portable_device_watcher)); |
731 monitor_->Init(); | 720 base::RunLoop runloop; |
732 // TODO(gbillock): Replace this with the correct event notification | 721 monitor_->Initialize(runloop.QuitClosure()); |
733 // on the storage monitor finishing the startup scan when that exists. | 722 runloop.Run(); |
734 base::RunLoop().RunUntilIdle(); | |
735 mount_watcher->FlushWorkerPoolForTesting(); | |
736 base::RunLoop().RunUntilIdle(); | |
737 mount_watcher->FlushWorkerPoolForTesting(); | |
738 base::RunLoop().RunUntilIdle(); | 723 base::RunLoop().RunUntilIdle(); |
739 #endif | 724 #endif |
740 | 725 |
741 ChromeRenderViewHostTestHarness::SetUp(); | |
742 DeleteContents(); | 726 DeleteContents(); |
743 SetRenderProcessHostFactory(&rph_factory_); | 727 SetRenderProcessHostFactory(&rph_factory_); |
744 | 728 |
745 test_file_system_context_ = new TestMediaFileSystemContext( | 729 test_file_system_context_ = new TestMediaFileSystemContext( |
746 g_browser_process->media_file_system_registry()); | 730 g_browser_process->media_file_system_registry()); |
747 | 731 |
| 732 #if defined OS_CHROMEOS |
| 733 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 734 #endif |
| 735 |
748 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); | 736 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); |
749 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); | 737 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); |
750 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); | 738 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); |
751 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim"); | 739 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim"); |
752 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_)); | 740 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_)); |
753 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); | 741 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); |
754 } | 742 } |
755 | 743 |
756 void MediaFileSystemRegistryTest::TearDown() { | 744 void MediaFileSystemRegistryTest::TearDown() { |
757 profile_states_.clear(); | 745 profile_states_.clear(); |
758 ChromeRenderViewHostTestHarness::TearDown(); | |
759 MediaFileSystemRegistry* registry = | 746 MediaFileSystemRegistry* registry = |
760 g_browser_process->media_file_system_registry(); | 747 g_browser_process->media_file_system_registry(); |
761 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests()); | 748 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests()); |
762 BrowserThread::GetBlockingPool()->FlushForTesting(); | 749 #if defined OS_CHROMEOS |
763 MessageLoop::current()->RunUntilIdle(); | 750 test_user_manager_.reset(); |
| 751 #endif |
| 752 |
| 753 #if defined(OS_WIN) |
| 754 monitor_.reset(); |
| 755 #endif |
| 756 ChromeRenderViewHostTestHarness::TearDown(); |
764 } | 757 } |
765 | 758 |
766 /////////// | 759 /////////// |
767 // Tests // | 760 // Tests // |
768 /////////// | 761 /////////// |
769 | 762 |
770 TEST_F(MediaFileSystemRegistryTest, Basic) { | 763 TEST_F(MediaFileSystemRegistryTest, Basic) { |
771 CreateProfileState(1); | 764 CreateProfileState(1); |
772 AssertAllAutoAddedGalleries(); | 765 AssertAllAutoAddedGalleries(); |
773 | 766 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 pref_info_with_relpath.device_id = device_id; | 963 pref_info_with_relpath.device_id = device_id; |
971 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), | 964 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), |
972 pref_info_with_relpath.AbsolutePath().value()); | 965 pref_info_with_relpath.AbsolutePath().value()); |
973 | 966 |
974 DetachDevice(device_id); | 967 DetachDevice(device_id); |
975 EXPECT_TRUE(pref_info.AbsolutePath().empty()); | 968 EXPECT_TRUE(pref_info.AbsolutePath().empty()); |
976 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); | 969 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); |
977 } | 970 } |
978 | 971 |
979 } // namespace chrome | 972 } // namespace chrome |
OLD | NEW |