tor-browser

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

status.htm (2493B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>CORS status</title>
      4 <link rel=help href=https://fetch.spec.whatwg.org/>
      5 <meta name=author title="Odin Hørthe Omdal" href="mailto:odiho@opera.com">
      6 
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <script src="support.js?pipe=sub"></script>
     10 
     11 <h1>The returned status code in different scenarios</h1>
     12 
     13 <script>
     14 
     15    var counter = 0
     16 
     17    function testit(allow, preflight, response, status) {
     18        async_test(
     19            (++counter) + '. ' +
     20            (allow ? 'CORS allowed' : 'CORS disallowed') +
     21            (preflight ? ', preflight status '+preflight : '') +
     22            (response ? ', response status '+response : '') +
     23            '.'
     24        ).step(function() {
     25            var client = new XMLHttpRequest()
     26            client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.py?' + counter +
     27                (allow ? '&headers=x-custom': '&origin=none') +
     28                (response ? '&code='+response : '') +
     29                (preflight ? '&preflight='+preflight : '')
     30            )
     31 
     32            if (preflight)
     33                client.setRequestHeader('X-Custom', 'preflight')
     34 
     35            client.onload = this.step_func(function() {
     36                if (!status)
     37                    assert_unreached("load event")
     38 
     39                /* Allow spurious error events to fire */
     40                this.step_timeout(() => {
     41                    assert_equals(client.status, status, "status")
     42                    this.done()
     43                }, 10)
     44            })
     45 
     46            client.onerror = this.step_func(function() {
     47                if (status)
     48                    assert_unreached("error event")
     49 
     50                assert_equals(client.readyState, client.DONE, 'readyState')
     51                assert_equals(client.status, 0, 'status')
     52                this.done()
     53            })
     54 
     55            client.send()
     56 
     57        })
     58    }
     59 
     60    /*     allow  pref  resp  status */
     61    testit(false, null, 400,  0)
     62    testit(false, 200,  null, 0)
     63    testit(true,  null, 400,  400)
     64    testit(true,  200,  400,  400)
     65    testit(true,  400,  null, 0)
     66 
     67 </script>
     68 
     69 <pre>
     70   allowed  preflight  response  | status |
     71   -------  ---------  --------  | ------ |
     72 1      no          x       400  |      0 |
     73 2      no        200         x  |      0 |
     74 3     yes          x       400  |    400 |
     75 4     yes        200       400  |    400 |
     76 5     yes        400         x  |      0 |
     77 </pre>
     78 
     79 <div id=log></div>