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

Side by Side Diff: third_party/WebKit/LayoutTests/dom/svg/level3/xpath/svgunit.js

Issue 2670783003: Move DOM conformance tests to dom/legacy_dom_conformance/, part 3/N. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « third_party/WebKit/LayoutTests/dom/svg/level3/xpath/resources/staffNS.xml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 Copyright (c) 2001-2005 World Wide Web Consortium,
3 (Massachusetts Institute of Technology, European Research Consortium
4 for Informatics and Mathematics, Keio University). All
5 Rights Reserved. This work is distributed under the W3C(r) Software License [1] in the
6 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
9 [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
10 */
11
12 /* Begin additions for WebKit layout test framework. */
13 if (window.testRunner)
14 testRunner.dumpAsText();
15 /* End additions for WebKit layout test framework. */
16
17 function assertSize(descr, expected, actual) {
18 var actualSize;
19 actualSize = actual.length;
20 assertEquals(descr, expected, actualSize);
21 }
22
23 function assertEqualsAutoCase(context, descr, expected, actual) {
24 if (builder.contentType == "text/html") {
25 if(context == "attribute") {
26 assertEquals(descr, expected.toLowerCase(), actual.toLowerCase());
27 } else {
28 assertEquals(descr, expected.toUpperCase(), actual);
29 }
30 } else {
31 assertEquals(descr, expected, actual);
32 }
33 }
34
35 function assertEqualsCollectionAutoCase(context, descr, expected, actual) {
36 //
37 // if they aren't the same size, they aren't equal
38 assertEquals(descr, expected.length, actual.length);
39
40 //
41 // if there length is the same, then every entry in the expected list
42 // must appear once and only once in the actual list
43 var expectedLen = expected.length;
44 var expectedValue;
45 var actualLen = actual.length;
46 var i;
47 var j;
48 var matches;
49 for(i = 0; i < expectedLen; i++) {
50 matches = 0;
51 expectedValue = expected[i];
52 for(j = 0; j < actualLen; j++) {
53 if (builder.contentType == "text/html") {
54 if (context == "attribute") {
55 if (expectedValue.toLowerCase() == actual[j].toLowerCase()) {
56 matches++;
57 }
58 } else {
59 if (expectedValue.toUpperCase() == actual[j]) {
60 matches++;
61 }
62 }
63 } else {
64 if(expectedValue == actual[j]) {
65 matches++;
66 }
67 }
68 }
69 if(matches == 0) {
70 assert(descr + ": No match found for " + expectedValue,false);
71 }
72 if(matches > 1) {
73 assert(descr + ": Multiple matches found for " + expectedValue, fals e);
74 }
75 }
76 }
77
78 function assertEqualsCollection(descr, expected, actual) {
79 //
80 // if they aren't the same size, they aren't equal
81 assertEquals(descr, expected.length, actual.length);
82 //
83 // if there length is the same, then every entry in the expected list
84 // must appear once and only once in the actual list
85 var expectedLen = expected.length;
86 var expectedValue;
87 var actualLen = actual.length;
88 var i;
89 var j;
90 var matches;
91 for(i = 0; i < expectedLen; i++) {
92 matches = 0;
93 expectedValue = expected[i];
94 for(j = 0; j < actualLen; j++) {
95 if(expectedValue == actual[j]) {
96 matches++;
97 }
98 }
99 if(matches == 0) {
100 assert(descr + ": No match found for " + expectedValue,false);
101 }
102 if(matches > 1) {
103 assert(descr + ": Multiple matches found for " + expectedValue, fals e);
104 }
105 }
106 }
107
108 function assertEqualsListAutoCase(context, descr, expected, actual) {
109 var minLength = expected.length;
110 if (actual.length < minLength) {
111 minLength = actual.length;
112 }
113 //
114 for(var i = 0; i < minLength; i++) {
115 assertEqualsAutoCase(context, descr, expected[i], actual[i]);
116 }
117 //
118 // if they aren't the same size, they aren't equal
119 assertEquals(descr, expected.length, actual.length);
120 }
121
122 function assertEqualsList(descr, expected, actual) {
123 var minLength = expected.length;
124 if (actual.length < minLength) {
125 minLength = actual.length;
126 }
127 //
128 for(var i = 0; i < minLength; i++) {
129 if(expected[i] != actual[i]) {
130 assertEquals(descr, expected[i], actual[i]);
131 }
132 }
133 //
134 // if they aren't the same size, they aren't equal
135 assertEquals(descr, expected.length, actual.length);
136 }
137
138 function assertInstanceOf(descr, type, obj) {
139 if(type == "Attr") {
140 assertEquals(descr,2,obj.nodeType);
141 var specd = obj.specified;
142 }
143 }
144
145 function assertSame(descr, expected, actual) {
146 if(expected != actual) {
147 assertEquals(descr, expected.nodeType, actual.nodeType);
148 assertEquals(descr, expected.nodeValue, actual.nodeValue);
149 }
150 }
151
152 function assertURIEquals(assertID, scheme, path, host, file, name, query, frag ment, isAbsolute, actual) {
153 //
154 // URI must be non-null
155 assertNotNull(assertID, actual);
156
157 var uri = actual;
158
159 var lastPound = actual.lastIndexOf("#");
160 var actualFragment = "";
161 if(lastPound != -1) {
162 //
163 // substring before pound
164 //
165 uri = actual.substring(0,lastPound);
166 actualFragment = actual.substring(lastPound+1);
167 }
168 if(fragment != null) assertEquals(assertID,fragment, actualFragment);
169
170 var lastQuestion = uri.lastIndexOf("?");
171 var actualQuery = "";
172 if(lastQuestion != -1) {
173 //
174 // substring before pound
175 //
176 uri = actual.substring(0,lastQuestion);
177 actualQuery = actual.substring(lastQuestion+1);
178 }
179 if(query != null) assertEquals(assertID, query, actualQuery);
180
181 var firstColon = uri.indexOf(":");
182 var firstSlash = uri.indexOf("/");
183 var actualPath = uri;
184 var actualScheme = "";
185 if(firstColon != -1 && firstColon < firstSlash) {
186 actualScheme = uri.substring(0,firstColon);
187 actualPath = uri.substring(firstColon + 1);
188 }
189
190 if(scheme != null) {
191 assertEquals(assertID, scheme, actualScheme);
192 }
193
194 if(path != null) {
195 assertEquals(assertID, path, actualPath);
196 }
197
198 if(host != null) {
199 var actualHost = "";
200 if(actualPath.substring(0,2) == "//") {
201 var termSlash = actualPath.substring(2).indexOf("/") + 2;
202 actualHost = actualPath.substring(0,termSlash);
203 }
204 assertEquals(assertID, host, actualHost);
205 }
206
207 if(file != null || name != null) {
208 var actualFile = actualPath;
209 var finalSlash = actualPath.lastIndexOf("/");
210 if(finalSlash != -1) {
211 actualFile = actualPath.substring(finalSlash+1);
212 }
213 if (file != null) {
214 assertEquals(assertID, file, actualFile);
215 }
216 if (name != null) {
217 var actualName = actualFile;
218 var finalDot = actualFile.lastIndexOf(".");
219 if (finalDot != -1) {
220 actualName = actualName.substring(0, finalDot);
221 }
222 assertEquals(assertID, name, actualName);
223 }
224 }
225
226 if(isAbsolute != null) {
227 assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
228 }
229 }
230
231 // size() used by assertSize element
232 function size(collection)
233 {
234 return collection.length;
235 }
236
237 function same(expected, actual)
238 {
239 return expected === actual;
240 }
241
242 function getSuffix(contentType) {
243 return ".svg";
244 }
245
246 function equalsAutoCase(context, expected, actual) {
247 if (builder.contentType == "text/html") {
248 if (context == "attribute") {
249 return expected.toLowerCase() == actual;
250 }
251 return expected.toUpperCase() == actual;
252 }
253 return expected == actual;
254 }
255
256 function createTempURI(scheme) {
257 if (scheme == "http") {
258 return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() * 100000) + ".xml";
259 }
260 return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml";
261 }
262
263 function EventMonitor() {
264 this.atEvents = new Array();
265 this.bubbledEvents = new Array();
266 this.capturedEvents = new Array();
267 this.allEvents = new Array();
268 }
269
270 EventMonitor.prototype.handleEvent = function(evt) {
271 switch(evt.eventPhase) {
272 case 1:
273 monitor.capturedEvents[monitor.capturedEvents.length] = evt;
274 break;
275
276 case 2:
277 monitor.atEvents[monitor.atEvents.length] = evt;
278 break;
279
280 case 3:
281 monitor.bubbledEvents[monitor.bubbledEvents.length] = evt;
282 break;
283 }
284 monitor.allEvents[monitor.allEvents.length] = evt;
285 }
286
287 function DOMErrorImpl(err) {
288 this.severity = err.severity;
289 this.message = err.message;
290 this.type = err.type;
291 this.relatedException = err.relatedException;
292 this.relatedData = err.relatedData;
293 this.location = err.location;
294 }
295
296 function DOMErrorMonitor() {
297 this.allErrors = new Array();
298 }
299
300 DOMErrorMonitor.prototype.handleError = function(err) {
301 errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err );
302 }
303
304 DOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) {
305 var i;
306 for (i = 0; i < this.allErrors.length; i++) {
307 if (this.allErrors[i].severity >= severity) {
308 assertEquals(id, severity - 1, this.allErrors[i].severity);
309 }
310 }
311 }
312
313 function UserDataNotification(operation, key, data, src, dst) {
314 this.operation = operation;
315 this.key = key;
316 this.data = data;
317 this.src = src;
318 this.dst = dst;
319 }
320
321 function UserDataMonitor() {
322 this.allNotifications = new Array();
323 }
324
325 UserDataMonitor.prototype.handle = function(operation, key, data, src, dst) {
326 userDataMonitor.allNotifications[userDataMonitor.allNotifications.length] =
327 new UserDataNotification(operation, key, data, src, dst);
328 }
329
330 function toLowerArray(src) {
331 var newArray = new Array();
332 var i;
333 for (i = 0; i < src.length; i++) {
334 newArray[i] = src[i].toLowerCase();
335 }
336 return newArray;
337 }
338
339 function SVGBuilder() {
340 this.contentType = "image/svg+xml";
341 this.supportedContentTypes = [ "image/svg+xml" ];
342
343 this.supportsAsyncChange = false;
344 this.async = false;
345 this.fixedAttributeNames = [
346 "validating", "expandEntityReferences", "coalescing",
347 "signed", "hasNullString", "ignoringElementContentWhitespace", "namespac eAware", "ignoringComments", "schemaValidating"];
348
349 this.fixedAttributeValues = [false, true, false, true, true , false, true, false, false ];
350 this.configurableAttributeNames = [ ];
351 this.configurableAttributeValues = [ ];
352 this.initializationError = null;
353 this.initializationFatalError = null;
354 this.skipIncompatibleTests = true;
355 this.documentURLs = new Array();
356 this.documentVarnames = new Array();
357 }
358
359 SVGBuilder.prototype.hasFeature = function(feature, version) {
360 return document.implementation.hasFeature(feature, version);
361 }
362
363 SVGBuilder.prototype.getImplementation = function() {
364 return document.implementation;
365 }
366
367 SVGBuilder.prototype.preload = function(frame, varname, url) {
368 var i;
369 this.documentVarnames[this.documentVarnames.length] = varname;
370 this.documentURLs[this.documentURLs.length] = url;
371 /*
372 if (this.documentURLs.length > 1) {
373 //
374 // if all the urls are not the same
375 //
376 for (i = 1; i < this.documentURLs.length; i++) {
377 if (this.documentURLs[i] != this.documentURLs[0]) {
378 throw "Tests with multiple loads of different documents are not cur rently supported";
379 }
380 }
381 }
382 */
383 return 1;
384 }
385
386 SVGBuilder.prototype.cloneNode = function(srcNode, doc) {
387 var clone = null;
388 switch(srcNode.nodeType) {
389 //
390 // element
391 case 1:
392 clone = doc.createElementNS(srcNode.namespaceURI, srcNode.nodeName);
393 var attrs = srcNode.attributes;
394 for(var i = 0; i < attrs.length; i++) {
395 var srcAttr = attrs.item(i);
396 clone.setAttributeNS(srcAttr.namespaceURI, srcAttr.nodeName, srcAttr.n odeValue);
397 }
398 var srcChild = srcNode.firstChild;
399 while(srcChild != null) {
400 var cloneChild = this.cloneNode(srcChild, doc);
401 if (cloneChild != null) {
402 clone.appendChild(cloneChild);
403 }
404 srcChild = srcChild.nextSibling;
405 }
406 break;
407
408 case 3:
409 clone = doc.createTextNode(srcNode.nodeValue);
410 break;
411
412 case 4:
413 clone = doc.createCDATASection(srcNode.nodeValue);
414 break;
415
416 case 5:
417 clone = doc.createEntityReference(srcNode.nodeName);
418 break;
419
420 case 7:
421 clone = doc.createProcessingInstruction(srcNode.target, srcNode.data);
422 break;
423
424 case 8:
425 clone = doc.createComment(srcNode.nodeValue);
426 break;
427 }
428 return clone;
429
430 }
431
432 SVGBuilder.prototype.load = function(frame, varname, url) {
433 req = new XMLHttpRequest;
434 req.open("GET", "resources/" + url + ".xml", false);
435 req.send(null);
436 return req.responseXML;
437 }
438
439 SVGBuilder.prototype.getImplementationAttribute = function(attr) {
440 for (var i = 0; i < this.fixedAttributeNames.length; i++) {
441 if (this.fixedAttributeNames[i] == attr) {
442 return this.fixedAttributeValues[i];
443 }
444 }
445 throw "Unrecognized implementation attribute: " + attr;
446 }
447
448 SVGBuilder.prototype.setImplementationAttribute = function(attribute, value) {
449 var supported = this.getImplementationAttribute(attribute);
450 if (supported != value) {
451 this.initializationError = "SVG loader does not support " + attribute + "=" + value;
452 }
453 }
454
455 SVGBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
456 var supported = this.getImplementationAttribute(attribute);
457 return (supported == value);
458 }
459
460 function createConfiguredBuilder() {
461 return new SVGBuilder();
462 }
463
464 function catchInitializationError(buildr, ex) {
465 buildr.initializationError = ex;
466 buildr.initializationFatalError = ex;
467 }
468
469 function checkFeature(feature, version)
470 {
471 if (!builder.hasFeature(feature, version))
472 {
473 //
474 // don't throw exception so that users can select to ignore the preconditi on
475 //
476 builder.initializationError = "builder does not support feature " + feature + " version " + version;
477 }
478 }
479
480 function changeColor(color) {
481 document.getElementsByTagName("rect").item(0).setAttribute("style", "fill:" + color);
482 }
483
484 function addMessage(x, y, msg) {
485 var textElem = document.createElementNS("http://www.w3.org/2000/svg", "text") ;
486 textElem.setAttributeNS(null, "x", x);
487 textElem.setAttributeNS(null, "y", y);
488 textElem.appendChild(document.createTextNode(msg));
489 document.documentElement.appendChild(textElem);
490 }
491
492 function checkInitialization(buildr, testname) {
493 if (buildr.initializationError != null) {
494 addMessage("0", "160", buildr.initializationError);
495 changeColor("yellow");
496 }
497 return buildr.initializationError;
498 }
499
500 function preload(docRef, varname, href) {
501 return builder.preload(docRef, varname, href);
502 }
503
504 function load(docRef, varname, href) {
505 return builder.load(docRef, varname, href);
506 }
507
508 function getImplementationAttribute(attr) {
509 return builder.getImplementationAttribute(attr);
510 }
511
512 function setImplementationAttribute(attribute, value) {
513 builder.setImplementationAttribute(attribute, value);
514 }
515
516 function createXPathEvaluator(doc) {
517 return doc;
518 }
519
520 function getImplementation() {
521 return builder.getImplementation();
522 }
523
524 function assertEquals(id, expected, actual) {
525 var myActual;
526 if (expected != actual) {
527 myActual = actual;
528 if (actual == null) {
529 myActual = "null";
530 }
531 throw id + ": assertEquals failed, actual " + actual + ", expected " + ex pected + ".";
532 }
533 }
534
535 function assertNull(id, actual) {
536 if (actual != null) {
537 throw id + ": assertNull failed, actual " + actual;
538 }
539 }
540
541 function assertTrue(id, actual) {
542 if (!actual) {
543 throw id + ": assertTrue failed";
544 }
545 }
546
547 function assert(id, actual) {
548 if (!actual) {
549 throw id + ": assert failed";
550 }
551 }
552
553 function assertFalse(id, actual) {
554 if (actual) {
555 throw id + ": assertFalse failed";
556 }
557 }
558
559 function assertNotNull(id, actual) {
560 if (actual == null) {
561 throw id + ": assertNotNull failed";
562 }
563 }
564
565 function fail(id) {
566 throw id + ": fail";
567 }
568
569 function getSuffix(contentType) {
570 switch(contentType) {
571 case "text/html":
572 return ".html";
573
574 case "application/xhtml+xml":
575 return ".xhtml";
576
577 case "image/svg+xml":
578 return ".svg";
579
580 case "text/mathml":
581 return ".mml";
582 }
583 return ".xml";
584 }
585
586 function getResourceURI(name, scheme, contentType) {
587 var base = document.documentURI;
588 if (base == null) {
589 base = "";
590 } else {
591 base = base.substring(0, base.lastIndexOf('/') + 1) + "files/";
592 }
593 return base + name + getSuffix(contentType);
594 }
595
596 function onloadHandler() {
597 //
598 // invoke test setup
599 //
600 setUpPage();
601
602 try {
603 runTest();
604 if (builder.initializationError == null) {
605 changeColor("green");
606 addMessage("0", "120", exposeTestFunctionNames()[0] + ": Success" );
607 } else {
608 addMessage("0", "120", exposeTestFunctionNames()[0]);
609 }
610 } catch(ex) {
611 addMessage("0", "120", exposeTestFunctionNames()[0]);
612 changeColor("red");
613 addMessage("0", "140", ex);
614 }
615 }
616 // Add loader
617 window.addEventListener('load', onloadHandler, false)
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/dom/svg/level3/xpath/resources/staffNS.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698