summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connection_prompt_setting.js
blob: dfee0c1ba00aa21757588cd0d1850989bf7cd1e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const USB_RUNTIME_ID = "1337id";
const USB_DEVICE_NAME = "Fancy Phone";
const USB_APP_NAME = "Lorem ipsum";

/**
 * Check whether can toggle enable/disable connection prompt setting.
 */
add_task(async function () {
  // enable USB devices mocks
  const mocks = new Mocks();
  const runtime = mocks.createUSBRuntime(USB_RUNTIME_ID, {
    deviceName: USB_DEVICE_NAME,
    name: USB_APP_NAME,
  });

  info("Set initial state for test");
  await pushPref("devtools.debugger.prompt-connection", true);

  // open a remote runtime page
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  mocks.emitUSBUpdate();
  await connectToRuntime(USB_DEVICE_NAME, document);
  await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);

  info("Check whether connection prompt toggle button exists");
  let connectionPromptToggleButton = document.querySelector(
    ".qa-connection-prompt-toggle-button"
  );
  ok(connectionPromptToggleButton, "Toggle button existed");
  ok(
    connectionPromptToggleButton.textContent.includes("Disable"),
    "Toggle button shows 'Disable'"
  );

  info("Click on the toggle button");
  connectionPromptToggleButton = document.querySelector(
    ".qa-connection-prompt-toggle-button"
  );
  connectionPromptToggleButton.click();
  info("Wait until the toggle button text is updated");
  await waitUntil(() =>
    connectionPromptToggleButton.textContent.includes("Enable")
  );
  info("Check the preference");
  const disabledPref = runtime.getPreference(
    "devtools.debugger.prompt-connection"
  );
  is(disabledPref, false, "The preference should be updated");

  info("Click on the toggle button again");
  connectionPromptToggleButton.click();
  info("Wait until the toggle button text is updated");
  await waitUntil(() =>
    connectionPromptToggleButton.textContent.includes("Disable")
  );
  info("Check the preference");
  const enabledPref = runtime.getPreference(
    "devtools.debugger.prompt-connection"
  );
  is(enabledPref, true, "The preference should be updated");

  await removeTab(tab);
});