test_xhr_method_case.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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" />
  10. <script type="text/javascript">
  11. const testMethods = [
  12. // these methods should be normalized
  13. ["get", "GET"],
  14. ["GET", "GET"],
  15. ["GeT", "GET"],
  16. ["geT", "GET"],
  17. ["GEt", "GET"],
  18. ["post", "POST"],
  19. ["POST", "POST"],
  20. ["delete", "DELETE"],
  21. ["DELETE", "DELETE"],
  22. ["options", "OPTIONS"],
  23. ["OPTIONS", "OPTIONS"],
  24. ["put", "PUT"],
  25. ["PUT", "PUT"],
  26. // HEAD is not tested because we use the resposne body as part of the test
  27. // ["head", "HEAD"],
  28. // ["HEAD", "HEAD"],
  29. // other custom methods should not be normalized
  30. ["Foo", "Foo"],
  31. ["bAR", "bAR"],
  32. ["foobar", "foobar"],
  33. ["FOOBAR", "FOOBAR"]
  34. ]
  35. function doIter(index)
  36. {
  37. var xhr = new XMLHttpRequest();
  38. xhr.open(testMethods[index][0], 'method.sjs', false); // sync request
  39. xhr.send();
  40. is(xhr.status, 200, 'transaction failed');
  41. is(xhr.response, testMethods[index][1], 'unexpected method');
  42. }
  43. function dotest()
  44. {
  45. SimpleTest.waitForExplicitFinish();
  46. for (var i = 0; i < testMethods.length; i++) {
  47. doIter(i);
  48. }
  49. SimpleTest.finish();
  50. }
  51. </script>
  52. </head>
  53. <body onload="dotest();">
  54. <p id="display"></p>
  55. <div id="content" style="display: none"></div>
  56. <pre id="test">
  57. </pre>
  58. </body>
  59. </html>