tor-browser

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

status-async.htm (4500B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>CORS - status</title>
      4 <meta name=author title="Odin Hørthe Omdal" href="mailto:odiho@opera.com">
      5 <meta name=timeout content=long>
      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>Status returned</h1>
     12 
     13 <div id=log></div>
     14 <script>
     15 
     16 function statusRequest(method, code, text, content, type) {
     17    async_test("Status on " + method + " " + code)
     18    .step(function() {
     19        var client = new XMLHttpRequest()
     20        client.open(method, CROSSDOMAIN + "resources/status.py?code="
     21            + code + "&text=" + text + "&content=" + content + "&type=" + type, true)
     22        client.onreadystatechange = this.step_func(function() {
     23            if (client.readyState != client.DONE)
     24                return
     25 
     26            assert_equals(client.status, code, 'response status')
     27            assert_equals(client.statusText, text, 'response status text')
     28            assert_equals(client.getResponseHeader("X-Request-Method"), method, 'method')
     29            if(method != "HEAD") {
     30                if(type == "text/xml") {
     31                    assert_equals(client.responseXML.documentElement.localName,
     32                                "x", 'responseXML')
     33                }
     34                assert_equals(client.response, content, 'response content')
     35            }
     36            this.done()
     37        })
     38 
     39        client.send(null)
     40    })
     41 }
     42 
     43  /*            method     code text  content        type */
     44  statusRequest("GET",     200, 'OK', 'Not today.',  '')
     45  statusRequest("GET",     201, 'OK/Created', 'Not today 01.',  '')
     46  statusRequest("GET",     202, 'OK/Accepted', 'Not today 02.',  '')
     47  statusRequest("GET",     203, 'OK/Non-Authoritative Information', 'Not today 03.',  '')
     48  statusRequest("GET",     204, 'OK/No Content', '',  '') // specifically no-content
     49  statusRequest("GET",     205, 'OK/Reset Content', '',  '') // specifically no-content
     50  statusRequest("GET",     206, 'OK/Partial Content', 'Not today 06.',  '')
     51  statusRequest("GET",     209, 'OK', 'Not today 09.',  '')
     52  statusRequest("GET",     299, 'OK', 'Not today 99.',  '')
     53  statusRequest("POST",    200, 'OK', '<x>402<\/x>', 'text/xml')
     54  statusRequest("HEAD",    200, 'OK', 'Nice!',       'text/doesnotmatter')
     55  statusRequest("PUT",     200, 'OK', '400',         'text/plain')
     56  statusRequest("CHICKEN", 200, 'OK', 'bah',         '')
     57 
     58 
     59 function statusRequestFail(method, code, expect_code, nonsimple) {
     60    if (expect_code === undefined)
     61        expect_code = code
     62 
     63    async_test("Status on " + method + " " + code + (nonsimple?' (nonsimple)':''))
     64    .step(function() {
     65        var client = new XMLHttpRequest()
     66 
     67        client.open(method, CROSSDOMAIN + "resources/status.py?code="
     68          + code + '&headers=x-nonsimple&text=OHAI', true)
     69 
     70        if (nonsimple)
     71            client.setRequestHeader('x-nonsimple', true)
     72 
     73        client.onreadystatechange = this.step_func(function() {
     74            if (client.readyState < client.HEADERS_RECEIVED)
     75                return
     76            assert_equals(client.response, "", "response data")
     77            assert_equals(client.status, expect_code, "response status")
     78            /* Response code 200 forces webserver to send OK(?) */
     79            if(expect_code == 200)
     80                assert_equals(client.statusText, "OK", "response statusText")
     81            else
     82                assert_equals(client.statusText, (expect_code == 0 ? "" : "OHAI"), "response statusText")
     83            if (client.readyState == client.DONE)
     84                this.done()
     85        })
     86 
     87        client.onerror = this.step_func(function(e) {
     88            assert_unreached("Got error event.")
     89        })
     90 
     91        client.send()
     92    })
     93 }
     94 
     95  /*                                 expect
     96                    method     code  status */
     97  statusRequestFail("GET",     400)
     98  statusRequestFail("HEAD",    401)
     99  statusRequestFail("POST",    404)
    100  statusRequestFail("POST",    500)
    101 
    102  /* Preflight response status is not 200, so the algorithm set status to 0. */
    103  statusRequestFail("PUT",     699,  0)
    104  statusRequestFail("CHICKEN", 501,  0)
    105 
    106  /*                                    "forced"
    107                                        preflight */
    108  statusRequestFail("GET",     400,  0, true)
    109  statusRequestFail("HEAD",    401,  0, true)
    110  statusRequestFail("POST",    404,  0, true)
    111  statusRequestFail("PUT",     699,  0, true)
    112  statusRequestFail("CHICKEN", 501,  0, true)
    113 
    114 </script>