tor-browser

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

browser_popup-record-capture-view.js (4928B)


      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 FRONTEND_BASE_HOST = "https://example.com";
      8 const FRONTEND_BASE_PATH =
      9  "/browser/devtools/client/performance-new/test/browser/fake-frontend.html";
     10 const FRONTEND_BASE_URL = FRONTEND_BASE_HOST + FRONTEND_BASE_PATH;
     11 
     12 add_setup(async function setup() {
     13  // The active tab view isn't enabled in all configurations. Let's make sure
     14  // it's enabled in these tests.
     15  SpecialPowers.pushPrefEnv({
     16    set: [["devtools.performance.recording.active-tab-view.enabled", true]],
     17  });
     18 });
     19 
     20 add_task(async function test() {
     21  info(
     22    "Test that the profiler pop-up correctly opens the captured profile on the " +
     23      "correct frontend view by adding proper view query string"
     24  );
     25 
     26  // This test assumes that the Web Developer preset is set by default, which is
     27  // not the case on Nightly and custom builds.
     28  PrefsPresets.changePreset(
     29    "aboutprofiling",
     30    "web-developer",
     31    Services.profiler.GetFeatures()
     32  );
     33 
     34  await setProfilerFrontendUrl(FRONTEND_BASE_HOST, FRONTEND_BASE_PATH);
     35  await makeSureProfilerPopupIsEnabled();
     36 
     37  // First check for the "Media" preset which will have no "view" query
     38  // string because it opens our traditional "full" view.
     39  await openPopupAndAssertUrlForPreset({
     40    window,
     41    preset: "Media",
     42    expectedUrl: FRONTEND_BASE_URL,
     43  });
     44 
     45  // Now, let's check for "web-developer" preset. This will open up the frontend
     46  // with "active-tab" view query string. Frontend will understand and open the active tab view for it.
     47  await openPopupAndAssertUrlForPreset({
     48    window,
     49    preset: "Web Developer",
     50    expectedUrl: FRONTEND_BASE_URL + "?view=active-tab&implementation=js",
     51  });
     52 });
     53 
     54 add_task(async function test_in_private_window() {
     55  info(
     56    "Test that the profiler pop-up correctly opens the captured profile on the " +
     57      "correct frontend view by adding proper view query string. This also tests " +
     58      "that a tab is opened on the non-private window even when the popup is used " +
     59      "in the private window."
     60  );
     61 
     62  // This test assumes that the Web Developer preset is set by default, which is
     63  // not the case on Nightly and custom builds.
     64  PrefsPresets.changePreset(
     65    "aboutprofiling",
     66    "web-developer",
     67    Services.profiler.GetFeatures()
     68  );
     69 
     70  await setProfilerFrontendUrl(FRONTEND_BASE_HOST, FRONTEND_BASE_PATH);
     71  await makeSureProfilerPopupIsEnabled();
     72 
     73  info("Open a private window.");
     74  const privateWindow = await BrowserTestUtils.openNewBrowserWindow({
     75    private: true,
     76  });
     77 
     78  // First check for the "Media" preset which will have no "view" query
     79  // string because it opens our traditional "full" view.
     80  // Note that this utility will check for a new tab in the main non-private
     81  // window, which is exactly what we want here.
     82  await openPopupAndAssertUrlForPreset({
     83    window: privateWindow,
     84    preset: "Media",
     85    expectedUrl: FRONTEND_BASE_URL,
     86  });
     87 
     88  // Now, let's check for "web-developer" preset. This will open up the frontend
     89  // with "active-tab" view query string. Frontend will understand and open the active tab view for it.
     90  await openPopupAndAssertUrlForPreset({
     91    window: privateWindow,
     92    preset: "Web Developer",
     93    expectedUrl: FRONTEND_BASE_URL + "?view=active-tab&implementation=js",
     94  });
     95 
     96  await BrowserTestUtils.closeWindow(privateWindow);
     97 });
     98 
     99 async function openPopupAndAssertUrlForPreset({ window, preset, expectedUrl }) {
    100  // Let's capture a profile and assert newly created tab's url.
    101  await openPopupAndEnsureCloses(window, async () => {
    102    const { document } = window;
    103    {
    104      // Select the preset in the popup
    105      const presetsInPopup = document.getElementById(
    106        "PanelUI-profiler-presets"
    107      );
    108      presetsInPopup.menupopup.openPopup();
    109      presetsInPopup.menupopup.activateItem(
    110        await getElementByLabel(presetsInPopup, preset)
    111      );
    112 
    113      await TestUtils.waitForCondition(
    114        () => presetsInPopup.label === preset,
    115        `After selecting the preset in the popup, waiting until the preset is changed to ${preset} in the popup.`
    116      );
    117    }
    118 
    119    {
    120      const button = await getElementByLabel(document, "Start Recording");
    121      info("Click the button to start recording.");
    122      button.click();
    123    }
    124 
    125    {
    126      const button = await getElementByLabel(document, "Capture");
    127      info("Click the button to capture the recording.");
    128      button.click();
    129    }
    130 
    131    info(
    132      "If the profiler successfully captures a profile, it will create a new " +
    133        "tab with the proper view query string depending on the preset."
    134    );
    135 
    136    await waitForTabUrl({
    137      initialTitle: "Waiting on the profile",
    138      successTitle: "Profile received",
    139      errorTitle: "Error",
    140      expectedUrl,
    141    });
    142  });
    143 }