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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/HTMLOutputElement/script-tests/dom-settable-token-list.js

Issue 1629403003: Merge DOMSettableTokensList into DOMTokensList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed non-oilpan inheritance Created 4 years, 10 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
OLDNEW
(Empty)
1 // This test mostly comes from fast/dom/HTMLElement/script-tests/class-list.js
2 description('Tests the htmlFor attribute and its properties.');
3
4 var container = document.createElement('div');
5 document.body.appendChild(container);
6
7 var element;
8
9 function createElement(tokenList)
10 {
11 container.innerHTML = '<output for="' + tokenList + '"></output>';
12 element = container.lastChild;
13 }
14
15 debug('- Tests from http://simon.html5.org/test/html/dom/reflecting/DOMTokenList /');
16
17 // HTMLOutputElement::htmlFor setter is forwarding assignment to DOMSettableToke nList.value attribute.
18 createElement('x');
19 shouldBeEqualToString('element.htmlFor.value', 'x');
20 shouldBeEqualToString('String(element.htmlFor)', 'x');
21 element.htmlFor = 'y';
22 shouldBeEqualToString('element.htmlFor.value', 'y');
23 shouldBeEqualToString('String(element.htmlFor)', 'y');
24
25 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/001.htm
26 createElement('');
27 shouldEvaluateTo('element.htmlFor.length', 0);
28
29 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/002.htm
30 createElement('x');
31 shouldEvaluateTo('element.htmlFor.length', 1);
32
33 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/003.htm
34 createElement('x x');
35 shouldEvaluateTo('element.htmlFor.length', 2);
36
37 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/004.htm
38 createElement('x y');
39 shouldEvaluateTo('element.htmlFor.length', 2);
40
41 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/005.htm
42 createElement('');
43 element.htmlFor.add('x');
44 shouldBeEqualToString('element.htmlFor.toString()', 'x');
45
46 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/006.htm
47 createElement('x');
48 element.htmlFor.add('x');
49 shouldBeEqualToString('element.htmlFor.toString()', 'x');
50
51 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/007.htm
52 createElement('x x');
53 element.htmlFor.add('x');
54 shouldBeEqualToString('element.htmlFor.toString()', 'x x');
55
56 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/008.htm
57 createElement('y');
58 element.htmlFor.add('x');
59 shouldBeEqualToString('element.htmlFor.toString()', 'y x');
60
61 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/009.htm
62 createElement('');
63 element.htmlFor.remove('x');
64 shouldBeEqualToString('element.htmlFor.toString()', '');
65
66 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/010.htm
67 createElement('x');
68 element.htmlFor.remove('x');
69 shouldBeEqualToString('element.htmlFor.toString()', '');
70
71 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/011.htm
72 createElement(' y x y ');
73 element.htmlFor.remove('x');
74 shouldBeEqualToString('element.htmlFor.toString()', 'y y');
75
76 // http://simon.html5.org/test/html/dom/reflecting/DOMTokenList/getting/012.htm
77 createElement(' x y x ');
78 element.htmlFor.remove('x');
79 shouldBeEqualToString('element.htmlFor.toString()', 'y');
80
81
82 debug('- Ensure that we can handle empty form attribute correctly');
83 element = document.createElement('output');
84 var list = element.htmlFor;
85 list.toggle('x');
86 shouldBeEqualToString('list.value', 'x');
87
88 list.toggle('x');
89 shouldBeEqualToString('list.value', '');
90
91 element = document.createElement('output');
92 shouldBeFalse('element.htmlFor.contains(\'x\')');
93 shouldBeUndefined('element.htmlFor[1]');
94 element.htmlFor.remove('x');
95 element.htmlFor.add('x')
96 shouldBeTrue('element.htmlFor.contains(\'x\')');
97 shouldBeUndefined('element.htmlFor[1]');
98
99 debug('- Testing add in presence of trailing white spaces.');
100
101 createElement('x ');
102 element.htmlFor.add('y');
103 shouldBeEqualToString('element.htmlFor.toString()', 'x y');
104
105 createElement('x\t');
106 element.htmlFor.add('y');
107 shouldBeEqualToString('element.htmlFor.toString()', 'x\ty');
108
109 createElement(' ');
110 element.htmlFor.add('y');
111 shouldBeEqualToString('element.htmlFor.toString()', ' y');
112
113
114 debug('- Test invalid tokens');
115
116 // Testing exception due to invalid token
117
118 // shouldThrow from js-test.js is not sufficient.
119 function shouldThrowDOMException(f, ec)
120 {
121 try {
122 f();
123 testFailed('Expected an exception');
124 } catch (ex) {
125 if (!(ex instanceof DOMException)) {
126 testFailed('Exception is not an instance of DOMException, found: ' +
127 Object.toString.call(ex));
128 return;
129 }
130 if (ec !== ex.code) {
131 testFailed('Wrong exception code: ' + ex.code);
132 return;
133 }
134 }
135 var formattedFunction = String(f).replace(/^function.+\{\s*/m, '').
136 replace(/;?\s+\}/m, '');
137 testPassed(formattedFunction + ' threw expected DOMException with code ' + e c);
138 }
139
140 createElement('x');
141 shouldThrowDOMException(function() {
142 element.htmlFor.contains('');
143 }, DOMException.SYNTAX_ERR);
144
145 createElement('x y');
146 shouldThrowDOMException(function() {
147 element.htmlFor.contains('x y');
148 }, DOMException.INVALID_CHARACTER_ERR);
149
150 createElement('');
151 shouldThrowDOMException(function() {
152 element.htmlFor.add('');
153 }, DOMException.SYNTAX_ERR);
154
155 createElement('');
156 shouldThrowDOMException(function() {
157 element.htmlFor.add('x y');
158 }, DOMException.INVALID_CHARACTER_ERR);
159
160 createElement('');
161 shouldThrowDOMException(function() {
162 element.htmlFor.remove('');
163 }, DOMException.SYNTAX_ERR);
164
165 createElement('');
166 shouldThrowDOMException(function() {
167 element.htmlFor.remove('x y');
168 }, DOMException.INVALID_CHARACTER_ERR);
169
170 createElement('');
171 shouldThrowDOMException(function() {
172 element.htmlFor.toggle('');
173 }, DOMException.SYNTAX_ERR);
174
175 createElement('x y');
176 shouldThrowDOMException(function() {
177 element.htmlFor.toggle('x y');
178 }, DOMException.INVALID_CHARACTER_ERR);
179
180
181 debug('- Indexing');
182
183 createElement('x');
184 shouldBeEqualToString('element.htmlFor[0]', 'x');
185 shouldBeEqualToString('element.htmlFor.item(0)', 'x');
186
187 createElement('x x');
188 shouldBeEqualToString('element.htmlFor[1]', 'x');
189 shouldBeEqualToString('element.htmlFor.item(1)', 'x');
190
191 createElement('x y');
192 shouldBeEqualToString('element.htmlFor[1]', 'y');
193 shouldBeEqualToString('element.htmlFor.item(1)', 'y');
194
195 createElement('');
196 shouldBeUndefined('element.htmlFor[0]');
197 shouldBeNull('element.htmlFor.item(0)');
198
199 createElement('x y z');
200 shouldBeUndefined('element.htmlFor[4]');
201 shouldBeNull('element.htmlFor.item(4)');
202 shouldBeUndefined('element.htmlFor[-1]'); // Not a valid index so should not tr igger item().
203 shouldBeNull('element.htmlFor.item(-1)');
204
205 debug('- Test case since DOMTokenList is case sensitive');
206
207 createElement('x');
208 shouldBeTrue('element.htmlFor.contains(\'x\')');
209 shouldBeFalse('element.htmlFor.contains(\'X\')');
210 shouldBeEqualToString('element.htmlFor[0]', 'x');
211
212 createElement('X');
213 shouldBeTrue('element.htmlFor.contains(\'X\')');
214 shouldBeFalse('element.htmlFor.contains(\'x\')');
215 shouldBeEqualToString('element.htmlFor[0]', 'X');
216
217
218 debug('- Testing whitespace');
219 // U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF),
220 // U+000C FORM FEED (FF), and U+000D CARRIAGE RETURN (CR)
221
222 createElement('x\u0020y');
223 shouldEvaluateTo('element.htmlFor.length', 2);
224
225 createElement('x\u0009y');
226 shouldEvaluateTo('element.htmlFor.length', 2);
227
228 createElement('x\u000Ay');
229 shouldEvaluateTo('element.htmlFor.length', 2);
230
231 createElement('x\u000Cy');
232 shouldEvaluateTo('element.htmlFor.length', 2);
233
234 createElement('x\u000Dy');
235 shouldEvaluateTo('element.htmlFor.length', 2);
236
237
238 debug('- DOMSettableTokenList presence and type');
239
240
241 // Safari returns object
242 // Firefox returns object
243 // IE8 returns object
244 // Chrome returns function
245 // assertEquals('object', typeof DOMSettableTokenList);
246 shouldBeTrue('\'undefined\' != typeof DOMSettableTokenList');
247
248 shouldBeEqualToString('typeof DOMSettableTokenList.prototype', 'object');
249
250 createElement('x');
251 shouldBeEqualToString('typeof element.htmlFor', 'object');
252
253 shouldEvaluateTo('element.htmlFor.constructor', 'DOMSettableTokenList');
254
255 shouldBeTrue('element.htmlFor === element.htmlFor');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698