| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 std::string device_version_; | 88 std::string device_version_; |
| 89 Logger* logger_; | 89 Logger* logger_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice); | 91 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class FakeMidiManagerClient : public MidiManagerClient { | 94 class FakeMidiManagerClient : public MidiManagerClient { |
| 95 public: | 95 public: |
| 96 explicit FakeMidiManagerClient(Logger* logger) | 96 explicit FakeMidiManagerClient(Logger* logger) |
| 97 : complete_start_session_(false), | 97 : complete_start_session_(false), |
| 98 result_(Result::NOT_SUPPORTED), | 98 result_(mojom::Result::NOT_SUPPORTED), |
| 99 logger_(logger) {} | 99 logger_(logger) {} |
| 100 ~FakeMidiManagerClient() override {} | 100 ~FakeMidiManagerClient() override {} |
| 101 | 101 |
| 102 void AddInputPort(const MidiPortInfo& info) override { | 102 void AddInputPort(const MidiPortInfo& info) override { |
| 103 input_ports_.push_back(info); | 103 input_ports_.push_back(info); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void AddOutputPort(const MidiPortInfo& info) override { | 106 void AddOutputPort(const MidiPortInfo& info) override { |
| 107 output_ports_.push_back(info); | 107 output_ports_.push_back(info); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void SetInputPortState(uint32_t port_index, MidiPortState state) override {} | 110 void SetInputPortState(uint32_t port_index, MidiPortState state) override {} |
| 111 | 111 |
| 112 void SetOutputPortState(uint32_t port_index, MidiPortState state) override {} | 112 void SetOutputPortState(uint32_t port_index, MidiPortState state) override {} |
| 113 | 113 |
| 114 void CompleteStartSession(Result result) override { | 114 void CompleteStartSession(mojom::Result result) override { |
| 115 complete_start_session_ = true; | 115 complete_start_session_ = true; |
| 116 result_ = result; | 116 result_ = result; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void ReceiveMidiData(uint32_t port_index, | 119 void ReceiveMidiData(uint32_t port_index, |
| 120 const uint8_t* data, | 120 const uint8_t* data, |
| 121 size_t size, | 121 size_t size, |
| 122 double timestamp) override { | 122 double timestamp) override { |
| 123 logger_->AddLog("MidiManagerClient::ReceiveMidiData "); | 123 logger_->AddLog("MidiManagerClient::ReceiveMidiData "); |
| 124 logger_->AddLog( | 124 logger_->AddLog( |
| 125 base::StringPrintf("usb:port_index = %d data =", port_index)); | 125 base::StringPrintf("usb:port_index = %d data =", port_index)); |
| 126 for (size_t i = 0; i < size; ++i) | 126 for (size_t i = 0; i < size; ++i) |
| 127 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); | 127 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); |
| 128 logger_->AddLog("\n"); | 128 logger_->AddLog("\n"); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void AccumulateMidiBytesSent(size_t size) override { | 131 void AccumulateMidiBytesSent(size_t size) override { |
| 132 logger_->AddLog("MidiManagerClient::AccumulateMidiBytesSent "); | 132 logger_->AddLog("MidiManagerClient::AccumulateMidiBytesSent "); |
| 133 // Windows has no "%zu". | 133 // Windows has no "%zu". |
| 134 logger_->AddLog(base::StringPrintf("size = %u\n", | 134 logger_->AddLog(base::StringPrintf("size = %u\n", |
| 135 static_cast<unsigned>(size))); | 135 static_cast<unsigned>(size))); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void Detach() override {} | 138 void Detach() override {} |
| 139 | 139 |
| 140 bool complete_start_session_; | 140 bool complete_start_session_; |
| 141 Result result_; | 141 mojom::Result result_; |
| 142 MidiPortInfoList input_ports_; | 142 MidiPortInfoList input_ports_; |
| 143 MidiPortInfoList output_ports_; | 143 MidiPortInfoList output_ports_; |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 Logger* logger_; | 146 Logger* logger_; |
| 147 | 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); | 148 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 class TestUsbMidiDeviceFactory : public UsbMidiDevice::Factory { | 151 class TestUsbMidiDeviceFactory : public UsbMidiDevice::Factory { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 DISALLOW_COPY_AND_ASSIGN(TestUsbMidiDeviceFactory); | 163 DISALLOW_COPY_AND_ASSIGN(TestUsbMidiDeviceFactory); |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 class MidiManagerUsbForTesting : public MidiManagerUsb { | 166 class MidiManagerUsbForTesting : public MidiManagerUsb { |
| 167 public: | 167 public: |
| 168 explicit MidiManagerUsbForTesting( | 168 explicit MidiManagerUsbForTesting( |
| 169 std::unique_ptr<UsbMidiDevice::Factory> device_factory) | 169 std::unique_ptr<UsbMidiDevice::Factory> device_factory) |
| 170 : MidiManagerUsb(std::move(device_factory)) {} | 170 : MidiManagerUsb(std::move(device_factory)) {} |
| 171 ~MidiManagerUsbForTesting() override {} | 171 ~MidiManagerUsbForTesting() override {} |
| 172 | 172 |
| 173 void CallCompleteInitialization(Result result) { | 173 void CallCompleteInitialization(mojom::Result result) { |
| 174 CompleteInitialization(result); | 174 CompleteInitialization(result); |
| 175 base::RunLoop run_loop; | 175 base::RunLoop run_loop; |
| 176 run_loop.RunUntilIdle(); | 176 run_loop.RunUntilIdle(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbForTesting); | 180 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbForTesting); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 class MidiManagerUsbTest : public ::testing::Test { | 183 class MidiManagerUsbTest : public ::testing::Test { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 void Finalize() { | 208 void Finalize() { |
| 209 manager_->EndSession(client_.get()); | 209 manager_->EndSession(client_.get()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool IsInitializationCallbackInvoked() { | 212 bool IsInitializationCallbackInvoked() { |
| 213 return client_->complete_start_session_; | 213 return client_->complete_start_session_; |
| 214 } | 214 } |
| 215 | 215 |
| 216 Result GetInitializationResult() { return client_->result_; } | 216 mojom::Result GetInitializationResult() { return client_->result_; } |
| 217 | 217 |
| 218 void RunCallbackUntilCallbackInvoked( | 218 void RunCallbackUntilCallbackInvoked( |
| 219 bool result, UsbMidiDevice::Devices* devices) { | 219 bool result, UsbMidiDevice::Devices* devices) { |
| 220 factory_->callback_.Run(result, devices); | 220 factory_->callback_.Run(result, devices); |
| 221 while (!client_->complete_start_session_) { | 221 while (!client_->complete_start_session_) { |
| 222 base::RunLoop run_loop; | 222 base::RunLoop run_loop; |
| 223 run_loop.RunUntilIdle(); | 223 run_loop.RunUntilIdle(); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 device->SetDescriptors(ToVector(descriptors)); | 259 device->SetDescriptors(ToVector(descriptors)); |
| 260 device->SetManufacturer("vendor1"); | 260 device->SetManufacturer("vendor1"); |
| 261 device->SetProductName("device1"); | 261 device->SetProductName("device1"); |
| 262 device->SetDeviceVersion("1.02"); | 262 device->SetDeviceVersion("1.02"); |
| 263 | 263 |
| 264 Initialize(); | 264 Initialize(); |
| 265 ScopedVector<UsbMidiDevice> devices; | 265 ScopedVector<UsbMidiDevice> devices; |
| 266 devices.push_back(std::move(device)); | 266 devices.push_back(std::move(device)); |
| 267 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 267 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 268 RunCallbackUntilCallbackInvoked(true, &devices); | 268 RunCallbackUntilCallbackInvoked(true, &devices); |
| 269 EXPECT_EQ(Result::OK, GetInitializationResult()); | 269 EXPECT_EQ(mojom::Result::OK, GetInitializationResult()); |
| 270 | 270 |
| 271 ASSERT_EQ(1u, input_ports().size()); | 271 ASSERT_EQ(1u, input_ports().size()); |
| 272 EXPECT_EQ("usb:port-0-2", input_ports()[0].id); | 272 EXPECT_EQ("usb:port-0-2", input_ports()[0].id); |
| 273 EXPECT_EQ("vendor1", input_ports()[0].manufacturer); | 273 EXPECT_EQ("vendor1", input_ports()[0].manufacturer); |
| 274 EXPECT_EQ("device1", input_ports()[0].name); | 274 EXPECT_EQ("device1", input_ports()[0].name); |
| 275 EXPECT_EQ("1.02", input_ports()[0].version); | 275 EXPECT_EQ("1.02", input_ports()[0].version); |
| 276 | 276 |
| 277 ASSERT_EQ(2u, output_ports().size()); | 277 ASSERT_EQ(2u, output_ports().size()); |
| 278 EXPECT_EQ("usb:port-0-0", output_ports()[0].id); | 278 EXPECT_EQ("usb:port-0-0", output_ports()[0].id); |
| 279 EXPECT_EQ("vendor1", output_ports()[0].manufacturer); | 279 EXPECT_EQ("vendor1", output_ports()[0].manufacturer); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 device2->SetManufacturer("vendor2"); | 320 device2->SetManufacturer("vendor2"); |
| 321 device2->SetProductName("device2"); | 321 device2->SetProductName("device2"); |
| 322 device2->SetDeviceVersion("98.76"); | 322 device2->SetDeviceVersion("98.76"); |
| 323 | 323 |
| 324 Initialize(); | 324 Initialize(); |
| 325 ScopedVector<UsbMidiDevice> devices; | 325 ScopedVector<UsbMidiDevice> devices; |
| 326 devices.push_back(std::move(device1)); | 326 devices.push_back(std::move(device1)); |
| 327 devices.push_back(std::move(device2)); | 327 devices.push_back(std::move(device2)); |
| 328 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 328 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 329 RunCallbackUntilCallbackInvoked(true, &devices); | 329 RunCallbackUntilCallbackInvoked(true, &devices); |
| 330 EXPECT_EQ(Result::OK, GetInitializationResult()); | 330 EXPECT_EQ(mojom::Result::OK, GetInitializationResult()); |
| 331 | 331 |
| 332 ASSERT_EQ(2u, input_ports().size()); | 332 ASSERT_EQ(2u, input_ports().size()); |
| 333 EXPECT_EQ("usb:port-0-2", input_ports()[0].id); | 333 EXPECT_EQ("usb:port-0-2", input_ports()[0].id); |
| 334 EXPECT_EQ("vendor1", input_ports()[0].manufacturer); | 334 EXPECT_EQ("vendor1", input_ports()[0].manufacturer); |
| 335 EXPECT_EQ("device1", input_ports()[0].name); | 335 EXPECT_EQ("device1", input_ports()[0].name); |
| 336 EXPECT_EQ("1.02", input_ports()[0].version); | 336 EXPECT_EQ("1.02", input_ports()[0].version); |
| 337 EXPECT_EQ("usb:port-1-2", input_ports()[1].id); | 337 EXPECT_EQ("usb:port-1-2", input_ports()[1].id); |
| 338 EXPECT_EQ("vendor2", input_ports()[1].manufacturer); | 338 EXPECT_EQ("vendor2", input_ports()[1].manufacturer); |
| 339 EXPECT_EQ("device2", input_ports()[1].name); | 339 EXPECT_EQ("device2", input_ports()[1].name); |
| 340 EXPECT_EQ("98.76", input_ports()[1].version); | 340 EXPECT_EQ("98.76", input_ports()[1].version); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 369 "UsbMidiDevice::GetDescriptors\n" | 369 "UsbMidiDevice::GetDescriptors\n" |
| 370 "UsbMidiDevice::GetDescriptors\n", | 370 "UsbMidiDevice::GetDescriptors\n", |
| 371 logger_.TakeLog()); | 371 logger_.TakeLog()); |
| 372 } | 372 } |
| 373 | 373 |
| 374 TEST_F(MidiManagerUsbTest, InitializeFail) { | 374 TEST_F(MidiManagerUsbTest, InitializeFail) { |
| 375 Initialize(); | 375 Initialize(); |
| 376 | 376 |
| 377 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 377 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 378 RunCallbackUntilCallbackInvoked(false, NULL); | 378 RunCallbackUntilCallbackInvoked(false, NULL); |
| 379 EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); | 379 EXPECT_EQ(mojom::Result::INITIALIZATION_ERROR, GetInitializationResult()); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { | 382 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { |
| 383 std::unique_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 383 std::unique_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
| 384 uint8_t descriptors[] = {0x04}; | 384 uint8_t descriptors[] = {0x04}; |
| 385 device->SetDescriptors(ToVector(descriptors)); | 385 device->SetDescriptors(ToVector(descriptors)); |
| 386 | 386 |
| 387 Initialize(); | 387 Initialize(); |
| 388 ScopedVector<UsbMidiDevice> devices; | 388 ScopedVector<UsbMidiDevice> devices; |
| 389 devices.push_back(std::move(device)); | 389 devices.push_back(std::move(device)); |
| 390 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 390 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 391 RunCallbackUntilCallbackInvoked(true, &devices); | 391 RunCallbackUntilCallbackInvoked(true, &devices); |
| 392 EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); | 392 EXPECT_EQ(mojom::Result::INITIALIZATION_ERROR, GetInitializationResult()); |
| 393 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 393 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
| 394 } | 394 } |
| 395 | 395 |
| 396 TEST_F(MidiManagerUsbTest, Send) { | 396 TEST_F(MidiManagerUsbTest, Send) { |
| 397 Initialize(); | 397 Initialize(); |
| 398 std::unique_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); | 398 std::unique_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); |
| 399 uint8_t descriptors[] = { | 399 uint8_t descriptors[] = { |
| 400 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, | 400 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75, |
| 401 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, | 401 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01, |
| 402 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, | 402 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 413 | 413 |
| 414 device->SetDescriptors(ToVector(descriptors)); | 414 device->SetDescriptors(ToVector(descriptors)); |
| 415 uint8_t data[] = { | 415 uint8_t data[] = { |
| 416 0x90, 0x45, 0x7f, 0xf0, 0x00, 0x01, 0xf7, | 416 0x90, 0x45, 0x7f, 0xf0, 0x00, 0x01, 0xf7, |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 ScopedVector<UsbMidiDevice> devices; | 419 ScopedVector<UsbMidiDevice> devices; |
| 420 devices.push_back(std::move(device)); | 420 devices.push_back(std::move(device)); |
| 421 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 421 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 422 RunCallbackUntilCallbackInvoked(true, &devices); | 422 RunCallbackUntilCallbackInvoked(true, &devices); |
| 423 EXPECT_EQ(Result::OK, GetInitializationResult()); | 423 EXPECT_EQ(mojom::Result::OK, GetInitializationResult()); |
| 424 ASSERT_EQ(2u, manager_->output_streams().size()); | 424 ASSERT_EQ(2u, manager_->output_streams().size()); |
| 425 | 425 |
| 426 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); | 426 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); |
| 427 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to | 427 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to |
| 428 // invoke the task. | 428 // invoke the task. |
| 429 base::RunLoop run_loop; | 429 base::RunLoop run_loop; |
| 430 run_loop.RunUntilIdle(); | 430 run_loop.RunUntilIdle(); |
| 431 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n" | 431 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n" |
| 432 "UsbMidiDevice::Send endpoint = 2 data = " | 432 "UsbMidiDevice::Send endpoint = 2 data = " |
| 433 "0x19 0x90 0x45 0x7f " | 433 "0x19 0x90 0x45 0x7f " |
| (...skipping 23 matching lines...) Expand all Loading... |
| 457 device->SetDescriptors(ToVector(descriptors)); | 457 device->SetDescriptors(ToVector(descriptors)); |
| 458 uint8_t data[] = { | 458 uint8_t data[] = { |
| 459 0x90, 0x45, 0x7f, 0xf0, 0x00, 0x01, 0xf7, | 459 0x90, 0x45, 0x7f, 0xf0, 0x00, 0x01, 0xf7, |
| 460 }; | 460 }; |
| 461 | 461 |
| 462 Initialize(); | 462 Initialize(); |
| 463 ScopedVector<UsbMidiDevice> devices; | 463 ScopedVector<UsbMidiDevice> devices; |
| 464 devices.push_back(std::move(device)); | 464 devices.push_back(std::move(device)); |
| 465 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 465 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 466 RunCallbackUntilCallbackInvoked(true, &devices); | 466 RunCallbackUntilCallbackInvoked(true, &devices); |
| 467 EXPECT_EQ(Result::OK, GetInitializationResult()); | 467 EXPECT_EQ(mojom::Result::OK, GetInitializationResult()); |
| 468 ASSERT_EQ(2u, manager_->output_streams().size()); | 468 ASSERT_EQ(2u, manager_->output_streams().size()); |
| 469 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 469 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
| 470 | 470 |
| 471 // The specified port index is invalid. The manager must ignore the request. | 471 // The specified port index is invalid. The manager must ignore the request. |
| 472 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0); | 472 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0); |
| 473 EXPECT_EQ("", logger_.TakeLog()); | 473 EXPECT_EQ("", logger_.TakeLog()); |
| 474 | 474 |
| 475 // The specified port index is invalid. The manager must ignore the request. | 475 // The specified port index is invalid. The manager must ignore the request. |
| 476 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0); | 476 manager_->DispatchSendMidiData(client_.get(), 2, ToVector(data), 0); |
| 477 EXPECT_EQ("", logger_.TakeLog()); | 477 EXPECT_EQ("", logger_.TakeLog()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 500 0x01, 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4). | 500 0x01, 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4). |
| 501 0x05, 0xf7, 0x00, 0x00, | 501 0x05, 0xf7, 0x00, 0x00, |
| 502 }; | 502 }; |
| 503 | 503 |
| 504 Initialize(); | 504 Initialize(); |
| 505 ScopedVector<UsbMidiDevice> devices; | 505 ScopedVector<UsbMidiDevice> devices; |
| 506 UsbMidiDevice* device_raw = device.get(); | 506 UsbMidiDevice* device_raw = device.get(); |
| 507 devices.push_back(std::move(device)); | 507 devices.push_back(std::move(device)); |
| 508 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 508 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 509 RunCallbackUntilCallbackInvoked(true, &devices); | 509 RunCallbackUntilCallbackInvoked(true, &devices); |
| 510 EXPECT_EQ(Result::OK, GetInitializationResult()); | 510 EXPECT_EQ(mojom::Result::OK, GetInitializationResult()); |
| 511 | 511 |
| 512 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), | 512 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), |
| 513 base::TimeTicks()); | 513 base::TimeTicks()); |
| 514 Finalize(); | 514 Finalize(); |
| 515 | 515 |
| 516 EXPECT_EQ( | 516 EXPECT_EQ( |
| 517 "UsbMidiDevice::GetDescriptors\n" | 517 "UsbMidiDevice::GetDescriptors\n" |
| 518 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " | 518 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " |
| 519 "data = 0x90 0x45 0x7f\n" | 519 "data = 0x90 0x45 0x7f\n" |
| 520 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " | 520 "MidiManagerClient::ReceiveMidiData usb:port_index = 0 " |
| (...skipping 15 matching lines...) Expand all Loading... |
| 536 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, | 536 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, |
| 537 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, | 537 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, |
| 538 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, | 538 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25, |
| 539 0x01, 0x01, 0x07, | 539 0x01, 0x01, 0x07, |
| 540 }; | 540 }; |
| 541 | 541 |
| 542 Initialize(); | 542 Initialize(); |
| 543 ScopedVector<UsbMidiDevice> devices; | 543 ScopedVector<UsbMidiDevice> devices; |
| 544 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 544 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
| 545 RunCallbackUntilCallbackInvoked(true, &devices); | 545 RunCallbackUntilCallbackInvoked(true, &devices); |
| 546 EXPECT_EQ(Result::OK, GetInitializationResult()); | 546 EXPECT_EQ(mojom::Result::OK, GetInitializationResult()); |
| 547 | 547 |
| 548 ASSERT_EQ(0u, input_ports().size()); | 548 ASSERT_EQ(0u, input_ports().size()); |
| 549 ASSERT_EQ(0u, output_ports().size()); | 549 ASSERT_EQ(0u, output_ports().size()); |
| 550 ASSERT_TRUE(manager_->input_stream()); | 550 ASSERT_TRUE(manager_->input_stream()); |
| 551 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks(); | 551 std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks(); |
| 552 ASSERT_EQ(0u, manager_->output_streams().size()); | 552 ASSERT_EQ(0u, manager_->output_streams().size()); |
| 553 ASSERT_EQ(0u, jacks.size()); | 553 ASSERT_EQ(0u, jacks.size()); |
| 554 EXPECT_EQ("", logger_.TakeLog()); | 554 EXPECT_EQ("", logger_.TakeLog()); |
| 555 | 555 |
| 556 std::unique_ptr<FakeUsbMidiDevice> new_device( | 556 std::unique_ptr<FakeUsbMidiDevice> new_device( |
| 557 new FakeUsbMidiDevice(&logger_)); | 557 new FakeUsbMidiDevice(&logger_)); |
| 558 new_device->SetDescriptors(ToVector(descriptors)); | 558 new_device->SetDescriptors(ToVector(descriptors)); |
| 559 manager_->OnDeviceAttached(std::move(new_device)); | 559 manager_->OnDeviceAttached(std::move(new_device)); |
| 560 | 560 |
| 561 ASSERT_EQ(1u, input_ports().size()); | 561 ASSERT_EQ(1u, input_ports().size()); |
| 562 ASSERT_EQ(2u, output_ports().size()); | 562 ASSERT_EQ(2u, output_ports().size()); |
| 563 ASSERT_TRUE(manager_->input_stream()); | 563 ASSERT_TRUE(manager_->input_stream()); |
| 564 jacks = manager_->input_stream()->jacks(); | 564 jacks = manager_->input_stream()->jacks(); |
| 565 ASSERT_EQ(2u, manager_->output_streams().size()); | 565 ASSERT_EQ(2u, manager_->output_streams().size()); |
| 566 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); | 566 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); |
| 567 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); | 567 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); |
| 568 ASSERT_EQ(1u, jacks.size()); | 568 ASSERT_EQ(1u, jacks.size()); |
| 569 EXPECT_EQ(2, jacks[0].endpoint_number()); | 569 EXPECT_EQ(2, jacks[0].endpoint_number()); |
| 570 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); | 570 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); |
| 571 } | 571 } |
| 572 | 572 |
| 573 } // namespace | 573 } // namespace |
| 574 | 574 |
| 575 } // namespace midi | 575 } // namespace midi |
| OLD | NEW |