tor-browser

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

browser_CrashService_crash.js (2210B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Ensures that content crashes are reported to the crash service
      6 // (nsICrashService and CrashManager.sys.mjs).
      7 
      8 /* eslint-disable mozilla/no-arbitrary-setTimeout */
      9 SimpleTest.requestFlakyTimeout("untriaged");
     10 SimpleTest.requestCompleteLog();
     11 
     12 add_task(async function () {
     13  let tab = await BrowserTestUtils.openNewForegroundTab({
     14    gBrowser,
     15    forceNewProcess: true,
     16  });
     17 
     18  SimpleTest.expectChildProcessCrash();
     19 
     20  let crashMan = Services.crashmanager;
     21 
     22  // First, clear the crash record store.
     23  info("Waiting for pruneOldCrashes");
     24  var future = new Date(Date.now() + 1000 * 60 * 60 * 24);
     25  await crashMan.pruneOldCrashes(future);
     26 
     27  var crashDateMS = Date.now();
     28 
     29  let crashPromise = BrowserTestUtils.crashFrame(tab.linkedBrowser);
     30 
     31  // Finally, poll for the new crash record.
     32  await new Promise((resolve, reject) => {
     33    function tryGetCrash() {
     34      info("Waiting for getCrashes");
     35      crashMan.getCrashes().then(
     36        function (crashes) {
     37          if (crashes.length) {
     38            is(crashes.length, 1, "There should be only one record");
     39            var crash = crashes[0];
     40            ok(
     41              crash.isOfType(
     42                crashMan.processTypes[Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT],
     43                crashMan.CRASH_TYPE_CRASH
     44              ),
     45              "Record should be a content crash"
     46            );
     47            ok(!!crash.id, "Record should have an ID");
     48            ok(!!crash.crashDate, "Record should have a crash date");
     49            var dateMS = crash.crashDate.valueOf();
     50            var twoMin = 1000 * 60 * 2;
     51            ok(
     52              crashDateMS - twoMin <= dateMS && dateMS <= crashDateMS + twoMin,
     53              `Record's crash date should be nowish: ` +
     54                `now=${crashDateMS} recordDate=${dateMS}`
     55            );
     56            resolve();
     57          } else {
     58            setTimeout(tryGetCrash, 1000);
     59          }
     60        },
     61        function (err) {
     62          reject(err);
     63        }
     64      );
     65    }
     66    setTimeout(tryGetCrash, 1000);
     67  });
     68 
     69  await crashPromise;
     70 
     71  await BrowserTestUtils.removeTab(tab);
     72 });