Index: chrome/browser/system_monitor/media_storage_util_unittest.cc |
diff --git a/chrome/browser/system_monitor/media_storage_util_unittest.cc b/chrome/browser/system_monitor/media_storage_util_unittest.cc |
index 175cb781cfaf37bded4fcec05b823e55f8535b15..de61f11a57c09ea43c8e2e16ecb2d0c121c96a03 100644 |
--- a/chrome/browser/system_monitor/media_storage_util_unittest.cc |
+++ b/chrome/browser/system_monitor/media_storage_util_unittest.cc |
@@ -4,7 +4,13 @@ |
#include <string> |
+#include "base/message_loop.h" |
+#include "base/synchronization/waitable_event.h" |
+#include "base/system_monitor/system_monitor.h" |
+#include "base/utf_string_conversions.h" |
#include "chrome/browser/system_monitor/media_storage_util.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/test/test_browser_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace chrome { |
@@ -37,4 +43,54 @@ TEST_F(MediaStorageUtilTest, CrackMtpDeviceId) { |
ASSERT_EQ(MediaStorageUtil::MTP_OR_PTP, type); |
} |
+TEST_F(MediaStorageUtilTest, TestImageCaptureDeviceId) { |
+ MediaStorageUtil::Type type; |
+ std::string id; |
+ EXPECT_TRUE(MediaStorageUtil::CrackDeviceId("ic:xyz", &type, &id)); |
+ EXPECT_EQ(MediaStorageUtil::MAC_IMAGE_CAPTURE, type); |
+ EXPECT_EQ("xyz", id); |
+} |
+ |
+TEST_F(MediaStorageUtilTest, CanCreateFileSystemForImageCapture) { |
+ EXPECT_TRUE(MediaStorageUtil::CanCreateFileSystem("ic:xyz", FilePath())); |
sail
2012/12/10 23:06:36
maybe also add a negative test for this?
Greg Billock
2012/12/11 00:11:22
Done
|
+} |
+ |
+void SignalEvent(base::WaitableEvent* event) { |
sail
2012/12/10 23:06:36
move this to the anonymous namespace above?
Greg Billock
2012/12/11 00:11:22
Done.
|
+ event->Signal(); |
+} |
+ |
+TEST_F(MediaStorageUtilTest, DetectDeviceFiltered) { |
+ MessageLoop loop; |
+#if defined(OS_MACOSX) |
+ // This needs to happen before SystemMonitor's ctor. |
+ base::SystemMonitor::AllocateSystemIOPorts(); |
+#endif |
+ // Installs global. Required MessageLoop. |
+ // On Mac, requires AllocateSystemIOPorts. |
+ base::SystemMonitor monitor; |
+ |
+ content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop); |
+ |
+ MediaStorageUtil::DeviceIdSet devices; |
+ devices.insert("ic:xyz"); |
+ |
+ base::WaitableEvent event(true, false); |
+ MediaStorageUtil::FilterAttachedDevices(&devices, |
+ base::Bind(&SignalEvent, &event)); |
sail
2012/12/10 23:06:36
would base::Bind(&base::WaitableEvent::SignalEvent
Greg Billock
2012/12/11 00:11:22
Done.
|
+ loop.RunUntilIdle(); |
+ event.Wait(); |
+ EXPECT_FALSE(devices.find("ic:xyz") != devices.end()); |
+ |
+ base::SystemMonitor::Get()->ProcessRemovableStorageAttached( |
+ "ic:xyz", ASCIIToUTF16("name"), "/location"); |
+ devices.insert("ic:xyz"); |
+ event.Reset(); |
+ MediaStorageUtil::FilterAttachedDevices(&devices, |
+ base::Bind(&SignalEvent, &event)); |
+ loop.RunUntilIdle(); |
+ event.Wait(); |
+ |
+ EXPECT_TRUE(devices.find("ic:xyz") != devices.end()); |
+} |
+ |
} // namespace chrome |