1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Check that we record hangs in the parent process in telemetry events.
8 * This test would be an xpcshell test except xpcshell does not think
9 * it is running e10s (see bug 1568333).
11 add_task(async function test_browser_hang() {
12 // Trip some testing code to ensure we can test this. Sadly, this is a magic
13 // number corresponding to code in XPCJSContext.cpp
14 await SpecialPowers.pushPrefEnv({
15 set: [["dom.max_chrome_script_run_time", 2]],
17 await SpecialPowers.promiseTimeout(0);
19 // Hang for 1.2 seconds.
23 while (Date.now() - now < 2500) {
24 // The system clock can go backwards. Don't time out the test:
25 if (Date.now() - now < 0) {
26 info("Yikes, the system clock changed while running this test.");
31 let duration = (Date.now() - now) / 1000;
32 info("Looped " + i + " iterations.");
35 await TestUtils.waitForCondition(() => {
36 events = Services.telemetry.snapshotEvents(
37 Ci.nsITelemetry.DATASET_ALL_CHANNELS,
40 return events.parent?.some(e => e[1] == "slow_script_warning");
41 }, "Should find an event after doing this.").catch(e => ok(false, e));
42 events = events.parent || [];
43 let event = events.find(e => e[1] == "slow_script_warning");
44 ok(event, "Should have registered an event.");
46 is(event[3], "browser", "Should register as browser hang.");
48 is(args.uri_type, "browser", "Should register browser uri type.");
51 parseFloat(args.hang_duration),
52 "hang duration should not exaggerate."
56 parseFloat(args.hang_duration),
57 "hang duration should not undersell."