tor-browser

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

freeze.html (2049B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>TestDriver freeze method</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <script>
      8 var test = async_test('Test freeze callback.');
      9 window.open('resources/window.html', 'Child Window');
     10 
     11 var total_steps = 0;
     12 
     13 const StepStatus = {
     14  ADDED: 0,
     15  SUCCESS: 1,
     16  FAIL: 2,
     17 };
     18 
     19 var steps_map = new Map();
     20 
     21 function poll_for_result(request_token, step_name, expect_success) {
     22  test.step(() => {
     23    var iteration = 5;
     24    var checkResult = () => {
     25      fetch("resources/beacon.py?query&token=" + request_token).then(test.step_func((response) => {
     26        var count = response.headers.get("Count");
     27        if (count != '0') {
     28          // If the server received something we can terminate polling.
     29          if (expect_success) {
     30            step_success(step_name);
     31          } else {
     32            step_fail(step_name);
     33          }
     34        } else if (!expect_success && count == '0' && iteration == 0) {
     35          // When we are out of iterations and we aren't expecting success, declare this step complete.
     36          // Should be 125 ms looking to make sure server didn't see the request.
     37          step_success(step_name);
     38        } else {
     39          iteration--;
     40          test.step_timeout(checkResult, 25);
     41        }
     42      }));
     43    };
     44    test.step_timeout(checkResult, 25);
     45  });
     46 }
     47 
     48 function add_step(name) {
     49  steps_map[name] = StepStatus.ADDED;
     50  total_steps++;
     51 }
     52 
     53 function step_success(name) {
     54  total_steps--;
     55  steps_map[name] = StepStatus.SUCCESS;
     56  if (total_steps == 0)
     57    test.done();
     58 }
     59 
     60 function step_fail(name) {
     61  total_steps--;
     62  steps_map[name] = StepStatus.FAIL;
     63  test.step(() => assert_unreached('During onfreeze: ' + name + ' failed to behave as expected.'));
     64  if (total_steps == 0)
     65    test.done();
     66 }
     67 
     68 test.step_timeout(() => {
     69  for (var step in steps_map) {
     70    if(steps_map[step] == StepStatus.ADDED)
     71      test.step(() => assert_unreached('During onfreeze: ' + step + ' never finshed.'));
     72  }
     73 }, 1000);
     74 
     75 </script>