tor-browser

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

browser_inspector_highlighter-reduced-motion-message.js (3547B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const REDUCED_MOTION_PREF = "ui.prefersReducedMotion";
      8 const DISMISS_MESSAGE_PREF =
      9  "devtools.inspector.simple-highlighters.message-dismissed";
     10 
     11 add_task(async function testMessageHiddenWhenPrefersReducedMotionDisabled() {
     12  info("Disable ui.prefersReducedMotion");
     13  await pushPref(REDUCED_MOTION_PREF, 0);
     14 
     15  await pushPref(DISMISS_MESSAGE_PREF, false);
     16 
     17  const tab = await addTab("data:text/html,test");
     18  const toolbox = await gDevTools.showToolboxForTab(tab);
     19 
     20  await wait(1000);
     21  ok(
     22    !getSimpleHighlightersMessage(toolbox),
     23    "The simple highlighters notification is not displayed"
     24  );
     25 });
     26 
     27 add_task(async function testMessageHiddenWhenAlreadyDismissed() {
     28  info("Enable ui.prefersReducedMotion");
     29  await pushPref(REDUCED_MOTION_PREF, 1);
     30 
     31  info("Simulate already dismissed message");
     32  await pushPref(DISMISS_MESSAGE_PREF, true);
     33 
     34  const tab = await addTab("data:text/html,test");
     35  const toolbox = await gDevTools.showToolboxForTab(tab);
     36 
     37  await wait(1000);
     38  ok(
     39    !getSimpleHighlightersMessage(toolbox),
     40    "The simple highlighters notification is not displayed"
     41  );
     42 });
     43 
     44 // Check that the message is displayed under the expected conditions, that the
     45 // settings button successfully opens the corresponding panel and that after
     46 // dismissing the message once, it is no longer displayed.
     47 add_task(async function () {
     48  info("Enable ui.prefersReducedMotion");
     49  await pushPref(REDUCED_MOTION_PREF, 1);
     50 
     51  info("Simulate already dismissed message");
     52  await pushPref(DISMISS_MESSAGE_PREF, false);
     53 
     54  const tab = await addTab("data:text/html,test");
     55  let toolbox = await gDevTools.showToolboxForTab(tab);
     56 
     57  info("Check the simple-highlighters message is displayed");
     58  let notification = await waitFor(() => getSimpleHighlightersMessage(toolbox));
     59  ok(notification, "A notification was displayed");
     60 
     61  info("Click on the settings button from the notification");
     62  const onSettingsCallbackDone = toolbox.once(
     63    "test-highlighters-settings-opened"
     64  );
     65  const settingsButton = notification.querySelector(".notificationButton");
     66  settingsButton.click();
     67 
     68  info("Wait until the open settings button callback is done");
     69  await onSettingsCallbackDone;
     70  is(toolbox.currentToolId, "options", "The options panel was selected");
     71 
     72  info("Close and reopen the toolbox");
     73  await toolbox.destroy();
     74  toolbox = await gDevTools.showToolboxForTab(tab);
     75 
     76  info("Check the notification is displayed again");
     77  notification = await waitFor(() => getSimpleHighlightersMessage(toolbox));
     78  ok(notification, "A notification was displayed after reopening the toolbox");
     79 
     80  info("Close the notification");
     81  const closeButton = notification.querySelector(".messageCloseButton");
     82  closeButton.click();
     83 
     84  info("Wait for the notification to be removed");
     85  await waitFor(() => !getSimpleHighlightersMessage(toolbox));
     86 
     87  info("Close and reopen the toolbox");
     88  await toolbox.destroy();
     89  toolbox = await gDevTools.showToolboxForTab(tab);
     90 
     91  await wait(1000);
     92  ok(!getSimpleHighlightersMessage(toolbox));
     93  is(
     94    Services.prefs.getBoolPref(DISMISS_MESSAGE_PREF),
     95    true,
     96    "The dismiss simple-highlighters-message preference was set to true"
     97  );
     98 });
     99 
    100 function getSimpleHighlightersMessage(toolbox) {
    101  return toolbox.doc.querySelector(
    102    '.notification[data-key="simple-highlighters-message"]'
    103  );
    104 }