diff options
author | jyasskin <jyasskin@chromium.org> | 2015-09-24 09:58:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-24 16:59:30 +0000 |
commit | 1e9f0c90c10d405dacfe7ab9b5ae4c1c05227a98 (patch) | |
tree | bcaf5d663c63d0d01c526417f2a636b9007f59dc /content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc | |
parent | 11f882b405f348be9a286164f14205f0184ff474 (diff) | |
download | chromium_src-1e9f0c90c10d405dacfe7ab9b5ae4c1c05227a98.zip chromium_src-1e9f0c90c10d405dacfe7ab9b5ae4c1c05227a98.tar.gz chromium_src-1e9f0c90c10d405dacfe7ab9b5ae4c1c05227a98.tar.bz2 |
Handle RESCAN events from the Bluetooth chooser by starting or extending a discovery session.
I also added interfaces to support tests that this works, documented in https://github.com/WebBluetoothCG/web-bluetooth/pull/165.
BUG=533185
TBR=mkwst@chromium.org
Review URL: https://codereview.chromium.org/1353053002
Cr-Commit-Position: refs/heads/master@{#350586}
Diffstat (limited to 'content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc')
-rw-r--r-- | content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc index cbc26af..ed27741 100644 --- a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc +++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc @@ -4,8 +4,12 @@ #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/format_macros.h" +#include "base/location.h" #include "base/strings/stringprintf.h" +#include "base/thread_task_runner_handle.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_discovery_session.h" @@ -122,6 +126,8 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( return GetFailingConnectionsAdapter(); else if (fake_adapter_name == "FailingGATTOperationsAdapter") return GetFailingGATTOperationsAdapter(); + else if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") + return GetSecondDiscoveryFindsHeartRateAdapter(); else if (fake_adapter_name == "") return NULL; @@ -248,6 +254,40 @@ LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { return adapter.Pass(); } +// Adds a device to |adapter| and notifies all observers about that new device. +// Mocks can call this asynchronously to cause changes in the middle of a test. +static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, + scoped_ptr<NiceMockBluetoothDevice> new_device) { + NiceMockBluetoothDevice* new_device_ptr = new_device.get(); + adapter->AddMockDevice(new_device.Pass()); + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), + DeviceAdded(adapter.get(), new_device_ptr)); +} + +// static +scoped_refptr<NiceMockBluetoothAdapter> +LayoutTestBluetoothAdapterProvider::GetSecondDiscoveryFindsHeartRateAdapter() { + scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); + NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); + + EXPECT_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) + .WillOnce(RunCallbackWithResult<1 /* success_callback */>( + []() { return GetDiscoverySession(); })) + .WillOnce( + RunCallbackWithResult<1 /* success_callback */>([adapter_ptr]() { + // In the second discovery session, have the adapter discover a new + // device, shortly after the session starts. + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, + base::Bind(&AddDevice, make_scoped_refptr(adapter_ptr), + + base::Passed(GetHeartRateDevice(adapter_ptr)))); + return GetDiscoverySession(); + })); + + return adapter; +} + // static scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::GetMissingServiceGenericAccessAdapter() { |