tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_parent_process_hang_telemetry.js (1943B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      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).
     10 */
     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]],
     16  });
     17  await SpecialPowers.promiseTimeout(0);
     18 
     19  // Hang for 1.2 seconds.
     20  let now = Date.now();
     21  let i = 0;
     22  info("Start loop");
     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.");
     27      now = Date.now();
     28    }
     29    i++;
     30  }
     31  let duration = (Date.now() - now) / 1000;
     32  info("Looped " + i + " iterations.");
     33 
     34  let events;
     35  await TestUtils.waitForCondition(() => {
     36    events = Services.telemetry.snapshotEvents(
     37      Ci.nsITelemetry.DATASET_ALL_CHANNELS,
     38      false
     39    );
     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.");
     45  if (event) {
     46    is(event[3], "browser", "Should register as browser hang.");
     47    let args = event[5];
     48    is(args.uri_type, "browser", "Should register browser uri type.");
     49    Assert.greater(
     50      duration + 1,
     51      parseFloat(args.hang_duration),
     52      "hang duration should not exaggerate."
     53    );
     54    Assert.less(
     55      duration - 1,
     56      parseFloat(args.hang_duration),
     57      "hang duration should not undersell."
     58    );
     59  }
     60 });