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

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

Issue 907793002: MidiManagerUsb should not trust indices provided by renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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') | 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 "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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 manager_->DispatchSendMidiData(&client, 1, ToVector(data), 0); 309 manager_->DispatchSendMidiData(&client, 1, ToVector(data), 0);
310 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n" 310 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n"
311 "UsbMidiDevice::Send endpoint = 2 data = " 311 "UsbMidiDevice::Send endpoint = 2 data = "
312 "0x19 0x90 0x45 0x7f " 312 "0x19 0x90 0x45 0x7f "
313 "0x14 0xf0 0x00 0x01 " 313 "0x14 0xf0 0x00 0x01 "
314 "0x15 0xf7 0x00 0x00\n" 314 "0x15 0xf7 0x00 0x00\n"
315 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n", 315 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n",
316 logger_.TakeLog()); 316 logger_.TakeLog());
317 } 317 }
318 318
319 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
320 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
321 FakeMidiManagerClient client(&logger_);
322 uint8 descriptor[] = {
323 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
324 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
325 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
326 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
327 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
328 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
329 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
330 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
331 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
332 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
333 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
334 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
335 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
336 0x05, 0x25, 0x01, 0x01, 0x07,
337 };
338
339 device->SetDescriptor(ToVector(descriptor));
340 uint8 data[] = {
341 0x90, 0x45, 0x7f,
342 0xf0, 0x00, 0x01, 0xf7,
343 };
344
345 Initialize();
346 ScopedVector<UsbMidiDevice> devices;
347 devices.push_back(device.release());
348 EXPECT_FALSE(IsInitializationCallbackInvoked());
349 RunCallbackUntilCallbackInvoked(true, &devices);
350 EXPECT_EQ(MIDI_OK, GetInitializationResult());
351 ASSERT_EQ(2u, manager_->output_streams().size());
352 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
353
354 // The specified port index is invalid. The manager must ignore the request.
355 manager_->DispatchSendMidiData(&client, 99, ToVector(data), 0);
356 EXPECT_EQ("", logger_.TakeLog());
357
358 // The specified port index is invalid. The manager must ignore the request.
359 manager_->DispatchSendMidiData(&client, 2, ToVector(data), 0);
360 EXPECT_EQ("", logger_.TakeLog());
361 }
362
319 TEST_F(MidiManagerUsbTest, Receive) { 363 TEST_F(MidiManagerUsbTest, Receive) {
320 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 364 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
321 uint8 descriptor[] = { 365 uint8 descriptor[] = {
322 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 366 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
323 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 367 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
324 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 368 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
325 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 369 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
326 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 370 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
327 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 371 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
328 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 372 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 "data = 0x90 0x45 0x7f\n" 404 "data = 0x90 0x45 0x7f\n"
361 "MidiManagerClient::ReceiveMidiData port_index = 0 " 405 "MidiManagerClient::ReceiveMidiData port_index = 0 "
362 "data = 0xf0 0x00 0x01\n" 406 "data = 0xf0 0x00 0x01\n"
363 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n", 407 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n",
364 logger_.TakeLog()); 408 logger_.TakeLog());
365 } 409 }
366 410
367 } // namespace 411 } // namespace
368 412
369 } // namespace media 413 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698