summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/test/browser/browser_popup-record-capture-view.js
blob: 144e63b63b9c066de38b888cf8f773ca97f79d2f (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const FRONTEND_BASE_HOST = "http://example.com";
const FRONTEND_BASE_PATH =
  "/browser/devtools/client/performance-new/test/browser/fake-frontend.html";
const FRONTEND_BASE_URL = FRONTEND_BASE_HOST + FRONTEND_BASE_PATH;

add_setup(async function setup() {
  // The active tab view isn't enabled in all configurations. Let's make sure
  // it's enabled in these tests.
  SpecialPowers.pushPrefEnv({
    set: [["devtools.performance.recording.active-tab-view.enabled", true]],
  });
});

add_task(async function test() {
  info(
    "Test that the profiler pop-up correctly opens the captured profile on the " +
      "correct frontend view by adding proper view query string"
  );

  // This test assumes that the Web Developer preset is set by default, which is
  // not the case on Nightly and custom builds.
  BackgroundJSM.changePreset(
    "aboutprofiling",
    "web-developer",
    Services.profiler.GetFeatures()
  );

  await setProfilerFrontendUrl(FRONTEND_BASE_HOST, FRONTEND_BASE_PATH);
  await makeSureProfilerPopupIsEnabled();

  // First check for the "Media" preset which will have no "view" query
  // string because it opens our traditional "full" view.
  await openPopupAndAssertUrlForPreset({
    window,
    preset: "Media",
    expectedUrl: FRONTEND_BASE_URL,
  });

  // Now, let's check for "web-developer" preset. This will open up the frontend
  // with "active-tab" view query string. Frontend will understand and open the active tab view for it.
  await openPopupAndAssertUrlForPreset({
    window,
    preset: "Web Developer",
    expectedUrl: FRONTEND_BASE_URL + "?view=active-tab&implementation=js",
  });
});

add_task(async function test_in_private_window() {
  info(
    "Test that the profiler pop-up correctly opens the captured profile on the " +
      "correct frontend view by adding proper view query string. This also tests " +
      "that a tab is opened on the non-private window even when the popup is used " +
      "in the private window."
  );

  // This test assumes that the Web Developer preset is set by default, which is
  // not the case on Nightly and custom builds.
  BackgroundJSM.changePreset(
    "aboutprofiling",
    "web-developer",
    Services.profiler.GetFeatures()
  );

  await setProfilerFrontendUrl(FRONTEND_BASE_HOST, FRONTEND_BASE_PATH);
  await makeSureProfilerPopupIsEnabled();

  info("Open a private window.");
  const privateWindow = await BrowserTestUtils.openNewBrowserWindow({
    private: true,
  });

  // First check for the "Media" preset which will have no "view" query
  // string because it opens our traditional "full" view.
  // Note that this utility will check for a new tab in the main non-private
  // window, which is exactly what we want here.
  await openPopupAndAssertUrlForPreset({
    window: privateWindow,
    preset: "Media",
    expectedUrl: FRONTEND_BASE_URL,
  });

  // Now, let's check for "web-developer" preset. This will open up the frontend
  // with "active-tab" view query string. Frontend will understand and open the active tab view for it.
  await openPopupAndAssertUrlForPreset({
    window: privateWindow,
    preset: "Web Developer",
    expectedUrl: FRONTEND_BASE_URL + "?view=active-tab&implementation=js",
  });

  await BrowserTestUtils.closeWindow(privateWindow);
});

async function openPopupAndAssertUrlForPreset({ window, preset, expectedUrl }) {
  // Let's capture a profile and assert newly created tab's url.
  await openPopupAndEnsureCloses(window, async () => {
    const { document } = window;
    {
      // Select the preset in the popup
      const presetsInPopup = document.getElementById(
        "PanelUI-profiler-presets"
      );
      presetsInPopup.menupopup.openPopup();
      presetsInPopup.menupopup.activateItem(
        await getElementByLabel(presetsInPopup, preset)
      );

      await TestUtils.waitForCondition(
        () => presetsInPopup.label === preset,
        `After selecting the preset in the popup, waiting until the preset is changed to ${preset} in the popup.`
      );
    }

    {
      const button = await getElementByLabel(document, "Start Recording");
      info("Click the button to start recording.");
      button.click();
    }

    {
      const button = await getElementByLabel(document, "Capture");
      info("Click the button to capture the recording.");
      button.click();
    }

    info(
      "If the profiler successfully captures a profile, it will create a new " +
        "tab with the proper view query string depending on the preset."
    );

    await waitForTabUrl({
      initialTitle: "Waiting on the profile",
      successTitle: "Profile received",
      errorTitle: "Error",
      expectedUrl,
    });
  });
}