test_bug590363.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=590363
  5. -->
  6. <head>
  7. <title>Test for Bug 590363</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=590363">Mozilla Bug 590363</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 590363 **/
  19. var testData = [
  20. /* type to test | is the value reset when changing to file then reverting */
  21. [ "button", false ],
  22. [ "checkbox", false ],
  23. [ "hidden", false ],
  24. [ "reset", false ],
  25. [ "image", false ],
  26. [ "radio", false ],
  27. [ "submit", false ],
  28. [ "tel", true ],
  29. [ "text", true ],
  30. [ "url", true ],
  31. [ "email", true ],
  32. [ "search", true ],
  33. [ "password", true ],
  34. [ "number", true ],
  35. [ "date", true ],
  36. [ "time", true ],
  37. [ "range", true ],
  38. [ "color", true ],
  39. [ 'month', true ],
  40. [ 'week', true ],
  41. [ 'datetime-local', true ]
  42. // 'file' is treated separatly.
  43. ];
  44. var nonTrivialSanitizing = [ 'number', 'date', 'time', 'color', 'month', 'week',
  45. 'datetime-local' ];
  46. var length = testData.length;
  47. for (var i=0; i<length; ++i) {
  48. for (var j=0; j<length; ++j) {
  49. var e = document.createElement('input');
  50. e.type = testData[i][0];
  51. var expectedValue;
  52. // range will sanitize its value to 50 (the default) if it isn't a valid
  53. // number. We need to handle that specially.
  54. if (testData[j][0] == 'range' || testData[i][0] == 'range') {
  55. if (testData[j][0] == 'date' || testData[j][0] == 'time' ||
  56. testData[j][0] == 'month' || testData[j][0] == 'week' ||
  57. testData[j][0] == 'datetime-local') {
  58. expectedValue = '';
  59. } else if (testData[j][0] == 'color') {
  60. expectedValue = '#000000';
  61. } else {
  62. expectedValue = '50';
  63. }
  64. } else if (testData[i][0] == 'color' || testData[j][0] == 'color') {
  65. if (testData[j][0] == 'number' || testData[j][0] == 'date' ||
  66. testData[j][0] == 'time' || testData[j][0] == 'month' ||
  67. testData[j][0] == 'week' || testData[j][0] == 'datetime-local') {
  68. expectedValue = ''
  69. } else {
  70. expectedValue = '#000000';
  71. }
  72. } else if (nonTrivialSanitizing.indexOf(testData[i][0]) != -1 &&
  73. nonTrivialSanitizing.indexOf(testData[j][0]) != -1) {
  74. expectedValue = '';
  75. } else if (testData[i][0] == 'number' || testData[j][0] == 'number') {
  76. expectedValue = '42';
  77. } else if (testData[i][0] == 'date' || testData[j][0] == 'date') {
  78. expectedValue = '2012-12-21';
  79. } else if (testData[i][0] == 'time' || testData[j][0] == 'time') {
  80. expectedValue = '21:21';
  81. } else if (testData[i][0] == 'month' || testData[j][0] == 'month') {
  82. expectedValue = '2013-03';
  83. } else if (testData[i][0] == 'week' || testData[j][0] == 'week') {
  84. expectedValue = '2016-W35';
  85. } else if (testData[i][0] == 'datetime-local' ||
  86. testData[j][0] == 'datetime-local') {
  87. expectedValue = '2016-11-07T16:40';
  88. } else {
  89. expectedValue = "foo";
  90. }
  91. e.value = expectedValue;
  92. e.type = testData[j][0];
  93. is(e.value, expectedValue, ".value should still return the same value after " +
  94. "changing type from " + testData[i][0] + " to " + testData[j][0]);
  95. }
  96. }
  97. // For type='file' .value doesn't behave the same way.
  98. // We are just going to check that we do not loose the value.
  99. for (var data of testData) {
  100. var e = document.createElement('input');
  101. e.type = data[0];
  102. e.value = 'foo';
  103. e.type = 'file';
  104. e.type = data[0];
  105. if (data[0] == 'range') {
  106. is(e.value, '50', ".value should still return the same value after " +
  107. "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
  108. } else if (data[0] == 'color') {
  109. is(e.value, '#000000', ".value should have been reset to the default color after " +
  110. "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
  111. } else if (data[1]) {
  112. is(e.value, '', ".value should have been reset to the empty string after " +
  113. "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
  114. } else {
  115. is(e.value, 'foo', ".value should still return the same value after " +
  116. "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
  117. }
  118. }
  119. </script>
  120. </pre>
  121. </body>
  122. </html>