OLD | NEW |
(Empty) | |
| 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/inpu
t-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 hav
e 'setSelectionRange' function"); |
| 17 },"input typeof(input.setSelectionRange)'"); |
| 18 |
| 19 test(function() { |
| 20 assert_equals(input.setSelectionRange(0,1,"forward"),undefined,"setSelection
Range is void functuon"); |
| 21 },"input setSelectionRange return void"); |
| 22 |
| 23 test(function() { |
| 24 input.setSelectionRange(0,1) |
| 25 assert_equals(input.selectionStart, 0, "element.selectionStart should be 0")
; |
| 26 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 27 },'input setSelectionRange(0,1)'); |
| 28 |
| 29 test(function() { |
| 30 input.setSelectionRange(0,input.value.length+1) |
| 31 assert_equals(input.selectionEnd, input.value.length, "Arguments greater tha
n the length of the value of the text field must be treated as pointing at the e
nd of the text field"); |
| 32 },'input setSelectionRange(0,input.value.length+1)'); |
| 33 |
| 34 test(function() { |
| 35 input.setSelectionRange(2,2) |
| 36 assert_equals(input.selectionStart, 2, "If end is less than or equal to star
t then the start of the selection and the end of the selection must both be plac
ed immediately before the character with offset end"); |
| 37 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"); |
| 38 },'input setSelectionRange(2,2)'); |
| 39 |
| 40 test(function() { |
| 41 input.setSelectionRange(2,1) |
| 42 assert_equals(input.selectionStart, 1, "If end is less than or equal to star
t then the start of the selection and the end of the selection must both be plac
ed immediately before the character with offset end"); |
| 43 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"); |
| 44 },'input setSelectionRange(2,1)'); |
| 45 |
| 46 test(function() { |
| 47 input.setSelectionRange(0,1,"backward") |
| 48 assert_equals(input.selectionDirection, "backward", 'The direction of the se
lection must be set to backward if direction is a case-sensitive match for the s
tring "backward"'); |
| 49 },'input direction of setSelectionRange(0,1,"backward")'); |
| 50 |
| 51 test(function() { |
| 52 input.setSelectionRange(0,1,"forward") |
| 53 assert_equals(input.selectionDirection, "forward", 'The direction of the sel
ection must be set to forward if direction is a case-sensitive match for the str
ing "forward"'); |
| 54 },'input direction of setSelectionRange(0,1,"forward")'); |
| 55 |
| 56 test(function() { |
| 57 input.setSelectionRange(0,1,"none") |
| 58 assert_equals(input.selectionDirection, "none", 'The direction of the select
ion must be set to forward if direction is a case-sensitive match for the string
"none"'); |
| 59 },'input direction of setSelectionRange(0,1,"none")'); |
| 60 |
| 61 test(function() { |
| 62 input.setSelectionRange(0,1,"hoge") |
| 63 assert_equals(input.selectionDirection, "none", "otherwise"); |
| 64 },'input direction of setSelectionRange(0,1,"hoge")'); |
| 65 |
| 66 test(function() { |
| 67 input.setSelectionRange(0,1,"BACKWARD") |
| 68 assert_equals(input.selectionDirection, "none", "selectionDirection should b
e 'none'"); |
| 69 },'input direction of setSelectionRange(0,1,"BACKWARD")'); |
| 70 |
| 71 test(function() { |
| 72 input.setSelectionRange(0,1) |
| 73 assert_equals(input.selectionDirection, "none", "if the argument is omitted"
); |
| 74 },'input direction of setSelectionRange(0,1)'); |
| 75 |
| 76 test(function() { |
| 77 input.setSelectionRange("string",1); |
| 78 assert_equals(input.selectionStart, 0, "element.selectionStart should be 0")
; |
| 79 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 80 },'input setSelectionRange("string",1)'); |
| 81 |
| 82 test(function() { |
| 83 input.setSelectionRange(true,1); |
| 84 assert_equals(input.selectionStart, 1, "element.selectionStart should be 1")
; |
| 85 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 86 },'input setSelectionRange(true,1)'); |
| 87 |
| 88 test(function() { |
| 89 input.setSelectionRange([],1); |
| 90 assert_equals(input.selectionStart, 0, "element.selectionStart should be 0")
; |
| 91 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 92 },'input setSelectionRange([],1)'); |
| 93 |
| 94 test(function() { |
| 95 input.setSelectionRange({},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({},1)'); |
| 99 |
| 100 test(function() { |
| 101 input.setSelectionRange(NaN,1); |
| 102 assert_equals(input.selectionStart, 0, "element.selectionStart should be 0")
; |
| 103 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 104 },'input setSelectionRange(NaN,1)'); |
| 105 |
| 106 test(function() { |
| 107 input.setSelectionRange(null,1); |
| 108 assert_equals(input.selectionStart, 0, "element.selectionStart should be 0")
; |
| 109 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 110 },'input setSelectionRange(null,1)'); |
| 111 |
| 112 test(function() { |
| 113 input.setSelectionRange(undefined,1); |
| 114 assert_equals(input.selectionStart, 0, "element.selectionStart should be 0")
; |
| 115 assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 116 },'input setSelectionRange(undefined,1)'); |
| 117 },"test of input.setSelectionRange"); |
| 118 |
| 119 test(function() { |
| 120 var textarea = document.getElementById("b"); |
| 121 test(function() { |
| 122 assert_equals(typeof(textarea.setSelectionRange), "function", "element must
have 'setSelectionRange' function"); |
| 123 },"textarea typeof(input.setSelectionRange)'"); |
| 124 |
| 125 test(function() { |
| 126 assert_equals(textarea.setSelectionRange(0,1,"forward"),undefined,"setSelect
ionRange is void functuon"); |
| 127 },"textarea setSelectionRange return void"); |
| 128 |
| 129 test(function() { |
| 130 textarea.setSelectionRange(0,1) |
| 131 assert_equals(textarea.selectionStart, 0, "element.selectionStart should be
0"); |
| 132 assert_equals(textarea.selectionEnd, 1, "element.selectionEnd should be 1"); |
| 133 },'textarea setSelectionRange(0,1)'); |
| 134 |
| 135 test(function() { |
| 136 textarea.setSelectionRange(0,textarea.value.length+1) |
| 137 assert_equals(textarea.selectionEnd, textarea.value.length, "Arguments great
er than the length of the value of the text field must be treated as pointing at
the end of the text field"); |
| 138 },'textarea setSelectionRange(0,textarea.value.length+1)'); |
| 139 |
| 140 test(function() { |
| 141 textarea.setSelectionRange(2,2) |
| 142 assert_equals(textarea.selectionStart, 2, "If end is less than or equal to s
tart then the start of the selection and the end of the selection must both be p
laced immediately before the character with offset end"); |
| 143 assert_equals(textarea.selectionEnd, 2, "If end is less than or equal to sta
rt then the start of the selection and the end of the selection must both be pla
ced immediately before the character with offset end"); |
| 144 },'textarea setSelectionRange(2,2)'); |
| 145 |
| 146 test(function() { |
| 147 textarea.setSelectionRange(2,1) |
| 148 assert_equals(textarea.selectionStart, 1, "If end is less than or equal to s
tart then the start of the selection and the end of the selection must both be p
laced immediately before the character with offset end"); |
| 149 assert_equals(textarea.selectionEnd, 1, "If end is less than or equal to sta
rt then the start of the selection and the end of the selection must both be pla
ced immediately before the character with offset end"); |
| 150 },'textarea setSelectionRange(2,1)'); |
| 151 |
| 152 test(function() { |
| 153 textarea.setSelectionRange(0,1,"backward") |
| 154 assert_equals(textarea.selectionDirection, "backward", 'The direction of the
selection must be set to backward if direction is a case-sensitive match for th
e string "backward"'); |
| 155 },'textarea direction of setSelectionRange(0,1,"backward")'); |
| 156 |
| 157 test(function() { |
| 158 textarea.setSelectionRange(0,1,"forward") |
| 159 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"'); |
| 160 },'textarea direction of setSelectionRange(0,1,"forward")'); |
| 161 |
| 162 test(function() { |
| 163 textarea.setSelectionRange(0,1,"none") |
| 164 assert_equals(textarea.selectionDirection, "none", 'The direction of the sel
ection must be set to forward if direction is a case-sensitive match for the str
ing "none"'); |
| 165 },'textarea direction of setSelectionRange(0,1,"none")'); |
| 166 |
| 167 test(function() { |
| 168 textarea.setSelectionRange(0,1,"hoge") |
| 169 assert_equals(textarea.selectionDirection, "none", "otherwise"); |
| 170 },'textarea direction of setSelectionRange(0,1,"hoge")'); |
| 171 |
| 172 test(function() { |
| 173 textarea.setSelectionRange(0,1,"BACKWARD") |
| 174 assert_equals(textarea.selectionDirection, "none", "selectionDirection shoul
d be 'none'"); |
| 175 },'textarea direction of setSelectionRange(0,1,"BACKWARD")'); |
| 176 |
| 177 test(function() { |
| 178 textarea.setSelectionRange(0,1) |
| 179 assert_equals(textarea.selectionDirection, "none", "if the argument is omitt
ed"); |
| 180 },'textarea direction of setSelectionRange(0,1)'); |
| 181 |
| 182 test(function() { |
| 183 textarea.setSelectionRange("string",1); |
| 184 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
0"); |
| 185 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 186 },'textarea setSelectionRange("string",1)'); |
| 187 |
| 188 test(function() { |
| 189 textarea.setSelectionRange(true,1); |
| 190 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
1"); |
| 191 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 192 },'textarea setSelectionRange(true,1)'); |
| 193 |
| 194 test(function() { |
| 195 textarea.setSelectionRange([],1); |
| 196 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
0"); |
| 197 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 198 },'textarea setSelectionRange([],1)'); |
| 199 |
| 200 test(function() { |
| 201 textarea.setSelectionRange({},1); |
| 202 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
0"); |
| 203 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 204 },'textarea setSelectionRange({},1)'); |
| 205 |
| 206 test(function() { |
| 207 textarea.setSelectionRange(NaN,1); |
| 208 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
0"); |
| 209 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 210 },'textarea setSelectionRange(NaN,1)'); |
| 211 |
| 212 test(function() { |
| 213 textarea.setSelectionRange(null,1); |
| 214 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
0"); |
| 215 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 216 },'textarea setSelectionRange(null,1)'); |
| 217 |
| 218 test(function() { |
| 219 textarea.setSelectionRange(undefined,1); |
| 220 assert_equals(textarea.selectionStart, 1, "element.selectionStart should be
0"); |
| 221 assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1"
); |
| 222 },'textarea setSelectionRange(undefined,1)'); |
| 223 },"test of textarea.setSelectionRange"); |
| 224 </script> |
OLD | NEW |