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 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/synchronization/waitable_event.h" | |
| 9 #include "base/system_monitor/system_monitor.h" | |
| 10 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/system_monitor/media_storage_util.h" | 11 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/test/test_browser_thread.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 15 |
| 10 namespace chrome { | 16 namespace chrome { |
| 11 | 17 |
| 12 namespace { | 18 namespace { |
| 13 | 19 |
| 14 // Sample mtp device id and unique id. | 20 // Sample mtp device id and unique id. |
| 15 const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; | 21 const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; |
| 16 const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; | 22 const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; |
| 17 | 23 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 30 // Test to verify |MediaStorageUtil::CrackDeviceId| functionality using a sample | 36 // Test to verify |MediaStorageUtil::CrackDeviceId| functionality using a sample |
| 31 // mtp device id. | 37 // mtp device id. |
| 32 TEST_F(MediaStorageUtilTest, CrackMtpDeviceId) { | 38 TEST_F(MediaStorageUtilTest, CrackMtpDeviceId) { |
| 33 MediaStorageUtil::Type type; | 39 MediaStorageUtil::Type type; |
| 34 std::string id; | 40 std::string id; |
| 35 ASSERT_TRUE(MediaStorageUtil::CrackDeviceId(kMtpDeviceId, &type, &id)); | 41 ASSERT_TRUE(MediaStorageUtil::CrackDeviceId(kMtpDeviceId, &type, &id)); |
| 36 ASSERT_EQ(kUniqueId, id); | 42 ASSERT_EQ(kUniqueId, id); |
| 37 ASSERT_EQ(MediaStorageUtil::MTP_OR_PTP, type); | 43 ASSERT_EQ(MediaStorageUtil::MTP_OR_PTP, type); |
| 38 } | 44 } |
| 39 | 45 |
| 46 TEST_F(MediaStorageUtilTest, TestImageCaptureDeviceId) { | |
| 47 MediaStorageUtil::Type type; | |
| 48 std::string id; | |
| 49 EXPECT_TRUE(MediaStorageUtil::CrackDeviceId("ic:xyz", &type, &id)); | |
| 50 EXPECT_EQ(MediaStorageUtil::MAC_IMAGE_CAPTURE, type); | |
| 51 EXPECT_EQ("xyz", id); | |
| 52 } | |
| 53 | |
| 54 TEST_F(MediaStorageUtilTest, CanCreateFileSystemForImageCapture) { | |
| 55 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
| |
| 56 } | |
| 57 | |
| 58 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.
| |
| 59 event->Signal(); | |
| 60 } | |
| 61 | |
| 62 TEST_F(MediaStorageUtilTest, DetectDeviceFiltered) { | |
| 63 MessageLoop loop; | |
| 64 #if defined(OS_MACOSX) | |
| 65 // This needs to happen before SystemMonitor's ctor. | |
| 66 base::SystemMonitor::AllocateSystemIOPorts(); | |
| 67 #endif | |
| 68 // Installs global. Required MessageLoop. | |
| 69 // On Mac, requires AllocateSystemIOPorts. | |
| 70 base::SystemMonitor monitor; | |
| 71 | |
| 72 content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop); | |
| 73 | |
| 74 MediaStorageUtil::DeviceIdSet devices; | |
| 75 devices.insert("ic:xyz"); | |
| 76 | |
| 77 base::WaitableEvent event(true, false); | |
| 78 MediaStorageUtil::FilterAttachedDevices(&devices, | |
| 79 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.
| |
| 80 loop.RunUntilIdle(); | |
| 81 event.Wait(); | |
| 82 EXPECT_FALSE(devices.find("ic:xyz") != devices.end()); | |
| 83 | |
| 84 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | |
| 85 "ic:xyz", ASCIIToUTF16("name"), "/location"); | |
| 86 devices.insert("ic:xyz"); | |
| 87 event.Reset(); | |
| 88 MediaStorageUtil::FilterAttachedDevices(&devices, | |
| 89 base::Bind(&SignalEvent, &event)); | |
| 90 loop.RunUntilIdle(); | |
| 91 event.Wait(); | |
| 92 | |
| 93 EXPECT_TRUE(devices.find("ic:xyz") != devices.end()); | |
| 94 } | |
| 95 | |
| 40 } // namespace chrome | 96 } // namespace chrome |
| OLD | NEW |