Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: device/usb/usb_service_unittest.cc

Issue 1314273002: Manage UsbService lifetime in DeviceClient implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/usb/usb_service_impl.cc ('k') | extensions/browser/api/usb/usb_apitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « device/usb/usb_service_impl.cc ('k') | extensions/browser/api/usb/usb_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698