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

Side by Side Diff: chrome/browser/system_monitor/image_capture_device_browser_mac_unittest.mm

Issue 11442057: [Media Galleries] Add an ImageCaptureCore listener for Mac. (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test for ImageCaptureCameraInterface 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/system_monitor/image_capture_device_browser_mac.h"
6
7 #import <ImageCaptureCore/ImageCaptureCore.h>
sail 2012/12/17 03:16:03 newline after system includes
Greg Billock 2012/12/17 23:20:41 Done.
8 #include "base/file_path.h"
9 #include "base/mac/foundation_util.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop.h"
12 #include "base/system_monitor/system_monitor.h"
13 #include "chrome/browser/system_monitor/image_capture_camera.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 @interface MockICCameraDevice : ICCameraDevice {
17 }
18
19 @end
20
21 @implementation MockICCameraDevice
22
23 - (NSString*)mountPoint {
24 return @"mountPoint";
25 }
26
27 - (NSString*)name {
28 return @"name";
29 }
30
31 - (NSString*)UUIDString {
32 return @"id";
sail 2012/12/17 03:16:03 make this a constant above in an anonymous namespa
Greg Billock 2012/12/17 23:20:41 Done.
33 }
34
35 - (ICDeviceType)type {
36 return ICDeviceTypeCamera;
37 }
38
39 - (void)requestOpenSession {
40 }
41
42 - (void)requestCloseSession {
43 }
44
45 @end
46
47 @interface MockICCameraFile : ICCameraFile {
48 @private
sail 2012/12/17 03:16:03 space
Greg Billock 2012/12/17 23:20:41 Done.
49 scoped_nsobject<NSString> name_;
50 scoped_nsobject<NSDate> date_;
51 }
52
53 - (id)init:(NSString*)name;
54
55 @end
56
57 @implementation MockICCameraFile
58
59 - (id)init:(NSString*)name {
60 if ((self = [super init])) {
61 name_.reset(name);
62 date_.reset([[NSDate dateWithNaturalLanguageString:@"12/12/12"] retain]);
63 }
64 return self;
65 }
66
67 - (NSString*)name {
68 return name_.get();
69 }
70
71 - (NSString*)UTI {
72 return base::mac::CFToNSCast(kUTTypeImage);
73 }
74
75 - (NSDate*)modificationDate {
76 return date_.get();
77 }
78
79 - (NSDate*)creationDate {
80 return date_.get();
81 }
82
83 - (off_t)fileSize {
84 return 1000;
85 }
86
87 @end
88
89 class TestCameraListener
90 : public ImageCaptureDeviceListener,
91 public base::SupportsWeakPtr<TestCameraListener> {
92 public:
93 TestCameraListener() : completed_(false), removed_(false) {}
94 ~TestCameraListener() {}
sail 2012/12/17 03:16:03 virtual
Greg Billock 2012/12/17 23:20:41 Done.
95
96 virtual void ItemAdded(const std::string& name,
97 const base::PlatformFileInfo& info) OVERRIDE {
98 items_.push_back(name);
99 }
100
101 virtual void NoMoreItems() OVERRIDE {
102 completed_ = true;
103 }
104
105 virtual void DownloadedFile(const std::string& name,
106 base::PlatformFileError error) OVERRIDE {
107 downloads_.push_back(name);
108 }
109
110 virtual void DeviceRemoved() OVERRIDE {
111 removed_ = true;
112 }
113
114 std::vector<std::string> items_;
sail 2012/12/17 03:16:03 private and add accessors as needed
Greg Billock 2012/12/17 23:20:41 I think that just adds noise to test-only objects.
sail 2012/12/17 23:55:03 I've never seen a test do that. Only structs have
Greg Billock 2012/12/19 00:05:09 ok, sure. On 2012/12/17 23:55:03, sail wrote:
115 std::vector<std::string> downloads_;
116 bool completed_;
117 bool removed_;
118 };
119
120 class ImageCaptureDeviceBrowserTest : public testing::Test {
121 public:
122 virtual void SetUp() OVERRIDE {
123 base::SystemMonitor::AllocateSystemIOPorts();
124 system_monitor_.reset(new base::SystemMonitor());
125 }
126
127 void AttachDevice(chrome::ImageCaptureDeviceBrowser* browser) {
128 ICCameraDevice* device = [MockICCameraDevice alloc];
sail 2012/12/17 03:16:03 scoped_nsobject, [[MockICCameraDevice alloc] init]
Greg Billock 2012/12/17 23:20:41 Yes. Saw this looking through the test as well. O
129 NSObject<ICDeviceBrowserDelegate>* delegate =
130 base::mac::ObjCCastStrict<NSObject<ICDeviceBrowserDelegate> >(
131 browser->device_browser_.get());
sail 2012/12/17 03:16:03 change to use an accessor, same in DetachDevice
Greg Billock 2012/12/17 23:20:41 Done.
132 [delegate deviceBrowser:nil didAddDevice:device moreComing:NO];
133 }
134
135 void DetachDevice(chrome::ImageCaptureDeviceBrowser* browser) {
136 ICCameraDevice* device = [MockICCameraDevice alloc];
137 NSObject<ICDeviceBrowserDelegate>* delegate =
138 base::mac::ObjCCastStrict<NSObject<ICDeviceBrowserDelegate> >(
139 browser->device_browser_.get());
140 [delegate deviceBrowser:nil didRemoveDevice:device moreGoing:NO];
141 }
142
143 MessageLoop message_loop_;
sail 2012/12/17 03:16:03 protected
Greg Billock 2012/12/17 23:20:41 Done.
144 scoped_ptr<base::SystemMonitor> system_monitor_;
145 TestCameraListener listener_;
146 };
147
148 TEST_F(ImageCaptureDeviceBrowserTest, TestAttachDetach) {
149 chrome::ImageCaptureDeviceBrowser browser;
150 AttachDevice(&browser);
151
152 std::vector<base::SystemMonitor::RemovableStorageInfo> devices =
153 system_monitor_->GetAttachedRemovableStorage();
154
155 ASSERT_EQ(1U, devices.size());
156 EXPECT_EQ("ic:id", devices[0].device_id);
sail 2012/12/17 03:16:03 use a constant for "id"?
Greg Billock 2012/12/17 23:20:41 Done.
157
158 DetachDevice(&browser);
159 devices = system_monitor_->GetAttachedRemovableStorage();
160 ASSERT_EQ(0U, devices.size());
161 };
162
163 TEST_F(ImageCaptureDeviceBrowserTest, OpenCamera) {
164 chrome::ImageCaptureDeviceBrowser browser;
165 AttachDevice(&browser);
166
167 EXPECT_FALSE(chrome::ImageCaptureDeviceBrowser::cameraInterfaceForUUID(
168 "nonexistent"));
169
170 scoped_nsobject<ImageCaptureCameraInterface> camera(
171 [chrome::ImageCaptureDeviceBrowser::cameraInterfaceForUUID("id") retain]);
sail 2012/12/17 03:16:03 use a constant for "id"?
Greg Billock 2012/12/17 23:20:41 Done.
172
173 [camera open];
174 [camera setListener:listener_.AsWeakPtr()];
175
176 scoped_nsobject<MockICCameraFile> picture1(
177 [[MockICCameraFile alloc] init:@"pic1"]);
178 [camera cameraDevice:nil didAddItem:picture1];
179 scoped_nsobject<MockICCameraFile> picture2(
180 [[MockICCameraFile alloc] init:@"pic2"]);
181 [camera cameraDevice:nil didAddItem:picture2];
182 ASSERT_EQ(2U, listener_.items_.size());
183 EXPECT_EQ("pic1", listener_.items_[0]);
184 EXPECT_EQ("pic2", listener_.items_[1]);
185 EXPECT_FALSE(listener_.completed_);
186
187 [camera deviceDidBecomeReadyWithCompleteContentCatalog:nil];
188 ASSERT_EQ(2U, listener_.items_.size());
189 EXPECT_TRUE(listener_.completed_);
190
191 [camera close];
sail 2012/12/17 03:16:03 add a test for DidRemoveDevice? test that removing
Greg Billock 2012/12/17 23:20:41 Added. I still need a couple more tests for the ca
sail 2012/12/17 23:55:03 I think now would be better.
Greg Billock 2012/12/19 00:05:09 Added. This was pretty low impact. Getting the dow
192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698