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