OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/media/midi_host.h" | 5 #include "content/browser/media/midi_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 port_index(in_port_index), | 64 port_index(in_port_index), |
65 data(in_data), | 65 data(in_data), |
66 timestamp(in_timestamp) {} | 66 timestamp(in_timestamp) {} |
67 | 67 |
68 MidiEventType type; | 68 MidiEventType type; |
69 uint32_t port_index; | 69 uint32_t port_index; |
70 std::vector<uint8_t> data; | 70 std::vector<uint8_t> data; |
71 double timestamp; | 71 double timestamp; |
72 }; | 72 }; |
73 | 73 |
74 class FakeMidiManager : public media::midi::MidiManager { | 74 class FakeMidiManager : public midi::MidiManager { |
75 public: | 75 public: |
76 void DispatchSendMidiData(media::midi::MidiManagerClient* client, | 76 void DispatchSendMidiData(midi::MidiManagerClient* client, |
77 uint32_t port_index, | 77 uint32_t port_index, |
78 const std::vector<uint8_t>& data, | 78 const std::vector<uint8_t>& data, |
79 double timestamp) override { | 79 double timestamp) override { |
80 events_.push_back(MidiEvent(DISPATCH_SEND_MIDI_DATA, | 80 events_.push_back(MidiEvent(DISPATCH_SEND_MIDI_DATA, |
81 port_index, | 81 port_index, |
82 data, | 82 data, |
83 timestamp)); | 83 timestamp)); |
84 } | 84 } |
85 std::vector<MidiEvent> events_; | 85 std::vector<MidiEvent> events_; |
86 }; | 86 }; |
87 | 87 |
88 class MidiHostForTesting : public MidiHost { | 88 class MidiHostForTesting : public MidiHost { |
89 public: | 89 public: |
90 MidiHostForTesting(int renderer_process_id, | 90 MidiHostForTesting(int renderer_process_id, |
91 media::midi::MidiManager* midi_manager) | 91 midi::MidiManager* midi_manager) |
92 : MidiHost(renderer_process_id, midi_manager) {} | 92 : MidiHost(renderer_process_id, midi_manager) {} |
93 | 93 |
94 private: | 94 private: |
95 ~MidiHostForTesting() override {} | 95 ~MidiHostForTesting() override {} |
96 | 96 |
97 // BrowserMessageFilter implementation. | 97 // BrowserMessageFilter implementation. |
98 // Override ShutdownForBadMessage() to do nothing since the original | 98 // Override ShutdownForBadMessage() to do nothing since the original |
99 // implementation to kill a malicious renderer process causes a check failure | 99 // implementation to kill a malicious renderer process causes a check failure |
100 // in unit tests. | 100 // in unit tests. |
101 void ShutdownForBadMessage() override {} | 101 void ShutdownForBadMessage() override {} |
(...skipping 10 matching lines...) Expand all Loading... |
112 manager_.Shutdown(); | 112 manager_.Shutdown(); |
113 RunLoopUntilIdle(); | 113 RunLoopUntilIdle(); |
114 } | 114 } |
115 | 115 |
116 protected: | 116 protected: |
117 void AddOutputPort() { | 117 void AddOutputPort() { |
118 const std::string id = base::StringPrintf("i-can-%d", port_id_++); | 118 const std::string id = base::StringPrintf("i-can-%d", port_id_++); |
119 const std::string manufacturer("yukatan"); | 119 const std::string manufacturer("yukatan"); |
120 const std::string name("doki-doki-pi-pine"); | 120 const std::string name("doki-doki-pi-pine"); |
121 const std::string version("3.14159265359"); | 121 const std::string version("3.14159265359"); |
122 media::midi::MidiPortState state = media::midi::MIDI_PORT_CONNECTED; | 122 midi::MidiPortState state = midi::MIDI_PORT_CONNECTED; |
123 media::midi::MidiPortInfo info(id, manufacturer, name, version, state); | 123 midi::MidiPortInfo info(id, manufacturer, name, version, state); |
124 | 124 |
125 host_->AddOutputPort(info); | 125 host_->AddOutputPort(info); |
126 } | 126 } |
127 | 127 |
128 void OnSendData(uint32_t port) { | 128 void OnSendData(uint32_t port) { |
129 std::unique_ptr<IPC::Message> message( | 129 std::unique_ptr<IPC::Message> message( |
130 new MidiHostMsg_SendData(port, data_, 0.0)); | 130 new MidiHostMsg_SendData(port, data_, 0.0)); |
131 host_->OnMessageReceived(*message.get()); | 131 host_->OnMessageReceived(*message.get()); |
132 } | 132 } |
133 | 133 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Sending data to port 0 and 1 should be delivered now. | 232 // Sending data to port 0 and 1 should be delivered now. |
233 OnSendData(port0); | 233 OnSendData(port0); |
234 OnSendData(port1); | 234 OnSendData(port1); |
235 RunLoopUntilIdle(); | 235 RunLoopUntilIdle(); |
236 EXPECT_EQ(3U, GetEventSize()); | 236 EXPECT_EQ(3U, GetEventSize()); |
237 CheckSendEventAt(1, port0); | 237 CheckSendEventAt(1, port0); |
238 CheckSendEventAt(2, port1); | 238 CheckSendEventAt(2, port1); |
239 } | 239 } |
240 | 240 |
241 } // namespace conent | 241 } // namespace conent |
OLD | NEW |