netwerk/test/mochitests/test_xhr_method_case.html

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 XHR uppercases certain method names, but not others
     5 -->
     6 <head>
     7   <title>Test for XHR Method casing</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 <script type="text/javascript">
    13 const testMethods = [
    14 // these methods should be normalized
    15  ["get", "GET"],
    16  ["GET", "GET"],
    17  ["GeT", "GET"],
    18  ["geT", "GET"],
    19  ["GEt", "GET"],
    20  ["post", "POST"],
    21  ["POST", "POST"],
    22  ["delete", "DELETE"],
    23  ["DELETE", "DELETE"],
    24  ["options", "OPTIONS"],
    25  ["OPTIONS", "OPTIONS"],
    26  ["put", "PUT"],
    27  ["PUT", "PUT"],
    28 // HEAD is not tested because we use the resposne body as part of the test
    29 // ["head", "HEAD"],
    30 // ["HEAD", "HEAD"],
    32 // other custom methods should not be normalized
    33  ["Foo", "Foo"],
    34  ["bAR", "bAR"],
    35  ["foobar", "foobar"],
    36  ["FOOBAR", "FOOBAR"]
    37 ]
    39 function doIter(index)
    40 {
    41   var xhr = new XMLHttpRequest();
    42   xhr.open(testMethods[index][0], 'method.sjs', false); // sync request
    43   xhr.send();
    44   is(xhr.status, 200, 'transaction failed');
    45   is(xhr.response, testMethods[index][1], 'unexpected method');
    46 }
    48 function dotest()
    49 {
    50   SimpleTest.waitForExplicitFinish();
    51   for (var i = 0; i < testMethods.length; i++) {
    52     doIter(i);
    53   }
    54   SimpleTest.finish();
    55 }
    57 </script>
    58 </head>
    59 <body onload="dotest();">
    60 <p id="display"></p>
    61 <div id="content" style="display: none"></div>
    62 <pre id="test">
    63 </pre>
    64 </body>
    65 </html>

mercurial