OLD | NEW |
1 ReflectionTests = {}; | 1 ReflectionTests = {}; |
2 | 2 |
3 ReflectionTests.start = new Date().getTime(); | 3 ReflectionTests.start = new Date().getTime(); |
4 | 4 |
5 /** | 5 /** |
6 * Resolve the given URL to an absolute URL, relative to the current document's | 6 * Resolve the given URL to an absolute URL, relative to the current document's |
7 * address. There's no API that I know of that exposes this directly, so we | 7 * address. There's no API that I know of that exposes this directly, so we |
8 * actually just create an <a> element, set its href, and stitch together the | 8 * actually just create an <a> element, set its href, and stitch together the |
9 * various properties. Seems to work. We don't try to reimplement the | 9 * various properties. Seems to work. We don't try to reimplement the |
10 * algorithm here, because we're not concerned with its correctness -- we're | 10 * algorithm here, because we're not concerned with its correctness -- we're |
11 * only testing HTML reflection, not Web Addresses. | 11 * only testing HTML reflection, not Web Addresses. |
12 * | 12 * |
13 * Return "" if the URL couldn't be resolved, since this is really for | 13 * Return the input if the URL couldn't be resolved, per the spec for |
14 * reflected URL attributes, and those are supposed to return "" if the URL | 14 * reflected URL attributes. |
15 * couldn't be resolved. | |
16 * | 15 * |
17 * It seems like IE9 doesn't implement URL decomposition attributes correctly | 16 * It seems like IE9 doesn't implement URL decomposition attributes correctly |
18 * for <a>, which causes all these tests to fail. Ideally I'd do this in some | 17 * for <a>, which causes all these tests to fail. Ideally I'd do this in some |
19 * other way, but the failure does stem from an incorrect implementation of | 18 * other way, but the failure does stem from an incorrect implementation of |
20 * HTML, so I'll leave it alone for now. | 19 * HTML, so I'll leave it alone for now. |
21 * | 20 * |
22 * TODO: This relies on reflection to test reflection, so it could mask bugs. | 21 * TODO: This relies on reflection to test reflection, so it could mask bugs. |
23 * Either get a JS implementation of the "resolve a URL" algorithm, or just | 22 * Either get a JS implementation of the "resolve a URL" algorithm, or just |
24 * specify expected values manually here. It shouldn't be too hard to write | 23 * specify expected values manually here. It shouldn't be too hard to write |
25 * special cases for all the values we test. | 24 * special cases for all the values we test. |
26 */ | 25 */ |
27 ReflectionTests.resolveUrl = function(url) { | 26 ReflectionTests.resolveUrl = function(url) { |
| 27 url = String(url); |
28 var el = document.createElement("a"); | 28 var el = document.createElement("a"); |
29 el.href = String(url); | 29 el.href = url; |
30 var ret = el.protocol + "//" + el.host + el.pathname + el.search + el.hash; | 30 var ret = el.protocol + "//" + el.host + el.pathname + el.search + el.hash; |
31 if (ret == "//") { | 31 if (ret == "//") { |
32 return ""; | 32 return url; |
33 } else { | 33 } else { |
34 return ret; | 34 return ret; |
35 } | 35 } |
36 }; | 36 }; |
37 | 37 |
38 /** | 38 /** |
39 * Given some input, convert to a multi-URL value for IDL get per the spec. | |
40 */ | |
41 ReflectionTests.urlsExpected = function(urls) { | |
42 var expected = ""; | |
43 // TODO: Test other whitespace? | |
44 urls = urls + ""; | |
45 var split = urls.split(" "); | |
46 for (var j = 0; j < split.length; j++) { | |
47 if (split[j] == "") { | |
48 continue; | |
49 } | |
50 var append = ReflectionTests.resolveUrl(split[j]); | |
51 if (append == "") { | |
52 continue; | |
53 } | |
54 if (expected == "") { | |
55 expected = append; | |
56 } else { | |
57 expected += " " + append; | |
58 } | |
59 } | |
60 return expected; | |
61 }; | |
62 | |
63 /** | |
64 * The "rules for parsing non-negative integers" from the HTML spec. They're | 39 * The "rules for parsing non-negative integers" from the HTML spec. They're |
65 * mostly used for reflection, so here seems like as good a place to test them | 40 * mostly used for reflection, so here seems like as good a place to test them |
66 * as any. Returns false on error. | 41 * as any. Returns false on error. |
67 */ | 42 */ |
68 ReflectionTests.parseNonneg = function(input) { | 43 ReflectionTests.parseNonneg = function(input) { |
69 var value = this.parseInt(input); | 44 var value = this.parseInt(input); |
70 if (value === false || value < 0) { | 45 if (value === false || value < 0) { |
71 return false; | 46 return false; |
72 } | 47 } |
73 return value; | 48 return value; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 "string": { | 145 "string": { |
171 "jsType": "string", | 146 "jsType": "string", |
172 "defaultVal": "", | 147 "defaultVal": "", |
173 "domTests": ["", " " + binaryString + " foo ", undefined, 7, 1.5, true, | 148 "domTests": ["", " " + binaryString + " foo ", undefined, 7, 1.5, true, |
174 false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null, | 149 false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null, |
175 {"toString":function(){return "test-toString";}}, | 150 {"toString":function(){return "test-toString";}}, |
176 {"valueOf":function(){return "test-valueOf";}, toString:nul
l} | 151 {"valueOf":function(){return "test-valueOf";}, toString:nul
l} |
177 ] | 152 ] |
178 }, | 153 }, |
179 /** | 154 /** |
180 * "If a reflecting IDL attribute is a DOMString attribute whose content | 155 * "If a reflecting IDL attribute is a USVString attribute whose content |
181 * attribute is defined to contain a URL, then on getting, the IDL | 156 * attribute is defined to contain a URL, then on getting, if the content |
182 * attribute must resolve the value of the content attribute relative to | 157 * attribute is absent, the IDL attribute must return the empty string. |
183 * the element and return the resulting absolute URL if that was | 158 * Otherwise, the IDL attribute must parse the value of the content |
184 * successful, or the empty string otherwise; and on setting, must set the | 159 * attribute relative to the element's node document and if that is |
185 * content attribute to the specified literal value. If the content | 160 * successful, return the resulting URL string. If parsing fails, then the |
186 * attribute is absent, the IDL attribute must return the default value, if | 161 * value of the content attribute must be returned instead, converted to a |
187 * the content attribute has one, or else the empty string." | 162 * USVString. On setting, the content attribute must be set to the specified |
| 163 * new value." |
| 164 * |
| 165 * Also HTMLHyperLinkElementUtils href, used by a.href and area.href |
188 */ | 166 */ |
189 "url": { | 167 "url": { |
190 "jsType": "string", | 168 "jsType": "string", |
191 "defaultVal": "", | 169 "defaultVal": "", |
192 "domTests": ["", " foo ", "http://site.example/", | 170 "domTests": ["", " foo ", "http://site.example/", |
193 "//site.example/path???@#l", binaryString, undefined, 7, 1.
5, true, | 171 "//site.example/path???@#l", binaryString, undefined, 7, 1.
5, true, |
194 false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null, | 172 false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null, |
195 {"toString":function(){return "test-toString";}}, | 173 {"toString":function(){return "test-toString";}}, |
196 {"valueOf":function(){return "test-valueOf";}, toString:nul
l}], | 174 {"valueOf":function(){return "test-valueOf";}, toString:nul
l}], |
197 "domExpected": ReflectionTests.resolveUrl, | 175 "domExpected": ReflectionTests.resolveUrl, |
198 "idlIdlExpected": ReflectionTests.resolveUrl | 176 "idlIdlExpected": ReflectionTests.resolveUrl |
199 }, | 177 }, |
200 /** | 178 /** |
201 * "If a reflecting IDL attribute is a DOMString attribute whose content | |
202 * attribute is defined to contain one or more URLs, then on getting, the | |
203 * IDL attribute must split the content attribute on spaces and return the | |
204 * concatenation of resolving each token URL to an absolute URL relative to | |
205 * the element, with a single U+0020 SPACE character between each URL, | |
206 * ignoring any tokens that did not resolve successfully. If the content | |
207 * attribute is absent, the IDL attribute must return the default value, if | |
208 * the content attribute has one, or else the empty string. On setting, the | |
209 * IDL attribute must set the content attribute to the specified literal | |
210 * value." | |
211 * | |
212 * Seems to only be used for ping. | |
213 */ | |
214 "urls": { | |
215 "jsType": "string", | |
216 "defaultVal": "", | |
217 "domTests": ["", " foo ", "http://site.example/ foo bar baz", | |
218 "//site.example/path???@#l", binaryString, undefined, 7, 1.
5, true, | |
219 false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null, | |
220 {"toString":function(){return "test-toString";}}, | |
221 {"valueOf":function(){return "test-valueOf";}, toString:nul
l}], | |
222 "domExpected": ReflectionTests.urlsExpected, | |
223 "idlIdlExpected": ReflectionTests.urlsExpected | |
224 }, | |
225 /** | |
226 * "If a reflecting IDL attribute is a DOMString whose content attribute is | 179 * "If a reflecting IDL attribute is a DOMString whose content attribute is |
227 * an enumerated attribute, and the IDL attribute is limited to only known | 180 * an enumerated attribute, and the IDL attribute is limited to only known |
228 * values, then, on getting, the IDL attribute must return the conforming | 181 * values, then, on getting, the IDL attribute must return the conforming |
229 * value associated with the state the attribute is in (in its canonical | 182 * value associated with the state the attribute is in (in its canonical |
230 * case), or the empty string if the attribute is in a state that has no | 183 * case), or the empty string if the attribute is in a state that has no |
231 * associated keyword value; and on setting, if the new value is an ASCII | 184 * associated keyword value; and on setting, if the new value is an ASCII |
232 * case-insensitive match for one of the keywords given for that attribute, | 185 * case-insensitive match for one of the keywords given for that attribute, |
233 * then the content attribute must be set to the conforming value | 186 * then the content attribute must be set to the conforming value |
234 * associated with the state that the attribute would be in if set to the | 187 * associated with the state that the attribute would be in if set to the |
235 * given new value, otherwise, if the new value is the empty string, then | 188 * given new value, otherwise, if the new value is the empty string, then |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 var time = document.getElementById("time"); | 815 var time = document.getElementById("time"); |
863 if (time) { | 816 if (time) { |
864 time.innerHTML = (new Date().getTime() - ReflectionTests.start)/1000; | 817 time.innerHTML = (new Date().getTime() - ReflectionTests.start)/1000; |
865 } | 818 } |
866 | 819 |
867 if (unimplemented.length) { | 820 if (unimplemented.length) { |
868 var p = document.createElement("p"); | 821 var p = document.createElement("p"); |
869 p.textContent = "(Note: missing tests for types " + unimplemented.join(", ")
+ ".)"; | 822 p.textContent = "(Note: missing tests for types " + unimplemented.join(", ")
+ ".)"; |
870 document.body.appendChild(p); | 823 document.body.appendChild(p); |
871 } | 824 } |
OLD | NEW |