tor-browser

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

test_HeapSnapshot_creationTime_01.js (1025B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // HeapSnapshot.prototype.creationTime returns the expected time.
      6 
      7 function waitForThirtyMilliseconds() {
      8  const start = Date.now();
      9  while (Date.now() - start < 30) {
     10    // do nothing
     11  }
     12 }
     13 
     14 function run_test() {
     15  const start = Date.now() * 1000;
     16  info("start                 = " + start);
     17 
     18  // Because Date.now() is less precise than the snapshot's time stamp, give it
     19  // a little bit of head room. Additionally, WinXP's timer only has granularity
     20  // of +/- 15ms.
     21  waitForThirtyMilliseconds();
     22  const path = ChromeUtils.saveHeapSnapshot({ runtime: true });
     23  waitForThirtyMilliseconds();
     24 
     25  const end = Date.now() * 1000;
     26  info("end                   = " + end);
     27 
     28  const snapshot = ChromeUtils.readHeapSnapshot(path);
     29  info("snapshot.creationTime = " + snapshot.creationTime);
     30 
     31  Assert.greaterOrEqual(snapshot.creationTime, start);
     32  Assert.lessOrEqual(snapshot.creationTime, end);
     33 }