Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: LayoutTests/imported/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setRangeText.html

Issue 1144143009: W3C Test: Import web-platform-tests/html/semantics (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>text field selection: setRangeText</title>
4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
5 <link rel=help href="https://html.spec.whatwg.org/multipage/#textFieldSelection" >
6 <script src="../../../../../../resources/testharness.js"></script>
7 <script src="../../../../../../resources/testharnessreport.js"></script>
8 <style>
9 #display_none {display:none;}
10 </style>
11 <div id="log"></div>
12 <input type=text id=text value="foobar">
13 <input type=search id=search value="foobar">
14 <input type=tel id=tel value="foobar">
15 <input type=url id=url value="foobar">
16 <input type=password id=password value="foobar">
17 <input id=display_none value="foobar">
18 <textarea id=textarea>foobar</textarea>
19 <script>
20 var input = document.createElement("input");
21 input.id = "input_not_in_doc";
22 input.value = "foobar";
23
24 var elements = [
25 document.getElementById("text"),
26 document.getElementById("search"),
27 document.getElementById("tel"),
28 document.getElementById("url"),
29 document.getElementById("password"),
30 document.getElementById("display_none"),
31 document.getElementById("textarea"),
32 input,
33 ]
34
35 elements.forEach(function(element) {
36 var t = async_test(element.id + " setRangeText fires a select event"),
37 q = false;
38
39 test(function() {
40 element.value = "foobar";
41 element.selectionStart = 0;
42 element.selectionEnd = 3;
43 assert_equals(element.selectionStart, 0);
44 assert_equals(element.selectionEnd, 3);
45 element.setRangeText("foobar2");
46 assert_equals(element.value, "foobar2bar");
47 assert_equals(element.selectionStart, 0);
48 assert_equals(element.selectionEnd, 7);
49 element.setRangeText("foobar3", 7, 10);
50 assert_equals(element.value, "foobar2foobar3");
51 }, element.id + " setRangeText with only one argument replaces the value bet ween selectionStart and selectionEnd, otherwise replaces the value between 2nd a nd 3rd arguments");
52
53 test(function(){
54 element.value = "foobar";
55 element.selectionStart = 0;
56 element.selectionEnd = 0;
57
58 element.setRangeText("foobar2", 0, 3); // no 4th arg, default "preserve"
59 assert_equals(element.value, "foobar2bar");
60 assert_equals(element.selectionStart, 0);
61 assert_equals(element.selectionEnd, 0);
62 }, element.id + " selectionMode missing");
63
64 test(function(){
65 element.value = "foobar"
66 element.setRangeText("foo", 3, 6, "select");
67 assert_equals(element.value, "foofoo");
68 assert_equals(element.selectionStart, 3);
69 assert_equals(element.selectionEnd, 6);
70 }, element.id + " selectionMode 'select'");
71
72 test(function(){
73 element.value = "foobar"
74 element.setRangeText("foo", 3, 6, "start");
75 assert_equals(element.value, "foofoo");
76 assert_equals(element.selectionStart, 3);
77 assert_equals(element.selectionEnd, 3);
78 }, element.id + " selectionMode 'start'");
79
80 test(function(){
81 element.value = "foobar"
82 element.setRangeText("foobar", 3, 6, "end");
83 assert_equals(element.value, "foofoobar");
84 assert_equals(element.selectionStart, 9);
85 assert_equals(element.selectionEnd, 9);
86 }, element.id + " selectionMode 'end'");
87
88 test(function(){
89 element.value = "foobar"
90 element.selectionStart = 0;
91 element.selectionEnd = 5;
92 assert_equals(element.selectionStart, 0);
93 element.setRangeText("", 3, 6, "preserve");
94 assert_equals(element.value, "foo");
95 assert_equals(element.selectionStart, 0);
96 assert_equals(element.selectionEnd, 3);
97 }, element.id + " selectionMode 'preserve'");
98
99 test(function(){
100 assert_throws("INDEX_SIZE_ERR", function() {
101 element.setRangeText("barfoo", 2, 1);
102 });
103 }, element.id + " setRangeText with 3rd argument greater than 2nd argument t hrows an IndexSizeError exception");
104
105 test(function(){
106 assert_throws(new TypeError(), function() {
107 element.setRangeText();
108 });
109 }, element.id + " setRangeText without argument throws a type error");
110
111 element.onselect = t.step_func_done(function(e) {
112 assert_true(q, "event should be queued");
113 assert_true(e.isTrusted, "event is trusted");
114 assert_false(e.bubbles, "event bubbles");
115 assert_false(e.cancelable, "event is not cancelable");
116 });
117 element.setRangeText("foobar2", 0, 6);
118 q=true;
119 })
120 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698