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

Side by Side Diff: device/hid/hid_connection_unittest.cc

Issue 542153004: Make the device::HidService destructor protected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « no previous file | device/hid/hid_service.h » ('j') | device/hid/hid_service.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 }; 66 };
67 67
68 } // namespace 68 } // namespace
69 69
70 class HidConnectionTest : public testing::Test { 70 class HidConnectionTest : public testing::Test {
71 protected: 71 protected:
72 virtual void SetUp() OVERRIDE { 72 virtual void SetUp() OVERRIDE {
73 if (!UsbTestGadget::IsTestEnabled()) return; 73 if (!UsbTestGadget::IsTestEnabled()) return;
74 74
75 message_loop_.reset(new base::MessageLoopForIO()); 75 message_loop_.reset(new base::MessageLoopForIO());
76 service_.reset(HidService::GetInstance( 76 service_ = HidService::GetInstance(message_loop_->message_loop_proxy());
77 message_loop_->message_loop_proxy()));
78 ASSERT_TRUE(service_); 77 ASSERT_TRUE(service_);
79 78
80 test_gadget_ = UsbTestGadget::Claim(); 79 test_gadget_ = UsbTestGadget::Claim();
81 ASSERT_TRUE(test_gadget_); 80 ASSERT_TRUE(test_gadget_);
82 ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO)); 81 ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO));
83 82
84 device_id_ = kInvalidHidDeviceId; 83 device_id_ = kInvalidHidDeviceId;
85 84
86 base::RunLoop run_loop; 85 base::RunLoop run_loop;
87 message_loop_->PostDelayedTask( 86 message_loop_->PostDelayedTask(
(...skipping 24 matching lines...) Expand all
112 FROM_HERE, 111 FROM_HERE,
113 base::Bind(&HidConnectionTest::FindDevice, base::Unretained(this), 112 base::Bind(&HidConnectionTest::FindDevice, base::Unretained(this),
114 done, retries), 113 done, retries),
115 base::TimeDelta::FromMilliseconds(10)); 114 base::TimeDelta::FromMilliseconds(10));
116 } else { 115 } else {
117 message_loop_->PostTask(FROM_HERE, done); 116 message_loop_->PostTask(FROM_HERE, done);
118 } 117 }
119 } 118 }
120 119
121 scoped_ptr<base::MessageLoopForIO> message_loop_; 120 scoped_ptr<base::MessageLoopForIO> message_loop_;
122 scoped_ptr<HidService> service_; 121 HidService* service_;
123 scoped_ptr<UsbTestGadget> test_gadget_; 122 scoped_ptr<UsbTestGadget> test_gadget_;
124 HidDeviceId device_id_; 123 HidDeviceId device_id_;
125 }; 124 };
126 125
127 TEST_F(HidConnectionTest, ReadWrite) { 126 TEST_F(HidConnectionTest, ReadWrite) {
128 if (!UsbTestGadget::IsTestEnabled()) return; 127 if (!UsbTestGadget::IsTestEnabled()) return;
129 128
130 scoped_refptr<HidConnection> conn = service_->Connect(device_id_); 129 scoped_refptr<HidConnection> conn = service_->Connect(device_id_);
131 ASSERT_TRUE(conn.get()); 130 ASSERT_TRUE(conn.get());
132 131
(...skipping 13 matching lines...) Expand all
146 ASSERT_TRUE(read_callback.WaitForResult()); 145 ASSERT_TRUE(read_callback.WaitForResult());
147 ASSERT_EQ(9UL, read_callback.size()); 146 ASSERT_EQ(9UL, read_callback.size());
148 ASSERT_EQ(0, read_callback.buffer()->data()[0]); 147 ASSERT_EQ(0, read_callback.buffer()->data()[0]);
149 for (int j = 1; j < buffer->size(); ++j) { 148 for (int j = 1; j < buffer->size(); ++j) {
150 ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]); 149 ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]);
151 } 150 }
152 } 151 }
153 } 152 }
154 153
155 } // namespace device 154 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/hid/hid_service.h » ('j') | device/hid/hid_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698