tor-browser

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

browser_aboutdebugging_runtime_usbclient_closed.js (3562B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const NETWORK_RUNTIME_HOST = "localhost:6080";
      7 const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
      8 const USB_RUNTIME_ID = "test-runtime-id";
      9 const USB_DEVICE_NAME = "test device name";
     10 const USB_APP_NAME = "TestApp";
     11 
     12 // Test that about:debugging navigates back to the default page when a USB device is
     13 // unplugged.
     14 add_task(async function testUsbDeviceUnplugged() {
     15  const mocks = new Mocks();
     16  const { document, tab, window } = await openAboutDebugging();
     17  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     18 
     19  mocks.createUSBRuntime(USB_RUNTIME_ID, {
     20    deviceName: USB_DEVICE_NAME,
     21    name: USB_APP_NAME,
     22  });
     23  mocks.emitUSBUpdate();
     24 
     25  info("Connect to and select the USB device");
     26  await connectToRuntime(USB_DEVICE_NAME, document);
     27  await waitForRuntimePage(USB_APP_NAME, document);
     28 
     29  info("Simulate a device unplugged");
     30  mocks.removeUSBRuntime(USB_RUNTIME_ID);
     31  mocks.emitUSBUpdate();
     32  await waitUntilUsbDeviceIsUnplugged(USB_DEVICE_NAME, document);
     33 
     34  is(
     35    document.location.hash,
     36    `#/runtime/this-firefox`,
     37    "Redirection to the default page (this-firefox)"
     38  );
     39 
     40  await removeTab(tab);
     41 });
     42 
     43 // Test that about:debugging navigates back to the default page when the server for the
     44 // current USB runtime is closed.
     45 add_task(async function testUsbClientDisconnected() {
     46  const mocks = new Mocks();
     47  const { document, tab, window } = await openAboutDebugging();
     48  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     49 
     50  const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
     51    deviceName: USB_DEVICE_NAME,
     52    name: USB_APP_NAME,
     53  });
     54  mocks.emitUSBUpdate();
     55 
     56  info("Connect to and select the USB device");
     57  await connectToRuntime(USB_DEVICE_NAME, document);
     58  await waitForRuntimePage(USB_APP_NAME, document);
     59 
     60  info("Simulate a client disconnection");
     61  usbClient.isClosed = () => true;
     62  usbClient._eventEmitter.emit("closed");
     63 
     64  info("Wait until the connect button for this runtime appears");
     65  await waitUntil(() => {
     66    const item = findSidebarItemByText(USB_DEVICE_NAME, document);
     67    return item && item.querySelector(".qa-connect-button");
     68  });
     69 
     70  is(
     71    document.location.hash,
     72    `#/runtime/this-firefox`,
     73    "Redirection to the default page (this-firefox)"
     74  );
     75  await removeTab(tab);
     76 });
     77 
     78 // Test that about:debugging navigates back to the default page when the server for the
     79 // current network runtime is closed.
     80 add_task(async function testNetworkClientDisconnected() {
     81  const mocks = new Mocks();
     82  const { document, tab, window } = await openAboutDebugging();
     83  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     84 
     85  const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
     86    name: NETWORK_RUNTIME_APP_NAME,
     87  });
     88 
     89  info("Connect to and select the network runtime");
     90  await connectToRuntime(NETWORK_RUNTIME_HOST, document);
     91  await waitForRuntimePage(NETWORK_RUNTIME_APP_NAME, document);
     92 
     93  info("Simulate a client disconnection");
     94  networkClient.isClosed = () => true;
     95  networkClient._eventEmitter.emit("closed");
     96 
     97  info("Wait until the connect button for this runtime appears");
     98  await waitUntil(() => {
     99    const item = findSidebarItemByText(NETWORK_RUNTIME_HOST, document);
    100    return item && item.querySelector(".qa-connect-button");
    101  });
    102 
    103  is(
    104    document.location.hash,
    105    `#/runtime/this-firefox`,
    106    "Redirection to the default page (this-firefox)"
    107  );
    108  await removeTab(tab);
    109 });