Chromium Code Reviews| 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..8e96abdfb3f0398220cb2236feb12477964d4907 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 { |
| @@ -14,6 +20,7 @@ namespace { |
| // Sample mtp device id and unique id. |
| const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; |
| const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; |
| +const char kImageCaptureDeviceId[] = "ic:xyz"; |
| } // namespace |
| @@ -37,4 +44,57 @@ 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(kImageCaptureDeviceId, |
| + &type, &id)); |
| + EXPECT_EQ(MediaStorageUtil::MAC_IMAGE_CAPTURE, type); |
| + EXPECT_EQ("xyz", id); |
| +} |
| + |
| +TEST_F(MediaStorageUtilTest, CanCreateFileSystemForImageCapture) { |
| + EXPECT_TRUE(MediaStorageUtil::CanCreateFileSystem(kImageCaptureDeviceId, |
| + FilePath())); |
| + EXPECT_FALSE(MediaStorageUtil::CanCreateFileSystem("dcim:xyz", |
| + FilePath("relative"))); |
|
Lei Zhang
2012/12/13 01:40:16
needs more FILE_PATH_LITERAL.
Greg Billock
2012/12/13 17:00:44
Oops. Yes. Forget about this spot...
On 2012/12/1
|
| + EXPECT_FALSE(MediaStorageUtil::CanCreateFileSystem("dcim:xyz", |
| + FilePath("../refparent"))); |
| +} |
| + |
| +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(kImageCaptureDeviceId); |
| + |
| + base::WaitableEvent event(true, false); |
| + MediaStorageUtil::FilterAttachedDevices(&devices, |
| + base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| + loop.RunUntilIdle(); |
| + event.Wait(); |
| + EXPECT_FALSE(devices.find(kImageCaptureDeviceId) != devices.end()); |
| + |
| + base::SystemMonitor::Get()->ProcessRemovableStorageAttached( |
| + kImageCaptureDeviceId, ASCIIToUTF16("name"), |
| + FILE_PATH_LITERAL("/location")); |
| + devices.insert(kImageCaptureDeviceId); |
| + event.Reset(); |
| + MediaStorageUtil::FilterAttachedDevices(&devices, |
| + base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| + loop.RunUntilIdle(); |
| + event.Wait(); |
| + |
| + EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); |
| +} |
| + |
| } // namespace chrome |