tor-browser

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

browser_aboutdebugging_connection_prompt_setting.js (2237B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const USB_RUNTIME_ID = "1337id";
      7 const USB_DEVICE_NAME = "Fancy Phone";
      8 const USB_APP_NAME = "Lorem ipsum";
      9 
     10 /**
     11 * Check whether can toggle enable/disable connection prompt setting.
     12 */
     13 add_task(async function () {
     14  // enable USB devices mocks
     15  const mocks = new Mocks();
     16  const runtime = mocks.createUSBRuntime(USB_RUNTIME_ID, {
     17    deviceName: USB_DEVICE_NAME,
     18    name: USB_APP_NAME,
     19  });
     20 
     21  info("Set initial state for test");
     22  await pushPref("devtools.debugger.prompt-connection", true);
     23 
     24  // open a remote runtime page
     25  const { document, tab, window } = await openAboutDebugging();
     26  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     27 
     28  mocks.emitUSBUpdate();
     29  await connectToRuntime(USB_DEVICE_NAME, document);
     30  await waitForRuntimePage(USB_APP_NAME, document);
     31 
     32  info("Check whether connection prompt toggle button exists");
     33  let connectionPromptToggleButton = document.querySelector(
     34    ".qa-connection-prompt-toggle-button"
     35  );
     36  ok(connectionPromptToggleButton, "Toggle button existed");
     37  ok(
     38    connectionPromptToggleButton.textContent.includes("Disable"),
     39    "Toggle button shows 'Disable'"
     40  );
     41 
     42  info("Click on the toggle button");
     43  connectionPromptToggleButton = document.querySelector(
     44    ".qa-connection-prompt-toggle-button"
     45  );
     46  connectionPromptToggleButton.click();
     47  info("Wait until the toggle button text is updated");
     48  await waitUntil(() =>
     49    connectionPromptToggleButton.textContent.includes("Enable")
     50  );
     51  info("Check the preference");
     52  const disabledPref = runtime.getPreference(
     53    "devtools.debugger.prompt-connection"
     54  );
     55  is(disabledPref, false, "The preference should be updated");
     56 
     57  info("Click on the toggle button again");
     58  connectionPromptToggleButton.click();
     59  info("Wait until the toggle button text is updated");
     60  await waitUntil(() =>
     61    connectionPromptToggleButton.textContent.includes("Disable")
     62  );
     63  info("Check the preference");
     64  const enabledPref = runtime.getPreference(
     65    "devtools.debugger.prompt-connection"
     66  );
     67  is(enabledPref, true, "The preference should be updated");
     68 
     69  await removeTab(tab);
     70 });