UNPKG

10.8 kBJavaScriptView Raw
1/* globals add_completion_callback */
2'use strict';
3var fs = require('fs');
4var Path = require('path');
5var domino = require('../lib');
6
7// These are the tests we currently fail.
8// Some of these failures are bugs we ought to fix.
9var blacklist = [
10 // web-platform-tests/html/dom
11 'interfaces',
12 'reflection-obsolete',
13 'documents dom-tree-accessors Document.body',
14 'documents dom-tree-accessors Document.currentScript',
15 'documents dom-tree-accessors Document.currentScript.sub',
16 'documents dom-tree-accessors document.embeds-document.plugins-01',
17 'documents dom-tree-accessors document.forms',
18 'documents dom-tree-accessors document.images',
19 'documents dom-tree-accessors document.title-05',
20 'documents dom-tree-accessors document.title-07',
21 'documents dom-tree-accessors document.title-09',
22 'documents dom-tree-accessors nameditem-01',
23 'documents dom-tree-accessors nameditem-02',
24 'documents dom-tree-accessors nameditem-03',
25 'documents dom-tree-accessors nameditem-04',
26 'documents dom-tree-accessors nameditem-05',
27 'documents dom-tree-accessors nameditem-06',
28 'documents dom-tree-accessors document.getElementsByName document.getElementsByName-interface',
29 'documents dom-tree-accessors document.getElementsByName document.getElementsByName-namespace-xhtml',
30 'documents dom-tree-accessors document.getElementsByName document.getElementsByName-namespace',
31 'documents resource-metadata-management document-compatmode-06',
32 'documents resource-metadata-management document-cookie',
33 'documents resource-metadata-management document-lastModified-01',
34 'documents resource-metadata-management document-lastModified',
35 'dynamic-markup-insertion closing-the-input-stream document.close-01',
36 /dynamic-markup-insertion document-write [0-9]+/,
37 /dynamic-markup-insertion document-write document.write-0[12]/,
38 /dynamic-markup-insertion document-write iframe_00[0-9]/,
39 /dynamic-markup-insertion document-write script_00[2456789]/,
40 /dynamic-markup-insertion document-write script_01[0123]/,
41 /dynamic-markup-insertion document-writeln document.writeln-0[123]/,
42 /dynamic-markup-insertion opening-the-input-stream 00[1789]/,
43 'dynamic-markup-insertion opening-the-input-stream 010-2',
44 /dynamic-markup-insertion opening-the-input-stream 01[123456]-1/,
45 'dynamic-markup-insertion opening-the-input-stream document.open-01',
46 'dynamic-markup-insertion opening-the-input-stream document.open-02',
47 'dynamic-markup-insertion opening-the-input-stream document.open-03-frame',
48 'elements global-attributes custom-attrs',
49 'elements global-attributes data_unicode_attr',
50 'elements global-attributes dataset-delete',
51 'elements global-attributes dataset-enumeration',
52 'elements global-attributes dataset-get',
53 'elements global-attributes dataset-prototype',
54 'elements global-attributes dataset-set',
55 'elements global-attributes dataset',
56 'elements global-attributes dir_auto-contained-script-L-ref',
57 'elements global-attributes dir_auto-contained-script-L',
58 'elements global-attributes id-attribute',
59 'elements global-attributes the-lang-attribute-001',
60 'elements global-attributes the-lang-attribute-002',
61 'elements global-attributes the-lang-attribute-003',
62 'elements global-attributes the-lang-attribute-004',
63 'elements global-attributes the-lang-attribute-005',
64 'elements global-attributes the-lang-attribute-006',
65 'elements global-attributes the-lang-attribute-007',
66 'elements global-attributes the-lang-attribute-008',
67 'elements global-attributes the-lang-attribute-009',
68 'elements global-attributes the-lang-attribute-010',
69 'elements global-attributes the-translate-attribute-007',
70 'elements global-attributes the-translate-attribute-008',
71 'elements global-attributes the-translate-attribute-009',
72 'elements global-attributes the-translate-attribute-010',
73 'elements global-attributes the-translate-attribute-011',
74 'elements global-attributes the-translate-attribute-012',
75
76 // web-platform-tests/dom/nodes
77 'CharacterData-appendData',
78 'CharacterData-data',
79 'CharacterData-deleteData',
80 'CharacterData-insertData',
81 'CharacterData-replaceData',
82 'CharacterData-substringData',
83 'Comment-constructor',
84 'DOMImplementation-createDocument',
85 'DOMImplementation-createDocumentType',
86 'DOMImplementation-createHTMLDocument',
87 'DOMImplementation-hasFeature',
88 'Document-URL.sub',
89 'Document-characterSet-normalization',
90 'Document-constructor',
91 /Document-contentType/,
92 'Document-createAttribute',
93 'Document-createComment',
94 'Document-createElement-namespace',
95 'Document-createElement',
96 'Document-createElementNS',
97 'Document-createEvent',
98 'Document-createTreeWalker',
99 'Document-getElementById',
100 'Document-getElementsByTagName',
101 'Document-getElementsByTagName-xhtml',
102 'Document-getElementsByTagNameNS',
103 'Element-childElement-null-xhtml',
104 'Element-childElementCount-dynamic-add-xhtml',
105 'Element-childElementCount-dynamic-remove-xhtml',
106 'Element-childElementCount-nochild-xhtml',
107 'Element-childElementCount-xhtml',
108 'Element-children',
109 'Element-classlist',
110 'Element-closest',
111 'Element-firstElementChild-entity-xhtml',
112 'Element-firstElementChild-xhtml',
113 'Element-firstElementChild-namespace-xhtml',
114 'Element-getElementsByClassName',
115 'Element-getElementsByTagName-change-document-HTMLNess',
116 'Element-getElementsByTagName',
117 'Element-getElementsByTagNameNS',
118 'Element-hasAttributes',
119 'Element-insertAdjacentElement',
120 'Element-insertAdjacentText',
121 'Element-lastElementChild-xhtml',
122 'Element-matches',
123 'Element-nextElementSibling-xhtml',
124 'Element-previousElementSibling-xhtml',
125 'Element-siblingElement-null-xhtml',
126 'Element-tagName',
127 'MutationObserver-attributes',
128 'MutationObserver-characterData',
129 'MutationObserver-childList',
130 'MutationObserver-disconnect',
131 'MutationObserver-document',
132 'MutationObserver-inner-outer',
133 'MutationObserver-takeRecords',
134 'Node-baseURI',
135 'Node-childNodes',
136 'Node-cloneNode',
137 'Node-compareDocumentPosition',
138 'Node-constants',
139 'Node-isConnected',
140 'Node-isEqualNode',
141 'Node-isEqualNode-xhtml',
142 'Node-lookupPrefix',
143 'Node-lookupNamespaceURI',
144 'Node-nodeName-xhtml',
145 'Node-nodeValue',
146 'Node-properties',
147 'Node-textContent',
148 'NodeList-Iterable',
149 'ParentNode-append',
150 'ParentNode-prepend',
151 'ParentNode-querySelector-All-content',
152 'ParentNode-querySelector-All',
153 /^ProcessingInstruction-/,
154 'Text-constructor',
155 'append-on-Document',
156 'attributes',
157 'case',
158 'insert-adjacent',
159 'prepend-on-Document',
160 'remove-unscopable',
161 'rootNode',
162].map(function(s) {
163 // Convert strings to equivalent regular expression matchers.
164 if (typeof s === 'string') {
165 return new RegExp('^' + s.replace(/[\^\\$*+?.()|{}\[\]\/]/g, '\\$&') + '$');
166 } else {
167 return s;
168 }
169});
170
171var onBlacklist = function(name) {
172 name = name.replace(/\//g, ' ').replace(/\.x?html$/, '');
173 for (var i=0; i<blacklist.length; i++) {
174 if (blacklist[i].test(name)) { return true; }
175 }
176 return false;
177};
178
179function read(file) {
180 return fs.readFileSync(Path.resolve(__dirname, '..', file), 'utf8');
181}
182
183var testharness = read(__dirname + '/web-platform-tests/resources/testharness.js');
184
185function list(base, dir, fn) {
186 var result = {};
187 var fulldir = Path.resolve(__dirname, '..', base, dir);
188 fs.readdirSync(fulldir).forEach(function(file) {
189 var path = Path.join(dir, file);
190 var stat = fs.statSync(Path.join(fulldir, file));
191 if (stat.isDirectory()) {
192 result[file] = list(base, path, fn);
193 }
194 else if (file.match(/\.x?html$/)) {
195 var test = fn(path, Path.join(fulldir, file));
196 if (test) result[file] = test;
197 }
198 });
199 return result;
200}
201
202var harness = function() {
203 var paths = [].slice.call(arguments);
204 return paths.map(function (path) {
205 return list(path, '', function(name, file) {
206 if (/\/html\/dom\/reflection-original.html$/.test(file)) {
207 // This is a compilation file & not a test suite.
208 return; // skip
209 }
210 var html = read(file);
211 var window = domino.createWindow(html, 'http://example.com/');
212 window._run(testharness);
213 var scripts = window.document.getElementsByTagName('script');
214 scripts = [].slice.call(scripts);
215
216 return function() {
217 var listen = onBlacklist(name) ? function listenForSuccess() {
218 add_completion_callback(function(tests, status) {
219 var failed = tests.filter(function(t) {
220 return t.status === t.FAIL || t.status === t.TIMEOUT;
221 });
222 if (failed.length===0) {
223 throw new Error("Expected blacklisted test to fail");
224 }
225 });
226 } : function listenForFailures() {
227 add_completion_callback(function(tests, status) {
228 var failed = tests.filter(function(t) {
229 return t.status === t.FAIL || t.status === t.TIMEOUT;
230 });
231 if (failed.length) {
232 throw new Error(failed[0].name+": "+failed[0].message);
233 }
234 });
235 };
236 window._run("(" + listen.toString() + ")();");
237
238 var concatenatedScripts = scripts.map(function(script) {
239 if (/^text\/plain$/.test(script.getAttribute('type')||'')) {
240 return '';
241 }
242 if (/^(\w+|..)/.test(script.getAttribute('src')||'')) {
243 var f = Path.resolve(path, script.getAttribute('src'));
244 if (fs.existsSync(f)) { return read(f); }
245 }
246 return script.textContent + '\n';
247 }).join("\n");
248 concatenatedScripts =
249 concatenatedScripts.replace(/\.attributes\[(\w+)\]/g,
250 '.attributes.item($1)');
251 // Workaround for https://github.com/w3c/web-platform-tests/pull/3984
252 concatenatedScripts =
253 'var x, doc, ReflectionTests;\n' +
254 // Hack in globals on window object
255 '"String|Boolean|Number".split("|").forEach(function(x){' +
256 'window[x] = global[x];})\n' +
257 // Hack in frames on window object
258 'Array.prototype.forEach.call(document.getElementsByTagName("iframe"),' +
259 'function(f,i){window[i]=f.contentWindow;});\n' +
260 'window.setup = function(f) { f(); };\n' +
261 concatenatedScripts +
262 '\nwindow.dispatchEvent(new Event("load"));';
263
264 var go = function() {
265 window._run(concatenatedScripts);
266 };
267 try {
268 go();
269 } catch (e) {
270 if ((!onBlacklist(name)) ||
271 /^Expected blacklisted test to fail/.test(e.message||'')) {
272 throw e;
273 }
274 }
275 };
276 });
277 });
278};
279
280module.exports = harness(__dirname + '/web-platform-tests/html/dom',
281 __dirname + '/web-platform-tests/dom/nodes');