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

Side by Side Diff: extensions/browser/api/bluetooth/bluetooth_private_apitest.cc

Issue 2137013005: [Extensions] Code Cleanup - Remove redundant smart-ptr get()s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 ~BluetoothPrivateApiTest() override {} 61 ~BluetoothPrivateApiTest() override {}
62 62
63 void SetUpOnMainThread() override { 63 void SetUpOnMainThread() override {
64 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 64 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
65 switches::kWhitelistedExtensionID, kTestExtensionId); 65 switches::kWhitelistedExtensionID, kTestExtensionId);
66 mock_adapter_ = new NiceMock<MockBluetoothAdapter>(); 66 mock_adapter_ = new NiceMock<MockBluetoothAdapter>();
67 event_router()->SetAdapterForTest(mock_adapter_.get()); 67 event_router()->SetAdapterForTest(mock_adapter_.get());
68 mock_device_.reset(new NiceMock<MockBluetoothDevice>( 68 mock_device_.reset(new NiceMock<MockBluetoothDevice>(
69 mock_adapter_.get(), 0, kDeviceName, kDeviceAddress, false, false)); 69 mock_adapter_.get(), 0, kDeviceName, kDeviceAddress, false, false));
70 ON_CALL(*mock_adapter_.get(), GetDevice(kDeviceAddress)) 70 ON_CALL(*mock_adapter_, GetDevice(kDeviceAddress))
71 .WillByDefault(Return(mock_device_.get())); 71 .WillByDefault(Return(mock_device_.get()));
72 ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(true)); 72 ON_CALL(*mock_adapter_, IsPresent()).WillByDefault(Return(true));
73 } 73 }
74 74
75 void TearDownOnMainThread() override {} 75 void TearDownOnMainThread() override {}
76 76
77 BluetoothEventRouter* event_router() { 77 BluetoothEventRouter* event_router() {
78 return BluetoothAPI::Get(browser()->profile())->event_router(); 78 return BluetoothAPI::Get(browser()->profile())->event_router();
79 } 79 }
80 80
81 void SetName(const std::string& name, const base::Closure& callback) { 81 void SetName(const std::string& name, const base::Closure& callback) {
82 adapter_name_ = name; 82 adapter_name_ = name;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 NiceMock<MockBluetoothDiscoverySession>* mock_discovery_session_; 153 NiceMock<MockBluetoothDiscoverySession>* mock_discovery_session_;
154 }; 154 };
155 155
156 ACTION_TEMPLATE(InvokeCallbackArgument, 156 ACTION_TEMPLATE(InvokeCallbackArgument,
157 HAS_1_TEMPLATE_PARAMS(int, k), 157 HAS_1_TEMPLATE_PARAMS(int, k),
158 AND_0_VALUE_PARAMS()) { 158 AND_0_VALUE_PARAMS()) {
159 ::std::tr1::get<k>(args).Run(); 159 ::std::tr1::get<k>(args).Run();
160 } 160 }
161 161
162 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, SetAdapterState) { 162 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, SetAdapterState) {
163 ON_CALL(*mock_adapter_.get(), GetName()) 163 ON_CALL(*mock_adapter_, GetName())
164 .WillByDefault(ReturnPointee(&adapter_name_)); 164 .WillByDefault(ReturnPointee(&adapter_name_));
165 ON_CALL(*mock_adapter_.get(), IsPowered()) 165 ON_CALL(*mock_adapter_, IsPowered())
166 .WillByDefault(ReturnPointee(&adapter_powered_)); 166 .WillByDefault(ReturnPointee(&adapter_powered_));
167 ON_CALL(*mock_adapter_.get(), IsDiscoverable()) 167 ON_CALL(*mock_adapter_, IsDiscoverable())
168 .WillByDefault(ReturnPointee(&adapter_discoverable_)); 168 .WillByDefault(ReturnPointee(&adapter_discoverable_));
169 169
170 EXPECT_CALL(*mock_adapter_.get(), SetName("Dome", _, _)).WillOnce( 170 EXPECT_CALL(*mock_adapter_, SetName("Dome", _, _))
171 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetName))); 171 .WillOnce(
172 EXPECT_CALL(*mock_adapter_.get(), SetPowered(true, _, _)).WillOnce( 172 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetName)));
173 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetPowered))); 173 EXPECT_CALL(*mock_adapter_, SetPowered(true, _, _))
174 EXPECT_CALL(*mock_adapter_.get(), SetDiscoverable(true, _, _)).WillOnce( 174 .WillOnce(
175 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetDiscoverable))); 175 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetPowered)));
176 EXPECT_CALL(*mock_adapter_, SetDiscoverable(true, _, _))
177 .WillOnce(WithArgs<0, 1>(
178 Invoke(this, &BluetoothPrivateApiTest::SetDiscoverable)));
176 179
177 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/adapter_state")) 180 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/adapter_state"))
178 << message_; 181 << message_;
179 } 182 }
180 183
181 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, NoBluetoothAdapter) { 184 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, NoBluetoothAdapter) {
182 ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(false)); 185 ON_CALL(*mock_adapter_, IsPresent()).WillByDefault(Return(false));
183 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/no_adapter")) 186 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/no_adapter"))
184 << message_; 187 << message_;
185 } 188 }
186 189
187 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, CancelPairing) { 190 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, CancelPairing) {
188 InSequence s; 191 InSequence s;
189 EXPECT_CALL(*mock_adapter_.get(), 192 EXPECT_CALL(*mock_adapter_,
190 AddPairingDelegate( 193 AddPairingDelegate(
191 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) 194 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH))
192 .WillOnce(WithoutArgs(Invoke( 195 .WillOnce(WithoutArgs(Invoke(
193 this, &BluetoothPrivateApiTest::DispatchAuthorizePairingEvent))); 196 this, &BluetoothPrivateApiTest::DispatchAuthorizePairingEvent)));
194 EXPECT_CALL(*mock_device_, ExpectingConfirmation()) 197 EXPECT_CALL(*mock_device_, ExpectingConfirmation())
195 .WillRepeatedly(Return(true)); 198 .WillRepeatedly(Return(true));
196 EXPECT_CALL(*mock_device_, CancelPairing()); 199 EXPECT_CALL(*mock_device_, CancelPairing());
197 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/cancel_pairing")) 200 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/cancel_pairing"))
198 << message_; 201 << message_;
199 } 202 }
200 203
201 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PincodePairing) { 204 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PincodePairing) {
202 EXPECT_CALL(*mock_adapter_.get(), 205 EXPECT_CALL(*mock_adapter_,
203 AddPairingDelegate( 206 AddPairingDelegate(
204 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) 207 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH))
205 .WillOnce(WithoutArgs( 208 .WillOnce(WithoutArgs(
206 Invoke(this, &BluetoothPrivateApiTest::DispatchPincodePairingEvent))); 209 Invoke(this, &BluetoothPrivateApiTest::DispatchPincodePairingEvent)));
207 EXPECT_CALL(*mock_device_, ExpectingPinCode()).WillRepeatedly(Return(true)); 210 EXPECT_CALL(*mock_device_, ExpectingPinCode()).WillRepeatedly(Return(true));
208 EXPECT_CALL(*mock_device_, SetPinCode("abbbbbbk")); 211 EXPECT_CALL(*mock_device_, SetPinCode("abbbbbbk"));
209 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/pincode_pairing")) 212 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/pincode_pairing"))
210 << message_; 213 << message_;
211 } 214 }
212 215
213 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PasskeyPairing) { 216 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PasskeyPairing) {
214 EXPECT_CALL(*mock_adapter_.get(), 217 EXPECT_CALL(*mock_adapter_,
215 AddPairingDelegate( 218 AddPairingDelegate(
216 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) 219 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH))
217 .WillOnce(WithoutArgs( 220 .WillOnce(WithoutArgs(
218 Invoke(this, &BluetoothPrivateApiTest::DispatchPasskeyPairingEvent))); 221 Invoke(this, &BluetoothPrivateApiTest::DispatchPasskeyPairingEvent)));
219 EXPECT_CALL(*mock_device_, ExpectingPasskey()).WillRepeatedly(Return(true)); 222 EXPECT_CALL(*mock_device_, ExpectingPasskey()).WillRepeatedly(Return(true));
220 EXPECT_CALL(*mock_device_, SetPasskey(900531)); 223 EXPECT_CALL(*mock_device_, SetPasskey(900531));
221 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/passkey_pairing")) 224 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/passkey_pairing"))
222 << message_; 225 << message_;
223 } 226 }
224 227
225 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, DisconnectAll) { 228 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, DisconnectAll) {
226 EXPECT_CALL(*mock_device_, IsConnected()) 229 EXPECT_CALL(*mock_device_, IsConnected())
227 .Times(6) 230 .Times(6)
228 .WillOnce(Return(false)) 231 .WillOnce(Return(false))
229 .WillOnce(Return(true)) 232 .WillOnce(Return(true))
230 .WillOnce(Return(false)) 233 .WillOnce(Return(false))
231 .WillRepeatedly(Return(true)); 234 .WillRepeatedly(Return(true));
232 EXPECT_CALL(*mock_device_, Disconnect(_, _)) 235 EXPECT_CALL(*mock_device_, Disconnect(_, _))
233 .Times(3) 236 .Times(3)
234 .WillOnce(InvokeCallbackArgument<1>()) 237 .WillOnce(InvokeCallbackArgument<1>())
235 .WillOnce(InvokeCallbackArgument<1>()) 238 .WillOnce(InvokeCallbackArgument<1>())
236 .WillOnce(InvokeCallbackArgument<0>()); 239 .WillOnce(InvokeCallbackArgument<0>());
237 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/disconnect")) 240 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/disconnect"))
238 << message_; 241 << message_;
239 } 242 }
240 243
241 // Device::Forget not implemented on OSX. 244 // Device::Forget not implemented on OSX.
242 #if !defined(OS_MACOSX) 245 #if !defined(OS_MACOSX)
243 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, ForgetDevice) { 246 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, ForgetDevice) {
244 EXPECT_CALL(*mock_device_.get(), Forget(_, _)) 247 EXPECT_CALL(*mock_device_, Forget(_, _))
245 .WillOnce( 248 .WillOnce(
246 WithArgs<0>(Invoke(this, &BluetoothPrivateApiTest::ForgetDevice))); 249 WithArgs<0>(Invoke(this, &BluetoothPrivateApiTest::ForgetDevice)));
247 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/forget_device")) 250 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/forget_device"))
248 << message_; 251 << message_;
249 } 252 }
250 #endif 253 #endif
251 254
252 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, DiscoveryFilter) { 255 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, DiscoveryFilter) {
253 mock_discovery_session_ = new NiceMock<MockBluetoothDiscoverySession>(); 256 mock_discovery_session_ = new NiceMock<MockBluetoothDiscoverySession>();
254 257
255 BluetoothDiscoveryFilter discovery_filter(device::BLUETOOTH_TRANSPORT_LE); 258 BluetoothDiscoveryFilter discovery_filter(device::BLUETOOTH_TRANSPORT_LE);
256 discovery_filter.SetPathloss(50); 259 discovery_filter.SetPathloss(50);
257 discovery_filter.AddUUID(BluetoothUUID("cafe")); 260 discovery_filter.AddUUID(BluetoothUUID("cafe"));
258 discovery_filter.AddUUID( 261 discovery_filter.AddUUID(
259 BluetoothUUID("0000bebe-0000-1000-8000-00805f9b34fb")); 262 BluetoothUUID("0000bebe-0000-1000-8000-00805f9b34fb"));
260 263
261 EXPECT_CALL(*mock_adapter_.get(), StartDiscoverySessionWithFilterRaw( 264 EXPECT_CALL(*mock_adapter_, StartDiscoverySessionWithFilterRaw(
262 IsFilterEqual(&discovery_filter), _, _)) 265 IsFilterEqual(&discovery_filter), _, _))
263 .Times(1) 266 .Times(1)
264 .WillOnce(WithArgs<1>(Invoke( 267 .WillOnce(WithArgs<1>(Invoke(
265 this, &BluetoothPrivateApiTest::CallSetDiscoveryFilterCallback))); 268 this, &BluetoothPrivateApiTest::CallSetDiscoveryFilterCallback)));
266 EXPECT_CALL(*mock_discovery_session_, IsActive()) 269 EXPECT_CALL(*mock_discovery_session_, IsActive())
267 .Times(1) 270 .Times(1)
268 .WillOnce(Return(true)); 271 .WillOnce(Return(true));
269 EXPECT_CALL(*mock_discovery_session_, 272 EXPECT_CALL(*mock_discovery_session_,
270 SetDiscoveryFilterRaw(Eq(nullptr), _, _)) 273 SetDiscoveryFilterRaw(Eq(nullptr), _, _))
271 .Times(1) 274 .Times(1)
272 .WillOnce(InvokeCallbackArgument<1>()); 275 .WillOnce(InvokeCallbackArgument<1>());
273 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/discovery_filter")) 276 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/discovery_filter"))
274 << message_; 277 << message_;
275 } 278 }
276 279
277 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, Connect) { 280 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, Connect) {
278 EXPECT_CALL(*mock_device_.get(), IsConnected()) 281 EXPECT_CALL(*mock_device_, IsConnected())
279 .Times(2) 282 .Times(2)
280 .WillOnce(Return(false)) 283 .WillOnce(Return(false))
281 .WillOnce(Return(true)); 284 .WillOnce(Return(true));
282 EXPECT_CALL(*mock_device_.get(), Connect(_, _, _)) 285 EXPECT_CALL(*mock_device_, Connect(_, _, _))
283 .WillOnce(InvokeCallbackArgument<1>()); 286 .WillOnce(InvokeCallbackArgument<1>());
284 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/connect")) 287 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/connect"))
285 << message_; 288 << message_;
286 } 289 }
287 290
288 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, Pair) { 291 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, Pair) {
289 EXPECT_CALL(*mock_adapter_.get(), 292 EXPECT_CALL(*mock_adapter_,
290 AddPairingDelegate( 293 AddPairingDelegate(
291 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)); 294 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH));
292 EXPECT_CALL(*mock_device_, ExpectingConfirmation()) 295 EXPECT_CALL(*mock_device_, ExpectingConfirmation())
293 .WillRepeatedly(Return(true)); 296 .WillRepeatedly(Return(true));
294 EXPECT_CALL(*mock_device_.get(), Pair(_, _, _)) 297 EXPECT_CALL(*mock_device_, Pair(_, _, _))
295 .WillOnce(DoAll( 298 .WillOnce(DoAll(
296 WithoutArgs(Invoke( 299 WithoutArgs(Invoke(
297 this, 300 this,
298 &BluetoothPrivateApiTest::DispatchConfirmPasskeyPairingEvent)), 301 &BluetoothPrivateApiTest::DispatchConfirmPasskeyPairingEvent)),
299 InvokeCallbackArgument<1>())); 302 InvokeCallbackArgument<1>()));
300 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/pair")) << message_; 303 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/pair")) << message_;
301 } 304 }
302 305
303 } // namespace extensions 306 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698