summaryrefslogtreecommitdiffstats
path: root/tools/profiler/tests/browser/browser_test_markers_preferencereads.js
blob: 0ae183f87440f341c4d63646eeaac59e6e58ef44 (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
/* 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);

const kContentPref = "font.size.variable.x-western";

function countPrefReadsInThread(pref, thread) {
  let count = 0;
  for (let payload of getPayloadsOfType(thread, "Preference")) {
    if (payload.prefName === pref) {
      count++;
    }
  }
  return count;
}

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

/**
 * Test the Preference Read markers.
 */
add_task(async function test_profile_preferencereads_markers() {
  Assert.ok(
    !Services.profiler.IsActive(),
    "The profiler is not currently active"
  );

  await startProfiler({ features: ["js"] });

  const url = BASE_URL + "single_frame.html";
  await BrowserTestUtils.withNewTab(url, async contentBrowser => {
    const contentPid = await SpecialPowers.spawn(
      contentBrowser,
      [],
      () => Services.appinfo.processID
    );

    await waitForPaintAfterLoad();

    // Ensure we read a pref in the content process.
    await SpecialPowers.spawn(contentBrowser, [kContentPref], pref => {
      Services.prefs.getIntPref(pref);
    });

    // Check that some Preference Read profile markers were generated.
    {
      const { contentThread } = await stopProfilerNowAndGetThreads(contentPid);

      Assert.greater(
        countPrefReadsInThread(kContentPref, contentThread),
        0,
        `Preference Read profile markers for ${kContentPref} were recorded.`
      );
    }
  });
});