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

Side by Side Diff: LayoutTests/imported/web-platform-tests/html/semantics/forms/textfieldselection/selection.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 <title>test if select() API returns correct attributes</title>
3 <meta charset="UTF-8">
4 <link rel="author" title="Koji Tashiro" href="mailto:koji.tashiro@gmail.com">
5 <link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/associat ion-of-controls-and-forms.html#textFieldSelection">
6 <script src="../../../../../../resources/testharness.js"></script>
7 <script src="../../../../../../resources/testharnessreport.js"></script>
8
9 <div id="log"></div>
10
11 <script>
12 var body = document.getElementsByTagName("body").item(0);
13 var dirs = ['forward', 'backward', 'none'];
14 var sampleText = "0123456789";
15
16 var createInputElement = function(value) {
17 var el = document.createElement("input");
18 el.type = "text";
19 el.value = value;
20 body.appendChild(el);
21 return el;
22 };
23
24 var createTextareaElement = function(value) {
25 var el = document.createElement("textarea");
26 el.value = value;
27 body.appendChild(el);
28 return el;
29 };
30
31
32 test(function() {
33 var text = 'a';
34 for (var i=0; i<255; i++) {
35 var el = createInputElement(text);
36 el.select();
37 var selectionText = el.value.substring(el.selectionStart, el.selectionEnd) ;
38 assert_equals(selectionText, text, "Selection text mismatched");
39 el.parentNode.removeChild(el);
40 text += 'a';
41 }
42 }, "test if selection text is correct for input");
43
44
45 test(function() {
46 var text = 'a';
47 for (var i=0; i<255; i++) {
48 var el = createTextareaElement(text);
49 el.select();
50 var selectionText = el.value.substring(el.selectionStart, el.selectionEnd) ;
51 assert_equals(selectionText, text, "Selection text mismatched");
52 el.parentNode.removeChild(el);
53 text += 'a';
54 }
55 }, "test if selection text is correct for textarea");
56
57
58 test(function() {
59 var text = 'あ';
60 for (var i=0; i<255; i++) {
61 var el = createInputElement(text);
62 el.select();
63 var selectionText = el.value.substring(el.selectionStart, el.selectionEnd) ;
64 assert_equals(selectionText, text, "Selection text mismatched");
65 el.parentNode.removeChild(el);
66 text += 'あ';
67 }
68 }, "test if non-ascii selection text is correct for input");
69
70
71 test(function() {
72 var text = 'あ';
73 for (var i=0; i<255; i++) {
74 var el = createTextareaElement(text);
75 el.select();
76 var selectionText = el.value.substring(el.selectionStart, el.selectionEnd) ;
77 assert_equals(selectionText, text, "Selection text mismatched");
78 el.parentNode.removeChild(el);
79 text += 'あ';
80 }
81 }, "test if non-ascii selection text is correct for textarea");
82
83
84 test(function() {
85 var el = createInputElement(sampleText);
86 // If there is no selection, then it must return the offset(in logical order )
87 // to the character that immediately follows the text entry cursor.
88 assert_equals(el.selectionStart, el.value.length, "SelectionStart offset wit hout selection");
89 el.select();
90 assert_equals(el.selectionStart, 0, "SelectionStart offset");
91 el.parentNode.removeChild(el);
92 }, "test SelectionStart offset for input");
93
94
95 test(function() {
96 var el = createTextareaElement(sampleText);
97 // If there is no selection, then it must return the offset(in logical order )
98 // to the character that immediately follows the text entry cursor.
99 assert_equals(el.selectionStart, el.value.length, "SelectionStart offset wit hout selection");
100 el.select();
101 assert_equals(el.selectionStart, 0, "SelectionStart offset");
102 el.parentNode.removeChild(el);
103 }, "test SelectionStart offset for textarea");
104
105
106 test(function() {
107 var el = createInputElement(sampleText);
108 // If there is no selection, then it must return the offset(in logical order )
109 // to the character that immediately follows the text entry cursor.
110 assert_equals(el.selectionEnd, el.value.length, "SelectionEnd offset without selection");
111 el.select();
112 assert_equals(el.selectionEnd, el.value.length, "SelectionEnd offset");
113 el.parentNode.removeChild(el);
114 }, "test SelectionEnd offset for input");
115
116
117 test(function() {
118 var el = createTextareaElement(sampleText);
119 // If there is no selection, then it must return the offset(in logical order )
120 // to the character that immediately follows the text entry cursor.
121 assert_equals(el.selectionEnd, el.value.length, "SelectionEnd offset without selection");
122 el.select();
123 assert_equals(el.selectionEnd, el.value.length, "SelectionEnd offset");
124 el.parentNode.removeChild(el);
125 }, "test SelectionEnd offset for textarea");
126
127
128 test(function() {
129 var el = createInputElement(sampleText);
130 assert_in_array(el.selectionDirection, dirs, "SelectionDirection");
131 el.select();
132 assert_in_array(el.selectionDirection, dirs, "SelectionDirection");
133 el.parentNode.removeChild(el);
134 }, "test SelectionDirection for input");
135
136
137 test(function() {
138 var el = createInputElement(sampleText);
139 assert_in_array(el.selectionDirection, dirs, "SelectionDirection");
140 el.select();
141 assert_in_array(el.selectionDirection, dirs, "SelectionDirection");
142 el.parentNode.removeChild(el);
143 }, "test SelectionDirection for textarea");
144 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698