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 LayoutTestBluetoothAdapterProvider::LayoutTestBluetoothAdapterProvider() { | |
| 31 } | |
| 32 | |
| 33 LayoutTestBluetoothAdapterProvider::~LayoutTestBluetoothAdapterProvider() { | |
| 34 } | |
| 35 | |
| 36 void LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( | |
| 37 const std::string& fake_adapter_name, | |
| 38 const BluetoothAdapterFactory::AdapterCallback& callback) { | |
| 39 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified | |
| 40 if (fake_adapter_name == "RejectRequestDevice_NotFoundError" || | |
| 41 fake_adapter_name == "EmptyAdapter") | |
| 42 GetEmptyAdapter(callback); | |
| 43 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified | |
| 44 else if (fake_adapter_name == "Single Empty Device" || | |
| 45 fake_adapter_name == "SingleEmptyDeviceAdapter") | |
| 46 GetSingleEmptyDeviceAdapter(callback); | |
| 47 else if (fake_adapter_name == "") | |
| 48 callback.Run(NULL); | |
|
scheib
2015/05/12 20:15:06
We start off with a real adapter, and then can ena
ortuno
2015/05/12 20:49:08
Done.
| |
| 49 else | |
| 50 NOTREACHED(); | |
| 51 } | |
| 52 | |
| 53 void LayoutTestBluetoothAdapterProvider::GetEmptyAdapter( | |
| 54 const BluetoothAdapterFactory::AdapterCallback& callback) { | |
| 55 adapter_ = new NiceMock<MockBluetoothAdapter>(); | |
| 56 ON_CALL(*adapter_, StartDiscoverySession(_, _)) | |
| 57 .WillByDefault(Invoke( | |
| 58 this, | |
| 59 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); | |
| 60 ON_CALL(*adapter_, GetDevices()) | |
| 61 .WillByDefault(Return(BluetoothAdapter::ConstDeviceList())); | |
| 62 callback.Run(adapter_); | |
| 63 } | |
| 64 | |
| 65 void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter( | |
| 66 const BluetoothAdapterFactory::AdapterCallback& callback) { | |
| 67 adapter_ = new NiceMock<MockBluetoothAdapter>(); | |
| 68 ON_CALL(*adapter_, StartDiscoverySession(_, _)) | |
| 69 .WillByDefault(Invoke( | |
| 70 this, | |
| 71 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); | |
| 72 SetupEmptyDevice(); | |
| 73 BluetoothAdapter::ConstDeviceList devices; | |
| 74 devices.push_back(empty_device_.get()); | |
| 75 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); | |
| 76 callback.Run(adapter_); | |
| 77 } | |
| 78 void LayoutTestBluetoothAdapterProvider::SetupEmptyDevice() { | |
| 79 empty_device_.reset(new NiceMock<MockBluetoothDevice>( | |
| 80 adapter_.get(), 0x1F00, "Empty Mock Device name", | |
|
scheib
2015/05/12 20:15:06
Comment the 0x1F00 literal with parameter name.
ortuno
2015/05/12 20:49:08
Done.
| |
| 81 "Empty Mock Device instanceID", true, /* Paired */ | |
| 82 true /* Connected */)); | |
| 83 ON_CALL(*empty_device_, GetVendorIDSource()) | |
| 84 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | |
| 85 ON_CALL(*empty_device_, GetVendorID()).WillByDefault(Return(0xFFFF)); | |
| 86 ON_CALL(*empty_device_, GetProductID()).WillByDefault(Return(1)); | |
| 87 ON_CALL(*empty_device_, GetDeviceID()).WillByDefault(Return(2)); | |
| 88 BluetoothDevice::UUIDList list; | |
| 89 list.push_back(BluetoothUUID("1800")); | |
| 90 list.push_back(BluetoothUUID("1801")); | |
| 91 ON_CALL(*empty_device_, GetUUIDs()).WillByDefault(Return(list)); | |
| 92 } | |
| 93 | |
| 94 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession( | |
| 95 const BluetoothAdapter::DiscoverySessionCallback& callback, | |
| 96 const BluetoothAdapter::ErrorCallback& error_callback) { | |
| 97 NiceMock<MockBluetoothDiscoverySession>* discovery_session = | |
| 98 new NiceMock<MockBluetoothDiscoverySession>(); | |
| 99 ON_CALL(*discovery_session, Stop(_, _)) | |
| 100 .WillByDefault(Invoke( | |
| 101 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop)); | |
| 102 callback.Run(scoped_ptr<BluetoothDiscoverySession>(discovery_session)); | |
| 103 } | |
| 104 | |
| 105 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop( | |
| 106 const base::Closure& callback, | |
| 107 const base::Closure& error_callback) { | |
| 108 callback.Run(); | |
| 109 } | |
| 110 | |
| 111 } // namespace content | |
| OLD | NEW |