Index: chrome/browser/media_galleries/media_file_system_registry_unittest.cc |
diff --git a/chrome/browser/media_galleries/media_file_system_registry_unittest.cc b/chrome/browser/media_galleries/media_file_system_registry_unittest.cc |
index 45e7fc2da9416eda5255fa2938e923351f183263..fbbecfee89677ce9e203aac60e74973acd77200d 100644 |
--- a/chrome/browser/media_galleries/media_file_system_registry_unittest.cc |
+++ b/chrome/browser/media_galleries/media_file_system_registry_unittest.cc |
@@ -17,6 +17,7 @@ |
#include "base/run_loop.h" |
#include "base/stl_util.h" |
#include "base/stringprintf.h" |
+#include "base/synchronization/waitable_event.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
@@ -295,6 +296,8 @@ class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { |
ProfileState* GetProfileState(size_t i); |
+ MediaGalleriesPreferences* GetPreferences(Profile* profile); |
+ |
base::FilePath empty_dir() { |
return empty_dir_; |
} |
@@ -386,7 +389,7 @@ class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { |
#if defined(OS_WIN) |
scoped_ptr<test::TestStorageMonitorWin> monitor_; |
#else |
- chrome::test::TestStorageMonitor monitor_; |
+ scoped_ptr<chrome::test::TestStorageMonitor> monitor_; |
#endif |
MockProfileSharedRenderProcessHostFactory rph_factory_; |
@@ -597,6 +600,24 @@ ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
return profile_states_[i]; |
} |
+void GetPreferencesForwarder(base::WaitableEvent* event, |
vandebo (ex-Chrome)
2013/05/16 18:56:27
As far as I can tell, you don't need a waitable ev
Greg Billock
2013/05/16 23:27:55
I was thinking I'd have to run this in another thr
vandebo (ex-Chrome)
2013/05/17 22:19:58
Yes, please remove the waitable events, it makes t
Greg Billock
2013/05/18 00:02:26
Done.
|
+ MediaGalleriesPreferences** prefs_ptr, |
+ MediaGalleriesPreferences* prefs) { |
+ *prefs_ptr = prefs; |
+ event->Signal(); |
+} |
+ |
+MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences( |
+ Profile* profile) { |
+ base::WaitableEvent pref_event(false, false); |
+ MediaGalleriesPreferences* prefs; |
+ GetMediaFileSystemRegistry()->GetPreferencesAsync( |
+ profile, base::Bind(&GetPreferencesForwarder, &pref_event, &prefs)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_TRUE(pref_event.IsSignaled()); |
+ return prefs; |
+} |
+ |
std::string MediaFileSystemRegistryTest::AddUserGallery( |
MediaStorageUtil::Type type, |
const std::string& unique_id, |
@@ -724,7 +745,15 @@ MediaFileSystemRegistryTest::GetAutoAddedGalleries( |
} |
void MediaFileSystemRegistryTest::SetUp() { |
-#if defined(OS_WIN) |
+#if !defined(OS_WIN) |
+ monitor_.reset(new test::TestStorageMonitor()); |
+ base::WaitableEvent wait_for_init(false, false); |
+ monitor_->Initialize(base::Bind(&base::WaitableEvent::Signal, |
+ base::Unretained(&wait_for_init))); |
+ monitor_->MarkInitialized(); |
+ base::RunLoop().RunUntilIdle(); |
+ DCHECK(wait_for_init.IsSignaled()); |
+#else |
test::TestPortableDeviceWatcherWin* portable_device_watcher = |
new test::TestPortableDeviceWatcherWin; |
test::TestVolumeMountWatcherWin* mount_watcher = |
@@ -732,7 +761,10 @@ void MediaFileSystemRegistryTest::SetUp() { |
portable_device_watcher->set_use_dummy_mtp_storage_info(true); |
monitor_.reset(new test::TestStorageMonitorWin( |
mount_watcher, portable_device_watcher)); |
- monitor_->Init(); |
+ base::WaitableEvent wait_for_init(false, false); |
+ wait_for_init.Reset(); |
+ monitor_->Initialize(base::Bind(&base::WaitableEvent::Signal, |
+ base::Unretained(&wait_for_init))); |
// TODO(gbillock): Replace this with the correct event notification |
// on the storage monitor finishing the startup scan when that exists. |
base::RunLoop().RunUntilIdle(); |
@@ -740,6 +772,7 @@ void MediaFileSystemRegistryTest::SetUp() { |
base::RunLoop().RunUntilIdle(); |
mount_watcher->FlushWorkerPoolForTesting(); |
base::RunLoop().RunUntilIdle(); |
+ DCHECK(wait_for_init.IsSignaled()); |
#endif |
ChromeRenderViewHostTestHarness::SetUp(); |
@@ -854,8 +887,7 @@ TEST_F(MediaFileSystemRegistryTest, |
// Forget the device. |
bool forget_gallery = false; |
- MediaGalleriesPreferences* prefs = |
- GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); |
+ MediaGalleriesPreferences* prefs = GetPreferences(profile_state->profile()); |
const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); |
for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
it != galleries.end(); ++it) { |
@@ -870,7 +902,7 @@ TEST_F(MediaFileSystemRegistryTest, |
EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); |
// Call GetPreferences() and the gallery count should not change. |
- GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); |
+ prefs = GetPreferences(profile_state->profile()); |
EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); |
} |
@@ -888,7 +920,7 @@ TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { |
// TODO(gbillock): Put the platform-specific parts of this test in tests |
// for those classes, not here. This test, internally, ends up creating an |
-// MTP delegate. |
+// MTP delegate. (Probably ./win/mtp_device_delegate_impl_win_unittest) |
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
#if !defined(OS_MACOSX) |
TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { |