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 "media/midi/midi_manager_usb.h" | 5 #include "media/midi/midi_manager_usb.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 std::string log_; | 39 std::string log_; |
40 | 40 |
41 DISALLOW_COPY_AND_ASSIGN(Logger); | 41 DISALLOW_COPY_AND_ASSIGN(Logger); |
42 }; | 42 }; |
43 | 43 |
44 class FakeUsbMidiDevice : public UsbMidiDevice { | 44 class FakeUsbMidiDevice : public UsbMidiDevice { |
45 public: | 45 public: |
46 explicit FakeUsbMidiDevice(Logger* logger) : logger_(logger) {} | 46 explicit FakeUsbMidiDevice(Logger* logger) : logger_(logger) {} |
47 ~FakeUsbMidiDevice() override {} | 47 ~FakeUsbMidiDevice() override {} |
48 | 48 |
49 std::vector<uint8> GetDescriptors() override { | 49 std::vector<uint8_t> GetDescriptors() override { |
50 logger_->AddLog("UsbMidiDevice::GetDescriptors\n"); | 50 logger_->AddLog("UsbMidiDevice::GetDescriptors\n"); |
51 return descriptors_; | 51 return descriptors_; |
52 } | 52 } |
53 | 53 |
54 std::string GetManufacturer() override { return manufacturer_; } | 54 std::string GetManufacturer() override { return manufacturer_; } |
55 std::string GetProductName() override { return product_name_; } | 55 std::string GetProductName() override { return product_name_; } |
56 std::string GetDeviceVersion() override { return device_version_; } | 56 std::string GetDeviceVersion() override { return device_version_; } |
57 | 57 |
58 void Send(int endpoint_number, const std::vector<uint8>& data) override { | 58 void Send(int endpoint_number, const std::vector<uint8_t>& data) override { |
59 logger_->AddLog("UsbMidiDevice::Send "); | 59 logger_->AddLog("UsbMidiDevice::Send "); |
60 logger_->AddLog(base::StringPrintf("endpoint = %d data =", | 60 logger_->AddLog(base::StringPrintf("endpoint = %d data =", |
61 endpoint_number)); | 61 endpoint_number)); |
62 for (size_t i = 0; i < data.size(); ++i) | 62 for (size_t i = 0; i < data.size(); ++i) |
63 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); | 63 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); |
64 logger_->AddLog("\n"); | 64 logger_->AddLog("\n"); |
65 } | 65 } |
66 | 66 |
67 void SetDescriptors(const std::vector<uint8> descriptors) { | 67 void SetDescriptors(const std::vector<uint8_t> descriptors) { |
68 descriptors_ = descriptors; | 68 descriptors_ = descriptors; |
69 } | 69 } |
70 void SetManufacturer(const std::string& manufacturer) { | 70 void SetManufacturer(const std::string& manufacturer) { |
71 manufacturer_ = manufacturer; | 71 manufacturer_ = manufacturer; |
72 } | 72 } |
73 void SetProductName(const std::string& product_name) { | 73 void SetProductName(const std::string& product_name) { |
74 product_name_ = product_name; | 74 product_name_ = product_name; |
75 } | 75 } |
76 void SetDeviceVersion(const std::string& device_version) { | 76 void SetDeviceVersion(const std::string& device_version) { |
77 device_version_ = device_version; | 77 device_version_ = device_version; |
78 } | 78 } |
79 | 79 |
80 private: | 80 private: |
81 std::vector<uint8> descriptors_; | 81 std::vector<uint8_t> descriptors_; |
82 std::string manufacturer_; | 82 std::string manufacturer_; |
83 std::string product_name_; | 83 std::string product_name_; |
84 std::string device_version_; | 84 std::string device_version_; |
85 Logger* logger_; | 85 Logger* logger_; |
86 | 86 |
87 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice); | 87 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice); |
88 }; | 88 }; |
89 | 89 |
90 class FakeMidiManagerClient : public MidiManagerClient { | 90 class FakeMidiManagerClient : public MidiManagerClient { |
91 public: | 91 public: |
92 explicit FakeMidiManagerClient(Logger* logger) | 92 explicit FakeMidiManagerClient(Logger* logger) |
93 : complete_start_session_(false), | 93 : complete_start_session_(false), |
94 result_(Result::NOT_SUPPORTED), | 94 result_(Result::NOT_SUPPORTED), |
95 logger_(logger) {} | 95 logger_(logger) {} |
96 ~FakeMidiManagerClient() override {} | 96 ~FakeMidiManagerClient() override {} |
97 | 97 |
98 void AddInputPort(const MidiPortInfo& info) override { | 98 void AddInputPort(const MidiPortInfo& info) override { |
99 input_ports_.push_back(info); | 99 input_ports_.push_back(info); |
100 } | 100 } |
101 | 101 |
102 void AddOutputPort(const MidiPortInfo& info) override { | 102 void AddOutputPort(const MidiPortInfo& info) override { |
103 output_ports_.push_back(info); | 103 output_ports_.push_back(info); |
104 } | 104 } |
105 | 105 |
106 void SetInputPortState(uint32 port_index, MidiPortState state) override {} | 106 void SetInputPortState(uint32_t port_index, MidiPortState state) override {} |
107 | 107 |
108 void SetOutputPortState(uint32 port_index, MidiPortState state) override {} | 108 void SetOutputPortState(uint32_t port_index, MidiPortState state) override {} |
109 | 109 |
110 void CompleteStartSession(Result result) override { | 110 void CompleteStartSession(Result result) override { |
111 complete_start_session_ = true; | 111 complete_start_session_ = true; |
112 result_ = result; | 112 result_ = result; |
113 } | 113 } |
114 | 114 |
115 void ReceiveMidiData(uint32 port_index, | 115 void ReceiveMidiData(uint32_t port_index, |
116 const uint8* data, | 116 const uint8_t* data, |
117 size_t size, | 117 size_t size, |
118 double timestamp) override { | 118 double timestamp) override { |
119 logger_->AddLog("MidiManagerClient::ReceiveMidiData "); | 119 logger_->AddLog("MidiManagerClient::ReceiveMidiData "); |
120 logger_->AddLog( | 120 logger_->AddLog( |
121 base::StringPrintf("usb:port_index = %d data =", port_index)); | 121 base::StringPrintf("usb:port_index = %d data =", port_index)); |
122 for (size_t i = 0; i < size; ++i) | 122 for (size_t i = 0; i < size; ++i) |
123 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); | 123 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); |
124 logger_->AddLog("\n"); | 124 logger_->AddLog("\n"); |
125 } | 125 } |
126 | 126 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 private: | 231 private: |
232 scoped_ptr<base::MessageLoop> message_loop_; | 232 scoped_ptr<base::MessageLoop> message_loop_; |
233 | 233 |
234 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbTest); | 234 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbTest); |
235 }; | 235 }; |
236 | 236 |
237 | 237 |
238 TEST_F(MidiManagerUsbTest, Initialize) { | 238 TEST_F(MidiManagerUsbTest, Initialize) { |
239 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 239 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
240 uint8 descriptors[] = { | 240 uint8_t descriptors[] = { |
241 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, | 241 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
242 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, | 242 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
243 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, | 243 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
244 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, | 244 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, |
245 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, | 245 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, |
246 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, | 246 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, |
247 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, | 247 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, |
248 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, | 248 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, |
249 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, | 249 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
250 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, | 250 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
251 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, | 251 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, |
252 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 252 0x01, 0x01, 0x07, |
253 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, | |
254 0x05, 0x25, 0x01, 0x01, 0x07, | |
255 }; | 253 }; |
256 device->SetDescriptors(ToVector(descriptors)); | 254 device->SetDescriptors(ToVector(descriptors)); |
257 device->SetManufacturer("vendor1"); | 255 device->SetManufacturer("vendor1"); |
258 device->SetProductName("device1"); | 256 device->SetProductName("device1"); |
259 device->SetDeviceVersion("1.02"); | 257 device->SetDeviceVersion("1.02"); |
260 | 258 |
261 Initialize(); | 259 Initialize(); |
262 ScopedVector<UsbMidiDevice> devices; | 260 ScopedVector<UsbMidiDevice> devices; |
263 devices.push_back(device.Pass()); | 261 devices.push_back(device.Pass()); |
264 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 262 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
(...skipping 23 matching lines...) Expand all Loading... |
288 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); | 286 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); |
289 ASSERT_EQ(1u, jacks.size()); | 287 ASSERT_EQ(1u, jacks.size()); |
290 EXPECT_EQ(2, jacks[0].endpoint_number()); | 288 EXPECT_EQ(2, jacks[0].endpoint_number()); |
291 | 289 |
292 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 290 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
293 } | 291 } |
294 | 292 |
295 TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) { | 293 TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) { |
296 scoped_ptr<FakeUsbMidiDevice> device1(new FakeUsbMidiDevice(&logger_)); | 294 scoped_ptr<FakeUsbMidiDevice> device1(new FakeUsbMidiDevice(&logger_)); |
297 scoped_ptr<FakeUsbMidiDevice> device2(new FakeUsbMidiDevice(&logger_)); | 295 scoped_ptr<FakeUsbMidiDevice> device2(new FakeUsbMidiDevice(&logger_)); |
298 uint8 descriptors[] = { | 296 uint8_t descriptors[] = { |
299 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, | 297 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
300 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, | 298 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
301 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, | 299 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
302 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, | 300 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, |
303 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, | 301 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, |
304 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, | 302 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, |
305 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, | 303 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, |
306 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, | 304 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, |
307 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, | 305 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
308 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 306 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 TEST_F(MidiManagerUsbTest, InitializeFail) { | 369 TEST_F(MidiManagerUsbTest, InitializeFail) { |
372 Initialize(); | 370 Initialize(); |
373 | 371 |
374 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 372 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
375 RunCallbackUntilCallbackInvoked(false, NULL); | 373 RunCallbackUntilCallbackInvoked(false, NULL); |
376 EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); | 374 EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); |
377 } | 375 } |
378 | 376 |
379 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { | 377 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { |
380 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 378 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
381 uint8 descriptors[] = {0x04}; | 379 uint8_t descriptors[] = {0x04}; |
382 device->SetDescriptors(ToVector(descriptors)); | 380 device->SetDescriptors(ToVector(descriptors)); |
383 | 381 |
384 Initialize(); | 382 Initialize(); |
385 ScopedVector<UsbMidiDevice> devices; | 383 ScopedVector<UsbMidiDevice> devices; |
386 devices.push_back(device.Pass()); | 384 devices.push_back(device.Pass()); |
387 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 385 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
388 RunCallbackUntilCallbackInvoked(true, &devices); | 386 RunCallbackUntilCallbackInvoked(true, &devices); |
389 EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); | 387 EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); |
390 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 388 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
391 } | 389 } |
392 | 390 |
393 TEST_F(MidiManagerUsbTest, Send) { | 391 TEST_F(MidiManagerUsbTest, Send) { |
394 Initialize(); | 392 Initialize(); |
395 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 393 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
396 uint8 descriptors[] = { | 394 uint8_t descriptors[] = { |
397 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, | 395 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
398 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, | 396 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
399 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, | 397 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
400 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, | 398 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, |
401 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, | 399 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, |
402 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, | 400 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, |
403 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, | 401 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, |
404 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, | 402 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, |
405 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, | 403 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
406 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, | 404 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
407 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, | 405 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, |
408 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 406 0x01, 0x01, 0x07, |
409 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, | |
410 0x05, 0x25, 0x01, 0x01, 0x07, | |
411 }; | 407 }; |
412 | 408 |
413 device->SetDescriptors(ToVector(descriptors)); | 409 device->SetDescriptors(ToVector(descriptors)); |
414 uint8 data[] = { | 410 uint8_t data[] = { |
415 0x90, 0x45, 0x7f, | 411 0x90, 0x45, 0x7f, 0xf0, 0x00, 0x01, 0xf7, |
416 0xf0, 0x00, 0x01, 0xf7, | |
417 }; | 412 }; |
418 | 413 |
419 ScopedVector<UsbMidiDevice> devices; | 414 ScopedVector<UsbMidiDevice> devices; |
420 devices.push_back(device.Pass()); | 415 devices.push_back(device.Pass()); |
421 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 416 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
422 RunCallbackUntilCallbackInvoked(true, &devices); | 417 RunCallbackUntilCallbackInvoked(true, &devices); |
423 EXPECT_EQ(Result::OK, GetInitializationResult()); | 418 EXPECT_EQ(Result::OK, GetInitializationResult()); |
424 ASSERT_EQ(2u, manager_->output_streams().size()); | 419 ASSERT_EQ(2u, manager_->output_streams().size()); |
425 | 420 |
426 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); | 421 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); |
427 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to | 422 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to |
428 // invoke the task. | 423 // invoke the task. |
429 base::RunLoop run_loop; | 424 base::RunLoop run_loop; |
430 run_loop.RunUntilIdle(); | 425 run_loop.RunUntilIdle(); |
431 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n" | 426 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n" |
432 "UsbMidiDevice::Send endpoint = 2 data = " | 427 "UsbMidiDevice::Send endpoint = 2 data = " |
433 "0x19 0x90 0x45 0x7f " | 428 "0x19 0x90 0x45 0x7f " |
434 "0x14 0xf0 0x00 0x01 " | 429 "0x14 0xf0 0x00 0x01 " |
435 "0x15 0xf7 0x00 0x00\n" | 430 "0x15 0xf7 0x00 0x00\n" |
436 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n", | 431 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n", |
437 logger_.TakeLog()); | 432 logger_.TakeLog()); |
438 } | 433 } |
439 | 434 |
440 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) { | 435 TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) { |
441 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 436 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
442 uint8 descriptors[] = { | 437 uint8_t descriptors[] = { |
443 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, | 438 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
444 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, | 439 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
445 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, | 440 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
446 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, | 441 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, |
447 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, | 442 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, |
448 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, | 443 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, |
449 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, | 444 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, |
450 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, | 445 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, |
451 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, | 446 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
452 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, | 447 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
453 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, | 448 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, |
454 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 449 0x01, 0x01, 0x07, |
455 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, | |
456 0x05, 0x25, 0x01, 0x01, 0x07, | |
457 }; | 450 }; |
458 | 451 |
459 device->SetDescriptors(ToVector(descriptors)); | 452 device->SetDescriptors(ToVector(descriptors)); |
460 uint8 data[] = { | 453 uint8_t data[] = { |
461 0x90, 0x45, 0x7f, | 454 0x90, 0x45, 0x7f, 0xf0, 0x00, 0x01, 0xf7, |
462 0xf0, 0x00, 0x01, 0xf7, | |
463 }; | 455 }; |
464 | 456 |
465 Initialize(); | 457 Initialize(); |
466 ScopedVector<UsbMidiDevice> devices; | 458 ScopedVector<UsbMidiDevice> devices; |
467 devices.push_back(device.Pass()); | 459 devices.push_back(device.Pass()); |
468 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 460 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
469 RunCallbackUntilCallbackInvoked(true, &devices); | 461 RunCallbackUntilCallbackInvoked(true, &devices); |
470 EXPECT_EQ(Result::OK, GetInitializationResult()); | 462 EXPECT_EQ(Result::OK, GetInitializationResult()); |
471 ASSERT_EQ(2u, manager_->output_streams().size()); | 463 ASSERT_EQ(2u, manager_->output_streams().size()); |
472 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 464 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
473 | 465 |
474 // The specified port index is invalid. The manager must ignore the request. | 466 // The specified port index is invalid. The manager must ignore the request. |
475 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0); | 467 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0); |
476 EXPECT_EQ("", logger_.TakeLog()); | 468 EXPECT_EQ("", logger_.TakeLog()); |
477 | 469 |
478 // The specified port index is invalid. The manager must ignore the request. | 470 // The specified port index is invalid. The manager must ignore the request. |
479 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0); | 471 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0); |
480 EXPECT_EQ("", logger_.TakeLog()); | 472 EXPECT_EQ("", logger_.TakeLog()); |
481 } | 473 } |
482 | 474 |
483 TEST_F(MidiManagerUsbTest, Receive) { | 475 TEST_F(MidiManagerUsbTest, Receive) { |
484 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 476 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
485 uint8 descriptors[] = { | 477 uint8_t descriptors[] = { |
486 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, | 478 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
487 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, | 479 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
488 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, | 480 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
489 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, | 481 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, |
490 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, | 482 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, |
491 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, | 483 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, |
492 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, | 484 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, |
493 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, | 485 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, |
494 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, | 486 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
495 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, | 487 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
496 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, | 488 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, |
497 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 489 0x01, 0x01, 0x07, |
498 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, | |
499 0x05, 0x25, 0x01, 0x01, 0x07, | |
500 }; | 490 }; |
501 | 491 |
502 device->SetDescriptors(ToVector(descriptors)); | 492 device->SetDescriptors(ToVector(descriptors)); |
503 uint8 data[] = { | 493 uint8_t data[] = { |
504 0x09, 0x90, 0x45, 0x7f, | 494 0x09, 0x90, 0x45, 0x7f, 0x04, 0xf0, 0x00, |
505 0x04, 0xf0, 0x00, 0x01, | 495 0x01, 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4). |
506 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4). | 496 0x05, 0xf7, 0x00, 0x00, |
507 0x05, 0xf7, 0x00, 0x00, | |
508 }; | 497 }; |
509 | 498 |
510 Initialize(); | 499 Initialize(); |
511 ScopedVector<UsbMidiDevice> devices; | 500 ScopedVector<UsbMidiDevice> devices; |
512 UsbMidiDevice* device_raw = device.get(); | 501 UsbMidiDevice* device_raw = device.get(); |
513 devices.push_back(device.Pass()); | 502 devices.push_back(device.Pass()); |
514 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 503 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
515 RunCallbackUntilCallbackInvoked(true, &devices); | 504 RunCallbackUntilCallbackInvoked(true, &devices); |
516 EXPECT_EQ(Result::OK, GetInitializationResult()); | 505 EXPECT_EQ(Result::OK, GetInitializationResult()); |
517 | 506 |
518 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), | 507 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), |
519 base::TimeTicks()); | 508 base::TimeTicks()); |
520 Finalize(); | 509 Finalize(); |
521 | 510 |
522 EXPECT_EQ( | 511 EXPECT_EQ( |
523 "UsbMidiDevice::GetDescriptors\n" | 512 "UsbMidiDevice::GetDescriptors\n" |
524 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " | 513 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " |
525 "data = 0x90 0x45 0x7f\n" | 514 "data = 0x90 0x45 0x7f\n" |
526 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " | 515 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " |
527 "data = 0xf0 0x00 0x01\n" | 516 "data = 0xf0 0x00 0x01\n" |
528 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 data = 0xf7\n", | 517 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 data = 0xf7\n", |
529 logger_.TakeLog()); | 518 logger_.TakeLog()); |
530 } | 519 } |
531 | 520 |
532 TEST_F(MidiManagerUsbTest, AttachDevice) { | 521 TEST_F(MidiManagerUsbTest, AttachDevice) { |
533 uint8 descriptors[] = { | 522 uint8_t descriptors[] = { |
534 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, | 523 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
535 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, | 524 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
536 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, | 525 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
537 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, | 526 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, |
538 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, | 527 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, |
539 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, | 528 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03, |
540 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, | 529 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07, |
541 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, | 530 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, |
542 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, | 531 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
543 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, | 532 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
544 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, | 533 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, |
545 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 534 0x01, 0x01, 0x07, |
546 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, | |
547 0x05, 0x25, 0x01, 0x01, 0x07, | |
548 }; | 535 }; |
549 | 536 |
550 Initialize(); | 537 Initialize(); |
551 ScopedVector<UsbMidiDevice> devices; | 538 ScopedVector<UsbMidiDevice> devices; |
552 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 539 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
553 RunCallbackUntilCallbackInvoked(true, &devices); | 540 RunCallbackUntilCallbackInvoked(true, &devices); |
554 EXPECT_EQ(Result::OK, GetInitializationResult()); | 541 EXPECT_EQ(Result::OK, GetInitializationResult()); |
555 | 542 |
556 ASSERT_EQ(0u, input_ports().size()); | 543 ASSERT_EQ(0u, input_ports().size()); |
557 ASSERT_EQ(0u, output_ports().size()); | 544 ASSERT_EQ(0u, output_ports().size()); |
(...skipping 16 matching lines...) Expand all Loading... |
574 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); | 561 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); |
575 ASSERT_EQ(1u, jacks.size()); | 562 ASSERT_EQ(1u, jacks.size()); |
576 EXPECT_EQ(2, jacks[0].endpoint_number()); | 563 EXPECT_EQ(2, jacks[0].endpoint_number()); |
577 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 564 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
578 } | 565 } |
579 | 566 |
580 } // namespace | 567 } // namespace |
581 | 568 |
582 } // namespace midi | 569 } // namespace midi |
583 } // namespace media | 570 } // namespace media |
OLD | NEW |