tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

one-event-per-disconnection.https.window.js (1109B)


      1 // META: script=/resources/testdriver.js?feature=bidi
      2 // META: script=/resources/testdriver-vendor.js
      3 // META: script=/bluetooth/resources/bluetooth-test.js
      4 // META: script=/bluetooth/resources/bluetooth-fake-devices.js
      5 // META: timeout=long
      6 'use strict';
      7 const test_desc = 'If a site disconnects from a device while the platform is ' +
      8    'disconnecting that device, only one gattserverdisconnected event should ' +
      9    'fire.';
     10 
     11 bluetooth_bidi_test(async () => {
     12  const {device, fake_peripheral} = await getConnectedHealthThermometerDevice();
     13  let num_events = 0;
     14 
     15  // 1. Listen for disconnections.
     16  device.addEventListener('gattserverdisconnected', () => num_events++);
     17 
     18  // 2. Disconnect several times.
     19  await Promise.all([
     20    eventPromise(device, 'gattserverdisconnected'),
     21    fake_peripheral.simulateGATTDisconnection(),
     22    device.gatt.disconnect(),
     23    device.gatt.disconnect(),
     24  ]);
     25 
     26  // 3. Wait to catch disconnect events.
     27  await new Promise(resolve => step_timeout(resolve, 50));
     28 
     29  // 4. Ensure there is exactly 1 disconnection recorded.
     30  assert_equals(num_events, 1);
     31 }, test_desc);