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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc

Issue 13224004: Bluetooth: remove private members from BluetoothAdapter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix BluetoothApiTest.Events Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h> 5 #include <string.h>
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
10 #include "chrome/browser/extensions/api/permissions/permissions_api.h" 10 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 virtual void SetUpOnMainThread() OVERRIDE { 49 virtual void SetUpOnMainThread() OVERRIDE {
50 SetUpMockAdapter(); 50 SetUpMockAdapter();
51 } 51 }
52 52
53 virtual void CleanUpOnMainThread() OVERRIDE { 53 virtual void CleanUpOnMainThread() OVERRIDE {
54 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); 54 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
55 } 55 }
56 56
57 void SetUpMockAdapter() { 57 void SetUpMockAdapter() {
58 // The browser will clean this up when it is torn down 58 // The browser will clean this up when it is torn down
59 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>( 59 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>;
youngki 2013/04/02 12:30:31 I think using an empty parenthesis is prevalent (i
keybuk 2013/04/02 19:03:09 Done.
60 kAdapterAddress, kName);
61 event_router()->SetAdapterForTest(mock_adapter_); 60 event_router()->SetAdapterForTest(mock_adapter_);
62 61
63 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( 62 device1_.reset(new testing::NiceMock<MockBluetoothDevice>(
64 mock_adapter_, "d1", "11:12:13:14:15:16", 63 mock_adapter_, "d1", "11:12:13:14:15:16",
65 true /* paired */, false /* bonded */, true /* connected */)); 64 true /* paired */, false /* bonded */, true /* connected */));
66 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( 65 device2_.reset(new testing::NiceMock<MockBluetoothDevice>(
67 mock_adapter_, "d2", "21:22:23:24:25:26", 66 mock_adapter_, "d2", "21:22:23:24:25:26",
68 false /* paired */, true /* bonded */, false /* connected */)); 67 false /* paired */, true /* bonded */, false /* connected */));
69 } 68 }
70 69
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 const std::string& name, 135 const std::string& name,
137 const BluetoothDevice::SocketCallback& callback) { 136 const BluetoothDevice::SocketCallback& callback) {
138 scoped_refptr<device::MockBluetoothSocket> socket = 137 scoped_refptr<device::MockBluetoothSocket> socket =
139 new device::MockBluetoothSocket(); 138 new device::MockBluetoothSocket();
140 callback.Run(socket); 139 callback.Run(socket);
141 } 140 }
142 141
143 } // namespace 142 } // namespace
144 143
145 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) { 144 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) {
145 EXPECT_CALL(*mock_adapter_, address())
146 .WillOnce(testing::Return(kAdapterAddress));
147 EXPECT_CALL(*mock_adapter_, name())
148 .WillOnce(testing::Return(kName));
146 EXPECT_CALL(*mock_adapter_, IsPresent()) 149 EXPECT_CALL(*mock_adapter_, IsPresent())
147 .WillOnce(testing::Return(false)); 150 .WillOnce(testing::Return(false));
148 EXPECT_CALL(*mock_adapter_, IsPowered()) 151 EXPECT_CALL(*mock_adapter_, IsPowered())
149 .WillOnce(testing::Return(true)); 152 .WillOnce(testing::Return(true));
150 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 153 EXPECT_CALL(*mock_adapter_, IsDiscovering())
151 .WillOnce(testing::Return(false)); 154 .WillOnce(testing::Return(false));
152 155
153 scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state; 156 scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state;
154 get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction); 157 get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction);
155 158
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); 307 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied());
305 308
306 SetUpMockAdapter(); 309 SetUpMockAdapter();
307 event_router()->DeviceAdded(mock_adapter_, device2_.get()); 310 event_router()->DeviceAdded(mock_adapter_, device2_.get());
308 discovery_stopped.Reply("go"); 311 discovery_stopped.Reply("go");
309 312
310 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 313 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
311 } 314 }
312 315
313 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { 316 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) {
317 EXPECT_CALL(*mock_adapter_, address())
318 .WillOnce(testing::Return(kAdapterAddress));
319 EXPECT_CALL(*mock_adapter_, name())
320 .WillOnce(testing::Return(kName));
314 EXPECT_CALL(*mock_adapter_, IsPresent()) 321 EXPECT_CALL(*mock_adapter_, IsPresent())
315 .WillOnce(testing::Return(true)); 322 .WillOnce(testing::Return(true));
316 EXPECT_CALL(*mock_adapter_, IsPowered()) 323 EXPECT_CALL(*mock_adapter_, IsPowered())
317 .WillOnce(testing::Return(true)); 324 .WillOnce(testing::Return(true));
318 325
319 // Fake that the adapter is discovering 326 // Fake that the adapter is discovering
320 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 327 EXPECT_CALL(*mock_adapter_, IsDiscovering())
321 .WillOnce(testing::Return(true)); 328 .WillOnce(testing::Return(true));
322 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 329 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
323 330
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 362
356 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { 363 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) {
357 ResultCatcher catcher; 364 ResultCatcher catcher;
358 catcher.RestrictToProfile(browser()->profile()); 365 catcher.RestrictToProfile(browser()->profile());
359 366
360 // Load and wait for setup 367 // Load and wait for setup
361 ExtensionTestMessageListener listener("ready", true); 368 ExtensionTestMessageListener listener("ready", true);
362 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bluetooth/events"))); 369 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bluetooth/events")));
363 EXPECT_TRUE(listener.WaitUntilSatisfied()); 370 EXPECT_TRUE(listener.WaitUntilSatisfied());
364 371
372 EXPECT_CALL(*mock_adapter_, address())
373 .WillOnce(testing::Return(kAdapterAddress));
374 EXPECT_CALL(*mock_adapter_, name())
375 .WillOnce(testing::Return(kName));
365 EXPECT_CALL(*mock_adapter_, IsPresent()) 376 EXPECT_CALL(*mock_adapter_, IsPresent())
366 .WillOnce(testing::Return(false)); 377 .WillOnce(testing::Return(false));
367 EXPECT_CALL(*mock_adapter_, IsPowered()) 378 EXPECT_CALL(*mock_adapter_, IsPowered())
368 .WillOnce(testing::Return(false)); 379 .WillOnce(testing::Return(false));
369 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 380 EXPECT_CALL(*mock_adapter_, IsDiscovering())
370 .WillOnce(testing::Return(false)); 381 .WillOnce(testing::Return(false));
371 event_router()->AdapterPoweredChanged(mock_adapter_, false); 382 event_router()->AdapterPoweredChanged(mock_adapter_, false);
372 383
384 EXPECT_CALL(*mock_adapter_, address())
385 .WillOnce(testing::Return(kAdapterAddress));
386 EXPECT_CALL(*mock_adapter_, name())
387 .WillOnce(testing::Return(kName));
373 EXPECT_CALL(*mock_adapter_, IsPresent()) 388 EXPECT_CALL(*mock_adapter_, IsPresent())
374 .WillOnce(testing::Return(true)); 389 .WillOnce(testing::Return(true));
375 EXPECT_CALL(*mock_adapter_, IsPowered()) 390 EXPECT_CALL(*mock_adapter_, IsPowered())
376 .WillOnce(testing::Return(true)); 391 .WillOnce(testing::Return(true));
377 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 392 EXPECT_CALL(*mock_adapter_, IsDiscovering())
378 .WillOnce(testing::Return(true)); 393 .WillOnce(testing::Return(true));
379 event_router()->AdapterPresentChanged(mock_adapter_, true); 394 event_router()->AdapterPresentChanged(mock_adapter_, true);
380 395
396 EXPECT_CALL(*mock_adapter_, address())
397 .WillOnce(testing::Return(kAdapterAddress));
398 EXPECT_CALL(*mock_adapter_, name())
399 .WillOnce(testing::Return(kName));
381 EXPECT_CALL(*mock_adapter_, IsPresent()) 400 EXPECT_CALL(*mock_adapter_, IsPresent())
382 .WillOnce(testing::Return(true)); 401 .WillOnce(testing::Return(true));
383 EXPECT_CALL(*mock_adapter_, IsPowered()) 402 EXPECT_CALL(*mock_adapter_, IsPowered())
384 .WillOnce(testing::Return(true)); 403 .WillOnce(testing::Return(true));
385 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 404 EXPECT_CALL(*mock_adapter_, IsDiscovering())
386 .WillOnce(testing::Return(true)); 405 .WillOnce(testing::Return(true));
387 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 406 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
388 407
389 listener.Reply("go"); 408 listener.Reply("go");
390 409
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 491 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
473 492
474 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address())) 493 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address()))
475 .WillOnce(testing::Return(device1_.get())); 494 .WillOnce(testing::Return(device1_.get()));
476 EXPECT_CALL(*device1_, 495 EXPECT_CALL(*device1_,
477 ConnectToService(testing::_, testing::_)) 496 ConnectToService(testing::_, testing::_))
478 .WillOnce(testing::Invoke(CallConnectToServiceCallback)); 497 .WillOnce(testing::Invoke(CallConnectToServiceCallback));
479 498
480 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_; 499 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_;
481 } 500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698