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