tor-browser

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

test_abort_controller.html (1610B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <!DOCTYPE HTML>
      6 <html>
      7 <head>
      8  <title>Test AbortController</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <script class="testbody" type="text/javascript">
     14 
     15 function testWebIDL() {
     16  ok("AbortController" in self, "We have a AbortController prototype");
     17  ok("AbortSignal" in self, "We have a AbortSignal prototype");
     18 
     19  var ac = new AbortController();
     20  ok(!!ac, "AbortController can be created");
     21  ok(ac instanceof AbortController, "AbortController is a AbortController");
     22 
     23  ok(!!ac.signal, "AbortController has a signal");
     24  ok(ac.signal instanceof AbortSignal, "abortSignal is a AbortSignal");
     25  is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
     26  next();
     27 }
     28 
     29 function testUpdateData() {
     30  var ac = new AbortController();
     31 
     32  is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
     33 
     34  ac.abort();
     35  is(ac.signal.aborted, true, "Signal is aborted");
     36 
     37  next();
     38 }
     39 
     40 function testAbortEvent() {
     41  var ac = new AbortController();
     42  ac.signal.onabort = function(e) {
     43    is(e.type, "abort", "Abort received");
     44    next();
     45  };
     46  ac.abort();
     47 }
     48 
     49 var steps = [
     50  // Simple stuff
     51  testWebIDL,
     52  testUpdateData,
     53 
     54  // Event propagation
     55  testAbortEvent,
     56 ];
     57 
     58 function next() {
     59  if (!steps.length) {
     60    SimpleTest.finish();
     61    return;
     62  }
     63 
     64  var step = steps.shift();
     65  step();
     66 }
     67 
     68 SimpleTest.waitForExplicitFinish();
     69 next();
     70 
     71 </script>
     72 </body>
     73 </html>