| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/test/test_io_thread.h" |
| 7 #include "device/test/usb_test_gadget.h" | 8 #include "device/test/usb_test_gadget.h" |
| 8 #include "device/usb/usb_device.h" | 9 #include "device/usb/usb_device.h" |
| 9 #include "device/usb/usb_device_handle.h" | 10 #include "device/usb/usb_device_handle.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace device { | 13 namespace device { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class UsbServiceTest : public ::testing::Test { | 17 class UsbServiceTest : public ::testing::Test { |
| 17 public: | 18 public: |
| 18 void SetUp() override { message_loop_.reset(new base::MessageLoopForIO); } | 19 void SetUp() override { |
| 20 message_loop_.reset(new base::MessageLoopForUI); |
| 21 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart)); |
| 22 } |
| 19 | 23 |
| 20 private: | 24 protected: |
| 21 scoped_ptr<base::MessageLoop> message_loop_; | 25 scoped_ptr<base::MessageLoop> message_loop_; |
| 26 scoped_ptr<base::TestIOThread> io_thread_; |
| 22 }; | 27 }; |
| 23 | 28 |
| 24 TEST_F(UsbServiceTest, ClaimGadget) { | 29 TEST_F(UsbServiceTest, ClaimGadget) { |
| 25 if (!UsbTestGadget::IsTestEnabled()) return; | 30 if (!UsbTestGadget::IsTestEnabled()) return; |
| 26 | 31 |
| 27 scoped_ptr<UsbTestGadget> gadget = UsbTestGadget::Claim(); | 32 scoped_ptr<UsbTestGadget> gadget = |
| 33 UsbTestGadget::Claim(io_thread_->task_runner()); |
| 28 ASSERT_TRUE(gadget.get()); | 34 ASSERT_TRUE(gadget.get()); |
| 29 | 35 |
| 30 scoped_refptr<UsbDevice> device = gadget->GetDevice(); | 36 scoped_refptr<UsbDevice> device = gadget->GetDevice(); |
| 31 base::string16 utf16; | 37 ASSERT_EQ("Google Inc.", base::UTF16ToUTF8(device->manufacturer_string())); |
| 32 ASSERT_TRUE(device->GetManufacturer(&utf16)); | 38 ASSERT_EQ("Test Gadget (default state)", |
| 33 ASSERT_EQ("Google Inc.", base::UTF16ToUTF8(utf16)); | 39 base::UTF16ToUTF8(device->product_string())); |
| 34 | |
| 35 ASSERT_TRUE(device->GetProduct(&utf16)); | |
| 36 ASSERT_EQ("Test Gadget (default state)", base::UTF16ToUTF8(utf16)); | |
| 37 | |
| 38 ASSERT_TRUE(device->GetSerialNumber(&utf16)); | |
| 39 ASSERT_EQ(gadget->GetSerialNumber(), base::UTF16ToUTF8(utf16)); | |
| 40 } | 40 } |
| 41 | 41 |
| 42 TEST_F(UsbServiceTest, DisconnectAndReconnect) { | 42 TEST_F(UsbServiceTest, DisconnectAndReconnect) { |
| 43 if (!UsbTestGadget::IsTestEnabled()) return; | 43 if (!UsbTestGadget::IsTestEnabled()) return; |
| 44 | 44 |
| 45 scoped_ptr<UsbTestGadget> gadget = UsbTestGadget::Claim(); | 45 scoped_ptr<UsbTestGadget> gadget = |
| 46 UsbTestGadget::Claim(io_thread_->task_runner()); |
| 46 ASSERT_TRUE(gadget.get()); | 47 ASSERT_TRUE(gadget.get()); |
| 47 ASSERT_TRUE(gadget->Disconnect()); | 48 ASSERT_TRUE(gadget->Disconnect()); |
| 48 ASSERT_TRUE(gadget->Reconnect()); | 49 ASSERT_TRUE(gadget->Reconnect()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 } // namespace | 52 } // namespace |
| 52 | 53 |
| 53 } // namespace device | 54 } // namespace device |
| OLD | NEW |