diff options
author | reillyg <reillyg@chromium.org> | 2015-06-19 14:06:34 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-19 21:08:17 +0000 |
commit | a4407051b3f269d24d8d190e9b65eb403a7e8263 (patch) | |
tree | 00d011d9d11f2c4d8b7b15d04bca924c51edae6b | |
parent | 6573dce68029e89f87113d9d66ab9a0207015fe7 (diff) | |
download | chromium_src-a4407051b3f269d24d8d190e9b65eb403a7e8263.zip chromium_src-a4407051b3f269d24d8d190e9b65eb403a7e8263.tar.gz chromium_src-a4407051b3f269d24d8d190e9b65eb403a7e8263.tar.bz2 |
Add a test to exercise GalleryWatchManager::OnRemoveableStorageDetached.
This path was previously unexercised and is implicated in issue 467627.
Another test based on this one will soon be added that tests what
happens when a storage removal event occurs after profile shutdown.
BUG=467627
Review URL: https://codereview.chromium.org/1197883002
Cr-Commit-Position: refs/heads/master@{#335345}
3 files changed, 48 insertions, 3 deletions
diff --git a/chrome/browser/media_galleries/gallery_watch_manager_unittest.cc b/chrome/browser/media_galleries/gallery_watch_manager_unittest.cc index 9a26dd7..4dcb951 100644 --- a/chrome/browser/media_galleries/gallery_watch_manager_unittest.cc +++ b/chrome/browser/media_galleries/gallery_watch_manager_unittest.cc @@ -62,7 +62,8 @@ class GalleryWatchManagerTest : public GalleryWatchManagerObserver, ~GalleryWatchManagerTest() override {} void SetUp() override { - ASSERT_TRUE(storage_monitor::TestStorageMonitor::CreateAndInstall()); + monitor_ = storage_monitor::TestStorageMonitor::CreateAndInstall(); + ASSERT_TRUE(monitor_); extensions::TestExtensionSystem* extension_system( static_cast<extensions::TestExtensionSystem*>( @@ -123,6 +124,8 @@ class GalleryWatchManagerTest : public GalleryWatchManagerObserver, MediaGalleriesPreferences* gallery_prefs() { return gallery_prefs_; } + storage_monitor::TestStorageMonitor* storage_monitor() { return monitor_; } + bool GalleryWatchesSupported() { return base::FilePathWatcher::RecursiveWatchAvailable(); } @@ -175,7 +178,7 @@ class GalleryWatchManagerTest : public GalleryWatchManagerObserver, chromeos::ScopedTestUserManager test_user_manager_; #endif - storage_monitor::TestStorageMonitor monitor_; + storage_monitor::TestStorageMonitor* monitor_; scoped_ptr<TestingProfile> profile_; MediaGalleriesPreferences* gallery_prefs_; @@ -312,6 +315,28 @@ TEST_F(GalleryWatchManagerTest, DropWatchOnGalleryPermissionRevoked) { success_loop.Run(); } +TEST_F(GalleryWatchManagerTest, DropWatchOnStorageRemoved) { + if (!GalleryWatchesSupported()) + return; + + // Create a temporary directory and treat is as a removable storage device. + base::ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + storage_monitor()->AddRemovablePath(temp_dir.path()); + storage_monitor::StorageInfo storage_info; + ASSERT_TRUE( + storage_monitor()->GetStorageInfoForPath(temp_dir.path(), &storage_info)); + storage_monitor()->receiver()->ProcessAttach(storage_info); + + MediaGalleryPrefId id = AddGallery(temp_dir.path()); + AddAndConfirmWatch(id); + + base::RunLoop success_loop; + ExpectGalleryWatchDropped(&success_loop); + storage_monitor()->receiver()->ProcessDetach(storage_info.device_id()); + success_loop.Run(); +} + TEST_F(GalleryWatchManagerTest, TestWatchOperation) { if (!GalleryWatchesSupported()) return; diff --git a/components/storage_monitor/test_storage_monitor.cc b/components/storage_monitor/test_storage_monitor.cc index fb5cc57..95a8198 100644 --- a/components/storage_monitor/test_storage_monitor.cc +++ b/components/storage_monitor/test_storage_monitor.cc @@ -84,8 +84,18 @@ bool TestStorageMonitor::GetStorageInfoForPath( if (!path.IsAbsolute()) return false; + bool is_removable = false; + for (const base::FilePath& removable : removable_paths_) { + if (path == removable || removable.IsParent(path)) { + is_removable = true; + break; + } + } + std::string device_id = StorageInfo::MakeDeviceId( - StorageInfo::FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); + is_removable ? StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM + : StorageInfo::FIXED_MASS_STORAGE, + path.AsUTF8Unsafe()); *device_info = StorageInfo(device_id, path.value(), base::string16(), base::string16(), base::string16(), 0); @@ -119,4 +129,9 @@ void TestStorageMonitor::EjectDevice( callback.Run(EJECT_OK); } +void TestStorageMonitor::AddRemovablePath(const base::FilePath& path) { + CHECK(path.IsAbsolute()); + removable_paths_.push_back(path); +} + } // namespace storage_monitor diff --git a/components/storage_monitor/test_storage_monitor.h b/components/storage_monitor/test_storage_monitor.h index 7726e57..da3809b 100644 --- a/components/storage_monitor/test_storage_monitor.h +++ b/components/storage_monitor/test_storage_monitor.h @@ -57,6 +57,8 @@ class TestStorageMonitor : public StorageMonitor { const std::string& ejected_device() const { return ejected_device_; } + void AddRemovablePath(const base::FilePath& path); + bool init_called() const { return init_called_; } private: @@ -66,6 +68,9 @@ class TestStorageMonitor : public StorageMonitor { // The last device to be ejected. std::string ejected_device_; + // Paths considered for testing purposes to be on removable storage. + std::vector<base::FilePath> removable_paths_; + #if defined(OS_LINUX) scoped_ptr<device::MediaTransferProtocolManager> media_transfer_protocol_manager_; |