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

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

Issue 2858803003: bluetooth: Implement simulatePreconnectedPeripheral. (Closed)
Patch Set: MOar fixes Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 (() => { 1 (() => {
2 let mojo_; 2 let mojo_;
3 3
4 async function loadFakeBluetoothInterfaces() { 4 async function loadFakeBluetoothInterfaces() {
5 if(typeof mojo_ !== 'undefined') { 5 if(typeof mojo_ !== 'undefined') {
6 return mojo_; 6 return mojo_;
7 } 7 }
8 8
9 if (typeof loadMojoModules === 'undefined') { 9 if (typeof loadMojoModules === 'undefined') {
10 throw 'Mojo is required for this API.' 10 throw 'Mojo is required for this API.'
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 return this.fake_bluetooth_ptr_; 94 return this.fake_bluetooth_ptr_;
95 } 95 }
96 } 96 }
97 97
98 // FakeCentral allows clients to simulate events that a device in the 98 // FakeCentral allows clients to simulate events that a device in the
99 // Central/Observer role would receive as well as monitor the operations 99 // Central/Observer role would receive as well as monitor the operations
100 // performed by the device in the Central/Observer role. 100 // performed by the device in the Central/Observer role.
101 class FakeCentral { 101 class FakeCentral {
102 constructor(fake_central_ptr) { 102 constructor(fake_central_ptr) {
103 this.fake_central_ptr = fake_central_ptr; 103 this.fake_central_ptr_ = fake_central_ptr;
104 this.peripherals_ = new Map();
105 }
106
107 // Simulates a peripheral with |address| and |name| that has already
108 // been connected to the system.
109 //
110 // Platforms offer methods to retrieve devices that have already been
111 // connected to the system or weren't connected through the UA e.g. a
112 // user connected a peripheral through the system's settings. This method is
113 // intended to simulate peripherals that those methods would return.
114 async simulatePreconnectedPeripheral({address, name}) {
115 let peripheral_id = await this.fake_central_ptr_
scheib 2017/05/04 04:54:20 Do we have reasons to use 'id' and not just addres
ortuno 2017/05/04 07:02:21 I was trying to get away from our reliance on addr
116 .simulatePreconnectedPeripheral(address, name);
117
118 let peripheral = this.peripherals_.get(peripheral_id);
119 if (peripheral === undefined) {
120 peripheral = new FakePeripheral(peripheral_id, this);
121 this.peripherals_.set(peripheral_id, peripheral);
122 }
123
124 return peripheral;
104 } 125 }
105 } 126 }
106 127
128 class FakePeripheral {
129 constructor(peripheral_id, fake_central) {
130 this.peripheral_id = peripheral_id;
131 this.fake_central = fake_central;
132 }
133 }
134
107 navigator.bluetooth.test = new FakeBluetooth(); 135 navigator.bluetooth.test = new FakeBluetooth();
108 })(); 136 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698