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_adapter.h" | |
| 8 #include "device/bluetooth/bluetooth_device.h" | |
| 9 #include "device/bluetooth/bluetooth_discovery_session.h" | |
| 10 #include "device/bluetooth/bluetooth_uuid.h" | |
| 11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | |
| 12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 | |
| 15 using device::BluetoothAdapter; | |
| 16 using device::BluetoothAdapterFactory; | |
| 17 using device::BluetoothDevice; | |
| 18 using device::BluetoothDiscoverySession; | |
| 19 using device::BluetoothUUID; | |
| 20 using device::MockBluetoothAdapter; | |
| 21 using device::MockBluetoothDevice; | |
| 22 using device::MockBluetoothDiscoverySession; | |
| 23 using testing::Invoke; | |
| 24 using testing::Return; | |
| 25 using testing::NiceMock; | |
| 26 using testing::_; | |
| 27 | |
| 28 namespace content { | |
| 29 | |
| 30 scoped_refptr<BluetoothAdapter> | |
|
scheib
2015/05/16 02:39:14
It's common, and I think useful, to add "// static
ortuno
2015/05/18 17:41:55
Done.
| |
| 31 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( | |
| 32 const std::string& fake_adapter_name) { | |
| 33 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified | |
| 34 if (fake_adapter_name == "RejectRequestDevice_NotFoundError" || | |
| 35 fake_adapter_name == "EmptyAdapter") { | |
| 36 return GetEmptyAdapter(); | |
| 37 } | |
| 38 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified | |
| 39 else if (fake_adapter_name == "Single Empty Device" || | |
| 40 fake_adapter_name == "SingleEmptyDeviceAdapter") { | |
| 41 return GetSingleEmptyDeviceAdapter(); | |
| 42 } else if (fake_adapter_name == "") { | |
| 43 return NULL; | |
| 44 } | |
| 45 NOTREACHED(); | |
| 46 return NULL; | |
| 47 } | |
| 48 | |
| 49 scoped_refptr<NiceMock<MockBluetoothAdapter>> | |
| 50 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { | |
| 51 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( | |
| 52 new NiceMock<MockBluetoothAdapter>()); | |
| 53 | |
| 54 ON_CALL(*adapter, StartDiscoverySession(_, _)) | |
| 55 .WillByDefault(Invoke( | |
| 56 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); | |
| 57 | |
| 58 ON_CALL(*adapter, GetDevices()) | |
| 59 .WillByDefault(Return(adapter->GetMockDevices())); | |
| 60 | |
| 61 return adapter.Pass(); | |
| 62 } | |
| 63 | |
| 64 scoped_refptr<NiceMock<MockBluetoothAdapter>> | |
| 65 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { | |
| 66 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( | |
| 67 new NiceMock<MockBluetoothAdapter>()); | |
| 68 | |
| 69 ON_CALL(*adapter, StartDiscoverySession(_, _)) | |
| 70 .WillByDefault(Invoke( | |
| 71 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); | |
| 72 | |
| 73 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); | |
| 74 | |
| 75 ON_CALL(*adapter, GetDevices()) | |
| 76 .WillByDefault(Return(adapter->GetMockDevices())); | |
| 77 | |
| 78 return adapter.Pass(); | |
| 79 } | |
| 80 | |
| 81 scoped_ptr<NiceMock<MockBluetoothDevice>> | |
| 82 LayoutTestBluetoothAdapterProvider::GetEmptyDevice( | |
| 83 MockBluetoothAdapter* adapter) { | |
| 84 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device( | |
| 85 new NiceMock<MockBluetoothDevice>( | |
| 86 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name", | |
| 87 "Empty Mock Device instanceID", true /* Paired */, | |
| 88 true /* Connected */)); | |
| 89 | |
| 90 ON_CALL(*empty_device, GetVendorIDSource()) | |
| 91 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | |
| 92 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); | |
| 93 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); | |
| 94 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); | |
| 95 | |
| 96 BluetoothDevice::UUIDList list; | |
| 97 list.push_back(BluetoothUUID("1800")); | |
| 98 list.push_back(BluetoothUUID("1801")); | |
| 99 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); | |
| 100 return empty_device.Pass(); | |
| 101 } | |
| 102 | |
| 103 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession( | |
| 104 const BluetoothAdapter::DiscoverySessionCallback& callback, | |
| 105 const BluetoothAdapter::ErrorCallback& error_callback) { | |
| 106 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( | |
| 107 new NiceMock<MockBluetoothDiscoverySession>()); | |
| 108 | |
| 109 ON_CALL(*discovery_session, Stop(_, _)) | |
| 110 .WillByDefault(Invoke( | |
| 111 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop)); | |
| 112 | |
| 113 callback.Run(discovery_session.Pass()); | |
| 114 } | |
| 115 | |
| 116 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop( | |
| 117 const base::Closure& callback, | |
| 118 const base::Closure& error_callback) { | |
| 119 callback.Run(); | |
| 120 } | |
| 121 | |
| 122 } // namespace content | |
| OLD | NEW |