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

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

Issue 2853433002: bluetooth: Implement simulateCentral (Closed)
Patch Set: FakeLECentralObserverManager -> FakeCentral 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
« no previous file with comments | « third_party/WebKit/LayoutTests/bluetooth/requestDevice/radio-off.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1d8d50185f59d072331fad227fb752eed5686117 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, {
+ CentralState: mojo_.CentralState,
+ FakeBluetooth: mojo_.FakeBluetooth,
+ FakeBluetoothPtr: mojo_.FakeBluetoothPtr,
+ FakeCentral: mojo_.FakeCentral,
+ FakeCentralPtr: mojo_.FakeCentralPtr,
+ }] = mojo_.modules;
+
return mojo_;
}
@@ -41,6 +48,44 @@
};
}
+ // Returns a promise that resolves with a FakeCentral 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 simulateCentral({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.CentralState.ABSENT;
+ break;
+ case 'poweredoff':
scheib 2017/05/02 03:26:59 poweredOff?
ortuno 2017/05/03 00:17:42 tldr; went with powered-off/powered-on WebIDl "st
+ mojo_manager_state = mojo.CentralState.POWERED_OFF;
+ break;
+ case 'poweredon':
+ mojo_manager_state = mojo.CentralState.POWERED_ON;
+ break;
+ default:
+ throw `Unsupported value ${state} for state.`;
+ }
+
+ let {fake_central:fake_central_ptr} =
+ await (await this.getFakeBluetoothInterface_()).simulateCentral(
+ mojo_manager_state);
+
+ return new FakeCentral(fake_central_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_;
}
}
+ // FakeCentral 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 FakeCentral {
+ constructor(fake_central_ptr) {
+ this.fake_central_ptr = fake_central_ptr;
+ }
+ }
+
navigator.bluetooth.test = new FakeBluetooth();
})();
« no previous file with comments | « third_party/WebKit/LayoutTests/bluetooth/requestDevice/radio-off.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698