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

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

Powered by Google App Engine
This is Rietveld 408576698