summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/browser/browser_perf-04.js
blob: c001576313e43c7841e570a86d496da5165a5470 (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
/* 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";

/**
 * Run through a series of basic recording actions for the perf actor.
 */
add_task(async function() {
  const { front, client } = await initPerfFront();

  // Assert the initial state.
  is(
    await front.isSupportedPlatform(),
    true,
    "This test only runs on supported platforms."
  );
  is(
    await front.isLockedForPrivateBrowsing(),
    false,
    "The browser is not in private browsing mode."
  );
  is(await front.isActive(), false, "The profiler is not active yet.");

  // Getting the active BrowsingContext ID to assert in the "profiler-started" event.
  const win = Services.wm.getMostRecentWindow("navigator:browser");
  const activeBrowsingContextID =
    win.gBrowser.selectedBrowser.browsingContext.id;

  front.once(
    "profiler-started",
    (entries, interval, features, duration, activeBCID) => {
      is(entries, 1024, "Should apply entries by startProfiler");
      is(interval, 0.1, "Should apply interval by startProfiler");
      is(typeof features, "number", "Should apply features by startProfiler");
      is(duration, 2, "Should apply duration by startProfiler");
      is(
        activeBCID,
        activeBrowsingContextID,
        "Should apply active browsing context ID by startProfiler"
      );
    }
  );

  // Start the profiler.
  await front.startProfiler({
    entries: 1000,
    duration: 2,
    interval: 0.1,
    features: ["js", "stackwalk"],
  });

  is(await front.isActive(), true, "The profiler is active.");

  // clean up
  await front.stopProfilerAndDiscardProfile();
  await front.destroy();
  await client.close();
});