tor-browser

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

browser_utility_hard_kill_delayed.js (2296B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async () => {
      7  const utilityPid = await startUtilityProcess();
      8 
      9  SimpleTest.expectChildProcessCrash();
     10 
     11  const utilityProcessGone = TestUtils.topicObserved("ipc:utility-shutdown");
     12 
     13  info("Hard kill Utility Process");
     14  const ProcessTools = Cc["@mozilla.org/processtools-service;1"].getService(
     15    Ci.nsIProcessToolsService
     16  );
     17 
     18  // Here we really want to exercise the fact that kill() might not be done
     19  // right now but a bit later, and we should wait for the process to be dead
     20  // before considering the test is finished.
     21  //
     22  // Without this, we get into bug 1754572 (where there was no setTimeout nor
     23  // the wait) where the kill() operation ends up really killing the child a
     24  // bit after the current test has been finished ; unfortunately, this happened
     25  // right after the next test, browser_utility_memoryReport.js did start and
     26  // even worse, after it thought it had started a new utility process. We were
     27  // in fact re-using the one we started here, and when we wanted to query its
     28  // pid in the browser_utility_memoryReport.js then the kill() happened, so
     29  // no more process and the test intermittently failed.
     30  //
     31  // The timeout value of 50ms should be long enough to allow the test to finish
     32  // and the next one to start and get a reference on the process we launched,
     33  // and yet allow us to kill the process in the middle of the next test. Higher
     34  // values would allow browser_utility_memoryReport.js to complete without
     35  // reproducing the issue (both locally and on try).
     36  //
     37  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     38  setTimeout(() => {
     39    ProcessTools.kill(utilityPid);
     40  }, 50);
     41 
     42  info(`Waiting for utility process ${utilityPid} to go away.`);
     43  let [subject, data] = await utilityProcessGone;
     44  ok(
     45    subject instanceof Ci.nsIPropertyBag2,
     46    "Subject needs to be a nsIPropertyBag2 to clean up properly"
     47  );
     48  is(
     49    parseInt(data, 10),
     50    utilityPid,
     51    `Should match the crashed PID ${utilityPid} with ${data}`
     52  );
     53 
     54  // Make sure the process is dead, otherwise there is a risk of race for
     55  // writing leak logs
     56  utilityProcessTest().noteIntentionalCrash(utilityPid);
     57 });