summaryrefslogtreecommitdiffstats
path: root/tools/profiler/tests/browser/browser_test_feature_ipcmessages.js
blob: f5fb2921a17713d8c5716031880bcaaa0a95c7b5 (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
/* 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/. */

requestLongerTimeout(10);

async function waitForLoad() {
  return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
    return new Promise(function (resolve) {
      if (content.document.readyState !== "complete") {
        content.document.addEventListener("readystatechange", () => {
          if (content.document.readyState === "complete") {
            resolve();
          }
        });
      } else {
        resolve();
      }
    });
  });
}

/**
 * Test the IPCMessages feature.
 */
add_task(async function test_profile_feature_ipcmessges() {
  const url = BASE_URL + "simple.html";

  info("Open a tab while profiling IPC messages.");
  await startProfiler({ features: ["js", "ipcmessages"] });
  info("Started the profiler sucessfully! Now, let's open a tab.");

  await BrowserTestUtils.withNewTab(url, async contentBrowser => {
    info("We opened a tab!");
    const contentPid = await SpecialPowers.spawn(
      contentBrowser,
      [],
      () => Services.appinfo.processID
    );
    info("Now let's wait until it's fully loaded.");
    await waitForLoad();

    info(
      "Check that some IPC profile markers were generated when " +
        "the feature is enabled."
    );
    {
      const { parentThread, contentThread } =
        await waitSamplingAndStopProfilerAndGetThreads(contentPid);

      Assert.greater(
        getPayloadsOfType(parentThread, "IPC").length,
        0,
        "IPC profile markers were recorded for the parent process' main " +
          "thread when the IPCMessages feature was turned on."
      );

      Assert.greater(
        getPayloadsOfType(contentThread, "IPC").length,
        0,
        "IPC profile markers were recorded for the content process' main " +
          "thread when the IPCMessages feature was turned on."
      );
    }
  });

  info("Now open a tab without profiling IPC messages.");
  await startProfiler({ features: ["js"] });

  await BrowserTestUtils.withNewTab(url, async contentBrowser => {
    const contentPid = await SpecialPowers.spawn(
      contentBrowser,
      [],
      () => Services.appinfo.processID
    );
    await waitForLoad();

    info(
      "Check that no IPC profile markers were recorded when the " +
        "feature is turned off."
    );
    {
      const { parentThread, contentThread } =
        await waitSamplingAndStopProfilerAndGetThreads(contentPid);
      Assert.equal(
        getPayloadsOfType(parentThread, "IPC").length,
        0,
        "No IPC profile markers were recorded for the parent process' main " +
          "thread when the IPCMessages feature was turned off."
      );

      Assert.equal(
        getPayloadsOfType(contentThread, "IPC").length,
        0,
        "No IPC profile markers were recorded for the content process' main " +
          "thread when the IPCMessages feature was turned off."
      );
    }
  });
});