PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/WebKit/LayoutTests/imported/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange.html

https://gitlab.com/jonnialva90/iridium-browser
HTML | 224 lines | 187 code | 37 blank | 0 comment | 0 complexity | 90163072ecca9d3eb220c46ba1c6a067 MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <title>Test of text field setSelectionRange</title>
  3. <link rel="author" title="Takeharu.Oshida" href="mailto:georgeosddev@gmail.com">
  4. <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-textarea/input-setselectionrange">
  5. <script src="../../../../../../resources/testharness.js"></script>
  6. <script src="../../../../../../resources/testharnessreport.js"></script>
  7. <div id="log"></div>
  8. <div id="hide" style="display: block">
  9. <input id="a" type="text" value="abcde">
  10. <textarea id="b">abcde</textarea>
  11. </div>
  12. <script>
  13. test(function() {
  14. var input = document.getElementById("a");
  15. test(function() {
  16. assert_equals(typeof(input.setSelectionRange), "function", "element must have 'setSelectionRange' function");
  17. },"input typeof(input.setSelectionRange)'");
  18. test(function() {
  19. assert_equals(input.setSelectionRange(0,1,"forward"),undefined,"setSelectionRange is void functuon");
  20. },"input setSelectionRange return void");
  21. test(function() {
  22. input.setSelectionRange(0,1)
  23. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  24. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  25. },'input setSelectionRange(0,1)');
  26. test(function() {
  27. input.setSelectionRange(0,input.value.length+1)
  28. assert_equals(input.selectionEnd, input.value.length, "Arguments greater than the length of the value of the text field must be treated as pointing at the end of the text field");
  29. },'input setSelectionRange(0,input.value.length+1)');
  30. test(function() {
  31. input.setSelectionRange(2,2)
  32. assert_equals(input.selectionStart, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  33. assert_equals(input.selectionEnd, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  34. },'input setSelectionRange(2,2)');
  35. test(function() {
  36. input.setSelectionRange(2,1)
  37. assert_equals(input.selectionStart, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  38. assert_equals(input.selectionEnd, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  39. },'input setSelectionRange(2,1)');
  40. test(function() {
  41. input.setSelectionRange(0,1,"backward")
  42. assert_equals(input.selectionDirection, "backward", 'The direction of the selection must be set to backward if direction is a case-sensitive match for the string "backward"');
  43. },'input direction of setSelectionRange(0,1,"backward")');
  44. test(function() {
  45. input.setSelectionRange(0,1,"forward")
  46. assert_equals(input.selectionDirection, "forward", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "forward"');
  47. },'input direction of setSelectionRange(0,1,"forward")');
  48. test(function() {
  49. input.setSelectionRange(0,1,"none")
  50. assert_equals(input.selectionDirection, "none", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none"');
  51. },'input direction of setSelectionRange(0,1,"none")');
  52. test(function() {
  53. input.setSelectionRange(0,1,"hoge")
  54. assert_equals(input.selectionDirection, "none", "otherwise");
  55. },'input direction of setSelectionRange(0,1,"hoge")');
  56. test(function() {
  57. input.setSelectionRange(0,1,"BACKWARD")
  58. assert_equals(input.selectionDirection, "none", "selectionDirection should be 'none'");
  59. },'input direction of setSelectionRange(0,1,"BACKWARD")');
  60. test(function() {
  61. input.setSelectionRange(0,1)
  62. assert_equals(input.selectionDirection, "none", "if the argument is omitted");
  63. },'input direction of setSelectionRange(0,1)');
  64. test(function() {
  65. input.setSelectionRange("string",1);
  66. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  67. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  68. },'input setSelectionRange("string",1)');
  69. test(function() {
  70. input.setSelectionRange(true,1);
  71. assert_equals(input.selectionStart, 1, "element.selectionStart should be 1");
  72. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  73. },'input setSelectionRange(true,1)');
  74. test(function() {
  75. input.setSelectionRange([],1);
  76. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  77. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  78. },'input setSelectionRange([],1)');
  79. test(function() {
  80. input.setSelectionRange({},1);
  81. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  82. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  83. },'input setSelectionRange({},1)');
  84. test(function() {
  85. input.setSelectionRange(NaN,1);
  86. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  87. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  88. },'input setSelectionRange(NaN,1)');
  89. test(function() {
  90. input.setSelectionRange(null,1);
  91. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  92. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  93. },'input setSelectionRange(null,1)');
  94. test(function() {
  95. input.setSelectionRange(undefined,1);
  96. assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
  97. assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
  98. },'input setSelectionRange(undefined,1)');
  99. },"test of input.setSelectionRange");
  100. test(function() {
  101. var textarea = document.getElementById("b");
  102. test(function() {
  103. assert_equals(typeof(textarea.setSelectionRange), "function", "element must have 'setSelectionRange' function");
  104. },"textarea typeof(input.setSelectionRange)'");
  105. test(function() {
  106. assert_equals(textarea.setSelectionRange(0,1,"forward"),undefined,"setSelectionRange is void functuon");
  107. },"textarea setSelectionRange return void");
  108. test(function() {
  109. textarea.setSelectionRange(0,1)
  110. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  111. assert_equals(textarea.selectionEnd, 1, "element.selectionEnd should be 1");
  112. },'textarea setSelectionRange(0,1)');
  113. test(function() {
  114. textarea.setSelectionRange(0,textarea.value.length+1)
  115. assert_equals(textarea.selectionEnd, textarea.value.length, "Arguments greater than the length of the value of the text field must be treated as pointing at the end of the text field");
  116. },'textarea setSelectionRange(0,textarea.value.length+1)');
  117. test(function() {
  118. textarea.setSelectionRange(2,2)
  119. assert_equals(textarea.selectionStart, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  120. assert_equals(textarea.selectionEnd, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  121. },'textarea setSelectionRange(2,2)');
  122. test(function() {
  123. textarea.setSelectionRange(2,1)
  124. assert_equals(textarea.selectionStart, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  125. assert_equals(textarea.selectionEnd, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
  126. },'textarea setSelectionRange(2,1)');
  127. test(function() {
  128. textarea.setSelectionRange(0,1,"backward")
  129. assert_equals(textarea.selectionDirection, "backward", 'The direction of the selection must be set to backward if direction is a case-sensitive match for the string "backward"');
  130. },'textarea direction of setSelectionRange(0,1,"backward")');
  131. test(function() {
  132. textarea.setSelectionRange(0,1,"forward")
  133. assert_equals(textarea.selectionDirection, "forward", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "forward"');
  134. },'textarea direction of setSelectionRange(0,1,"forward")');
  135. test(function() {
  136. textarea.setSelectionRange(0,1,"none")
  137. assert_equals(textarea.selectionDirection, "none", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none"');
  138. },'textarea direction of setSelectionRange(0,1,"none")');
  139. test(function() {
  140. textarea.setSelectionRange(0,1,"hoge")
  141. assert_equals(textarea.selectionDirection, "none", "otherwise");
  142. },'textarea direction of setSelectionRange(0,1,"hoge")');
  143. test(function() {
  144. textarea.setSelectionRange(0,1,"BACKWARD")
  145. assert_equals(textarea.selectionDirection, "none", "selectionDirection should be 'none'");
  146. },'textarea direction of setSelectionRange(0,1,"BACKWARD")');
  147. test(function() {
  148. textarea.setSelectionRange(0,1)
  149. assert_equals(textarea.selectionDirection, "none", "if the argument is omitted");
  150. },'textarea direction of setSelectionRange(0,1)');
  151. test(function() {
  152. textarea.setSelectionRange("string",1);
  153. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  154. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  155. },'textarea setSelectionRange("string",1)');
  156. test(function() {
  157. textarea.setSelectionRange(true,1);
  158. assert_equals(textarea.selectionStart, 1, "element.selectionStart should be 1");
  159. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  160. },'textarea setSelectionRange(true,1)');
  161. test(function() {
  162. textarea.setSelectionRange([],1);
  163. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  164. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  165. },'textarea setSelectionRange([],1)');
  166. test(function() {
  167. textarea.setSelectionRange({},1);
  168. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  169. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  170. },'textarea setSelectionRange({},1)');
  171. test(function() {
  172. textarea.setSelectionRange(NaN,1);
  173. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  174. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  175. },'textarea setSelectionRange(NaN,1)');
  176. test(function() {
  177. textarea.setSelectionRange(null,1);
  178. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  179. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  180. },'textarea setSelectionRange(null,1)');
  181. test(function() {
  182. textarea.setSelectionRange(undefined,1);
  183. assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
  184. assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
  185. },'textarea setSelectionRange(undefined,1)');
  186. },"test of textarea.setSelectionRange");
  187. </script>