Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2421)

Unified Diff: third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js

Issue 2853433002: bluetooth: Implement simulateCentral (Closed)
Patch Set: even moar cleanup Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
diff --git a/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
index d391827f227e120cff52f08b585481fc11e3d79f..a5d586453073eae31d221c9899fad8a2c71a05ac 100644
--- a/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
+++ b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
@@ -15,7 +15,14 @@
'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom'
]);
- [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules;
+ [mojo_.bindings, {
+ LECentralObserverManagerState: mojo_.LECentralObserverManagerState,
+ FakeBluetooth: mojo_.FakeBluetooth,
+ FakeBluetoothPtr: mojo_.FakeBluetoothPtr,
+ FakeLECentralObserverManager: mojo_.FakeLECentralObserverManager,
+ FakeLECentralObserverManagerPtr: mojo_.FakeLECentralObserverManagerPtr,
+ }] = mojo_.modules;
+
return mojo_;
}
@@ -41,6 +48,44 @@
};
}
+ // Returns a promise that resolves with a FakeLECentralObserverManager that
+ // clients can use to simulate events that a device in the Central/Observer
+ // role would receive as well as monitor the operations performed by the
+ // device in the Central/Observer role.
+ async simulateCentralObserverManager({state}) {
+ // Call setBluetoothFakeAdapter() to clean up any fake adapters left over
+ // by legacy tests.
+ // Legacy tests that use setBluetoothFakeAdapter() sometimes fail to clean
+ // their fake adapter. This is not a problem for these tests because the
+ // next setBluetoothFakeAdapter() will clean it up anyway but it is a
+ // problem for the new tests that do not use setBluetoothFakeAdapter().
+ // TODO(crbug.com/569709): Remove once setBluetoothFakeAdapter is no
+ // longer used.
+ await setBluetoothFakeAdapter('');
+ let mojo = await loadFakeBluetoothInterfaces();
+
+ let mojo_manager_state;
+ switch (state) {
+ case 'absent':
+ mojo_manager_state = mojo.LECentralObserverManagerState.ABSENT;
+ break;
+ case 'poweredoff':
+ mojo_manager_state = mojo.LECentralObserverManagerState.POWERED_OFF;
+ break;
+ case 'poweredon':
+ mojo_manager_state = mojo.LECentralObserverManagerState.POWERED_ON;
+ break;
+ default:
+ throw `Unsupported value ${state} for state.`;
+ }
+
+ let {fake_manager:fake_manager_ptr} =
+ await (await this.getFakeBluetoothInterface_())
+ .simulateLECentralObserverManager(mojo_manager_state);
+
+ return new FakeLECentralObserverManager(fake_manager_ptr);
+ }
+
async getFakeBluetoothInterface_() {
if (typeof this.fake_bluetooth_ptr_ !== 'undefined') {
return this.fake_bluetooth_ptr_;
@@ -48,13 +93,21 @@
let mojo = await loadFakeBluetoothInterfaces();
- this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr(
- mojo.interfaces.getInterface(
- mojo.FakeBluetooth.FakeBluetooth.name));
+ this.fake_bluetooth_ptr_ = new mojo.FakeBluetoothPtr(
+ mojo.interfaces.getInterface(mojo.FakeBluetooth.name));
return this.fake_bluetooth_ptr_;
}
}
+ // FakeLECentralObserverManager allows clients to simulate events that a device
+ // in the Central/Observer role would receive as well as monitor the operations
+ // performed by the device in the Central/Observer role.
+ class FakeLECentralObserverManager {
+ constructor(fake_manager_ptr) {
+ this.fake_manager_ptr = fake_manager_ptr;
+ }
+ }
+
navigator.bluetooth.test = new FakeBluetooth();
})();

Powered by Google App Engine
This is Rietveld 408576698