Commit 25e7f8dd authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

Reland "Reland "bluetooth: FakeBluetoothChooser impl.""

This is a reland of cb85732c

The previous change caused the WebKit Linux Trusty ASAN trybot to fail
because the FakeBluetoothChooser mojom JS file was not included when the
blink_web_tests_exparchive target was isolated.

Bug: 957867
TBR=ortuno@chromium.org

Original change's description:
> Reland "bluetooth: FakeBluetoothChooser impl."
>
> This is a reland of 6a337f19
>
> This previous change caused tests to fail because of a Mojo validation
> error, which is now taken care of by allowing the Bluetooth tests to
> use the path to the generated Mojom files.
>
> Design doc:
> https://docs.google.com/document/d/1XFl_4ZAgO8ddM6U53A9AfUuZeWgJnlYD5wtbXqEpzeg
>
> 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.
> >
> > This change reverts commit 42624492, which
> > reverted the original change. The original change caused the
> > new-scan-device-added.html test to fail because of a Mojo validation error
> > resulting from not updating the
> > third_party/.../external/wpt/resources/chromium/fake_bluetooth_chooser.mojom.js
> > file needed by the test.
> >
> > Bug: 719827, 719826, 824704, 826787
> > Change-Id: I5e5cce7e809b4d71216c2d074a417ea822d5e527
> > Reviewed-on: https://chromium-review.googlesource.com/985195
> > Commit-Queue: Ovidio Henriquez <odejesush@chromium.org>
> > Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
> > Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#546729}
>
> Bug: 719827, 719826, 824704, 826787
> Change-Id: If63a681becbb2ac0f646a11ea20b1db18d42395d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/986593
> Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#655081}

