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

Side by Side Diff: third_party/WebKit/LayoutTests/typedcssom/inlinestyle/properties/property-suite.js

Issue 2529043002: [CSS Typed OM] Add a property test generator for testing the inline StylePropertyMap (Closed)
Patch Set: Add expectation files Created 4 years 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 /**
2 * @fileoverview A standard set of tests for using a single property in an
3 * inline StylePropertyMap.
qyearsley 2016/11/30 18:37:24 Might be helpful to add a link to the spec, e.g. h
meade_UTC10 2016/12/01 03:48:20 Done.
4 *
5 * Create a config object containing {
6 * validKeywords: [list of strings],
qyearsley 2016/11/30 18:37:24 Do the square brackets here indicate that this is
meade_UTC10 2016/12/01 03:48:21 Done.
7 * validObjects: [list of CSSStyleValue instances that are valid for the
8 * property],
9 * supportsMultiple: boolean; whether the property supports a list of
10 * properties,
11 * invalidObjects: [list of CSSStyleValue instances that are invalid for the
12 * property]
13 * }
14 *
15 * Note that CSS-wide keywords, and non-CSSStyleValue invalid types do not need
16 * to be specified.
17 *
18 * Finally, call "generatePropertySuite" to generate the standard set of tests.
qyearsley 2016/11/30 18:37:24 Possible optional rephrasing: Call generatePropert
meade_UTC10 2016/12/01 03:48:20 Done.
19 *
20 * If necessary, you can continue to define non-standard tests in your html
21 * file as usual.
22 */
23
24 function generatePropertySuite(propertyName, config, element) {
qyearsley 2016/11/30 18:37:24 Arguably, these functions could also be named as "
meade_UTC10 2016/12/01 03:48:20 I had actually renamed these to "runFooTests" but
qyearsley 2016/12/01 16:39:44 That sounds good to me too :-)
25 var validKeywords = config.validKeywords.concat([
26 // CSS wide keywords
qyearsley 2016/11/30 18:37:24 Nit: CSS-wide could be written with a dash.
meade_UTC10 2016/12/01 03:48:21 Done.
27 'initial',
28 'inherit',
29 'unset'
30 ]);
31 var validObjects = config.validObjects;
32 var invalidObjects = config.invalidObjects.concat([
33 // No properties should take these values
34 null,
35 undefined,
36 true,
37 false,
38 1,
39 'hello',
40 {},
41 new CSSKeywordValue('notAKeyword')
42 ]);
43 var validObject = validObjects.length ? validObjects[0] : new CSSKeywordValue( validKeywords[0]);
44
45 var styleMap = element.styleMap;
46 generateSetterTests(propertyName, validKeywords, validObjects, invalidObjects, element);
47 generateGetterTests(propertyName, validKeywords, validObjects, element);
48 generateGetAllTests(propertyName, validObject, element, config.supportsMultipl e);
49 generateDeletionTests(propertyName, validObject, element);
50 generateGetPropertiesTests(propertyName, validObject, element);
51 if (config.supportsMultiple) {
52 generateSequenceSetterTests(propertyName, validObject, invalidObjects[0], el ement);
53 generateAppendTests(propertyName, validObject, invalidObjects[0], element);
54 } else {
55 generateMultipleValuesNotSupportedTests(propertyName, validObject, element);
56 }
57 }
58
59 function generateSetterTests(propertyName, validKeywords, validObjects, invalidO bjects, element) {
60 for (var i = 0; i < validKeywords.length; i++) {
61 var keyword = validKeywords[i];
62 var keywordValue = new CSSKeywordValue(keyword);
63
64 test(function() {
65 element.style = '';
66
67 element.styleMap.set(propertyName, keywordValue);
68 assert_equals(element.style[propertyName], keyword);
69 }, 'Setting ' + propertyName + ' to ' + keyword);
70 }
71 for (var i = 0; i < validObjects.length; i++) {
72 var validObject = validObjects[i];
73
74 test(function() {
75 element.style = '';
76
77 element.styleMap.set(propertyName, validObject);
78 assert_equals(element.style[propertyName], validObject.cssText);
79 }, 'Setting ' + propertyName + ' to ' + validObject.constructor.name + ' wit h value ' + validObject.cssText);
80 }
81
82 // Negative tests
83 for (var i = 0; i < invalidObjects.length; i++) {
84 test(function() {
85 assert_throws(new TypeError(), function() {
86 element.styleMap.set(propertyName, invalidObjects[i]);
87 });
88 }, 'Setting ' + propertyName + ' to invalid value ' + invalidObjects[i] + ' fails');
89 }
90 }
91
92 function generateGetterTests(propertyName, validKeywords, validObjects, element) {
93 for (var i = 0; i < validKeywords.length; i++) {
94 var keyword = validKeywords[i];
95 test(function() {
96 element.style[propertyName] = keyword;
97
98 var result = element.styleMap.get(propertyName);
99 assert_true(result instanceof CSSKeywordValue);
100 assert_equals(result.cssText, keyword);
101 }, 'Getting ' + propertyName + ' when it is set to ' + keyword);
102 }
103 for (var i = 0; i < validObjects.length; i++) {
104 var validObject = validObjects[i];
105
106 test(function() {
107 element.style[propertyName] = validObject.cssText;
108
109 var result = element.styleMap.get(propertyName);
110 assert_equals(result.constructor, validObject.constructor);
111 assert_equals(result.cssText, validObject.cssText);
112 }, 'Getting ' + propertyName + ' with a ' + validObject.constructor.name + ' whose value is ' + validObject.cssText);
113 }
114 }
115
116 function generateSequenceSetterTests(propertyName, validObject, invalidObject, e lement) {
117 test(function() {
118 element.style = '';
119
120 element.styleMap.set(propertyName, [validObject, validObject]);
121 assert_equals(element.style[propertyName], validObject.cssText + ' ' + valid Object.cssText);
shans 2016/11/29 20:58:13 BTW shouldn't this be comma separated?
meade_UTC10 2016/12/01 03:48:20 Ugh, yes. I should really fix that bug...
122 }, 'Set ' + propertyName + ' to a sequence');
123
124 test(function() {
125 var sequence = [validObject, invalidObject];
126 assert_throws(new TypeError(), function() {
127 element.styleMap.set(propertyName, sequence);
128 });
129 }, 'Set ' + propertyName + ' to a sequence containing an invalid type');
130 }
131
132 function generateAppendTests(propertyName, validObject, invalidObject, element) {
133 test(function() {
134 element.style = '';
135
136 element.styleMap.append(propertyName, validObject);
137 assert_equals(element.style[propertyName], validObject.cssText);
138
139 element.styleMap.append(propertyName, validObject);
140 assert_equals(element.style[propertyName], validObject.cssText + ' ' + valid Object.cssText);
141 }, 'Appending a ' + validObject.constructor.name + ' to ' + propertyName);
142
143 test(function() {
144 element.style = '';
145
146 element.styleMap.append(propertyName, [validObject, validObject]);
147 assert_equals(element.style[propertyName], validObject.cssText + ' ' + valid Object.cssText);
148 }, 'Append a sequence to ' + propertyName);
149
150 // Negative tests
151 test(function() {
152 assert_throws(new TypeError(), function() {
153 element.styleMap.append(propertyName, invalidObject);
154 });
155 }, 'Appending an invalid value to ' + propertyName);
156
157 test(function() {
158 var sequence = [validObject, invalidObject];
159 assert_throws(new TypeError(), function() {
160 element.styleMap.append(propertyName, sequence);
161 });
162 }, 'Append a sequence containing an invalid value to ' + propertyName);
163 }
164
165 function generateGetAllTests(propertyName, validObject, element, supportsMultipl e) {
166 test(function() {
167 element.style = '';
168 assert_array_equals(element.styleMap.getAll(propertyName), []);
169
170 element.style[propertyName] = validObject.cssText;
171 var result = element.styleMap.getAll(propertyName);
172 assert_equals(result.length, 1);
173 assert_equals(result[0].constructor, validObject.constructor);
174 }, 'getAll for single-valued ' + propertyName);
175
176 if (supportsMultiple) {
177 test(function() {
178 element.style = '';
179 element.styleMap.set(propertyName, [validObject, validObject]);
180 var result = element.styleMap.getAll(propertyName);
181 assert_equals(result.length, 2);
182 assert_equals(result[0].constructor, validObject.constructor);
183 assert_equals(result[1].constructor, validObject.constructor);
184 assert_equals(result[0].cssText, validObject.cssText);
185 assert_equals(result[1].cssText, validObject.cssText);
186 }, 'getAll for list-valued ' + propertyName);
187 }
188 }
189
190 function generateDeletionTests(propertyName, validObject, element) {
191 test(function() {
192 element.style[propertyName] = validObject.cssText;
193
194 assert_not_equals(element.styleMap.get(propertyName), null);
195
196 element.styleMap.delete(propertyName);
197 assert_equals(element.style[propertyName], '');
198 assert_equals(element.styleMap.get(propertyName), null);
199 }, 'Delete ' + propertyName + ' removes the value form the styleMap');
200 }
201
202 function generateGetPropertiesTests(propertyName, validObject, element) {
203 test(function() {
204 element.style = '';
205 assert_array_equals(element.styleMap.getProperties(), []);
206
207 element.styleMap.set(propertyName, validObject);
208
209 assert_array_equals(element.styleMap.getProperties(), [propertyName]);
210 }, propertyName + ' shows up in getProperties');
211 }
212
213 function generateMultipleValuesNotSupportedTests(propertyName, validObject, elem ent) {
214 test(function() {
215 element.style = '';
216 assert_throws(new TypeError(), function() {
217 element.styleMap.set(propertyName, [validObject, validObject]);
218 });
219 }, 'Setting ' + propertyName + ' to a sequence throws');
220
221 test(function() {
222 element.style = '';
223 assert_throws(new TypeError(), function() {
224 element.styleMap.append(propertyName, validObject);
225 });
226 }, 'Appending to ' + propertyName + ' throws');
227 }
228
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698