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

Side by Side Diff: device/usb/usb_device_handle_unittest.cc

Issue 1847183002: Use interface associations to check function permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit and fixed Windows build. Created 4 years, 8 months 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
« no previous file with comments | « device/usb/usb_device_handle_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 TestOpenCallback open_device; 126 TestOpenCallback open_device;
127 gadget->GetDevice()->Open(open_device.callback()); 127 gadget->GetDevice()->Open(open_device.callback());
128 scoped_refptr<UsbDeviceHandle> handle = open_device.WaitForResult(); 128 scoped_refptr<UsbDeviceHandle> handle = open_device.WaitForResult();
129 ASSERT_TRUE(handle.get()); 129 ASSERT_TRUE(handle.get());
130 130
131 TestResultCallback claim_interface; 131 TestResultCallback claim_interface;
132 handle->ClaimInterface(0, claim_interface.callback()); 132 handle->ClaimInterface(0, claim_interface.callback());
133 ASSERT_TRUE(claim_interface.WaitForResult()); 133 ASSERT_TRUE(claim_interface.WaitForResult());
134 134
135 const UsbInterfaceDescriptor* interface =
136 handle->FindInterfaceByEndpoint(0x81);
137 EXPECT_TRUE(interface);
138 EXPECT_EQ(0, interface->interface_number);
139 interface = handle->FindInterfaceByEndpoint(0x01);
140 EXPECT_TRUE(interface);
141 EXPECT_EQ(0, interface->interface_number);
142 EXPECT_FALSE(handle->FindInterfaceByEndpoint(0x82));
143 EXPECT_FALSE(handle->FindInterfaceByEndpoint(0x02));
144
135 scoped_refptr<net::IOBufferWithSize> in_buffer(new net::IOBufferWithSize(64)); 145 scoped_refptr<net::IOBufferWithSize> in_buffer(new net::IOBufferWithSize(64));
136 TestCompletionCallback in_completion; 146 TestCompletionCallback in_completion;
137 handle->GenericTransfer(USB_DIRECTION_INBOUND, 0x81, in_buffer.get(), 147 handle->GenericTransfer(USB_DIRECTION_INBOUND, 0x81, in_buffer.get(),
138 in_buffer->size(), 148 in_buffer->size(),
139 5000, // 5 second timeout 149 5000, // 5 second timeout
140 in_completion.callback()); 150 in_completion.callback());
141 151
142 scoped_refptr<net::IOBufferWithSize> out_buffer( 152 scoped_refptr<net::IOBufferWithSize> out_buffer(
143 new net::IOBufferWithSize(in_buffer->size())); 153 new net::IOBufferWithSize(in_buffer->size()));
144 TestCompletionCallback out_completion; 154 TestCompletionCallback out_completion;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 193
184 TestOpenCallback open_device; 194 TestOpenCallback open_device;
185 gadget->GetDevice()->Open(open_device.callback()); 195 gadget->GetDevice()->Open(open_device.callback());
186 scoped_refptr<UsbDeviceHandle> handle = open_device.WaitForResult(); 196 scoped_refptr<UsbDeviceHandle> handle = open_device.WaitForResult();
187 ASSERT_TRUE(handle.get()); 197 ASSERT_TRUE(handle.get());
188 198
189 TestResultCallback claim_interface; 199 TestResultCallback claim_interface;
190 handle->ClaimInterface(1, claim_interface.callback()); 200 handle->ClaimInterface(1, claim_interface.callback());
191 ASSERT_TRUE(claim_interface.WaitForResult()); 201 ASSERT_TRUE(claim_interface.WaitForResult());
192 202
203 EXPECT_FALSE(handle->FindInterfaceByEndpoint(0x81));
204 EXPECT_FALSE(handle->FindInterfaceByEndpoint(0x01));
205 const UsbInterfaceDescriptor* interface =
206 handle->FindInterfaceByEndpoint(0x82);
207 EXPECT_TRUE(interface);
208 EXPECT_EQ(1, interface->interface_number);
209 interface = handle->FindInterfaceByEndpoint(0x02);
210 EXPECT_TRUE(interface);
211 EXPECT_EQ(1, interface->interface_number);
212
193 scoped_refptr<net::IOBufferWithSize> in_buffer( 213 scoped_refptr<net::IOBufferWithSize> in_buffer(
194 new net::IOBufferWithSize(512)); 214 new net::IOBufferWithSize(512));
195 TestCompletionCallback in_completion; 215 TestCompletionCallback in_completion;
196 handle->GenericTransfer(USB_DIRECTION_INBOUND, 0x82, in_buffer.get(), 216 handle->GenericTransfer(USB_DIRECTION_INBOUND, 0x82, in_buffer.get(),
197 in_buffer->size(), 217 in_buffer->size(),
198 5000, // 5 second timeout 218 5000, // 5 second timeout
199 in_completion.callback()); 219 in_completion.callback());
200 220
201 scoped_refptr<net::IOBufferWithSize> out_buffer( 221 scoped_refptr<net::IOBufferWithSize> out_buffer(
202 new net::IOBufferWithSize(in_buffer->size())); 222 new net::IOBufferWithSize(in_buffer->size()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 TestResultCallback release_interface; 276 TestResultCallback release_interface;
257 handle->ReleaseInterface(2, release_interface.callback()); 277 handle->ReleaseInterface(2, release_interface.callback());
258 ASSERT_TRUE(release_interface.WaitForResult()); 278 ASSERT_TRUE(release_interface.WaitForResult());
259 279
260 handle->Close(); 280 handle->Close();
261 } 281 }
262 282
263 } // namespace 283 } // namespace
264 284
265 } // namespace device 285 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_handle_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698