Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" | |
| 6 | |
| 7 #include "device/bluetooth/bluetooth_discovery_session.h" | |
| 8 #include "testing/gmock/include/gmock/gmock.h" | |
| 9 | |
|
scheib
2015/05/12 01:16:28
Add using statements to simplify code below, such
ortuno
2015/05/12 19:33:20
Done.
| |
| 10 namespace content { | |
| 11 | |
| 12 const uint32 kUnspecifiedDeviceClass = | |
| 13 0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband | |
| 14 | |
| 15 LayoutTestBluetoothAdapterProvider::LayoutTestBluetoothAdapterProvider() | |
| 16 : uuid1(new BluetoothUUID("1800")), uuid2(new BluetoothUUID("1801")) { | |
| 17 } | |
| 18 LayoutTestBluetoothAdapterProvider::~LayoutTestBluetoothAdapterProvider() { | |
|
scheib
2015/05/11 20:19:26
Insert blank line above.
ortuno
2015/05/12 19:33:19
Done.
| |
| 19 } | |
| 20 | |
| 21 void LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( | |
| 22 const BluetoothAdapterFactory::AdapterCallback& callback, | |
| 23 const std::string& adapter) { | |
| 24 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified | |
| 25 if (adapter == "RejectRequestDevice_NotFoundError" || | |
| 26 adapter == "EmptyAdapter") | |
| 27 GetEmptyAdapter(callback); | |
| 28 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified | |
| 29 else if (adapter == "Single Empty Device" || | |
| 30 adapter == "SingleEmptyDeviceAdapter") | |
| 31 GetSingleEmptyDeviceAdapter(callback); | |
| 32 else if (adapter == "") { | |
| 33 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) | |
| 34 BluetoothAdapterFactory::GetAdapter(callback); | |
| 35 } else | |
| 36 NOTREACHED(); | |
|
scheib
2015/05/12 01:16:28
"if one part of an if-else statement uses curly br
ortuno
2015/05/12 19:33:19
Done.
| |
| 37 } | |
| 38 | |
| 39 void LayoutTestBluetoothAdapterProvider::GetEmptyAdapter( | |
| 40 const BluetoothAdapterFactory::AdapterCallback& callback) { | |
| 41 testing::NiceMock<MockBluetoothAdapter>* mock_adapter_ = | |
|
scheib
2015/05/12 01:16:28
Let's keep a scoped_refptr in this class to the ad
ortuno
2015/05/12 19:33:20
Done.
Jeffrey Yasskin
2015/05/12 22:37:49
We shouldn't stash single-function-call objects in
scheib
2015/05/13 04:11:05
The reason I discussed with ortuno in person was t
Jeffrey Yasskin
2015/05/13 19:40:50
Yeah, even if it increases the size of a line or t
| |
| 42 new testing::NiceMock<MockBluetoothAdapter>(); | |
| 43 ON_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_)) | |
| 44 .WillByDefault( | |
| 45 testing::Invoke(this, &LayoutTestBluetoothAdapterProvider:: | |
|
scheib
2015/05/12 01:16:28
The LayoutTestBluetoothAdapterProvider:: is redund
ortuno
2015/05/12 19:33:19
It is not :(
| |
| 46 SuccessfulDiscoverySessionCallback)); | |
| 47 ON_CALL(*mock_adapter_, GetDevices()) | |
| 48 .WillByDefault(testing::Return(BluetoothAdapter::ConstDeviceList())); | |
| 49 callback.Run(scoped_refptr<BluetoothAdapter>(mock_adapter_)); | |
|
scheib
2015/05/12 01:16:27
These should then be able to collapse to just call
ortuno
2015/05/12 19:33:19
Done.
| |
| 50 } | |
| 51 | |
| 52 void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter( | |
| 53 const BluetoothAdapterFactory::AdapterCallback& callback) { | |
| 54 testing::NiceMock<MockBluetoothAdapter>* mock_adapter_ = | |
| 55 new testing::NiceMock<MockBluetoothAdapter>(); | |
| 56 ON_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_)) | |
| 57 .WillByDefault( | |
| 58 testing::Invoke(this, &LayoutTestBluetoothAdapterProvider:: | |
| 59 SuccessfulDiscoverySessionCallback)); | |
| 60 SetUpMockEmptyDevice(mock_adapter_); | |
| 61 BluetoothAdapter::ConstDeviceList devices; | |
| 62 devices.push_back(empty_device_.get()); | |
| 63 ON_CALL(*mock_adapter_, GetDevices()).WillByDefault(testing::Return(devices)); | |
| 64 callback.Run(scoped_refptr<BluetoothAdapter>(mock_adapter_)); | |
| 65 } | |
| 66 void LayoutTestBluetoothAdapterProvider::SetUpMockEmptyDevice( | |
| 67 MockBluetoothAdapter* adapter) { | |
| 68 testing::NiceMock<MockBluetoothDevice>* empty_device = | |
| 69 new testing::NiceMock<MockBluetoothDevice>( | |
| 70 adapter, kUnspecifiedDeviceClass, "Empty Mock Device name", | |
| 71 "Empty Mock Device instanceID", true, /* Paired */ | |
| 72 true /* Connected */); | |
| 73 ON_CALL(*empty_device, GetVendorIDSource()) | |
| 74 .WillByDefault(testing::Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | |
| 75 ON_CALL(*empty_device, GetVendorID()).WillByDefault(testing::Return(0xFFFF)); | |
| 76 ON_CALL(*empty_device, GetProductID()).WillByDefault(testing::Return(1)); | |
| 77 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(testing::Return(2)); | |
| 78 BluetoothDevice::UUIDList list; | |
| 79 list.push_back(*uuid1.get()); | |
| 80 list.push_back(*uuid2.get()); | |
| 81 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(testing::Return(list)); | |
| 82 empty_device_.reset(empty_device); | |
|
scheib
2015/05/12 01:16:28
Just set the device member at the top of this meth
ortuno
2015/05/12 19:33:20
Done.
| |
| 83 } | |
| 84 | |
| 85 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionCallback( | |
| 86 const BluetoothAdapter::DiscoverySessionCallback& callback, | |
| 87 const BluetoothAdapter::ErrorCallback& error_callback) { | |
| 88 testing::NiceMock<MockBluetoothDiscoverySession>* discovery_session = | |
| 89 new testing::NiceMock<MockBluetoothDiscoverySession>(); | |
| 90 ON_CALL(*discovery_session, Stop(testing::_, testing::_)) | |
| 91 .WillByDefault(testing::Invoke(SuccessfulStopDiscoverySessionCallback)); | |
| 92 callback.Run(scoped_ptr<BluetoothDiscoverySession>(discovery_session)); | |
| 93 } | |
| 94 | |
| 95 void LayoutTestBluetoothAdapterProvider::SuccessfulStopDiscoverySessionCallback( | |
| 96 const base::Closure& callback, | |
| 97 const base::Closure& error_callback) { | |
| 98 callback.Run(); | |
| 99 } | |
| 100 | |
| 101 } // namespace content | |
| OLD | NEW |