tor-browser

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

max-buffer-size.window.js (1535B)


      1 // META: script=resources/profile-utils.js
      2 
      3 promise_test(async t => {
      4  assert_throws_js(TypeError, () => {
      5    new Profiler({ sampleInterval: 10 });
      6  });
      7 }, 'max buffer size must be defined');
      8 
      9 promise_test(async t => {
     10  const profiler = new Profiler({
     11    sampleInterval: 10,
     12    maxBufferSize: 2,
     13  });
     14 
     15  // Force 3 samples with a max buffer size of 2.
     16  for (let i = 0; i < 3; i++) {
     17    ProfileUtils.forceSample();
     18  }
     19 
     20  const trace = await profiler.stop();
     21  assert_equals(trace.samples.length, 2);
     22 }, 'max buffer size is not exceeded');
     23 
     24 promise_test(async t => {
     25  const largeBufferProfiler = new Profiler({ sampleInterval: 10,  maxBufferSize: Number.MAX_SAFE_INTEGER });
     26  const smallBufferProfiler = new Profiler({ sampleInterval: 10,  maxBufferSize: 1 });
     27 
     28  const watcher = new EventWatcher(t, smallBufferProfiler, ['samplebufferfull']);
     29 
     30  largeBufferProfiler.addEventListener('samplebufferfull', () => {
     31    assert_unreached('samplebufferfull invoked on wrong profiler');
     32    largeBufferProfiler.stop();
     33    smallBufferProfiler.stop();
     34  });
     35 
     36  smallBufferProfiler.addEventListener('samplebufferfull', () => {
     37    largeBufferProfiler.stop();
     38    smallBufferProfiler.stop();
     39  });
     40 
     41  // Force two samples to be taken, which should exceed
     42  // |smallBufferProfiler|'s buffer size.
     43  for (let i = 0; i < 2; i++) {
     44    ProfileUtils.forceSample();
     45  }
     46 
     47  // Ensure that |smallBufferProfiler|'s buffer size is exceeded.
     48  await watcher.wait_for('samplebufferfull');
     49 }, 'ensure samplebufferfull is fired on full profiler');