tor-browser

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

compute_pressure_timestamp_continuously_increasing.https.window.js (1331B)


      1 // META: timeout=long
      2 // META: variant=?globalScope=window
      3 // META: variant=?globalScope=dedicated_worker
      4 // META: script=/resources/testdriver.js
      5 // META: script=/resources/testdriver-vendor.js
      6 // META: script=/common/utils.js
      7 // META: script=/common/dispatcher/dispatcher.js
      8 // META: script=./resources/common.js
      9 // META: script=./resources/sync-pressure-observer.js
     10 
     11 'use strict';
     12 
     13 pressure_test(async t => {
     14  await create_virtual_pressure_source('cpu');
     15  t.add_cleanup(async () => {
     16    await remove_virtual_pressure_source('cpu');
     17  });
     18 
     19  const readings = ['nominal', 'fair', 'serious', 'critical'];
     20 
     21  const syncObserver = new SyncPressureObserver(t);
     22  await syncObserver.observer().observe('cpu', {sampleInterval: 250});
     23 
     24  for (let i = 0; i < readings.length; ++i) {
     25    await update_virtual_pressure_source('cpu', readings[i]);
     26    await syncObserver.waitForUpdate();
     27  }
     28 
     29  const pressureChanges = syncObserver.changes();
     30  assert_equals(pressureChanges.length, readings.length);
     31 
     32  assert_greater_than(pressureChanges[1][0].time, pressureChanges[0][0].time);
     33  assert_greater_than(pressureChanges[2][0].time, pressureChanges[1][0].time);
     34  assert_greater_than(pressureChanges[3][0].time, pressureChanges[2][0].time);
     35 }, 'Timestamp difference between two changes should be continuously increasing');
     36 
     37 mark_as_done();