test_bug590353-2.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=590353
  5. -->
  6. <head>
  7. <title>Test for Bug 590353</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=590353">Mozilla Bug 590353</a>
  13. <p id="display"></p>
  14. <div id="content" style="display: none">
  15. </div>
  16. <pre id="test">
  17. <script type="application/javascript">
  18. /** Test for Bug 590353 **/
  19. var testData = [
  20. [ "text", "foo", "" ],
  21. [ "email", "foo@bar.com", "" ],
  22. [ "url", "http:///foo.com", "" ],
  23. [ "tel", "555 555 555 555", "" ],
  24. [ "search", "foo", "" ],
  25. [ "password", "secret", "" ],
  26. [ "hidden", "foo", "foo" ],
  27. [ "button", "foo", "foo" ],
  28. [ "reset", "foo", "foo" ],
  29. [ "submit", "foo", "foo" ],
  30. [ "checkbox", true, false ],
  31. [ "radio", true, false ],
  32. [ "file", "590353_file", "" ],
  33. ];
  34. function createFileWithData(fileName, fileData) {
  35. return new File([new Blob([fileData], { type: "text/plain" })], fileName);
  36. }
  37. var content = document.getElementById('content');
  38. var form = document.createElement('form');
  39. content.appendChild(form);
  40. for (var data of testData) {
  41. var e = document.createElement('input');
  42. e.type = data[0];
  43. if (data[0] == 'checkbox' || data[0] == 'radio') {
  44. e.checked = data[1];
  45. } else if (data[0] == 'file') {
  46. var file = createFileWithData(data[1], "file content");
  47. SpecialPowers.wrap(e).mozSetFileArray([file]);
  48. } else {
  49. e.value = data[1];
  50. }
  51. form.appendChild(e);
  52. }
  53. form.reset();
  54. var size = form.elements.length;
  55. for (var i=0; i<size; ++i) {
  56. var e = form.elements[i];
  57. if (e.type == 'radio' || e.type == 'checkbox') {
  58. is(e.checked, testData[i][2],
  59. "the element checked value should be " + testData[i][2]);
  60. } else {
  61. is(e.value, testData[i][2],
  62. "the element value should be " + testData[i][2]);
  63. }
  64. }
  65. </script>
  66. </pre>
  67. </body>
  68. </html>