Bug: 719827, 719826, 824704, 826787
Change-Id: Iaddf24a659573d3815c9c004f6fb05a41c446616
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1589845
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#655869}
parent ac054d17
......@@ -1003,6 +1003,7 @@ if (!is_ios) {
":layout_test_data_mojo_bindings_lite",
"//content/shell:content_shell",
"//content/test:mojo_web_test_bindings_js_data_deps",
"//content/shell:mojo_bindings_js_data_deps",
"//device/bluetooth/public/mojom:fake_bluetooth_interfaces_js_data_deps",
"//device/usb/public/mojom:mojom_js_data_deps",
"//device/vr/public/mojom:mojom_js_data_deps",
......
......@@ -261,6 +261,9 @@ jumbo_static_library("content_shell_lib") {
# #include'ed by renderer/web_test/blink_test_runner.h
":mojo_bindings",
# The generated mojom JS bindings are used by web tests.
":mojo_bindings_js",
# This exposes all public content APIs.
"//content/public/app:both",
"//content/public/browser",
......@@ -922,6 +925,7 @@ mojom("mojo_bindings") {
"//skia/public/interfaces",
"//ui/gfx/geometry/mojo",
"//url/mojom:url_mojom_gurl",
"//url/mojom:url_mojom_origin",
]
}
......
......@@ -16,6 +16,8 @@ namespace content {
FakeBluetoothChooser::~FakeBluetoothChooser() {
SetTestBluetoothScanDuration(
BluetoothTestScanDurationSetting::kImmediateTimeout);
// TODO(https://crbug.com/719826): Send a
// mojom::ChooserEventType::CHOOSER_CLOSED event to the client.
}
// static
......@@ -41,34 +43,35 @@ void FakeBluetoothChooser::WaitForEvents(uint32_t num_of_events,
}
void FakeBluetoothChooser::SelectPeripheral(
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();
const std::string& peripheral_address) {
event_handler_.Run(BluetoothChooser::Event::SELECTED, peripheral_address);
}
void FakeBluetoothChooser::Cancel(CancelCallback callback) {
// TODO(https://crbug.com/719826): Record the event and send a
// BluetoothChooser::CANCELLED event to |event_handler_|.
void FakeBluetoothChooser::Cancel() {
// TODO(https://crbug.com/719826): Send a BluetoothChooser::CANCELLED event to
// |event_handler_| and a mojom::ChooserEventType::CHOOSER_CLOSED to the
// client.
NOTREACHED();
}
void FakeBluetoothChooser::Rescan(RescanCallback callback) {
// TODO(https://crbug.com/719826): Record the event and send a
// BluetoothChooser::RESCAN event to |event_handler_|.
void FakeBluetoothChooser::Rescan() {
// TODO(https://crbug.com/719826): Send a BluetoothChooser::RESCAN event to
// |event_handler_| and the appropriate mojom::ChooserEventType to describe
// the discovery session.
NOTREACHED();
}
// BluetoothChooser overrides
void FakeBluetoothChooser::SetAdapterPresence(AdapterPresence presence) {
// TODO(https://crbug.com/719826): Record the event.
// TODO(https://crbug.com/719826): Send the appropriate
// mojom::ChooserEventType to the client.
NOTREACHED();
}
void FakeBluetoothChooser::ShowDiscoveryState(DiscoveryState state) {
// TODO(https://crbug.com/719826): Record the event.
// TODO(https://crbug.com/719826): Send the appropriate
// mojom::ChooserEventType to the client.
NOTREACHED();
}
......@@ -78,7 +81,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): Record the event.
// TODO(https://crbug.com/719826): Send a
// mojom::ChooserEventType::ADD_OR_UPDATE_DEVICE to the client.
NOTREACHED();
}
......
......@@ -46,10 +46,9 @@ class FakeBluetoothChooser : public mojom::FakeBluetoothChooser,
void WaitForEvents(uint32_t num_of_events,
WaitForEventsCallback callback) override;
void SelectPeripheral(const std::string& peripheral_address,
SelectPeripheralCallback callback) override;
void Cancel(CancelCallback callback) override;
void Rescan(RescanCallback callback) override;
void SelectPeripheral(const std::string& peripheral_address) override;
void Cancel() override;
void Rescan() override;
// BluetoothChooser overrides:
......
......@@ -4,6 +4,8 @@
module content.mojom;
import "url/mojom/origin.mojom";
// This interface is being developed to support Web Platform Tests for Web
// Bluetooth.
// https://docs.google.com/document/d/1Nhv_oVDCodd1pEH_jj9k8gF4rPGb_84VYaZ9IG8M_WY
......@@ -24,15 +26,14 @@ module content.mojom;
// Indicates the types of Bluetooth chooser events.
enum ChooserEventType {
CHOOSER_OPENED,
SCAN_STARTED,
DEVICE_UPDATE,
CHOOSER_CLOSED,
ADAPTER_REMOVED,
ADAPTER_DISABLED,
ADAPTER_ENABLED,
DISCOVERY_FAILED_TO_START,
DISCOVERING,
DISCOVERY_IDLE,
ADD_DEVICE,
ADD_OR_UPDATE_DEVICE,
};
// FakeBluetoothChooser allows clients to control the global state of the
......@@ -45,13 +46,13 @@ 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() => ();
Rescan();
};
// FakeBluetoothChooserEvent describes the type of chooser event that has been
......@@ -61,7 +62,7 @@ struct FakeBluetoothChooserEvent {
// Describes the origin the chooser is currently displaying.
// This field will be used by the |CHOOSER_OPENED| event type.
string? origin;
url.mojom.Origin? origin;
// Describes the MAC address of the Bluetooth device.
string? peripheral_address;
......
......@@ -8,11 +8,6 @@ mojom("mojom") {
sources = [
"uuid.mojom",
]
# This mojom interface is exposed publicly to layout tests which use
# prepackaged redistributable JS bindings. It is therefore not desirable to
# scramble these messages.
scramble_message_ids = false
}
mojom("fake_bluetooth_interfaces") {
......@@ -23,11 +18,6 @@ mojom("fake_bluetooth_interfaces") {
public_deps = [
":mojom",
]
# This mojom interface is exposed publicly to layout tests which use
# prepackaged redistributable JS bindings. It is therefore not desirable to
# scramble these messages.
scramble_message_ids = false
}
# Experimental interfaces are not ready for production use yet. See README.md
......
......@@ -66,8 +66,7 @@ void FakeCentral::SimulatePreconnectedPeripheral(
void FakeCentral::SimulateAdvertisementReceived(
mojom::ScanResultPtr scan_result_ptr,
SimulateAdvertisementReceivedCallback callback) {
// TODO(https://crbug.com/719826): Add a DCHECK to proceed only if a scan is
// currently in progress.
DCHECK(num_discovery_sessions_ > 0);
auto* fake_peripheral = GetFakePeripheral(scan_result_ptr->device_address);
const bool is_new_device = fake_peripheral == nullptr;
if (is_new_device) {
......
<!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>
......@@ -25,6 +25,7 @@ function performChromiumSetup() {
// Load the Chromium-specific resources.
let prefix = '/resources/chromium';
let genPrefix = '/gen';
let extra = [];
const pathname = window.location.pathname;
if (pathname.includes('/LayoutTests/') || pathname.includes('/web_tests/')) {
......@@ -33,17 +34,19 @@ function performChromiumSetup() {
extra = [
`${root}/resources/bluetooth/bluetooth-fake-adapter.js`,
];
genPrefix = 'file:///gen';
} else if (window.location.pathname.startsWith('/bluetooth/https/')) {
extra = [
'/js-test-resources/bluetooth/bluetooth-fake-adapter.js',
];
}
return loadScripts([
`${prefix}/mojo_bindings.js`,
`${prefix}/mojo_web_test_helper_test.mojom.js`,
`${prefix}/uuid.mojom.js`,
`${prefix}/fake_bluetooth.mojom.js`,
`${prefix}/fake_bluetooth_chooser.mojom.js`,
`${genPrefix}/layout_test_data/mojo/public/js/mojo_bindings.js`,
`${genPrefix}/content/test/data/mojo_web_test_helper_test.mojom.js`,
`${genPrefix}/device/bluetooth/public/mojom/uuid.mojom.js`,
`${genPrefix}/url/mojom/origin.mojom.js`,
`${genPrefix}/device/bluetooth/public/mojom/test/fake_bluetooth.mojom.js`,
`${genPrefix}/content/shell/common/web_test/fake_bluetooth_chooser.mojom.js`,
`${prefix}/web-bluetooth-test.js`,
].concat(extra))
// Call setBluetoothFakeAdapter() to clean up any fake adapters left over
......@@ -498,6 +501,15 @@ 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'.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
(function() {
var mojomId = 'device/bluetooth/public/mojom/uuid.mojom';
if (mojo.internal.isMojomLoaded(mojomId)) {
console.warn('The following mojom is loaded multiple times: ' + mojomId);
return;
}
mojo.internal.markMojomLoaded(mojomId);
var bindings = mojo;
var associatedBindings = mojo;
var codec = mojo.internal;
var validator = mojo.internal;
var exports = mojo.internal.exposeNamespace('bluetooth.mojom');
function UUID(values) {
this.initDefaults_();
this.initFields_(values);
}
UUID.prototype.initDefaults_ = function() {
this.uuid = null;
};
UUID.prototype.initFields_ = function(fields) {
for(var field in fields) {
if (this.hasOwnProperty(field))
this[field] = fields[field];
}
};
UUID.validate = function(messageValidator, offset) {
var err;
err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize);
if (err !== validator.validationError.NONE)
return err;
var kVersionSizes = [
{version: 0, numBytes: 16}
];
err = messageValidator.validateStructVersion(offset, kVersionSizes);
if (err !== validator.validationError.NONE)
return err;
// validate UUID.uuid
err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, false)
if (err !== validator.validationError.NONE)
return err;
return validator.validationError.NONE;
};
UUID.encodedSize = codec.kStructHeaderSize + 8;
UUID.decode = function(decoder) {
var packed;
var val = new UUID();
var numberOfBytes = decoder.readUint32();
var version = decoder.readUint32();
val.uuid = decoder.decodeStruct(codec.String);
return val;
};
UUID.encode = function(encoder, val) {
var packed;
encoder.writeUint32(UUID.encodedSize);
encoder.writeUint32(0);
encoder.encodeStruct(codec.String, val.uuid);
};
exports.UUID = UUID;
})();
\ No newline at end of file
......@@ -513,6 +513,13 @@ 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);
}
}
// 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