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

Side by Side Diff: media/midi/midi_manager_usb_unittest.cc

Issue 1098913003: [WebMIDI] [Android] Set appropriate port properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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 | « media/midi/midi_manager_usb.cc ('k') | media/midi/usb_midi_descriptor_parser.h » ('j') | 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 "media/midi/midi_manager_usb.h" 5 #include "media/midi/midi_manager_usb.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 27 matching lines...) Expand all
38 std::string log_; 38 std::string log_;
39 39
40 DISALLOW_COPY_AND_ASSIGN(Logger); 40 DISALLOW_COPY_AND_ASSIGN(Logger);
41 }; 41 };
42 42
43 class FakeUsbMidiDevice : public UsbMidiDevice { 43 class FakeUsbMidiDevice : public UsbMidiDevice {
44 public: 44 public:
45 explicit FakeUsbMidiDevice(Logger* logger) : logger_(logger) {} 45 explicit FakeUsbMidiDevice(Logger* logger) : logger_(logger) {}
46 ~FakeUsbMidiDevice() override {} 46 ~FakeUsbMidiDevice() override {}
47 47
48 std::vector<uint8> GetDescriptor() override { 48 std::vector<uint8> GetDescriptors() override {
49 logger_->AddLog("UsbMidiDevice::GetDescriptor\n"); 49 logger_->AddLog("UsbMidiDevice::GetDescriptors\n");
50 return descriptor_; 50 return descriptors_;
51 } 51 }
52 52
53 std::string GetManufacturer() override { return manufacturer_; }
54 std::string GetProductName() override { return product_name_; }
55 std::string GetDeviceVersion() override { return device_version_; }
56
53 void Send(int endpoint_number, const std::vector<uint8>& data) override { 57 void Send(int endpoint_number, const std::vector<uint8>& data) override {
54 logger_->AddLog("UsbMidiDevice::Send "); 58 logger_->AddLog("UsbMidiDevice::Send ");
55 logger_->AddLog(base::StringPrintf("endpoint = %d data =", 59 logger_->AddLog(base::StringPrintf("endpoint = %d data =",
56 endpoint_number)); 60 endpoint_number));
57 for (size_t i = 0; i < data.size(); ++i) 61 for (size_t i = 0; i < data.size(); ++i)
58 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); 62 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i]));
59 logger_->AddLog("\n"); 63 logger_->AddLog("\n");
60 } 64 }
61 65
62 void SetDescriptor(const std::vector<uint8> descriptor) { 66 void SetDescriptors(const std::vector<uint8> descriptors) {
63 descriptor_ = descriptor; 67 descriptors_ = descriptors;
68 }
69 void SetManufacturer(const std::string& manufacturer) {
70 manufacturer_ = manufacturer;
71 }
72 void SetProductName(const std::string& product_name) {
73 product_name_ = product_name;
74 }
75 void SetDeviceVersion(const std::string& device_version) {
76 device_version_ = device_version;
64 } 77 }
65 78
66 private: 79 private:
67 std::vector<uint8> descriptor_; 80 std::vector<uint8> descriptors_;
81 std::string manufacturer_;
82 std::string product_name_;
83 std::string device_version_;
68 Logger* logger_; 84 Logger* logger_;
69 85
70 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice); 86 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice);
71 }; 87 };
72 88
73 class FakeMidiManagerClient : public MidiManagerClient { 89 class FakeMidiManagerClient : public MidiManagerClient {
74 public: 90 public:
75 explicit FakeMidiManagerClient(Logger* logger) 91 explicit FakeMidiManagerClient(Logger* logger)
76 : complete_start_session_(false), 92 : complete_start_session_(false),
77 result_(MIDI_NOT_SUPPORTED), 93 result_(MIDI_NOT_SUPPORTED),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 224
209 private: 225 private:
210 scoped_ptr<base::MessageLoop> message_loop_; 226 scoped_ptr<base::MessageLoop> message_loop_;
211 227
212 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbTest); 228 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbTest);
213 }; 229 };
214 230
215 231
216 TEST_F(MidiManagerUsbTest, Initialize) { 232 TEST_F(MidiManagerUsbTest, Initialize) {
217 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 233 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
218 uint8 descriptor[] = { 234 uint8 descriptors[] = {
219 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 235 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
220 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 236 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
221 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 237 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
222 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 238 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
223 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 239 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
224 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 240 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
225 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 241 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
226 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 242 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
227 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 243 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
228 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 244 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
229 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 245 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
230 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 246 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
231 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 247 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
232 0x05, 0x25, 0x01, 0x01, 0x07, 248 0x05, 0x25, 0x01, 0x01, 0x07,
233 }; 249 };
234 device->SetDescriptor(ToVector(descriptor)); 250 device->SetDescriptors(ToVector(descriptors));
251 device->SetManufacturer("vendor1");
252 device->SetProductName("device1");
253 device->SetDeviceVersion("1.02");
235 254
236 Initialize(); 255 Initialize();
237 ScopedVector<UsbMidiDevice> devices; 256 ScopedVector<UsbMidiDevice> devices;
238 devices.push_back(device.release()); 257 devices.push_back(device.release());
239 EXPECT_FALSE(IsInitializationCallbackInvoked()); 258 EXPECT_FALSE(IsInitializationCallbackInvoked());
240 RunCallbackUntilCallbackInvoked(true, &devices); 259 RunCallbackUntilCallbackInvoked(true, &devices);
241 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 260 EXPECT_EQ(MIDI_OK, GetInitializationResult());
242 261
243 ASSERT_EQ(1u, input_ports().size()); 262 ASSERT_EQ(1u, input_ports().size());
263 EXPECT_EQ("port-0-2", input_ports()[0].id);
264 EXPECT_EQ("vendor1", input_ports()[0].manufacturer);
265 EXPECT_EQ("device1", input_ports()[0].name);
266 EXPECT_EQ("1.02", input_ports()[0].version);
267
244 ASSERT_EQ(2u, output_ports().size()); 268 ASSERT_EQ(2u, output_ports().size());
269 EXPECT_EQ("port-0-0", output_ports()[0].id);
270 EXPECT_EQ("vendor1", output_ports()[0].manufacturer);
271 EXPECT_EQ("device1", output_ports()[0].name);
272 EXPECT_EQ("1.02", output_ports()[0].version);
273 EXPECT_EQ("port-0-1", output_ports()[1].id);
274 EXPECT_EQ("vendor1", output_ports()[1].manufacturer);
275 EXPECT_EQ("device1", output_ports()[1].name);
276 EXPECT_EQ("1.02", output_ports()[1].version);
277
245 ASSERT_TRUE(manager_->input_stream()); 278 ASSERT_TRUE(manager_->input_stream());
246 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks(); 279 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks();
247 ASSERT_EQ(2u, manager_->output_streams().size()); 280 ASSERT_EQ(2u, manager_->output_streams().size());
248 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); 281 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id);
249 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); 282 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id);
250 ASSERT_EQ(1u, jacks.size()); 283 ASSERT_EQ(1u, jacks.size());
251 EXPECT_EQ(2, jacks[0].endpoint_number()); 284 EXPECT_EQ(2, jacks[0].endpoint_number());
252 285
253 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 286 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
254 } 287 }
255 288
256 TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) { 289 TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) {
257 scoped_ptr<FakeUsbMidiDevice> device1(new FakeUsbMidiDevice(&logger_)); 290 scoped_ptr<FakeUsbMidiDevice> device1(new FakeUsbMidiDevice(&logger_));
258 scoped_ptr<FakeUsbMidiDevice> device2(new FakeUsbMidiDevice(&logger_)); 291 scoped_ptr<FakeUsbMidiDevice> device2(new FakeUsbMidiDevice(&logger_));
259 uint8 descriptor[] = { 292 uint8 descriptors[] = {
260 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, 293 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75,
261 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, 294 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01,
262 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 295 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
263 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 296 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01,
264 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 297 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
265 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, 298 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03,
266 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, 299 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07,
267 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 300 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01,
268 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 301 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05,
269 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 302 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
270 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, 303 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25,
271 0x01, 0x01, 0x07, 304 0x01, 0x01, 0x07,
272 }; 305 };
273 device1->SetDescriptor(ToVector(descriptor)); 306 device1->SetDescriptors(ToVector(descriptors));
274 device2->SetDescriptor(ToVector(descriptor)); 307 device1->SetManufacturer("vendor1");
308 device1->SetProductName("device1");
309 device1->SetDeviceVersion("1.02");
310 device2->SetDescriptors(ToVector(descriptors));
311 device2->SetManufacturer("vendor2");
312 device2->SetProductName("device2");
313 device2->SetDeviceVersion("98.76");
275 314
276 Initialize(); 315 Initialize();
277 ScopedVector<UsbMidiDevice> devices; 316 ScopedVector<UsbMidiDevice> devices;
278 devices.push_back(device1.release()); 317 devices.push_back(device1.release());
279 devices.push_back(device2.release()); 318 devices.push_back(device2.release());
280 EXPECT_FALSE(IsInitializationCallbackInvoked()); 319 EXPECT_FALSE(IsInitializationCallbackInvoked());
281 RunCallbackUntilCallbackInvoked(true, &devices); 320 RunCallbackUntilCallbackInvoked(true, &devices);
282 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 321 EXPECT_EQ(MIDI_OK, GetInitializationResult());
283 322
284 ASSERT_EQ(2u, input_ports().size()); 323 ASSERT_EQ(2u, input_ports().size());
324 EXPECT_EQ("port-0-2", input_ports()[0].id);
325 EXPECT_EQ("vendor1", input_ports()[0].manufacturer);
326 EXPECT_EQ("device1", input_ports()[0].name);
327 EXPECT_EQ("1.02", input_ports()[0].version);
328 EXPECT_EQ("port-1-2", input_ports()[1].id);
329 EXPECT_EQ("vendor2", input_ports()[1].manufacturer);
330 EXPECT_EQ("device2", input_ports()[1].name);
331 EXPECT_EQ("98.76", input_ports()[1].version);
332
285 ASSERT_EQ(4u, output_ports().size()); 333 ASSERT_EQ(4u, output_ports().size());
334 EXPECT_EQ("port-0-0", output_ports()[0].id);
335 EXPECT_EQ("vendor1", output_ports()[0].manufacturer);
336 EXPECT_EQ("device1", output_ports()[0].name);
337 EXPECT_EQ("1.02", output_ports()[0].version);
338 EXPECT_EQ("port-0-1", output_ports()[1].id);
339 EXPECT_EQ("vendor1", output_ports()[1].manufacturer);
340 EXPECT_EQ("device1", output_ports()[1].name);
341 EXPECT_EQ("1.02", output_ports()[1].version);
342 EXPECT_EQ("port-1-0", output_ports()[2].id);
343 EXPECT_EQ("vendor2", output_ports()[2].manufacturer);
344 EXPECT_EQ("device2", output_ports()[2].name);
345 EXPECT_EQ("98.76", output_ports()[2].version);
346 EXPECT_EQ("port-1-1", output_ports()[3].id);
347 EXPECT_EQ("vendor2", output_ports()[3].manufacturer);
348 EXPECT_EQ("device2", output_ports()[3].name);
349 EXPECT_EQ("98.76", output_ports()[3].version);
350
286 ASSERT_TRUE(manager_->input_stream()); 351 ASSERT_TRUE(manager_->input_stream());
287 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks(); 352 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks();
288 ASSERT_EQ(4u, manager_->output_streams().size()); 353 ASSERT_EQ(4u, manager_->output_streams().size());
289 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); 354 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id);
290 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); 355 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id);
291 ASSERT_EQ(2u, jacks.size()); 356 ASSERT_EQ(2u, jacks.size());
292 EXPECT_EQ(2, jacks[0].endpoint_number()); 357 EXPECT_EQ(2, jacks[0].endpoint_number());
293 358
294 EXPECT_EQ( 359 EXPECT_EQ(
295 "UsbMidiDevice::GetDescriptor\n" 360 "UsbMidiDevice::GetDescriptors\n"
296 "UsbMidiDevice::GetDescriptor\n", 361 "UsbMidiDevice::GetDescriptors\n",
297 logger_.TakeLog()); 362 logger_.TakeLog());
298 } 363 }
299 364
300 TEST_F(MidiManagerUsbTest, InitializeFail) { 365 TEST_F(MidiManagerUsbTest, InitializeFail) {
301 Initialize(); 366 Initialize();
302 367
303 EXPECT_FALSE(IsInitializationCallbackInvoked()); 368 EXPECT_FALSE(IsInitializationCallbackInvoked());
304 RunCallbackUntilCallbackInvoked(false, NULL); 369 RunCallbackUntilCallbackInvoked(false, NULL);
305 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); 370 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
306 } 371 }
307 372
308 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptor) { 373 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) {
309 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 374 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
310 uint8 descriptor[] = {0x04}; 375 uint8 descriptors[] = {0x04};
311 device->SetDescriptor(ToVector(descriptor)); 376 device->SetDescriptors(ToVector(descriptors));
312 377
313 Initialize(); 378 Initialize();
314 ScopedVector<UsbMidiDevice> devices; 379 ScopedVector<UsbMidiDevice> devices;
315 devices.push_back(device.release()); 380 devices.push_back(device.release());
316 EXPECT_FALSE(IsInitializationCallbackInvoked()); 381 EXPECT_FALSE(IsInitializationCallbackInvoked());
317 RunCallbackUntilCallbackInvoked(true, &devices); 382 RunCallbackUntilCallbackInvoked(true, &devices);
318 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); 383 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
319 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 384 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
320 } 385 }
321 386
322 TEST_F(MidiManagerUsbTest, Send) { 387 TEST_F(MidiManagerUsbTest, Send) {
323 Initialize(); 388 Initialize();
324 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 389 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
325 uint8 descriptor[] = { 390 uint8 descriptors[] = {
326 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 391 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
327 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 392 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
328 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 393 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
329 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 394 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
330 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 395 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
331 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 396 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
332 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 397 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
333 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 398 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
334 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 399 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
335 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 400 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
336 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 401 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
337 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 402 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
338 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 403 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
339 0x05, 0x25, 0x01, 0x01, 0x07, 404 0x05, 0x25, 0x01, 0x01, 0x07,
340 }; 405 };
341 406
342 device->SetDescriptor(ToVector(descriptor)); 407 device->SetDescriptors(ToVector(descriptors));
343 uint8 data[] = { 408 uint8 data[] = {
344 0x90, 0x45, 0x7f, 409 0x90, 0x45, 0x7f,
345 0xf0, 0x00, 0x01, 0xf7, 410 0xf0, 0x00, 0x01, 0xf7,
346 }; 411 };
347 412
348 ScopedVector<UsbMidiDevice> devices; 413 ScopedVector<UsbMidiDevice> devices;
349 devices.push_back(device.release()); 414 devices.push_back(device.release());
350 EXPECT_FALSE(IsInitializationCallbackInvoked()); 415 EXPECT_FALSE(IsInitializationCallbackInvoked());
351 RunCallbackUntilCallbackInvoked(true, &devices); 416 RunCallbackUntilCallbackInvoked(true, &devices);
352 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 417 EXPECT_EQ(MIDI_OK, GetInitializationResult());
353 ASSERT_EQ(2u, manager_->output_streams().size()); 418 ASSERT_EQ(2u, manager_->output_streams().size());
354 419
355 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); 420 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0);
356 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to 421 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to
357 // invoke the task. 422 // invoke the task.
358 base::RunLoop run_loop; 423 base::RunLoop run_loop;
359 run_loop.RunUntilIdle(); 424 run_loop.RunUntilIdle();
360 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n" 425 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n"
361 "UsbMidiDevice::Send endpoint = 2 data = " 426 "UsbMidiDevice::Send endpoint = 2 data = "
362 "0x19 0x90 0x45 0x7f " 427 "0x19 0x90 0x45 0x7f "
363 "0x14 0xf0 0x00 0x01 " 428 "0x14 0xf0 0x00 0x01 "
364 "0x15 0xf7 0x00 0x00\n" 429 "0x15 0xf7 0x00 0x00\n"
365 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n", 430 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n",
366 logger_.TakeLog()); 431 logger_.TakeLog());
367 } 432 }
368 433
369 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) { 434 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
370 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 435 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
371 uint8 descriptor[] = { 436 uint8 descriptors[] = {
372 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 437 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
373 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 438 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
374 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 439 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
375 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 440 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
376 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 441 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
377 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 442 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
378 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 443 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
379 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 444 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
380 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 445 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
381 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 446 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
382 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 447 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
383 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 448 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
384 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 449 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
385 0x05, 0x25, 0x01, 0x01, 0x07, 450 0x05, 0x25, 0x01, 0x01, 0x07,
386 }; 451 };
387 452
388 device->SetDescriptor(ToVector(descriptor)); 453 device->SetDescriptors(ToVector(descriptors));
389 uint8 data[] = { 454 uint8 data[] = {
390 0x90, 0x45, 0x7f, 455 0x90, 0x45, 0x7f,
391 0xf0, 0x00, 0x01, 0xf7, 456 0xf0, 0x00, 0x01, 0xf7,
392 }; 457 };
393 458
394 Initialize(); 459 Initialize();
395 ScopedVector<UsbMidiDevice> devices; 460 ScopedVector<UsbMidiDevice> devices;
396 devices.push_back(device.release()); 461 devices.push_back(device.release());
397 EXPECT_FALSE(IsInitializationCallbackInvoked()); 462 EXPECT_FALSE(IsInitializationCallbackInvoked());
398 RunCallbackUntilCallbackInvoked(true, &devices); 463 RunCallbackUntilCallbackInvoked(true, &devices);
399 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 464 EXPECT_EQ(MIDI_OK, GetInitializationResult());
400 ASSERT_EQ(2u, manager_->output_streams().size()); 465 ASSERT_EQ(2u, manager_->output_streams().size());
401 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 466 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
402 467
403 // The specified port index is invalid. The manager must ignore the request. 468 // The specified port index is invalid. The manager must ignore the request.
404 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0); 469 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0);
405 EXPECT_EQ("", logger_.TakeLog()); 470 EXPECT_EQ("", logger_.TakeLog());
406 471
407 // The specified port index is invalid. The manager must ignore the request. 472 // The specified port index is invalid. The manager must ignore the request.
408 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0); 473 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0);
409 EXPECT_EQ("", logger_.TakeLog()); 474 EXPECT_EQ("", logger_.TakeLog());
410 } 475 }
411 476
412 TEST_F(MidiManagerUsbTest, Receive) { 477 TEST_F(MidiManagerUsbTest, Receive) {
413 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 478 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
414 uint8 descriptor[] = { 479 uint8 descriptors[] = {
415 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 480 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
416 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 481 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
417 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 482 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
418 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 483 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
419 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 484 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
420 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 485 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
421 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 486 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
422 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 487 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
423 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 488 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
424 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 489 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
425 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 490 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
426 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 491 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
427 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 492 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
428 0x05, 0x25, 0x01, 0x01, 0x07, 493 0x05, 0x25, 0x01, 0x01, 0x07,
429 }; 494 };
430 495
431 device->SetDescriptor(ToVector(descriptor)); 496 device->SetDescriptors(ToVector(descriptors));
432 uint8 data[] = { 497 uint8 data[] = {
433 0x09, 0x90, 0x45, 0x7f, 498 0x09, 0x90, 0x45, 0x7f,
434 0x04, 0xf0, 0x00, 0x01, 499 0x04, 0xf0, 0x00, 0x01,
435 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4). 500 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4).
436 0x05, 0xf7, 0x00, 0x00, 501 0x05, 0xf7, 0x00, 0x00,
437 }; 502 };
438 503
439 Initialize(); 504 Initialize();
440 ScopedVector<UsbMidiDevice> devices; 505 ScopedVector<UsbMidiDevice> devices;
441 UsbMidiDevice* device_raw = device.get(); 506 UsbMidiDevice* device_raw = device.get();
442 devices.push_back(device.release()); 507 devices.push_back(device.release());
443 EXPECT_FALSE(IsInitializationCallbackInvoked()); 508 EXPECT_FALSE(IsInitializationCallbackInvoked());
444 RunCallbackUntilCallbackInvoked(true, &devices); 509 RunCallbackUntilCallbackInvoked(true, &devices);
445 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 510 EXPECT_EQ(MIDI_OK, GetInitializationResult());
446 511
447 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), 512 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data),
448 base::TimeTicks()); 513 base::TimeTicks());
449 Finalize(); 514 Finalize();
450 515
451 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n" 516 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n"
452 "MidiManagerClient::ReceiveMidiData port_index = 0 " 517 "MidiManagerClient::ReceiveMidiData port_index = 0 "
453 "data = 0x90 0x45 0x7f\n" 518 "data = 0x90 0x45 0x7f\n"
454 "MidiManagerClient::ReceiveMidiData port_index = 0 " 519 "MidiManagerClient::ReceiveMidiData port_index = 0 "
455 "data = 0xf0 0x00 0x01\n" 520 "data = 0xf0 0x00 0x01\n"
456 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n", 521 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n",
457 logger_.TakeLog()); 522 logger_.TakeLog());
458 } 523 }
459 524
460 TEST_F(MidiManagerUsbTest, AttachDevice) { 525 TEST_F(MidiManagerUsbTest, AttachDevice) {
461 uint8 descriptor[] = { 526 uint8 descriptors[] = {
462 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 527 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
463 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 528 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
464 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 529 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
465 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 530 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
466 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 531 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
467 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 532 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
468 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 533 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
469 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 534 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
470 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 535 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
471 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 536 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
(...skipping 11 matching lines...) Expand all
483 548
484 ASSERT_EQ(0u, input_ports().size()); 549 ASSERT_EQ(0u, input_ports().size());
485 ASSERT_EQ(0u, output_ports().size()); 550 ASSERT_EQ(0u, output_ports().size());
486 ASSERT_TRUE(manager_->input_stream()); 551 ASSERT_TRUE(manager_->input_stream());
487 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks(); 552 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks();
488 ASSERT_EQ(0u, manager_->output_streams().size()); 553 ASSERT_EQ(0u, manager_->output_streams().size());
489 ASSERT_EQ(0u, jacks.size()); 554 ASSERT_EQ(0u, jacks.size());
490 EXPECT_EQ("", logger_.TakeLog()); 555 EXPECT_EQ("", logger_.TakeLog());
491 556
492 scoped_ptr<FakeUsbMidiDevice> new_device(new FakeUsbMidiDevice(&logger_)); 557 scoped_ptr<FakeUsbMidiDevice> new_device(new FakeUsbMidiDevice(&logger_));
493 new_device->SetDescriptor(ToVector(descriptor)); 558 new_device->SetDescriptors(ToVector(descriptors));
494 manager_->OnDeviceAttached(new_device.Pass()); 559 manager_->OnDeviceAttached(new_device.Pass());
495 560
496 ASSERT_EQ(1u, input_ports().size()); 561 ASSERT_EQ(1u, input_ports().size());
497 ASSERT_EQ(2u, output_ports().size()); 562 ASSERT_EQ(2u, output_ports().size());
498 ASSERT_TRUE(manager_->input_stream()); 563 ASSERT_TRUE(manager_->input_stream());
499 jacks = manager_->input_stream()->jacks(); 564 jacks = manager_->input_stream()->jacks();
500 ASSERT_EQ(2u, manager_->output_streams().size()); 565 ASSERT_EQ(2u, manager_->output_streams().size());
501 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); 566 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id);
502 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); 567 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id);
503 ASSERT_EQ(1u, jacks.size()); 568 ASSERT_EQ(1u, jacks.size());
504 EXPECT_EQ(2, jacks[0].endpoint_number()); 569 EXPECT_EQ(2, jacks[0].endpoint_number());
505 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 570 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
506 } 571 }
507 572
508 } // namespace 573 } // namespace
509 574
510 } // namespace media 575 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | media/midi/usb_midi_descriptor_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698