Commit 42624492 authored by François Doray's avatar François Doray Committed by Commit Bot

Revert "bluetooth: FakeBluetoothChooser impl."

This reverts commit 188adfb5.

Reason for revert: https://crbug.com/826787

Original change's description:
> bluetooth: FakeBluetoothChooser impl.
>
> Implements the interfaces that FakeBluetoothChooser overrides. The
> mojom::FakeBluetoothChooser overrides are implemented by running
> |event_handler_| with the appropriate arguments. The BluetoothChooser
> overrides do nothing at the moment, since the base class is only meant
> to update the chooser user interface.
>
> This change also begins to partially convert a Bluetooth chooser test to test
> the interface and deletes the temporary tests that were created to test this
> API.
>
> BUG=719827,719826,824704
>
> Change-Id: I56a04e6bdb2de38d9163d7bc350db578deeb9ba3
> Reviewed-on: https://chromium-review.googlesource.com/962983
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Reviewed-by: Conley Owens <cco3@chromium.org>
> Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
> Commit-Queue: Ovidio Henriquez <odejesush@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#546509}

TBR=dcheng@chromium.org,cco3@chromium.org,ortuno@chromium.org,odejesush@chromium.org

Change-Id: I0597151ec5878d41ac631b72296203bc99b1f2c8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 719827, 719826, 824704, 826787
Reviewed-on: https://chromium-review.googlesource.com/984299
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546572}
parent 44b139f2
......@@ -41,30 +41,35 @@ void FakeBluetoothChooser::WaitForEvents(uint32_t num_of_events,
}
void FakeBluetoothChooser::SelectPeripheral(
const std::string& peripheral_address) {
event_handler_.Run(BluetoothChooser::Event::SELECTED, peripheral_address);
const std::string& peripheral_address,
SelectPeripheralCallback callback) {
// TODO(https://crbug.com/719826): Record the event and send a
// BluetoothChooser::SELECTED event to |event_handler_|.
NOTREACHED();
}
void FakeBluetoothChooser::Cancel() {
// TODO(https://crbug.com/719826): Run |event_handler_| with
// BluetoothChooser::CANCELLED.
void FakeBluetoothChooser::Cancel(CancelCallback callback) {
// TODO(https://crbug.com/719826): Record the event and send a
// BluetoothChooser::CANCELLED event to |event_handler_|.
NOTREACHED();
}
void FakeBluetoothChooser::Rescan(RescanCallback callback) {
// TODO(https://crbug.com/719826): Run |event_handler_| with
// BluetoothChooser::RESCAN.
// TODO(https://crbug.com/719826): Record the event and send a
// BluetoothChooser::RESCAN event to |event_handler_|.
NOTREACHED();
}
// BluetoothChooser overrides
void FakeBluetoothChooser::SetAdapterPresence(AdapterPresence presence) {
// TODO(https://crbug.com/719826): Send the event to the client.
// TODO(https://crbug.com/719826): Record the event.
NOTREACHED();
}
void FakeBluetoothChooser::ShowDiscoveryState(DiscoveryState state) {
// TODO(https://crbug.com/719826): Send the event to the client.
// TODO(https://crbug.com/719826): Record the event.
NOTREACHED();
}
void FakeBluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
......@@ -73,7 +78,8 @@ void FakeBluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
bool is_gatt_connected,
bool is_paired,
int signal_strength_level) {
// TODO(https://crbug.com/719826): Send the event to the client.
// TODO(https://crbug.com/719826): Record the event.
NOTREACHED();
}
// private
......
......@@ -46,8 +46,9 @@ class FakeBluetoothChooser : public mojom::FakeBluetoothChooser,
void WaitForEvents(uint32_t num_of_events,
WaitForEventsCallback callback) override;
void SelectPeripheral(const std::string& peripheral_address) override;
void Cancel() override;
void SelectPeripheral(const std::string& peripheral_address,
SelectPeripheralCallback callback) override;
void Cancel(CancelCallback callback) override;
void Rescan(RescanCallback callback) override;
// BluetoothChooser overrides:
......
......@@ -45,10 +45,10 @@ interface FakeBluetoothChooser {
// Simulates a user selecting the given |peripheral_address| in the Bluetooth
// chooser.
SelectPeripheral(string peripheral_address);
SelectPeripheral(string peripheral_address) => ();
// Calls the event handler function with the CANCELLED event.
Cancel();
Cancel() => ();
// Calls the event handler function with the RESCAN event.
Rescan() => ();
......
......@@ -580,7 +580,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// Helper class to easily update the sets of UUIDs and keep them in sync with
// the set of all the device's UUIDs.
class DEVICE_BLUETOOTH_EXPORT DeviceUUIDs {
class DeviceUUIDs {
public:
DeviceUUIDs();
~DeviceUUIDs();
......
......@@ -53,7 +53,8 @@ void FakeCentral::SimulatePreconnectedPeripheral(
void FakeCentral::SimulateAdvertisementReceived(
mojom::ScanResultPtr scan_result_ptr,
SimulateAdvertisementReceivedCallback callback) {
DCHECK(has_pending_or_active_discovery_session_);
// TODO(https://crbug.com/719826): Add a DCHECK to proceed only if a scan is
// currently in progress.
auto* fake_peripheral = GetFakePeripheral(scan_result_ptr->device_address);
const bool is_new_device = fake_peripheral == nullptr;
if (is_new_device) {
......
......@@ -181,19 +181,7 @@ bool FakePeripheral::IsConnecting() const {
}
device::BluetoothDevice::UUIDSet FakePeripheral::GetUUIDs() const {
// Since the advertisement packets use the DeviceUUIDs helper class and the
// pre-connected devices use the service_uuids_ data member, it is necessary
// to combine the two so that the chooser can properly filter out devices.
// This is a temporary workaround until the class can be successfully
// refactored to use DeviceUUIDs to manage the service UUIDs.
// TODO(https://crbug.com/824704): This override should be removed once the
// class is refactored.
device::BluetoothDevice::UUIDSet services;
std::set_union(service_uuids_.begin(), service_uuids_.end(),
device_uuids_.GetUUIDs().begin(),
device_uuids_.GetUUIDs().end(),
std::inserter(services, services.begin()));
return services;
return service_uuids_;
}
bool FakePeripheral::ExpectingPinCode() const {
......
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/testdriver.js"></script>
<script src="../../../resources/testdriver-vendor.js"></script>
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script>
'use strict';
// TODO(https://crbug.com/719826): This is a temporary test to try the
// FakeBluetoothChooser API as it is implemented. This test should be delete after
// the feature is completed. The implementation details can be found in the design
// document.
// https://docs.google.com/document/d/1XFl_4ZAgO8ddM6U53A9AfUuZeWgJnlYD5wtbXqEpzeg
const test_desc = 'Ensure that the FakeBluetoothChooser API works correctly.';
bluetooth_test(() => navigator.bluetooth.test.simulateCentral({
state: 'powered-on'
})
.then(() => navigator.bluetooth.test.getManualChooser())
.then(chooser => assert_true(typeof chooser !== 'undefined')),
test_desc);
</script>
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/testdriver.js"></script>
<script src="../../../resources/testdriver-vendor.js"></script>
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script>
'use strict';
// TODO(https://crbug.com/719826): This is a temporary test to try the
// FakeBluetoothChooser API as it is implemented. This test should be deleted
// after the feature is completed.
const test_desc = 'Ensure that the SimulateAdvertisementReceived API works ' +
'correctly.';
const company_id = '224';
const data = new TextEncoder().encode('foo');
const manufacturerDataMap = {[company_id]: data};
const serviceDataMap = {[health_thermometer.uuid]: data};
const scanRecord = {
name: 'Health Thermometer',
uuids: ['generic_access', health_thermometer.uuid],
txPower: 20,
appearance: 100,
manufacturerData: manufacturerDataMap,
serviceData: serviceDataMap,
};
let fake_central;
let scanResult = {
deviceAddress: '09:09:09:09:09:09',
rssi: 100,
scanRecord: {},
};
bluetooth_test(() => navigator.bluetooth.test.simulateCentral({
state: 'powered-on'
})
.then(_ => fake_central = _)
// Test that scanRecord fields are indeed optional.
.then(() => fake_central.simulateAdvertisementReceived(scanResult))
.then(fake_peripheral => assert_true(
fake_peripheral.address === '09:09:09:09:09:09'))
// Test the scanRecord fields.
.then(() => {
scanResult.scanRecord = scanRecord;
return fake_central.simulateAdvertisementReceived(scanResult);
}), test_desc);
</script>
......@@ -6,41 +6,23 @@
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script>
'use strict';
const test_desc = 'The chooser should display newly detected devices.';
let fake_central, fake_chooser;
bluetooth_test(() => {
setBluetoothManualChooser(true);
bluetooth_test(() => navigator.bluetooth.test.simulateCentral({
state: 'powered-on',
})
.then(_ => fake_central = _)
.then(() => navigator.bluetooth.test.getManualChooser())
.then(_ => fake_chooser = _)
.then(() => {
// 1. Open the chooser.
let requestDevicePromise = requestDeviceWithTrustedClick({
filters: [{services: ['health_thermometer']}]
});
// We can only simulate advertisements after the chooser is opened and a
// scan is active. There are currently no events to signal that the
// chooser is opened , so we wait a second before we try to simulate an
// advertisement.
// TODO(https://crbug.com/719827): Once the chooser can send events,
// replace this with a promise that resolves when the chooser sends the
// 'chooser-opened' and 'discovering' events.
// 2. Send the advertisement packet to central.
setTimeout(() => fake_central.simulateAdvertisementReceived(
health_thermometer_ad_packet)
// 3. Select the device on the chooser.
.then(fake_peripheral => fake_chooser.selectPeripheral(
fake_peripheral)),
1000);
return requestDevicePromise;
})
// 4. Check that the device and advertisement packet have the same name.
.then(device => assert_equals(
device.name,
health_thermometer_ad_packet.scanRecord.name)),
test_desc);
let requestDevicePromise =
setBluetoothFakeAdapter('DeviceEventAdapter')
.then(() => requestDeviceWithTrustedClick({
filters: [{services: ['glucose']}]}));
return getBluetoothManualChooserEvents(4).then(events => {
assert_equals(events[0], 'chooser-opened(file://)');
assert_equals(events[1], 'discovering');
let idsByName = new AddDeviceEventSet();
idsByName.assert_add_device_event(events[2]);
assert_true(idsByName.has('New Glucose Device'));
assert_equals(events[3], 'discovery-idle');
sendBluetoothManualChooserEvent(
'selected', idsByName.get('New Glucose Device'));
return requestDevicePromise;
});
});
</script>
......@@ -477,15 +477,6 @@ function setUpPreconnectedDevice({
}));
}
const health_thermometer_ad_packet = {
deviceAddress: '09:09:09:09:09:09',
rssi: -10,
scanRecord: {
name: 'Health Thermometer',
uuids: [health_thermometer.uuid],
},
};
// Returns a FakePeripheral that corresponds to a simulated pre-connected device
// called 'Health Thermometer'. The device has two known serviceUUIDs:
// 'generic_access' and 'health_thermometer'.
......
......@@ -489,21 +489,6 @@ class FakeChooser {
Mojo.bindInterface(content.mojom.FakeBluetoothChooser.name,
mojo.makeRequest(this.fake_bluetooth_chooser_ptr_).handle, 'process');
}
async selectPeripheral(peripheral) {
if (!(peripheral instanceof FakePeripheral)) {
throw '|peripheral| must be an instance of FakePeripheral';
}
await this.fake_bluetooth_chooser_ptr_.selectPeripheral(peripheral.address);
}
async cancel() {
await this.fake_bluetooth_chooser_ptr_.cancel();
}
async rescan() {
await this.fake_bluetooth_chooser_ptr_.rescan();
}
}
// If this line fails, it means that current environment does not support the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment