Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/system_monitor/media_storage_util_unittest.cc

Issue 11490010: [Media Galleries] Introduce a new type for Mac Image Capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix include Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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));
Lei Zhang 2012/12/10 23:21:53 nit: replace "ic:xyz" with a constant. It's used a
Greg Billock 2012/12/11 00:11:22 Done.
Greg Billock 2012/12/11 00:11:22 Done.
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()));
56 }
57
58 void SignalEvent(base::WaitableEvent* event) {
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));
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");
Lei Zhang 2012/12/10 23:21:53 |location| needs to be FILE_PATH_LITERAL("/locatio
Greg Billock 2012/12/11 00:11:22 Good catch. Done. On 2012/12/10 23:21:53, Lei Zhan
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698