netwerk/test/mochitests/test_xhr_method_case.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial