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

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

Issue 1060553003: Web MIDI: call AccumulateMidiBytesSent() after operation finished (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review 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/midi_scheduler.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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 Initialize(); 313 Initialize();
314 ScopedVector<UsbMidiDevice> devices; 314 ScopedVector<UsbMidiDevice> devices;
315 devices.push_back(device.release()); 315 devices.push_back(device.release());
316 EXPECT_FALSE(IsInitializationCallbackInvoked()); 316 EXPECT_FALSE(IsInitializationCallbackInvoked());
317 RunCallbackUntilCallbackInvoked(true, &devices); 317 RunCallbackUntilCallbackInvoked(true, &devices);
318 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); 318 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
319 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 319 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
320 } 320 }
321 321
322 TEST_F(MidiManagerUsbTest, Send) { 322 TEST_F(MidiManagerUsbTest, Send) {
323 Initialize();
323 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 324 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
324 FakeMidiManagerClient client(&logger_);
325 uint8 descriptor[] = { 325 uint8 descriptor[] = {
326 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 326 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
327 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 327 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
328 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 328 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
329 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 329 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
330 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 330 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
331 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 331 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
332 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 332 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
333 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 333 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
334 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 334 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
335 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 335 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
336 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 336 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
337 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 337 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
338 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 338 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
339 0x05, 0x25, 0x01, 0x01, 0x07, 339 0x05, 0x25, 0x01, 0x01, 0x07,
340 }; 340 };
341 341
342 device->SetDescriptor(ToVector(descriptor)); 342 device->SetDescriptor(ToVector(descriptor));
343 uint8 data[] = { 343 uint8 data[] = {
344 0x90, 0x45, 0x7f, 344 0x90, 0x45, 0x7f,
345 0xf0, 0x00, 0x01, 0xf7, 345 0xf0, 0x00, 0x01, 0xf7,
346 }; 346 };
347 347
348 Initialize();
349 ScopedVector<UsbMidiDevice> devices; 348 ScopedVector<UsbMidiDevice> devices;
350 devices.push_back(device.release()); 349 devices.push_back(device.release());
351 EXPECT_FALSE(IsInitializationCallbackInvoked()); 350 EXPECT_FALSE(IsInitializationCallbackInvoked());
352 RunCallbackUntilCallbackInvoked(true, &devices); 351 RunCallbackUntilCallbackInvoked(true, &devices);
353 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 352 EXPECT_EQ(MIDI_OK, GetInitializationResult());
354 ASSERT_EQ(2u, manager_->output_streams().size()); 353 ASSERT_EQ(2u, manager_->output_streams().size());
355 354
356 manager_->DispatchSendMidiData(&client, 1, ToVector(data), 0); 355 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0);
357 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to 356 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to
358 // invoke the task. 357 // invoke the task.
359 // TODO(crbug.com/467442): AccumulateMidiBytesSent is recorded before
360 // UsbMidiDevice is invoked for now, but this should be after the invocation.
361 base::RunLoop run_loop; 358 base::RunLoop run_loop;
362 run_loop.RunUntilIdle(); 359 run_loop.RunUntilIdle();
363 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n" 360 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n"
364 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n"
365 "UsbMidiDevice::Send endpoint = 2 data = " 361 "UsbMidiDevice::Send endpoint = 2 data = "
366 "0x19 0x90 0x45 0x7f " 362 "0x19 0x90 0x45 0x7f "
367 "0x14 0xf0 0x00 0x01 " 363 "0x14 0xf0 0x00 0x01 "
368 "0x15 0xf7 0x00 0x00\n", 364 "0x15 0xf7 0x00 0x00\n"
365 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n",
369 logger_.TakeLog()); 366 logger_.TakeLog());
370 } 367 }
371 368
372 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) { 369 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
373 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 370 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
374 FakeMidiManagerClient client(&logger_);
375 uint8 descriptor[] = { 371 uint8 descriptor[] = {
376 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 372 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
377 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 373 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
378 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 374 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
379 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 375 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
380 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 376 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
381 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 377 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
382 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 378 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
383 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 379 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
384 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 380 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
(...skipping 13 matching lines...) Expand all
398 Initialize(); 394 Initialize();
399 ScopedVector<UsbMidiDevice> devices; 395 ScopedVector<UsbMidiDevice> devices;
400 devices.push_back(device.release()); 396 devices.push_back(device.release());
401 EXPECT_FALSE(IsInitializationCallbackInvoked()); 397 EXPECT_FALSE(IsInitializationCallbackInvoked());
402 RunCallbackUntilCallbackInvoked(true, &devices); 398 RunCallbackUntilCallbackInvoked(true, &devices);
403 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 399 EXPECT_EQ(MIDI_OK, GetInitializationResult());
404 ASSERT_EQ(2u, manager_->output_streams().size()); 400 ASSERT_EQ(2u, manager_->output_streams().size());
405 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 401 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
406 402
407 // The specified port index is invalid. The manager must ignore the request. 403 // The specified port index is invalid. The manager must ignore the request.
408 manager_->DispatchSendMidiData(&client, 99, ToVector(data), 0); 404 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0);
409 EXPECT_EQ("", logger_.TakeLog()); 405 EXPECT_EQ("", logger_.TakeLog());
410 406
411 // The specified port index is invalid. The manager must ignore the request. 407 // The specified port index is invalid. The manager must ignore the request.
412 manager_->DispatchSendMidiData(&client, 2, ToVector(data), 0); 408 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0);
413 EXPECT_EQ("", logger_.TakeLog()); 409 EXPECT_EQ("", logger_.TakeLog());
414 } 410 }
415 411
416 TEST_F(MidiManagerUsbTest, Receive) { 412 TEST_F(MidiManagerUsbTest, Receive) {
417 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 413 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
418 uint8 descriptor[] = { 414 uint8 descriptor[] = {
419 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 415 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
420 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 416 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
421 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 417 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
422 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 418 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); 501 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id);
506 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); 502 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id);
507 ASSERT_EQ(1u, jacks.size()); 503 ASSERT_EQ(1u, jacks.size());
508 EXPECT_EQ(2, jacks[0].endpoint_number()); 504 EXPECT_EQ(2, jacks[0].endpoint_number());
509 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); 505 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
510 } 506 }
511 507
512 } // namespace 508 } // namespace
513 509
514 } // namespace media 510 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | media/midi/midi_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698