Chromium Code Reviews| 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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 content::MockRenderProcessHost* single_rph_; | 273 content::MockRenderProcessHost* single_rph_; |
| 274 content::MockRenderProcessHost* shared_rph_; | 274 content::MockRenderProcessHost* shared_rph_; |
| 275 | 275 |
| 276 DISALLOW_COPY_AND_ASSIGN(ProfileState); | 276 DISALLOW_COPY_AND_ASSIGN(ProfileState); |
| 277 }; | 277 }; |
| 278 | 278 |
| 279 } // namespace | 279 } // namespace |
| 280 | 280 |
| 281 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { | 281 class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { |
| 282 public: | 282 public: |
| 283 MediaFileSystemRegistryTest(); | |
| 284 virtual ~MediaFileSystemRegistryTest() {} | |
| 285 | |
| 286 void CreateProfileState(size_t profile_count); | 283 void CreateProfileState(size_t profile_count); |
| 287 | 284 |
| 288 ProfileState* GetProfileState(size_t i); | 285 ProfileState* GetProfileState(size_t i); |
| 289 | 286 |
| 290 MediaGalleriesPreferences* GetPreferences(Profile* profile); | 287 MediaGalleriesPreferences* GetPreferences(Profile* profile); |
| 291 | 288 |
| 292 base::FilePath empty_dir() { | 289 base::FilePath empty_dir() { |
| 293 return empty_dir_; | 290 return empty_dir_; |
| 294 } | 291 } |
| 295 | 292 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 base::ScopedTempDir galleries_dir_; | 360 base::ScopedTempDir galleries_dir_; |
| 364 // An empty directory in |galleries_dir_| | 361 // An empty directory in |galleries_dir_| |
| 365 base::FilePath empty_dir_; | 362 base::FilePath empty_dir_; |
| 366 // A directory in |galleries_dir_| with a DCIM directory in it. | 363 // A directory in |galleries_dir_| with a DCIM directory in it. |
| 367 base::FilePath dcim_dir_; | 364 base::FilePath dcim_dir_; |
| 368 | 365 |
| 369 // MediaFileSystemRegistry owns this. | 366 // MediaFileSystemRegistry owns this. |
| 370 TestMediaFileSystemContext* test_file_system_context_; | 367 TestMediaFileSystemContext* test_file_system_context_; |
| 371 | 368 |
| 372 // Needed for extension service & friends to work. | 369 // Needed for extension service & friends to work. |
| 373 content::TestBrowserThread ui_thread_; | |
| 374 content::TestBrowserThread file_thread_; | |
| 375 | 370 |
| 376 #if defined OS_CHROMEOS | 371 #if defined OS_CHROMEOS |
| 377 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 372 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 378 chromeos::ScopedTestCrosSettings test_cros_settings_; | 373 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 379 chromeos::ScopedTestUserManager test_user_manager_; | 374 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 380 #endif | 375 #endif |
| 381 | 376 |
| 382 // TODO(gbillock): Eliminate windows-specific code from this test. | 377 // TODO(gbillock): Eliminate windows-specific code from this test. |
| 383 #if defined(OS_WIN) | 378 #if defined(OS_WIN) |
| 384 scoped_ptr<test::TestStorageMonitorWin> monitor_; | 379 scoped_ptr<test::TestStorageMonitorWin> monitor_; |
| 385 #else | 380 #else |
| 386 scoped_ptr<chrome::test::TestStorageMonitor> monitor_; | 381 scoped_ptr<chrome::test::TestStorageMonitor> monitor_; |
| 387 #endif | 382 #endif |
| 388 | 383 |
| 389 MockProfileSharedRenderProcessHostFactory rph_factory_; | 384 MockProfileSharedRenderProcessHostFactory rph_factory_; |
| 390 | 385 |
| 391 ScopedVector<ProfileState> profile_states_; | 386 ScopedVector<ProfileState> profile_states_; |
| 392 | |
| 393 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); | |
| 394 }; | 387 }; |
| 395 | 388 |
| 396 namespace { | 389 namespace { |
| 397 | 390 |
| 398 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, | 391 bool MediaFileSystemInfoComparator(const MediaFileSystemInfo& a, |
| 399 const MediaFileSystemInfo& b) { | 392 const MediaFileSystemInfo& b) { |
| 400 CHECK_NE(a.name, b.name); // Name must be unique. | 393 CHECK_NE(a.name, b.name); // Name must be unique. |
| 401 return a.name < b.name; | 394 return a.name < b.name; |
| 402 } | 395 } |
| 403 | 396 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 num_comparisons_ = 0; | 564 num_comparisons_ = 0; |
| 572 return result; | 565 return result; |
| 573 } | 566 } |
| 574 | 567 |
| 575 } // namespace | 568 } // namespace |
| 576 | 569 |
| 577 ///////////////////////////////// | 570 ///////////////////////////////// |
| 578 // MediaFileSystemRegistryTest // | 571 // MediaFileSystemRegistryTest // |
| 579 ///////////////////////////////// | 572 ///////////////////////////////// |
| 580 | 573 |
| 581 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() | |
| 582 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), | |
| 583 file_thread_(content::BrowserThread::FILE, base::MessageLoop::current()) { | |
| 584 } | |
| 585 | |
| 586 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 574 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
| 587 for (size_t i = 0; i < profile_count; ++i) { | 575 for (size_t i = 0; i < profile_count; ++i) { |
| 588 ProfileState* state = new ProfileState(&rph_factory_); | 576 ProfileState* state = new ProfileState(&rph_factory_); |
| 589 profile_states_.push_back(state); | 577 profile_states_.push_back(state); |
| 590 } | 578 } |
| 591 } | 579 } |
| 592 | 580 |
| 593 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { | 581 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
| 594 return profile_states_[i]; | 582 return profile_states_[i]; |
| 595 } | 583 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 registry->extension_hosts_map_.begin(); | 720 registry->extension_hosts_map_.begin(); |
| 733 it != registry->extension_hosts_map_.end(); | 721 it != registry->extension_hosts_map_.end(); |
| 734 ++it) { | 722 ++it) { |
| 735 extension_galleries_host_count += it->second.size(); | 723 extension_galleries_host_count += it->second.size(); |
| 736 } | 724 } |
| 737 return extension_galleries_host_count; | 725 return extension_galleries_host_count; |
| 738 } | 726 } |
| 739 | 727 |
| 740 | 728 |
| 741 void MediaFileSystemRegistryTest::SetUp() { | 729 void MediaFileSystemRegistryTest::SetUp() { |
| 730 ChromeRenderViewHostTestHarness::SetUp(); | |
| 742 #if defined(OS_WIN) | 731 #if defined(OS_WIN) |
| 743 test::TestPortableDeviceWatcherWin* portable_device_watcher = | 732 test::TestPortableDeviceWatcherWin* portable_device_watcher = |
| 744 new test::TestPortableDeviceWatcherWin; | 733 new test::TestPortableDeviceWatcherWin; |
| 745 test::TestVolumeMountWatcherWin* mount_watcher = | 734 test::TestVolumeMountWatcherWin* mount_watcher = |
| 746 new test::TestVolumeMountWatcherWin; | 735 new test::TestVolumeMountWatcherWin; |
| 747 portable_device_watcher->set_use_dummy_mtp_storage_info(true); | 736 portable_device_watcher->set_use_dummy_mtp_storage_info(true); |
| 748 monitor_.reset(new test::TestStorageMonitorWin( | 737 monitor_.reset(new test::TestStorageMonitorWin( |
| 749 mount_watcher, portable_device_watcher)); | 738 mount_watcher, portable_device_watcher)); |
| 750 monitor_->Initialize(base::Bind(&base::DoNothing)); | |
| 751 // TODO(gbillock): Replace this with the correct event notification | |
| 752 // on the storage monitor finishing the startup scan when that exists. | |
| 753 base::RunLoop().RunUntilIdle(); | |
| 754 mount_watcher->FlushWorkerPoolForTesting(); | |
| 755 base::RunLoop().RunUntilIdle(); | |
| 756 mount_watcher->FlushWorkerPoolForTesting(); | |
| 757 base::RunLoop().RunUntilIdle(); | |
| 758 #else | 739 #else |
| 759 monitor_.reset(new test::TestStorageMonitor()); | 740 monitor_.reset(new test::TestStorageMonitor()); |
| 760 monitor_->Initialize(base::Bind(&base::DoNothing)); | 741 // TODO(ajwong): ask gbillock if we need this MarkInitialized? |
|
Greg Billock
2013/06/05 23:31:33
The TestStorageMonitor is set up so the tests run
| |
| 761 monitor_->MarkInitialized(); | 742 monitor_->MarkInitialized(); |
| 762 base::RunLoop().RunUntilIdle(); | |
| 763 #endif | 743 #endif |
| 744 base::RunLoop runloop; | |
| 745 monitor_->Initialize(runloop.QuitClosure()); | |
| 746 runloop.Run(); | |
| 764 | 747 |
| 765 ChromeRenderViewHostTestHarness::SetUp(); | |
| 766 DeleteContents(); | 748 DeleteContents(); |
| 767 SetRenderProcessHostFactory(&rph_factory_); | 749 SetRenderProcessHostFactory(&rph_factory_); |
| 768 | 750 |
| 769 test_file_system_context_ = new TestMediaFileSystemContext( | 751 test_file_system_context_ = new TestMediaFileSystemContext( |
| 770 g_browser_process->media_file_system_registry()); | 752 g_browser_process->media_file_system_registry()); |
| 771 | 753 |
| 754 #if defined(OS_CHROMEOS) | |
| 755 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | |
| 756 #endif | |
| 757 | |
| 772 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); | 758 ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); |
| 773 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); | 759 empty_dir_ = galleries_dir_.path().AppendASCII("empty"); |
| 774 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); | 760 ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); |
| 775 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim"); | 761 dcim_dir_ = galleries_dir_.path().AppendASCII("with_dcim"); |
| 776 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_)); | 762 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_)); |
| 777 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); | 763 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); |
| 778 } | 764 } |
| 779 | 765 |
| 780 void MediaFileSystemRegistryTest::TearDown() { | 766 void MediaFileSystemRegistryTest::TearDown() { |
| 781 profile_states_.clear(); | 767 profile_states_.clear(); |
| 782 ChromeRenderViewHostTestHarness::TearDown(); | |
| 783 MediaFileSystemRegistry* registry = | 768 MediaFileSystemRegistry* registry = |
| 784 g_browser_process->media_file_system_registry(); | 769 g_browser_process->media_file_system_registry(); |
| 785 EXPECT_EQ(0U, GetExtensionGalleriesHostCount(registry)); | 770 EXPECT_EQ(0U, GetExtensionGalleriesHostCount(registry)); |
| 786 BrowserThread::GetBlockingPool()->FlushForTesting(); | 771 #if defined(OS_CHROMEOS) |
| 787 base::MessageLoop::current()->RunUntilIdle(); | 772 test_user_manager_.reset(); |
| 773 #endif | |
| 774 | |
| 775 #if defined(OS_WIN) | |
| 776 monitor_.reset(); | |
| 777 #endif | |
| 778 ChromeRenderViewHostTestHarness::TearDown(); | |
| 788 } | 779 } |
| 789 | 780 |
| 790 /////////// | 781 /////////// |
| 791 // Tests // | 782 // Tests // |
| 792 /////////// | 783 /////////// |
| 793 | 784 |
| 794 TEST_F(MediaFileSystemRegistryTest, Basic) { | 785 TEST_F(MediaFileSystemRegistryTest, Basic) { |
| 795 CreateProfileState(1); | 786 CreateProfileState(1); |
| 796 AssertAllAutoAddedGalleries(); | 787 AssertAllAutoAddedGalleries(); |
| 797 | 788 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 pref_info_with_relpath.device_id = device_id; | 984 pref_info_with_relpath.device_id = device_id; |
| 994 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), | 985 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), |
| 995 pref_info_with_relpath.AbsolutePath().value()); | 986 pref_info_with_relpath.AbsolutePath().value()); |
| 996 | 987 |
| 997 DetachDevice(device_id); | 988 DetachDevice(device_id); |
| 998 EXPECT_TRUE(pref_info.AbsolutePath().empty()); | 989 EXPECT_TRUE(pref_info.AbsolutePath().empty()); |
| 999 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); | 990 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); |
| 1000 } | 991 } |
| 1001 | 992 |
| 1002 } // namespace chrome | 993 } // namespace chrome |
| OLD | NEW |