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
3 // found in the LICENSE file.
5 #include "components/test_runner/mock_web_midi_accessor.h"
7 #include "components/test_runner/test_interfaces.h"
8 #include "components/test_runner/test_runner.h"
9 #include "components/test_runner/web_test_delegate.h"
10 #include "components/test_runner/web_test_runner.h"
11 #include "third_party/WebKit/public/platform/WebMIDIAccessorClient.h"
13 namespace test_runner
{
17 class DidStartSessionTask
: public WebMethodTask
<MockWebMIDIAccessor
> {
19 DidStartSessionTask(MockWebMIDIAccessor
* object
,
20 blink::WebMIDIAccessorClient
* client
,
22 : WebMethodTask
<MockWebMIDIAccessor
>(object
),
26 void RunIfValid() override
{
27 client_
->didStartSession(result_
, "InvalidStateError", "");
31 blink::WebMIDIAccessorClient
* client_
;
34 DISALLOW_COPY_AND_ASSIGN(DidStartSessionTask
);
39 MockWebMIDIAccessor::MockWebMIDIAccessor(blink::WebMIDIAccessorClient
* client
,
40 TestInterfaces
* interfaces
)
41 : client_(client
), interfaces_(interfaces
) {
44 MockWebMIDIAccessor::~MockWebMIDIAccessor() {
47 void MockWebMIDIAccessor::startSession() {
48 // Add a mock input and output port.
49 blink::WebMIDIAccessorClient::MIDIPortState state
=
50 blink::WebMIDIAccessorClient::MIDIPortStateConnected
;
51 client_
->didAddInputPort("MockInputID",
52 "MockInputManufacturer",
56 client_
->didAddOutputPort("MockOutputID",
57 "MockOutputManufacturer",
61 interfaces_
->GetDelegate()->PostTask(new DidStartSessionTask(
62 this, client_
, interfaces_
->GetTestRunner()->midiAccessorResult()));
65 void MockWebMIDIAccessor::sendMIDIData(unsigned port_index
,
66 const unsigned char* data
,
69 // Emulate a loopback device for testing.
70 client_
->didReceiveMIDIData(port_index
, data
, length
, timestamp
);
73 } // namespace test_runner