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