| OLD | NEW |
| 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 "components/test_runner/mock_web_midi_accessor.h" | 5 #include "components/test_runner/mock_web_midi_accessor.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "components/test_runner/test_interfaces.h" | 10 #include "components/test_runner/test_interfaces.h" |
| 11 #include "components/test_runner/test_runner.h" | 11 #include "components/test_runner/test_runner.h" |
| 12 #include "components/test_runner/web_task.h" | |
| 13 #include "components/test_runner/web_test_delegate.h" | 12 #include "components/test_runner/web_test_delegate.h" |
| 14 #include "components/test_runner/web_test_runner.h" | 13 #include "components/test_runner/web_test_runner.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "third_party/WebKit/public/platform/modules/webmidi/WebMIDIAccessorClie
nt.h" | 15 #include "third_party/WebKit/public/platform/modules/webmidi/WebMIDIAccessorClie
nt.h" |
| 17 | 16 |
| 18 namespace test_runner { | 17 namespace test_runner { |
| 19 | 18 |
| 20 MockWebMIDIAccessor::MockWebMIDIAccessor(blink::WebMIDIAccessorClient* client, | 19 MockWebMIDIAccessor::MockWebMIDIAccessor(blink::WebMIDIAccessorClient* client, |
| 21 TestInterfaces* interfaces) | 20 TestInterfaces* interfaces) |
| 22 : client_(client), interfaces_(interfaces), weak_factory_(this) {} | 21 : client_(client), interfaces_(interfaces), weak_factory_(this) {} |
| 23 | 22 |
| 24 MockWebMIDIAccessor::~MockWebMIDIAccessor() { | 23 MockWebMIDIAccessor::~MockWebMIDIAccessor() { |
| 25 } | 24 } |
| 26 | 25 |
| 27 void MockWebMIDIAccessor::startSession() { | 26 void MockWebMIDIAccessor::startSession() { |
| 28 // Add a mock input and output port. | 27 // Add a mock input and output port. |
| 29 blink::WebMIDIAccessorClient::MIDIPortState state = | 28 blink::WebMIDIAccessorClient::MIDIPortState state = |
| 30 blink::WebMIDIAccessorClient::MIDIPortStateConnected; | 29 blink::WebMIDIAccessorClient::MIDIPortStateConnected; |
| 31 client_->didAddInputPort("MockInputID", | 30 client_->didAddInputPort("MockInputID", |
| 32 "MockInputManufacturer", | 31 "MockInputManufacturer", |
| 33 "MockInputName", | 32 "MockInputName", |
| 34 "MockInputVersion", | 33 "MockInputVersion", |
| 35 state); | 34 state); |
| 36 client_->didAddOutputPort("MockOutputID", | 35 client_->didAddOutputPort("MockOutputID", |
| 37 "MockOutputManufacturer", | 36 "MockOutputManufacturer", |
| 38 "MockOutputName", | 37 "MockOutputName", |
| 39 "MockOutputVersion", | 38 "MockOutputVersion", |
| 40 state); | 39 state); |
| 41 interfaces_->GetDelegate()->PostTask(new WebCallbackTask(base::Bind( | 40 interfaces_->GetDelegate()->PostTask(base::Bind( |
| 42 &MockWebMIDIAccessor::ReportStartedSession, weak_factory_.GetWeakPtr(), | 41 &MockWebMIDIAccessor::ReportStartedSession, weak_factory_.GetWeakPtr(), |
| 43 interfaces_->GetTestRunner()->midiAccessorResult()))); | 42 interfaces_->GetTestRunner()->midiAccessorResult())); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void MockWebMIDIAccessor::ReportStartedSession(bool success) { | 45 void MockWebMIDIAccessor::ReportStartedSession(bool success) { |
| 47 client_->didStartSession(success, "InvalidStateError", ""); | 46 client_->didStartSession(success, "InvalidStateError", ""); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void MockWebMIDIAccessor::sendMIDIData(unsigned port_index, | 49 void MockWebMIDIAccessor::sendMIDIData(unsigned port_index, |
| 51 const unsigned char* data, | 50 const unsigned char* data, |
| 52 size_t length, | 51 size_t length, |
| 53 double timestamp) { | 52 double timestamp) { |
| 54 // Emulate a loopback device for testing. | 53 // Emulate a loopback device for testing. |
| 55 client_->didReceiveMIDIData(port_index, data, length, timestamp); | 54 client_->didReceiveMIDIData(port_index, data, length, timestamp); |
| 56 } | 55 } |
| 57 | 56 |
| 58 } // namespace test_runner | 57 } // namespace test_runner |
| OLD | NEW |