summaryrefslogtreecommitdiffstats
path: root/tools/profiler/tests/browser/browser_test_profile_fission.js
blob: 775fc8048ebe9e8933ed0770860dec8ba2822435 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* 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/. */

if (SpecialPowers.useRemoteSubframes) {
  // Bug 1586105: these tests could time out in some extremely slow conditions,
  // when fission is enabled.
  // Requesting a longer timeout should make it pass.
  requestLongerTimeout(2);
}

add_task(async function test_profile_fission_no_private_browsing() {
  // Requesting the complete log to be able to debug Bug 1586105.
  SimpleTest.requestCompleteLog();
  Assert.ok(!Services.profiler.IsActive());
  info("Clear the previous pages just in case we still have some open tabs.");
  await Services.profiler.ClearAllPages();

  info(
    "Start the profiler to test the page information with single frame page."
  );
  await startProfiler();

  info("Open a private window with single_frame.html in it.");
  const win = await BrowserTestUtils.openNewBrowserWindow({
    fission: true,
  });

  try {
    const url = BASE_URL_HTTPS + "single_frame.html";
    const contentBrowser = win.gBrowser.selectedBrowser;
    BrowserTestUtils.loadURIString(contentBrowser, url);
    await BrowserTestUtils.browserLoaded(contentBrowser, false, url);

    const parentPid = Services.appinfo.processID;
    const contentPid = await SpecialPowers.spawn(contentBrowser, [], () => {
      return Services.appinfo.processID;
    });

    // Getting the active Browser ID to assert the page info tabID later.
    const activeTabID = contentBrowser.browsingContext.browserId;

    info("Capture the profile data.");
    const { profile, contentProcess, contentThread } =
      await stopProfilerNowAndGetThreads(contentPid);

    Assert.equal(
      contentThread.isPrivateBrowsing,
      false,
      "The content process has the private browsing flag set to false."
    );

    Assert.equal(
      contentThread.userContextId,
      0,
      "The content process has the information about the container used for this process"
    );

    info(
      "Check if the captured page is the one with correct values we created."
    );

    let pageFound = false;
    for (const page of contentProcess.pages) {
      if (page.url == url) {
        Assert.equal(page.url, url);
        Assert.equal(typeof page.tabID, "number");
        Assert.equal(page.tabID, activeTabID);
        Assert.equal(typeof page.innerWindowID, "number");
        // Top level document will have no embedder.
        Assert.equal(page.embedderInnerWindowID, 0);
        Assert.equal(typeof page.isPrivateBrowsing, "boolean");
        Assert.equal(page.isPrivateBrowsing, false);
        pageFound = true;
        break;
      }
    }
    Assert.equal(pageFound, true);

    info("Check that the profiling logs exist with the expected properties.");
    Assert.equal(typeof profile.profilingLog, "object");
    Assert.equal(typeof profile.profilingLog[parentPid], "object");
    const parentLog = profile.profilingLog[parentPid];
    Assert.equal(typeof parentLog.profilingLogBegin_TSms, "number");
    Assert.equal(typeof parentLog.profilingLogEnd_TSms, "number");
    Assert.equal(typeof parentLog.bufferGlobalController, "object");
    Assert.equal(
      typeof parentLog.bufferGlobalController.controllerCreationTime_TSms,
      "number"
    );

    Assert.equal(typeof profile.profileGatheringLog, "object");
    Assert.equal(typeof profile.profileGatheringLog[parentPid], "object");
    Assert.equal(
      typeof profile.profileGatheringLog[parentPid]
        .profileGatheringLogBegin_TSms,
      "number"
    );
    Assert.equal(
      typeof profile.profileGatheringLog[parentPid].profileGatheringLogEnd_TSms,
      "number"
    );

    Assert.equal(typeof contentProcess.profilingLog, "object");
    Assert.equal(typeof contentProcess.profilingLog[contentPid], "object");
    Assert.equal(
      typeof contentProcess.profilingLog[contentPid].profilingLogBegin_TSms,
      "number"
    );
    Assert.equal(
      typeof contentProcess.profilingLog[contentPid].profilingLogEnd_TSms,
      "number"
    );

    Assert.equal(typeof contentProcess.profileGatheringLog, "undefined");
  } finally {
    await BrowserTestUtils.closeWindow(win);
  }
});

add_task(async function test_profile_fission_private_browsing() {
  // Requesting the complete log to be able to debug Bug 1586105.
  SimpleTest.requestCompleteLog();
  Assert.ok(!Services.profiler.IsActive());
  info("Clear the previous pages just in case we still have some open tabs.");
  await Services.profiler.ClearAllPages();

  info(
    "Start the profiler to test the page information with single frame page."
  );
  await startProfiler();

  info("Open a private window with single_frame.html in it.");
  const win = await BrowserTestUtils.openNewBrowserWindow({
    private: true,
    fission: true,
  });

  try {
    const url = BASE_URL_HTTPS + "single_frame.html";
    const contentBrowser = win.gBrowser.selectedBrowser;
    BrowserTestUtils.loadURIString(contentBrowser, url);
    await BrowserTestUtils.browserLoaded(contentBrowser, false, url);

    const contentPid = await SpecialPowers.spawn(contentBrowser, [], () => {
      return Services.appinfo.processID;
    });

    // Getting the active Browser ID to assert the page info tabID later.
    const activeTabID = contentBrowser.browsingContext.browserId;

    info("Capture the profile data.");
    const { contentProcess, contentThread } =
      await stopProfilerNowAndGetThreads(contentPid);

    Assert.equal(
      contentThread.isPrivateBrowsing,
      true,
      "The content process has the private browsing flag set to true."
    );

    Assert.equal(
      contentThread.userContextId,
      0,
      "The content process has the information about the container used for this process"
    );

    info(
      "Check if the captured page is the one with correct values we created."
    );

    let pageFound = false;
    for (const page of contentProcess.pages) {
      if (page.url == url) {
        Assert.equal(page.url, url);
        Assert.equal(typeof page.tabID, "number");
        Assert.equal(page.tabID, activeTabID);
        Assert.equal(typeof page.innerWindowID, "number");
        // Top level document will have no embedder.
        Assert.equal(page.embedderInnerWindowID, 0);
        Assert.equal(typeof page.isPrivateBrowsing, "boolean");
        Assert.equal(page.isPrivateBrowsing, true);
        pageFound = true;
        break;
      }
    }
    Assert.equal(pageFound, true);
  } finally {
    await BrowserTestUtils.closeWindow(win);
  }
});