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

Side by Side Diff: content/browser/media/midi_host_unittest.cc

Issue 1086073004: Web MIDI: namespace change from media to media::midi (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@null
Patch Set: (rebase) Created 5 years, 7 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 | « content/browser/media/midi_host.cc ('k') | content/common/media/midi_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/common/media/midi_messages.h" 10 #include "content/common/media/midi_messages.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 port_index(in_port_index), 60 port_index(in_port_index),
61 data(in_data), 61 data(in_data),
62 timestamp(in_timestamp) {} 62 timestamp(in_timestamp) {}
63 63
64 MidiEventType type; 64 MidiEventType type;
65 uint32 port_index; 65 uint32 port_index;
66 std::vector<uint8> data; 66 std::vector<uint8> data;
67 double timestamp; 67 double timestamp;
68 }; 68 };
69 69
70 class FakeMidiManager : public media::MidiManager { 70 class FakeMidiManager : public media::midi::MidiManager {
71 public: 71 public:
72 void DispatchSendMidiData(media::MidiManagerClient* client, 72 void DispatchSendMidiData(media::midi::MidiManagerClient* client,
73 uint32 port_index, 73 uint32 port_index,
74 const std::vector<uint8>& data, 74 const std::vector<uint8>& data,
75 double timestamp) override { 75 double timestamp) override {
76 events_.push_back(MidiEvent(DISPATCH_SEND_MIDI_DATA, 76 events_.push_back(MidiEvent(DISPATCH_SEND_MIDI_DATA,
77 port_index, 77 port_index,
78 data, 78 data,
79 timestamp)); 79 timestamp));
80 } 80 }
81 std::vector<MidiEvent> events_; 81 std::vector<MidiEvent> events_;
82 }; 82 };
83 83
84 class MidiHostForTesting : public MidiHost { 84 class MidiHostForTesting : public MidiHost {
85 public: 85 public:
86 MidiHostForTesting(int renderer_process_id, media::MidiManager* midi_manager) 86 MidiHostForTesting(int renderer_process_id,
87 : MidiHost(renderer_process_id, midi_manager) {} 87 media::midi::MidiManager* midi_manager)
88 : MidiHost(renderer_process_id, midi_manager) {}
88 89
89 private: 90 private:
90 ~MidiHostForTesting() override {} 91 ~MidiHostForTesting() override {}
91 92
92 // BrowserMessageFilter implementation. 93 // BrowserMessageFilter implementation.
93 // Override BadMessageReceived() so to do nothing since the original 94 // Override BadMessageReceived() so to do nothing since the original
94 // implementation to kill a malicious renderer process causes a check failure 95 // implementation to kill a malicious renderer process causes a check failure
95 // in unit tests. 96 // in unit tests.
96 void BadMessageReceived() override {} 97 void BadMessageReceived() override {}
97 }; 98 };
98 99
99 class MidiHostTest : public testing::Test { 100 class MidiHostTest : public testing::Test {
100 public: 101 public:
101 MidiHostTest() 102 MidiHostTest()
102 : io_browser_thread_(BrowserThread::IO, &message_loop_), 103 : io_browser_thread_(BrowserThread::IO, &message_loop_),
103 host_(new MidiHostForTesting(kRenderProcessId, &manager_)), 104 host_(new MidiHostForTesting(kRenderProcessId, &manager_)),
104 data_(kNoteOn, kNoteOn + arraysize(kNoteOn)), 105 data_(kNoteOn, kNoteOn + arraysize(kNoteOn)),
105 port_id_(0) {} 106 port_id_(0) {}
106 107
107 protected: 108 protected:
108 void AddOutputPort() { 109 void AddOutputPort() {
109 const std::string id = base::StringPrintf("i-can-%d", port_id_++); 110 const std::string id = base::StringPrintf("i-can-%d", port_id_++);
110 const std::string manufacturer("yukatan"); 111 const std::string manufacturer("yukatan");
111 const std::string name("doki-doki-pi-pine"); 112 const std::string name("doki-doki-pi-pine");
112 const std::string version("3.14159265359"); 113 const std::string version("3.14159265359");
113 media::MidiPortState state = media::MIDI_PORT_CONNECTED; 114 media::midi::MidiPortState state = media::midi::MIDI_PORT_CONNECTED;
114 media::MidiPortInfo info(id, manufacturer, name, version, state); 115 media::midi::MidiPortInfo info(id, manufacturer, name, version, state);
115 116
116 host_->AddOutputPort(info); 117 host_->AddOutputPort(info);
117 } 118 }
118 119
119 void OnSendData(uint32 port) { 120 void OnSendData(uint32 port) {
120 scoped_ptr<IPC::Message> message( 121 scoped_ptr<IPC::Message> message(
121 new MidiHostMsg_SendData(port, data_, 0.0)); 122 new MidiHostMsg_SendData(port, data_, 0.0));
122 host_->OnMessageReceived(*message.get()); 123 host_->OnMessageReceived(*message.get());
123 } 124 }
124 125
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // Sending data to port 0 and 1 should be delivered now. 224 // Sending data to port 0 and 1 should be delivered now.
224 OnSendData(port0); 225 OnSendData(port0);
225 OnSendData(port1); 226 OnSendData(port1);
226 RunLoopUntilIdle(); 227 RunLoopUntilIdle();
227 EXPECT_EQ(3U, GetEventSize()); 228 EXPECT_EQ(3U, GetEventSize());
228 CheckSendEventAt(1, port0); 229 CheckSendEventAt(1, port0);
229 CheckSendEventAt(2, port1); 230 CheckSendEventAt(2, port1);
230 } 231 }
231 232
232 } // namespace conent 233 } // namespace conent
OLDNEW
« no previous file with comments | « content/browser/media/midi_host.cc ('k') | content/common/media/midi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698