test_bug542914.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=542914
  5. -->
  6. <head>
  7. <title>Test for Bug 542914</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=542914">Mozilla Bug 542914</a>
  14. <p id="display">
  15. <input type="text" id="a" value="test">
  16. <input type="text" id="b">
  17. <input type="text" id="c">
  18. </p>
  19. <div id="content" style="display: none">
  20. </div>
  21. <pre id="test">
  22. <script type="application/javascript">
  23. /** Test for Bug 542914 **/
  24. SimpleTest.waitForExplicitFinish();
  25. function runTests(callback, type) {
  26. var a = $("a");
  27. // Test that the initial value of the control is available to script
  28. // without initilization of the editor
  29. is(a.value, "test", "The value is available before initialization");
  30. // Initialize the editor
  31. a.focus();
  32. // Test that the value does not change after initialization
  33. is(a.value, "test", "The value does not change after initializtion");
  34. var b = $("b");
  35. // Test that the initial value is empty before initialization.
  36. is(b.value, "", "The value is empty before initialization");
  37. // Make sure that the value can be changed before initialization
  38. b.value ="some value";
  39. is(b.value, "some value", "The value can be changed before initialization");
  40. // Initialize the editor
  41. b.focus();
  42. // Make sure that the value does not change after initialization
  43. is(b.value, "some value", "The value does not change after initialization");
  44. // Make sure that the value does not change if the element is hidden
  45. b.style.display = "none";
  46. document.body.offsetHeight;
  47. is(b.value, "some value", "The value does not change while hidden");
  48. b.style.display = "";
  49. document.body.offsetHeight;
  50. b.focus();
  51. is(b.value, "some value", "The value does not change after being shown");
  52. var c = $("c");
  53. // Make sure that the control accepts input events without explicit initialization
  54. is(c.value, "", "Control is empty initially");
  55. c.focus();
  56. sendChar("a");
  57. is(c.value, "a", "Control accepts input without explicit initialization");
  58. // Make sure that the control retains its caret position
  59. c.focus();
  60. c.blur();
  61. c.focus();
  62. sendChar("b");
  63. is(c.value, "ab", "Control retains caret position after being re-focused");
  64. var d = document.createElement("input");
  65. d.setAttribute("type", type);
  66. $("display").appendChild(d);
  67. document.body.offsetHeight;
  68. // Make sure dynamically injected inputs work as expected
  69. is(d.value, "", "Dynamic control's initial value should be empty");
  70. d.value = "new";
  71. d.focus();
  72. is(d.value, "new", "Dynamic control's value can be set before initialization");
  73. sendChar("x");
  74. is(d.value, "newx", "Dynamic control accepts keyboard input without explicit initialization");
  75. $("display").removeChild(d);
  76. is(d.value, "newx", "Dynamic control retains value after being removed from the document");
  77. callback();
  78. }
  79. var gPreviousType = "text";
  80. function setTypes(aType) {
  81. var content = document.getElementById("display");
  82. content.innerHTML = content.innerHTML.replace(gPreviousType, aType);
  83. gPreviousType = aType;
  84. }
  85. addLoadEvent(function() {
  86. ok(true, "Running tests on <input type=text>");
  87. runTests(function() {
  88. ok(true, "Running tests on <input type=password>");
  89. setTypes("password");
  90. runTests(function() {
  91. ok(true, "Running tests on <input type=tel>");
  92. setTypes("tel");
  93. runTests(function() {
  94. SimpleTest.finish();
  95. }, "tel");
  96. }, "password");
  97. }, "text");
  98. });
  99. </script>
  100. </pre>
  101. </body>
  102. </html>