Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 didn't connected through the UA e.g. a | |
|
scheib
2017/05/03 20:38:49
ditto
ortuno
2017/05/04 04:16:21
Done.
| |
| 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 simulateSystemConnectedPeripheral({address, name}) { | |
| 115 let peripheral_id = await this.fake_central_ptr_ | |
| 116 .simulateSystemConnectedPeripheral(address, name); | |
| 117 let peripheral = new FakePeripheral(peripheral_id, this); | |
| 118 this.peripherals_.set(peripheral_id, peripheral); | |
| 104 } | 119 } |
| 105 } | 120 } |
| 106 | 121 |
| 122 class FakePeripheral { | |
| 123 constructor(peripheral_id, fake_central) { | |
| 124 this.peripheral_id = peripheral_id; | |
| 125 this.fake_central = fake_central; | |
| 126 } | |
| 127 } | |
| 128 | |
| 107 navigator.bluetooth.test = new FakeBluetooth(); | 129 navigator.bluetooth.test = new FakeBluetooth(); |
| 108 })(); | 130 })(); |
| OLD | NEW |