| Index: media/midi/midi_manager_usb_unittest.cc
|
| diff --git a/media/midi/midi_manager_usb_unittest.cc b/media/midi/midi_manager_usb_unittest.cc
|
| index 7f5bb27b42f850f9500b8da5baba2920d875d55d..01248c12b04ec40dccc6b5b60bd047db25459863 100644
|
| --- a/media/midi/midi_manager_usb_unittest.cc
|
| +++ b/media/midi/midi_manager_usb_unittest.cc
|
| @@ -45,11 +45,15 @@ class FakeUsbMidiDevice : public UsbMidiDevice {
|
| explicit FakeUsbMidiDevice(Logger* logger) : logger_(logger) {}
|
| ~FakeUsbMidiDevice() override {}
|
|
|
| - std::vector<uint8> GetDescriptor() override {
|
| - logger_->AddLog("UsbMidiDevice::GetDescriptor\n");
|
| - return descriptor_;
|
| + std::vector<uint8> GetDescriptors() override {
|
| + logger_->AddLog("UsbMidiDevice::GetDescriptors\n");
|
| + return descriptors_;
|
| }
|
|
|
| + std::string GetManufacturer() override { return manufacturer_; }
|
| + std::string GetProductName() override { return product_name_; }
|
| + std::string GetDeviceVersion() override { return device_version_; }
|
| +
|
| void Send(int endpoint_number, const std::vector<uint8>& data) override {
|
| logger_->AddLog("UsbMidiDevice::Send ");
|
| logger_->AddLog(base::StringPrintf("endpoint = %d data =",
|
| @@ -59,12 +63,24 @@ class FakeUsbMidiDevice : public UsbMidiDevice {
|
| logger_->AddLog("\n");
|
| }
|
|
|
| - void SetDescriptor(const std::vector<uint8> descriptor) {
|
| - descriptor_ = descriptor;
|
| + void SetDescriptors(const std::vector<uint8> descriptors) {
|
| + descriptors_ = descriptors;
|
| + }
|
| + void SetManufacturer(const std::string& manufacturer) {
|
| + manufacturer_ = manufacturer;
|
| + }
|
| + void SetProductName(const std::string& product_name) {
|
| + product_name_ = product_name;
|
| + }
|
| + void SetDeviceVersion(const std::string& device_version) {
|
| + device_version_ = device_version;
|
| }
|
|
|
| private:
|
| - std::vector<uint8> descriptor_;
|
| + std::vector<uint8> descriptors_;
|
| + std::string manufacturer_;
|
| + std::string product_name_;
|
| + std::string device_version_;
|
| Logger* logger_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice);
|
| @@ -215,7 +231,7 @@ class MidiManagerUsbTest : public ::testing::Test {
|
|
|
| TEST_F(MidiManagerUsbTest, Initialize) {
|
| scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
|
| - uint8 descriptor[] = {
|
| + uint8 descriptors[] = {
|
| 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
|
| 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
|
| 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
|
| @@ -231,7 +247,10 @@ TEST_F(MidiManagerUsbTest, Initialize) {
|
| 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
|
| 0x05, 0x25, 0x01, 0x01, 0x07,
|
| };
|
| - device->SetDescriptor(ToVector(descriptor));
|
| + device->SetDescriptors(ToVector(descriptors));
|
| + device->SetManufacturer("vendor1");
|
| + device->SetProductName("device1");
|
| + device->SetDeviceVersion("1.02");
|
|
|
| Initialize();
|
| ScopedVector<UsbMidiDevice> devices;
|
| @@ -241,7 +260,21 @@ TEST_F(MidiManagerUsbTest, Initialize) {
|
| EXPECT_EQ(MIDI_OK, GetInitializationResult());
|
|
|
| ASSERT_EQ(1u, input_ports().size());
|
| + EXPECT_EQ("port-0-2", input_ports()[0].id);
|
| + EXPECT_EQ("vendor1", input_ports()[0].manufacturer);
|
| + EXPECT_EQ("device1", input_ports()[0].name);
|
| + EXPECT_EQ("1.02", input_ports()[0].version);
|
| +
|
| ASSERT_EQ(2u, output_ports().size());
|
| + EXPECT_EQ("port-0-0", output_ports()[0].id);
|
| + EXPECT_EQ("vendor1", output_ports()[0].manufacturer);
|
| + EXPECT_EQ("device1", output_ports()[0].name);
|
| + EXPECT_EQ("1.02", output_ports()[0].version);
|
| + EXPECT_EQ("port-0-1", output_ports()[1].id);
|
| + EXPECT_EQ("vendor1", output_ports()[1].manufacturer);
|
| + EXPECT_EQ("device1", output_ports()[1].name);
|
| + EXPECT_EQ("1.02", output_ports()[1].version);
|
| +
|
| ASSERT_TRUE(manager_->input_stream());
|
| std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks();
|
| ASSERT_EQ(2u, manager_->output_streams().size());
|
| @@ -250,13 +283,13 @@ TEST_F(MidiManagerUsbTest, Initialize) {
|
| ASSERT_EQ(1u, jacks.size());
|
| EXPECT_EQ(2, jacks[0].endpoint_number());
|
|
|
| - EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
|
| + EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
|
| }
|
|
|
| TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) {
|
| scoped_ptr<FakeUsbMidiDevice> device1(new FakeUsbMidiDevice(&logger_));
|
| scoped_ptr<FakeUsbMidiDevice> device2(new FakeUsbMidiDevice(&logger_));
|
| - uint8 descriptor[] = {
|
| + uint8 descriptors[] = {
|
| 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75,
|
| 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01,
|
| 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
|
| @@ -270,8 +303,14 @@ TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) {
|
| 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25,
|
| 0x01, 0x01, 0x07,
|
| };
|
| - device1->SetDescriptor(ToVector(descriptor));
|
| - device2->SetDescriptor(ToVector(descriptor));
|
| + device1->SetDescriptors(ToVector(descriptors));
|
| + device1->SetManufacturer("vendor1");
|
| + device1->SetProductName("device1");
|
| + device1->SetDeviceVersion("1.02");
|
| + device2->SetDescriptors(ToVector(descriptors));
|
| + device2->SetManufacturer("vendor2");
|
| + device2->SetProductName("device2");
|
| + device2->SetDeviceVersion("98.76");
|
|
|
| Initialize();
|
| ScopedVector<UsbMidiDevice> devices;
|
| @@ -282,7 +321,33 @@ TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) {
|
| EXPECT_EQ(MIDI_OK, GetInitializationResult());
|
|
|
| ASSERT_EQ(2u, input_ports().size());
|
| + EXPECT_EQ("port-0-2", input_ports()[0].id);
|
| + EXPECT_EQ("vendor1", input_ports()[0].manufacturer);
|
| + EXPECT_EQ("device1", input_ports()[0].name);
|
| + EXPECT_EQ("1.02", input_ports()[0].version);
|
| + EXPECT_EQ("port-1-2", input_ports()[1].id);
|
| + EXPECT_EQ("vendor2", input_ports()[1].manufacturer);
|
| + EXPECT_EQ("device2", input_ports()[1].name);
|
| + EXPECT_EQ("98.76", input_ports()[1].version);
|
| +
|
| ASSERT_EQ(4u, output_ports().size());
|
| + EXPECT_EQ("port-0-0", output_ports()[0].id);
|
| + EXPECT_EQ("vendor1", output_ports()[0].manufacturer);
|
| + EXPECT_EQ("device1", output_ports()[0].name);
|
| + EXPECT_EQ("1.02", output_ports()[0].version);
|
| + EXPECT_EQ("port-0-1", output_ports()[1].id);
|
| + EXPECT_EQ("vendor1", output_ports()[1].manufacturer);
|
| + EXPECT_EQ("device1", output_ports()[1].name);
|
| + EXPECT_EQ("1.02", output_ports()[1].version);
|
| + EXPECT_EQ("port-1-0", output_ports()[2].id);
|
| + EXPECT_EQ("vendor2", output_ports()[2].manufacturer);
|
| + EXPECT_EQ("device2", output_ports()[2].name);
|
| + EXPECT_EQ("98.76", output_ports()[2].version);
|
| + EXPECT_EQ("port-1-1", output_ports()[3].id);
|
| + EXPECT_EQ("vendor2", output_ports()[3].manufacturer);
|
| + EXPECT_EQ("device2", output_ports()[3].name);
|
| + EXPECT_EQ("98.76", output_ports()[3].version);
|
| +
|
| ASSERT_TRUE(manager_->input_stream());
|
| std::vector<UsbMidiJack> jacks = manager_->input_stream()->jacks();
|
| ASSERT_EQ(4u, manager_->output_streams().size());
|
| @@ -292,8 +357,8 @@ TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) {
|
| EXPECT_EQ(2, jacks[0].endpoint_number());
|
|
|
| EXPECT_EQ(
|
| - "UsbMidiDevice::GetDescriptor\n"
|
| - "UsbMidiDevice::GetDescriptor\n",
|
| + "UsbMidiDevice::GetDescriptors\n"
|
| + "UsbMidiDevice::GetDescriptors\n",
|
| logger_.TakeLog());
|
| }
|
|
|
| @@ -305,10 +370,10 @@ TEST_F(MidiManagerUsbTest, InitializeFail) {
|
| EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
|
| }
|
|
|
| -TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptor) {
|
| +TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) {
|
| scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
|
| - uint8 descriptor[] = {0x04};
|
| - device->SetDescriptor(ToVector(descriptor));
|
| + uint8 descriptors[] = {0x04};
|
| + device->SetDescriptors(ToVector(descriptors));
|
|
|
| Initialize();
|
| ScopedVector<UsbMidiDevice> devices;
|
| @@ -316,13 +381,13 @@ TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptor) {
|
| EXPECT_FALSE(IsInitializationCallbackInvoked());
|
| RunCallbackUntilCallbackInvoked(true, &devices);
|
| EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
|
| - EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
|
| + EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
|
| }
|
|
|
| TEST_F(MidiManagerUsbTest, Send) {
|
| Initialize();
|
| scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
|
| - uint8 descriptor[] = {
|
| + uint8 descriptors[] = {
|
| 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
|
| 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
|
| 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
|
| @@ -339,7 +404,7 @@ TEST_F(MidiManagerUsbTest, Send) {
|
| 0x05, 0x25, 0x01, 0x01, 0x07,
|
| };
|
|
|
| - device->SetDescriptor(ToVector(descriptor));
|
| + device->SetDescriptors(ToVector(descriptors));
|
| uint8 data[] = {
|
| 0x90, 0x45, 0x7f,
|
| 0xf0, 0x00, 0x01, 0xf7,
|
| @@ -357,7 +422,7 @@ TEST_F(MidiManagerUsbTest, Send) {
|
| // invoke the task.
|
| base::RunLoop run_loop;
|
| run_loop.RunUntilIdle();
|
| - EXPECT_EQ("UsbMidiDevice::GetDescriptor\n"
|
| + EXPECT_EQ("UsbMidiDevice::GetDescriptors\n"
|
| "UsbMidiDevice::Send endpoint = 2 data = "
|
| "0x19 0x90 0x45 0x7f "
|
| "0x14 0xf0 0x00 0x01 "
|
| @@ -368,7 +433,7 @@ TEST_F(MidiManagerUsbTest, Send) {
|
|
|
| TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
|
| scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
|
| - uint8 descriptor[] = {
|
| + uint8 descriptors[] = {
|
| 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
|
| 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
|
| 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
|
| @@ -385,7 +450,7 @@ TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
|
| 0x05, 0x25, 0x01, 0x01, 0x07,
|
| };
|
|
|
| - device->SetDescriptor(ToVector(descriptor));
|
| + device->SetDescriptors(ToVector(descriptors));
|
| uint8 data[] = {
|
| 0x90, 0x45, 0x7f,
|
| 0xf0, 0x00, 0x01, 0xf7,
|
| @@ -398,7 +463,7 @@ TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
|
| RunCallbackUntilCallbackInvoked(true, &devices);
|
| EXPECT_EQ(MIDI_OK, GetInitializationResult());
|
| ASSERT_EQ(2u, manager_->output_streams().size());
|
| - EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
|
| + EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
|
|
|
| // The specified port index is invalid. The manager must ignore the request.
|
| manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0);
|
| @@ -411,7 +476,7 @@ TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) {
|
|
|
| TEST_F(MidiManagerUsbTest, Receive) {
|
| scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
|
| - uint8 descriptor[] = {
|
| + uint8 descriptors[] = {
|
| 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
|
| 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
|
| 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
|
| @@ -428,7 +493,7 @@ TEST_F(MidiManagerUsbTest, Receive) {
|
| 0x05, 0x25, 0x01, 0x01, 0x07,
|
| };
|
|
|
| - device->SetDescriptor(ToVector(descriptor));
|
| + device->SetDescriptors(ToVector(descriptors));
|
| uint8 data[] = {
|
| 0x09, 0x90, 0x45, 0x7f,
|
| 0x04, 0xf0, 0x00, 0x01,
|
| @@ -448,7 +513,7 @@ TEST_F(MidiManagerUsbTest, Receive) {
|
| base::TimeTicks());
|
| Finalize();
|
|
|
| - EXPECT_EQ("UsbMidiDevice::GetDescriptor\n"
|
| + EXPECT_EQ("UsbMidiDevice::GetDescriptors\n"
|
| "MidiManagerClient::ReceiveMidiData port_index = 0 "
|
| "data = 0x90 0x45 0x7f\n"
|
| "MidiManagerClient::ReceiveMidiData port_index = 0 "
|
| @@ -458,7 +523,7 @@ TEST_F(MidiManagerUsbTest, Receive) {
|
| }
|
|
|
| TEST_F(MidiManagerUsbTest, AttachDevice) {
|
| - uint8 descriptor[] = {
|
| + uint8 descriptors[] = {
|
| 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
|
| 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
|
| 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
|
| @@ -490,7 +555,7 @@ TEST_F(MidiManagerUsbTest, AttachDevice) {
|
| EXPECT_EQ("", logger_.TakeLog());
|
|
|
| scoped_ptr<FakeUsbMidiDevice> new_device(new FakeUsbMidiDevice(&logger_));
|
| - new_device->SetDescriptor(ToVector(descriptor));
|
| + new_device->SetDescriptors(ToVector(descriptors));
|
| manager_->OnDeviceAttached(new_device.Pass());
|
|
|
| ASSERT_EQ(1u, input_ports().size());
|
| @@ -502,7 +567,7 @@ TEST_F(MidiManagerUsbTest, AttachDevice) {
|
| EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id);
|
| ASSERT_EQ(1u, jacks.size());
|
| EXPECT_EQ(2, jacks[0].endpoint_number());
|
| - EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog());
|
| + EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
|
| }
|
|
|
| } // namespace
|
|
|