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

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

Issue 2858803003: bluetooth: Implement simulatePreconnectedPeripheral. (Closed)
Patch Set: Address moar feedback 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 return this.fake_bluetooth_ptr_; 100 return this.fake_bluetooth_ptr_;
101 } 101 }
102 } 102 }
103 103
104 // FakeCentral allows clients to simulate events that a device in the 104 // FakeCentral allows clients to simulate events that a device in the
105 // Central/Observer role would receive as well as monitor the operations 105 // Central/Observer role would receive as well as monitor the operations
106 // performed by the device in the Central/Observer role. 106 // performed by the device in the Central/Observer role.
107 class FakeCentral { 107 class FakeCentral {
108 constructor(fake_central_ptr) { 108 constructor(fake_central_ptr) {
109 this.fake_central_ptr = fake_central_ptr; 109 this.fake_central_ptr_ = fake_central_ptr;
110 this.peripherals_ = new Map();
111 }
112
113 // Simulates a peripheral with |address| and |name| that has already
114 // been connected to the system. If the peripheral existed already it
115 // updates its name.
116 //
117 // Platforms offer methods to retrieve devices that have already been
118 // connected to the system or weren't connected through the UA e.g. a
119 // user connected a peripheral through the system's settings. This method is
120 // intended to simulate peripherals that those methods would return.
121 async simulatePreconnectedPeripheral({address, name}) {
122 await this.fake_central_ptr_.simulatePreconnectedPeripheral(
123 address, name);
124
125 let peripheral = this.peripherals_.get(address);
126 if (peripheral === undefined) {
127 peripheral = new FakePeripheral(address, this);
128 this.peripherals_.set(address, peripheral);
129 }
130
131 return peripheral;
110 } 132 }
111 } 133 }
112 134
135 class FakePeripheral {
136 constructor(address, fake_central) {
137 this.address = address;
138 this.fake_central_ = fake_central;
139 }
140 }
141
113 navigator.bluetooth.test = new FakeBluetooth(); 142 navigator.bluetooth.test = new FakeBluetooth();
114 })(); 143 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698