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"; |
23 const char kImageCaptureDeviceId[] = "ic:xyz"; | |
17 | 24 |
18 } // namespace | 25 } // namespace |
19 | 26 |
20 typedef testing::Test MediaStorageUtilTest; | 27 typedef testing::Test MediaStorageUtilTest; |
21 | 28 |
22 // Test to verify |MediaStorageUtil::MakeDeviceId| functionality using a sample | 29 // Test to verify |MediaStorageUtil::MakeDeviceId| functionality using a sample |
23 // mtp device unique id. | 30 // mtp device unique id. |
24 TEST_F(MediaStorageUtilTest, MakeMtpDeviceId) { | 31 TEST_F(MediaStorageUtilTest, MakeMtpDeviceId) { |
25 std::string device_id = | 32 std::string device_id = |
26 MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, kUniqueId); | 33 MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, kUniqueId); |
27 ASSERT_EQ(kMtpDeviceId, device_id); | 34 ASSERT_EQ(kMtpDeviceId, device_id); |
28 } | 35 } |
29 | 36 |
30 // Test to verify |MediaStorageUtil::CrackDeviceId| functionality using a sample | 37 // Test to verify |MediaStorageUtil::CrackDeviceId| functionality using a sample |
31 // mtp device id. | 38 // mtp device id. |
32 TEST_F(MediaStorageUtilTest, CrackMtpDeviceId) { | 39 TEST_F(MediaStorageUtilTest, CrackMtpDeviceId) { |
33 MediaStorageUtil::Type type; | 40 MediaStorageUtil::Type type; |
34 std::string id; | 41 std::string id; |
35 ASSERT_TRUE(MediaStorageUtil::CrackDeviceId(kMtpDeviceId, &type, &id)); | 42 ASSERT_TRUE(MediaStorageUtil::CrackDeviceId(kMtpDeviceId, &type, &id)); |
36 ASSERT_EQ(kUniqueId, id); | 43 ASSERT_EQ(kUniqueId, id); |
37 ASSERT_EQ(MediaStorageUtil::MTP_OR_PTP, type); | 44 ASSERT_EQ(MediaStorageUtil::MTP_OR_PTP, type); |
38 } | 45 } |
39 | 46 |
47 TEST_F(MediaStorageUtilTest, TestImageCaptureDeviceId) { | |
48 MediaStorageUtil::Type type; | |
49 std::string id; | |
50 EXPECT_TRUE(MediaStorageUtil::CrackDeviceId(kImageCaptureDeviceId, | |
51 &type, &id)); | |
52 EXPECT_EQ(MediaStorageUtil::MAC_IMAGE_CAPTURE, type); | |
53 EXPECT_EQ("xyz", id); | |
54 } | |
55 | |
56 TEST_F(MediaStorageUtilTest, CanCreateFileSystemForImageCapture) { | |
57 EXPECT_TRUE(MediaStorageUtil::CanCreateFileSystem(kImageCaptureDeviceId, | |
58 FilePath())); | |
59 EXPECT_FALSE(MediaStorageUtil::CanCreateFileSystem("dcim:xyz", | |
60 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
| |
61 EXPECT_FALSE(MediaStorageUtil::CanCreateFileSystem("dcim:xyz", | |
62 FilePath("../refparent"))); | |
63 } | |
64 | |
65 TEST_F(MediaStorageUtilTest, DetectDeviceFiltered) { | |
66 MessageLoop loop; | |
67 #if defined(OS_MACOSX) | |
68 // This needs to happen before SystemMonitor's ctor. | |
69 base::SystemMonitor::AllocateSystemIOPorts(); | |
70 #endif | |
71 // Installs global. Required MessageLoop. | |
72 // On Mac, requires AllocateSystemIOPorts. | |
73 base::SystemMonitor monitor; | |
74 | |
75 content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop); | |
76 | |
77 MediaStorageUtil::DeviceIdSet devices; | |
78 devices.insert(kImageCaptureDeviceId); | |
79 | |
80 base::WaitableEvent event(true, false); | |
81 MediaStorageUtil::FilterAttachedDevices(&devices, | |
82 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | |
83 loop.RunUntilIdle(); | |
84 event.Wait(); | |
85 EXPECT_FALSE(devices.find(kImageCaptureDeviceId) != devices.end()); | |
86 | |
87 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | |
88 kImageCaptureDeviceId, ASCIIToUTF16("name"), | |
89 FILE_PATH_LITERAL("/location")); | |
90 devices.insert(kImageCaptureDeviceId); | |
91 event.Reset(); | |
92 MediaStorageUtil::FilterAttachedDevices(&devices, | |
93 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | |
94 loop.RunUntilIdle(); | |
95 event.Wait(); | |
96 | |
97 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); | |
98 } | |
99 | |
40 } // namespace chrome | 100 } // namespace chrome |
OLD | NEW |