tor-browser

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

browser_devtools-onboarding.js (2803B)


      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 ONBOARDING_PREF = "devtools.performance.new-panel-onboarding";
      8 
      9 add_task(async function testWithOnboardingPreferenceFalse() {
     10  info("Test that the onboarding message is displayed as expected.");
     11 
     12  info("Test the onboarding message when the preference is false");
     13  await SpecialPowers.pushPrefEnv({
     14    set: [[ONBOARDING_PREF, false]],
     15  });
     16  await withDevToolsPanel(async document => {
     17    {
     18      // Wait for another UI element to be rendered before asserting the
     19      // onboarding message.
     20      await getActiveButtonFromText(document, "Start recording");
     21      ok(
     22        !isOnboardingDisplayed(document),
     23        "Onboarding message is not displayed"
     24      );
     25    }
     26  });
     27 });
     28 
     29 add_task(async function testWithOnboardingPreferenceTrue() {
     30  info("Test the onboarding message when the preference is true");
     31  await SpecialPowers.pushPrefEnv({
     32    set: [[ONBOARDING_PREF, true]],
     33  });
     34 
     35  await withDevToolsPanel(async document => {
     36    await waitUntil(
     37      () => isOnboardingDisplayed(document),
     38      "Waiting for the onboarding message to be displayed"
     39    );
     40    ok(true, "Onboarding message is displayed");
     41    await closeOnboardingMessage(document);
     42  });
     43 
     44  is(
     45    Services.prefs.getBoolPref(ONBOARDING_PREF),
     46    false,
     47    "onboarding preference should be false after closing the message"
     48  );
     49 });
     50 
     51 add_task(async function testWithOnboardingPreferenceNotSet() {
     52  info("Test the onboarding message when the preference is not set");
     53  await SpecialPowers.pushPrefEnv({
     54    clear: [[ONBOARDING_PREF]],
     55  });
     56 
     57  await withDevToolsPanel(async document => {
     58    await waitUntil(
     59      () => isOnboardingDisplayed(document),
     60      "Waiting for the onboarding message to be displayed"
     61    );
     62    ok(true, "Onboarding message is displayed");
     63    await closeOnboardingMessage(document);
     64  });
     65 
     66  is(
     67    Services.prefs.getBoolPref(ONBOARDING_PREF),
     68    false,
     69    "onboarding preference should be false after closing the message"
     70  );
     71 });
     72 
     73 /**
     74 * Helper to close the onboarding message by clicking on the close button.
     75 */
     76 async function closeOnboardingMessage(document) {
     77  const closeButton = await getActiveButtonFromText(
     78    document,
     79    "Close the onboarding message"
     80  );
     81  info("Click the close button to hide the onboarding message.");
     82  closeButton.click();
     83 
     84  await waitUntil(
     85    () => !isOnboardingDisplayed(document),
     86    "Waiting for the onboarding message to disappear"
     87  );
     88 }
     89 
     90 function isOnboardingDisplayed(document) {
     91  return maybeGetElementFromDocumentByText(
     92    document,
     93    "Firefox Profiler is now integrated into Developer Tools"
     94  );
     95 }