Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.35
1.1 dom-ts-4 1: /*
1.32 dom-ts-4 2: Copyright (c) 2001-2004 World Wide Web Consortium,
1.1 dom-ts-4 3: (Massachusetts Institute of Technology, Institut National de
4: Recherche en Informatique et en Automatique, Keio University). All
5: Rights Reserved. This program is distributed under the W3C's Software
6: Intellectual Property License. This program is distributed in the
7: hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8: the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9: PURPOSE.
10: See W3C License http://www.w3.org/Consortium/Legal/ for more details.
11: */
1.3 dom-ts-4 12: function assertSize(descr, expected, actual) {
13: var actualSize;
14: actualSize = actual.length;
15: assertEquals(descr, expected, actualSize);
16: }
1.15 dom-ts-4 17:
1.32 dom-ts-4 18: function assertEqualsAutoCase(context, descr, expected, actual) {
19: if (builder.contentType == "text/html") {
20: if(context == "attribute") {
21: assertEquals(descr, expected.toLowerCase(), actual.toLowerCase());
22: } else {
23: assertEquals(descr, expected.toUpperCase(), actual);
24: }
25: } else {
26: assertEquals(descr, expected, actual);
27: }
28: }
1.9 dom-ts-4 29:
1.32 dom-ts-4 30:
31: function assertEqualsCollectionAutoCase(context, descr, expected, actual) {
32: //
33: // if they aren't the same size, they aren't equal
34: assertEquals(descr, expected.length, actual.length);
35:
36: //
37: // if there length is the same, then every entry in the expected list
38: // must appear once and only once in the actual list
39: var expectedLen = expected.length;
40: var expectedValue;
41: var actualLen = actual.length;
42: var i;
43: var j;
44: var matches;
45: for(i = 0; i < expectedLen; i++) {
46: matches = 0;
47: expectedValue = expected[i];
48: for(j = 0; j < actualLen; j++) {
49: if (builder.contentType == "text/html") {
50: if (context == "attribute") {
51: if (expectedValue.toLowerCase() == actual[j].toLowerCase()) {
52: matches++;
53: }
54: } else {
55: if (expectedValue.toUpperCase() == actual[j]) {
56: matches++;
57: }
58: }
59: } else {
60: if(expectedValue == actual[j]) {
61: matches++;
62: }
63: }
64: }
65: if(matches == 0) {
66: assert(descr + ": No match found for " + expectedValue,false);
67: }
68: if(matches > 1) {
69: assert(descr + ": Multiple matches found for " + expectedValue, false);
70: }
71: }
72: }
73:
1.13 dom-ts-4 74: function assertEqualsCollection(descr, expected, actual) {
1.3 dom-ts-4 75: //
76: // if they aren't the same size, they aren't equal
1.17 dom-ts-4 77: assertEquals(descr, expected.length, actual.length);
1.3 dom-ts-4 78: //
79: // if there length is the same, then every entry in the expected list
80: // must appear once and only once in the actual list
81: var expectedLen = expected.length;
82: var expectedValue;
83: var actualLen = actual.length;
84: var i;
85: var j;
86: var matches;
87: for(i = 0; i < expectedLen; i++) {
88: matches = 0;
89: expectedValue = expected[i];
90: for(j = 0; j < actualLen; j++) {
91: if(expectedValue == actual[j]) {
92: matches++;
93: }
94: }
95: if(matches == 0) {
1.17 dom-ts-4 96: assert(descr + ": No match found for " + expectedValue,false);
1.3 dom-ts-4 97: }
98: if(matches > 1) {
1.17 dom-ts-4 99: assert(descr + ": Multiple matches found for " + expectedValue, false);
1.3 dom-ts-4 100: }
101: }
102: }
103:
104:
1.32 dom-ts-4 105: function assertEqualsListAutoCase(context, descr, expected, actual) {
106: var minLength = expected.length;
107: if (actual.length < minLength) {
108: minLength = actual.length;
109: }
110: //
111: for(var i = 0; i < minLength; i++) {
112: assertEqualsAutoCase(context, descr, expected[i], actual[i]);
113: }
114: //
115: // if they aren't the same size, they aren't equal
116: assertEquals(descr, expected.length, actual.length);
117: }
118:
119:
1.13 dom-ts-4 120: function assertEqualsList(descr, expected, actual) {
1.27 dom-ts-4 121: var minLength = expected.length;
122: if (actual.length < minLength) {
123: minLength = actual.length;
124: }
1.3 dom-ts-4 125: //
1.27 dom-ts-4 126: for(var i = 0; i < minLength; i++) {
1.3 dom-ts-4 127: if(expected[i] != actual[i]) {
1.17 dom-ts-4 128: assertEquals(descr, expected[i], actual[i]);
1.3 dom-ts-4 129: }
130: }
1.27 dom-ts-4 131: //
132: // if they aren't the same size, they aren't equal
133: assertEquals(descr, expected.length, actual.length);
1.3 dom-ts-4 134: }
135:
136: function assertInstanceOf(descr, type, obj) {
137: if(type == "Attr") {
1.17 dom-ts-4 138: assertEquals(descr,2,obj.nodeType);
1.3 dom-ts-4 139: var specd = obj.specified;
140: }
141: }
142:
143: function assertSame(descr, expected, actual) {
144: if(expected != actual) {
1.17 dom-ts-4 145: assertEquals(descr, expected.nodeType, actual.nodeType);
146: assertEquals(descr, expected.nodeValue, actual.nodeValue);
1.3 dom-ts-4 147: }
148: }
149:
1.16 dom-ts-4 150: function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
1.7 dom-ts-4 151: //
152: // URI must be non-null
1.17 dom-ts-4 153: assertNotNull(assertID, actual);
1.7 dom-ts-4 154:
155: var uri = actual;
156:
157: var lastPound = actual.lastIndexOf("#");
158: var actualFragment = "";
159: if(lastPound != -1) {
160: //
161: // substring before pound
162: //
163: uri = actual.substring(0,lastPound);
164: actualFragment = actual.substring(lastPound+1);
165: }
1.17 dom-ts-4 166: if(fragment != null) assertEquals(assertID,fragment, actualFragment);
1.7 dom-ts-4 167:
168: var lastQuestion = uri.lastIndexOf("?");
169: var actualQuery = "";
170: if(lastQuestion != -1) {
171: //
172: // substring before pound
173: //
174: uri = actual.substring(0,lastQuestion);
175: actualQuery = actual.substring(lastQuestion+1);
176: }
1.17 dom-ts-4 177: if(query != null) assertEquals(assertID, query, actualQuery);
1.7 dom-ts-4 178:
179: var firstColon = uri.indexOf(":");
180: var firstSlash = uri.indexOf("/");
181: var actualPath = uri;
182: var actualScheme = "";
183: if(firstColon != -1 && firstColon < firstSlash) {
184: actualScheme = uri.substring(0,firstColon);
185: actualPath = uri.substring(firstColon + 1);
186: }
187:
188: if(scheme != null) {
1.17 dom-ts-4 189: assertEquals(assertID, scheme, actualScheme);
1.7 dom-ts-4 190: }
191:
192: if(path != null) {
1.17 dom-ts-4 193: assertEquals(assertID, path, actualPath);
1.7 dom-ts-4 194: }
195:
196: if(host != null) {
197: var actualHost = "";
1.16 dom-ts-4 198: if(actualPath.substring(0,2) == "//") {
1.8 dom-ts-4 199: var termSlash = actualPath.substring(2).indexOf("/") + 2;
1.7 dom-ts-4 200: actualHost = actualPath.substring(0,termSlash);
201: }
1.17 dom-ts-4 202: assertEquals(assertID, host, actualHost);
1.7 dom-ts-4 203: }
204:
1.16 dom-ts-4 205: if(file != null || name != null) {
1.7 dom-ts-4 206: var actualFile = actualPath;
207: var finalSlash = actualPath.lastIndexOf("/");
208: if(finalSlash != -1) {
209: actualFile = actualPath.substring(finalSlash+1);
210: }
1.16 dom-ts-4 211: if (file != null) {
1.17 dom-ts-4 212: assertEquals(assertID, file, actualFile);
1.16 dom-ts-4 213: }
214: if (name != null) {
215: var actualName = actualFile;
216: var finalDot = actualFile.lastIndexOf(".");
217: if (finalDot != -1) {
218: actualName = actualName.substring(0, finalDot);
219: }
1.17 dom-ts-4 220: assertEquals(assertID, name, actualName);
1.16 dom-ts-4 221: }
1.7 dom-ts-4 222: }
223:
224: if(isAbsolute != null) {
1.17 dom-ts-4 225: assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
1.13 dom-ts-4 226: }
227: }
228:
1.29 dom-ts-4 229:
230: // size() used by assertSize element
231: function size(collection)
232: {
233: return collection.length;
234: }
235:
1.30 dom-ts-4 236: function same(expected, actual)
237: {
238: return expected === actual;
239: }
240:
1.18 dom-ts-4 241: function getSuffix(contentType) {
242: switch(contentType) {
243: case "text/html":
244: return ".html";
245:
246: case "text/xml":
247: return ".xml";
248:
249: case "application/xhtml+xml":
250: return ".xhtml";
251:
252: case "image/svg+xml":
253: return ".svg";
254:
255: case "text/mathml":
256: return ".mml";
257: }
258: return ".html";
259: }
260:
1.34 dom-ts-4 261: function equalsAutoCase(context, expected, actual) {
262: if (builder.contentType == "text/html") {
263: if (content == "attribute") {
264: return expected.toLowerCase() == actual;
265: }
266: return expected.toUpperCase() == actual;
267: }
268: return expected == actual;
269: }
270:
271: function catchInitializationError(blder, ex) {
272: blder.initializationError = ex;
273: blder.initializationFatalError = ex;
274: }
275:
276: function checkInitialization(blder, testname) {
277: if (blder.initializationError != null) {
278: if (blder.skipIncompatibleTests) {
279: info(testname + " not run:" + blder.initializationError);
280: return blder.initializationError;
281: } else {
282: //
283: // if an exception was thrown
284: // rethrow it and do not run the test
285: if (blder.initializationFatalError != null) {
286: throw blder.initializationFatalError;
287: } else {
288: //
289: // might be recoverable, warn but continue the test
290: warn(testname + ": " + blder.initializationError);
291: }
292: }
293: }
294: return null;
295: }
296:
297:
1.35 ! dom-ts-4 298: function EventMonitor() {
! 299: this.atEvents = new Array();
! 300: this.bubbledEvents = new Array();
! 301: this.capturedEvents = new Array();
! 302: this.allEvents = new Array();
! 303: }
! 304:
! 305: EventMonitor.prototype.handleEvent = function(evt) {
! 306: switch(evt.eventPhase) {
! 307: case 1:
! 308: monitor.capturedEvents[monitor.capturedEvents.length] = evt;
! 309: break;
! 310:
! 311: case 2:
! 312: monitor.atEvents[monitor.atEvents.length] = evt;
! 313: break;
! 314:
! 315: case 3:
! 316: monitor.bubbledEvents[monitor.bubbledEvents.length] = evt;
! 317: break;
! 318: }
! 319: monitor.allEvents[monitor.allEvents.length] = evt;
! 320: }
! 321:
! 322:
! 323:
1.17 dom-ts-4 324: function IFrameBuilder() {
1.18 dom-ts-4 325: this.contentType = "text/html";
1.26 dom-ts-4 326: this.supportedContentTypes = [ "text/html",
327: "text/xml",
328: "image/svg+xml",
329: "application/xhtml+xml",
330: "text/mathml" ];
1.18 dom-ts-4 331:
332: this.supportsAsyncChange = false;
1.26 dom-ts-4 333: this.async = true;
1.18 dom-ts-4 334: this.fixedAttributeNames = [
335: "validating", "expandEntityReferences", "coalescing",
1.34 dom-ts-4 336: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments"];
1.18 dom-ts-4 337:
1.31 dom-ts-4 338: this.fixedAttributeValues = [false, true, false, true, true , false, false, true ];
1.18 dom-ts-4 339: this.configurableAttributeNames = [ ];
340: this.configurableAttributeValues = [ ];
1.34 dom-ts-4 341: this.initializationError = null;
342: this.initializationFatalError = null;
343: this.skipIncompatibleTests = false;
1.17 dom-ts-4 344: }
1.12 dom-ts-4 345:
1.18 dom-ts-4 346: IFrameBuilder.prototype.hasFeature = function(feature, version) {
347: return document.implementation.hasFeature(feature, version);
348: }
349:
1.23 dom-ts-4 350: IFrameBuilder.prototype.getImplementation = function() {
351: return document.implementation;
352: }
353:
1.31 dom-ts-4 354: IFrameBuilder.prototype.setContentType = function(contentType) {
355: this.contentType = contentType;
356: if (contentType == "text/html") {
1.34 dom-ts-4 357: this.fixedAttributeValues[6] = false;
1.31 dom-ts-4 358: } else {
1.34 dom-ts-4 359: this.fixedAttributeValues[6] = true;
1.31 dom-ts-4 360: }
361: }
362:
363:
1.18 dom-ts-4 364:
1.17 dom-ts-4 365: IFrameBuilder.prototype.preload = function(frame, varname, url) {
1.34 dom-ts-4 366: if (this.contentType == "text/html" || this.contentType == "application/xhtml+xml") {
367: if (url.substring(0,5) == "staff" || url == "nodtdstaff" || url == "datatype_normalization") {
1.26 dom-ts-4 368: throw "Tests using staff or nodtdstaff are not supported by HTML processors";
369: }
1.18 dom-ts-4 370: }
1.26 dom-ts-4 371: var iframe = document.createElement("iframe");
372: var srcname = url + getSuffix(this.contentType);
373: iframe.setAttribute("name", srcname);
374: iframe.setAttribute("src", fileBase + srcname);
1.33 dom-ts-4 375: jsUnitSetOnLoad(iframe, loadComplete);
1.26 dom-ts-4 376: document.getElementsByTagName("body").item(0).appendChild(iframe);
377: return 0;
1.17 dom-ts-4 378: }
1.9 dom-ts-4 379:
1.17 dom-ts-4 380: IFrameBuilder.prototype.load = function(frame, varname, url) {
1.26 dom-ts-4 381: if (this.contentType == "text/html") {
382: return frame.document;
383: }
384: var name = url + getSuffix(this.contentType);
385: var iframes = document.getElementsByTagName("iframe");
386: for(var i = 0; i < iframes.length; i++) {
387: if (iframes.item(i).getAttribute("name") == name) {
1.33 dom-ts-4 388: var item = iframes.item(i);
389: if (typeof(item.contentDocument) != 'undefined') {
390: return item.contentDocument;
391: }
392: if (typeof(item.document) != 'undefined') {
393: return item.document;
394: }
395: return null;
1.26 dom-ts-4 396: }
397: }
398: return null;
1.17 dom-ts-4 399: }
1.9 dom-ts-4 400:
1.17 dom-ts-4 401: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
1.18 dom-ts-4 402: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
403: if (this.fixedAttributeNames[i] == attr) {
404: return this.fixedAttributeValues[i];
1.15 dom-ts-4 405: }
1.9 dom-ts-4 406: }
1.18 dom-ts-4 407: throw "Unrecognized implementation attribute: " + attr;
1.17 dom-ts-4 408: }
1.9 dom-ts-4 409:
1.5 dom-ts-4 410:
1.1 dom-ts-4 411:
1.18 dom-ts-4 412: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
413: var supported = this.getImplementationAttribute(attribute);
414: if (supported != value) {
1.34 dom-ts-4 415: this.initializationError = "IFrame loader does not support " + attribute + "=" + value;
1.18 dom-ts-4 416: }
417: }
418:
419:
1.34 dom-ts-4 420: IFrameBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
421: var supported = this.getImplementationAttribute(attribute);
422: return (supported == value);
423: }
424:
1.22 dom-ts-4 425:
426:
1.20 dom-ts-4 427: function SVGPluginBuilder() {
428: this.contentType = "image/svg+xml";
429: this.supportedContentTypes = [ "image/svg+xml" ];
430:
431: this.supportsAsyncChange = false;
432: this.async = true;
433: this.fixedAttributeNames = [
434: "validating", "expandEntityReferences", "coalescing",
1.31 dom-ts-4 435: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments"];
1.20 dom-ts-4 436:
1.34 dom-ts-4 437: this.fixedAttributeValues = [false, true, false, true, true , false, true, false ];
1.20 dom-ts-4 438: this.configurableAttributeNames = [ ];
439: this.configurableAttributeValues = [ ];
1.34 dom-ts-4 440: this.initializationError = null;
441: this.initializationFatalError = null;
442: this.skipIncompatibleTests = false;
1.20 dom-ts-4 443: }
444:
445: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
446: if (feature == "XML") {
447: if (version == null || version == "1.0" || version == "2.0") {
448: return true;
449: }
450: }
1.33 dom-ts-4 451: return false;
1.20 dom-ts-4 452: }
453:
1.31 dom-ts-4 454: SVGPluginBuilder.prototype.setContentType = function(contentType) {
455: this.contentType = contentType;
456: }
457:
1.23 dom-ts-4 458: SVGPluginBuilder.prototype.getImplementation = function() {
459: var embed = document.createElement("embed");
460: embed.src = fileBase + url + getSuffix(this.contentType);
461: embed.height = 100;
462: embed.width = 100;
463: embed.type = "image/svg+xml";
464: embed.id = varname;
465: var child = document.documentElement.firstChild;
466: while(child != null) {
467: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
468: child.appendChild(embed);
469: return child.getSVGDocument.implementation;
470: }
471: child = child.nextSibling;
472: }
473: return null;
474: }
475:
1.20 dom-ts-4 476: var svgloadcount = 0;
477: function SVGPluginBuilder_pollreadystate() {
478: var newCount = 0;
479: var child = document.documentElement.firstChild;
480: while(child != null) {
481: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
482: var grand = child.firstChild;
483: while (grand != null) {
484: if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
485: newCount++;
486: }
487: grand = grand.nextSibling;
488: }
489: break;
490: }
491: child = child.nextSibling;
492: }
493: if (newCount > svgloadcount) {
494: svgloadcount++;
495: loadComplete();
496: if (setUpPageStatus == 'complete') {
497: return;
498: }
499: }
500: setTimeout(SVGPluginBuilder_pollreadystate, 100);
501: }
502:
503: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
504: var embed = document.createElement("embed");
505: embed.src = fileBase + url + getSuffix(this.contentType);
506: embed.height = 100;
507: embed.width = 100;
508: embed.type = "image/svg+xml";
509: embed.id = varname;
510: var child = document.documentElement.firstChild;
511: while(child != null) {
512: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
513: child.appendChild(embed);
514: break;
515: }
516: child = child.nextSibling;
517: }
518: //
519: // if unable to monitor ready state change then
520: // check if load is complete every in 0.1 second
521: setTimeout(SVGPluginBuilder_pollreadystate , 100);
522: return 0;
523: }
524:
525: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
526: var child = document.documentElement.firstChild;
527: while(child != null) {
528: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
529: var grand = child.firstChild;
530: while (grand != null) {
531: if (grand.id == varname) {
532: return grand.getSVGDocument();
533: }
534: grand = grand.nextSibling;
535: }
536: }
537: child = child.nextSibling;
538: }
539: return null;
540: }
541:
542: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
543: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
544: if (this.fixedAttributeNames[i] == attr) {
545: return this.fixedAttributeValues[i];
546: }
547: }
548: throw "Unrecognized implementation attribute: " + attr;
549: }
550:
551:
552: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
553: var supported = this.getImplementationAttribute(attribute);
554: if (supported != value) {
1.34 dom-ts-4 555: this.initializationError = "SVG Plugin loader does not support " + attribute + "=" + value;
1.20 dom-ts-4 556: }
557: }
558:
1.34 dom-ts-4 559: SVGPluginBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
560: var supported = this.getImplementationAttribute(attribute);
561: return (supported == value);
562: }
1.20 dom-ts-4 563:
564:
1.22 dom-ts-4 565:
566:
1.18 dom-ts-4 567: function MSXMLBuilder(progID) {
568: this.progID = progID;
569: this.configurableAttributeNames = [
570: "validating", "ignoringElementContentWhitespace"];
571: this.configurableAttributeValues = [ false, false ];
572: this.fixedAttributeNames = [ "signed", "hasNullString",
1.31 dom-ts-4 573: "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
574: this.fixedAttributeValues = [ true, true, false, false, false, false ];
1.18 dom-ts-4 575:
576: this.contentType = "text/xml";
577: this.supportedContentTypes = [
578: "text/xml",
579: "image/svg+xml",
580: "application/xhtml+xml",
581: "text/mathml" ];
582:
583: this.async = false;
584: this.supportsAsyncChange = true;
585: this.parser = null;
1.34 dom-ts-4 586: this.initializationError = null;
587: this.initializationFatalError = null;
588: this.skipIncompatibleTests = false;
1.18 dom-ts-4 589: }
590:
591: MSXMLBuilder.prototype.createMSXML = function() {
1.19 dom-ts-4 592: var parser = new ActiveXObject(this.progID);
1.18 dom-ts-4 593: parser.async = this.async;
594: parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
595: parser.validateOnParse = this.configurableAttributeValues[0];
596: return parser;
597: }
1.31 dom-ts-4 598:
599: MSXMLBuilder.prototype.setContentType = function(contentType) {
600: this.contentType = contentType;
601: }
602:
1.18 dom-ts-4 603:
604: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
605: if (this.async) {
606: this.parser = this.createMSXML();
607: parser.async = true;
608: parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
609: parser.load(fileBase + url + getSuffix(this.contentType));
610: if (parser.readystate != 4) {
611: return 0;
612: }
613: }
614: return 1;
615: }
616:
617: MSXMLBuilder.prototype.load = function(frame, varname, url) {
1.19 dom-ts-4 618: var parser = this.createMSXML();
1.18 dom-ts-4 619: if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
620: throw parser.parseError.reason;
621: }
622: //
623: // if the first child of the document is a PI representing
624: // the XML Declaration, remove it from the tree.
625: //
626: // According to the DOM FAQ, this behavior is not wrong,
627: // but the tests are written assuming that it is not there.
628: //
629: var xmlDecl = parser.firstChild;
630: if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
631: parser.removeChild(xmlDecl);
632: }
633: return parser;
634: }
635:
636: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
637: var i;
638: for (i = 0; i < this.fixedAttributeNames.length; i++) {
639: if (this.fixedAttributeNames[i] == attr) {
640: return this.fixedAttributeValues[i];
641: }
642: }
643:
644: for (i = 0; i < this.configurableAttributeNames.length; i++) {
645: if (this.configurableAttributeNames[i] == attr) {
646: return this.configurableAttributeValues[i];
647: }
648: }
649:
650: throw "Unrecognized implementation attribute: " + attr;
651: }
652:
653:
654: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
655: var i;
656: for (i = 0; i < this.fixedAttributeNames.length; i++) {
1.19 dom-ts-4 657: if (this.fixedAttributeNames[i] == attribute) {
1.18 dom-ts-4 658: if (this.fixedAttributeValues[i] != value) {
1.34 dom-ts-4 659: this.initializationError = "MSXML does not support " + attribute + "=" + value;
1.18 dom-ts-4 660: }
661: return;
662: }
663: }
664: for (i = 0; i < this.configurableAttributeNames.length; i++) {
665: if (this.configurableAttributeNames[i] == attribute) {
666: this.configurableAttributeValues[i] = value;
667: return;
668: }
669: }
1.34 dom-ts-4 670: this.initializationError = "Unrecognized implementation attribute: " + attr;
1.18 dom-ts-4 671: }
672:
673:
1.34 dom-ts-4 674: MSXMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
675: var i;
676: for (i = 0; i < this.fixedAttributeNames.length; i++) {
677: if (this.fixedAttributeNames[i] == attribute) {
678: return (this.fixedAttributeValues[i] == value);
679: }
680: }
681: for (i = 0; i < this.configurableAttributeNames.length; i++) {
682: if (this.configurableAttributeNames[i] == attribute) {
683: return true;
684: }
685: }
686: return false;
687: }
688:
689:
1.23 dom-ts-4 690: MSXMLBuilder.prototype.getImplementation = function() {
691: var doc = this.CreateMSXML();
692: return doc.implementation;
693: }
1.18 dom-ts-4 694:
695: //
696: // Only used to select tests compatible with implementation
697: // not used on tests that actually test hasFeature()
698: //
699: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
700: //
701: // MSXML will take null, unfortunately
702: // there is no way to get it to there from script
703: // without a type mismatch error
704: if(version == null) {
705: switch(feature.toUpperCase()) {
706: case "XML":
707: case "CORE":
708: return true;
709:
710: case "HTML":
711: case "ORG.W3C.DOM":
712: return false;
713: }
714: if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
715: return true;
716: }
717: if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
718: return true;
719: }
720: if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
721: return true;
722: }
723: }
724: return this.getDOMImplementation().hasFeature(feature,version);
725: }
726:
727:
1.9 dom-ts-4 728:
1.17 dom-ts-4 729: function MozillaXMLBuilder() {
1.18 dom-ts-4 730: this.contentType = "text/xml";
731:
732: this.configurableAttributeNames = [ ];
733: this.configurableAttributeValues = [ ];
734: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
1.31 dom-ts-4 735: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
736: this.fixedAttributeValues = [ false, false, true, true, false, false, false, false ];
1.18 dom-ts-4 737:
738: this.contentType = "text/xml";
739: this.supportedContentTypes = [
740: "text/xml",
741: "image/svg+xml",
742: "application/xhtml+xml",
743: "text/mathml" ];
744:
745: this.async = true;
746: this.supportsAsyncChange = false;
747:
1.17 dom-ts-4 748: this.docs = new Array();
749: this.docnames = new Array();
1.34 dom-ts-4 750: this.initializationError = null;
751: this.initializationFatalError = null;
752: this.skipIncompatibleTests = false;
1.17 dom-ts-4 753: }
1.1 dom-ts-4 754:
1.23 dom-ts-4 755: MozillaXMLBuilder.prototype.getImplementation = function() {
756: return document.implementation;
757: }
758:
1.31 dom-ts-4 759: MozillaXMLBuilder.prototype.setContentType = function(contentType) {
760: this.contentType = contentType;
761: }
762:
763:
1.23 dom-ts-4 764:
1.17 dom-ts-4 765: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
766: var domimpl = document.implementation;
767: var doc = domimpl.createDocument("", "temp", null);
768: doc.addEventListener("load", loadComplete, false);
1.18 dom-ts-4 769: doc.load(fileBase + url + getSuffix(this.contentType));
1.17 dom-ts-4 770: this.docs[this.docs.length] = doc;
771: this.docnames[this.docnames.length] = varname;
772: return 0;
773: }
1.1 dom-ts-4 774:
1.17 dom-ts-4 775: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
776: for(i = 0; i < this.docnames.length; i++) {
777: if (this.docnames[i] == varname) {
778: return this.docs[i];
1.9 dom-ts-4 779: }
780: }
1.17 dom-ts-4 781: return null;
782: }
1.1 dom-ts-4 783:
1.9 dom-ts-4 784:
1.17 dom-ts-4 785: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
1.22 dom-ts-4 786: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
787: if (this.fixedAttributeNames[i] == attr) {
788: return this.fixedAttributeValues[i];
789: }
790: }
1.17 dom-ts-4 791: return false;
792: }
1.1 dom-ts-4 793:
794:
1.33 dom-ts-4 795: MozillaXMLBuilder.prototype.hasFeature = function(feature, version)
796: {
797: return this.getImplementation().hasFeature(feature, version);
798: }
799:
800: MozillaXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
801: var supported = this.getImplementationAttribute(attribute);
802: if (supported != value) {
1.34 dom-ts-4 803: this.initializationError = "Mozilla XML loader does not support " + attribute + "=" + value;
1.33 dom-ts-4 804: }
805: }
1.22 dom-ts-4 806:
1.34 dom-ts-4 807:
808: MozillaXMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
809: var supported = this.getImplementationAttribute(attribute);
810: return (supported == value);
811: }
812:
1.22 dom-ts-4 813: function DOM3LSBuilder() {
814: this.contentType = "text/xml";
815:
1.34 dom-ts-4 816: this.fixedAttributeNames = [ signed, "hasNullString" ];
817: this.fixedAttributeValues = [ true, true ];
818: this.configurableAttributeNames = [ "validating", "ignoringElementContentWhitespace",
819: "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
820: this.configurableAttributeValues = [ false, false, true, true, false, false, true, false ];
821: this.domConfigNames = [ "validate", "element-content-whitespace",
822: "entities", "cdata-sections", "namespaces", "comments" ];
823: this.domConfigSense = [ true, false, false, false, true, false ];
1.22 dom-ts-4 824:
825: this.contentType = "text/xml";
826: this.supportedContentTypes = [
827: "text/xml",
828: "image/svg+xml",
829: "application/xhtml+xml",
830: "text/mathml" ];
831:
1.34 dom-ts-4 832: this.async = false;
1.22 dom-ts-4 833: this.supportsAsyncChange = true;
834:
835: this.docs = new Array();
836: this.docnames = new Array();
1.34 dom-ts-4 837: this.lsparser = null;
838: this.initializationError = null;
839: this.initializationFatalError = null;
840: this.skipIncompatibleTests = false;
1.22 dom-ts-4 841: }
842:
1.23 dom-ts-4 843: DOM3LSBuilder.prototype.getImplementation = function() {
844: return document.implementation;
845: }
846:
847:
1.31 dom-ts-4 848: DOM3LSBuilder.prototype.setContentType = function(contentType) {
849: this.contentType = contentType;
850: }
851:
1.22 dom-ts-4 852: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
1.34 dom-ts-4 853: if (!this.async) {
854: return 1;
855: }
856: var domimpl = document.implementation;
857: this.lsparser = domimpl.createLSParser(2, null);
858: this.lsparser.addEventListener("load", loadComplete, false);
859: var uri = fileBase + url + getSuffix(this.contentType);
860: var doc = this.lsparser.parseURI(uri);
861: this.docs[this.docs.length] = doc;
862: this.docnames[this.docnames.length] = varname;
863: return 0;
1.22 dom-ts-4 864: }
865:
866: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
867: if (this.async) {
868: for(i = 0; i < this.docnames.length; i++) {
869: if (this.docnames[i] == varname) {
870: return this.docs[i];
871: }
872: }
873: return null;
874: }
1.34 dom-ts-4 875: this.lsparser = document.implementation.createLSParser(1, null);
1.22 dom-ts-4 876: var uri = fileBase + url + getSuffix(this.contentType);
1.34 dom-ts-4 877: return this.lsparser.parseURI(uri);
1.22 dom-ts-4 878: }
879:
880:
881: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
1.34 dom-ts-4 882: var i;
883: for (i = 0; i < this.fixedAttributeNames.length; i++) {
884: if (this.fixedAttributeNames[i] == attr) {
885: return this.fixedAttributeValues[i];
886: }
887: }
888: for (i = 0; i < this.configurableAttributeNames.length; i++) {
889: if (this.configurableAttributeNames[i] == attr) {
890: if(this.lsparser.domConfig.getParameter(this.domConfigNames[i])) {
891: return this.domConfigSense[i];
892: } else {
893: return !this.domConfigSense[i];
894: }
1.22 dom-ts-4 895: }
896: }
1.34 dom-ts-4 897: throw "unrecognized implementation attribute " + att;
1.22 dom-ts-4 898: }
899:
1.28 dom-ts-4 900: DOM3LSBuilder.prototype.hasFeature = function(feature, version) {
901: return document.implementation.hasFeature(feature, version);
902: }
903:
904:
1.34 dom-ts-4 905:
1.18 dom-ts-4 906: function createBuilder(implementation) {
1.34 dom-ts-4 907: if (implementation == null) {
908: return new IFrameBuilder();
909: }
1.18 dom-ts-4 910: switch(implementation) {
911: case "msxml3":
1.27 dom-ts-4 912: return new MSXMLBuilder("Msxml2.DOMDocument.3.0");
1.18 dom-ts-4 913:
914: case "msxml4":
915: return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
916:
1.33 dom-ts-4 917: case "mozillaXML":
1.18 dom-ts-4 918: return new MozillaXMLBuilder();
919:
1.20 dom-ts-4 920: case "svgplugin":
921: return new SVGPluginBuilder();
1.18 dom-ts-4 922:
923: case "dom3ls":
1.22 dom-ts-4 924: return new DOM3LSBuilder();
1.33 dom-ts-4 925:
926: case "iframe":
927: return new IFrameBuilder();
1.34 dom-ts-4 928:
929: default:
930: alert ("unrecognized implementation " + implementation);
1.18 dom-ts-4 931: }
1.34 dom-ts-4 932: return new IFrameBuilder();
1.18 dom-ts-4 933: }
934:
1.30 dom-ts-4 935: function checkFeature(feature, version)
936: {
937: if (!builder.hasFeature(feature, version))
938: {
1.34 dom-ts-4 939: //
940: // don't throw exception so that users can select to ignore the precondition
941: //
942: builder.initializationError = "builder does not support feature " + feature + " version " + version;
1.30 dom-ts-4 943: }
944: }
945:
1.34 dom-ts-4 946: function createConfiguredBuilder() {
947: var builder = null;
948: var contentType = null;
949: var i;
950: var contentTypeSet = false;
951: var parm = null;
952: if (top && typeof(top.jsUnitParmHash) != 'undefined') {
953: builder = createBuilder(top.jsUnitGetParm('implementation'));
954:
955: parm = top.jsUnitGetParm("skipincompatibletests");
956: if (parm) {
957: if (parm == 'true') {
958: builder.skipIncompatibleTests = true;
959: } else {
960: builder.skipIncompatibleTests = false;
961: }
962: }
963:
964: if (top.jsUnitGetParm('asynchronous') == 'true' && builder.supportAsync) {
965: builder.async = true;
966: }
967: if (top.jsUnitGetParm('expandentityreferences')) {
968: if (top.jsUnitGetParm('expandEntityReferences') == 'true') {
969: builder.setImplementationAttribute('expandEntityReferences', true);
970: } else {
971: builder.setImplementationAttribute('expandEntityReferences', false);
972: }
973: }
974: if (top.jsUnitGetParm('ignoringelementcontentwhitespace')) {
975: if (top.jsUnitGetParm('ignoringElementContentWhitespace') == 'true') {
976: builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
977: } else {
978: builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
1.19 dom-ts-4 979: }
980: }
1.34 dom-ts-4 981: if (top.jsUnitGetParm('validating')) {
982: if (top.jsUnitGetParm('validating') == 'true') {
983: builder.setImplementationAttribute('validating', true);
984: } else {
985: builder.setImplementationAttribute('validating', false);
986: }
987: }
988: if (top.jsUnitGetParm('coalescing')) {
989: if (top.jsUnitGetParm('coalescing') == 'true') {
990: builder.setImplementationAttribute('coalescing', true);
991: } else {
992: builder.setImplementationAttribute('coalescing', false);
993: }
994: }
995: if (top.jsUnitGetParm('namespaceaware')) {
996: if (top.jsUnitGetParm('namespaceaware') == 'true') {
997: builder.setImplementationAttribute('namespaceAware', true);
998: } else {
999: builder.setImplementationAttribute('namespaceAware', false);
1000: }
1001: }
1002: contentType = top.jsUnitGetParm('contenttype');
1003: if (contentType != null) {
1004: contentTypeSet = false;
1005: for (i = 0; i < builder.supportedContentTypes.length; i++) {
1006: if (builder.supportedContentTypes[i] == contentType) {
1007: builder.setContentType(contentType);
1008: contentTypeSet = true;
1009: break;
1010: }
1011: }
1012: if (!contentTypeSet) {
1013: this.exception = "Builder does not support content type " + contentType;
1014: }
1015: }
1016: if (top.jsUnitGetParm('ignoringcomments')) {
1017: if (top.jsUnitGetParm('ignoringcomments') == 'true') {
1018: builder.setImplementationAttribute('ignoringComments', true);
1019: } else {
1020: builder.setImplementationAttribute('ignoringComments', false);
1021: }
1022: }
1023: } else {
1024: builder = new IFrameBuilder();
1025: }
1026: return builder;
1.18 dom-ts-4 1027: }
1.16 dom-ts-4 1028:
1029:
1.17 dom-ts-4 1030: function preload(frame, varname, url) {
1031: return builder.preload(frame, varname, url);
1.15 dom-ts-4 1032: }
1033:
1.17 dom-ts-4 1034: function load(frame, varname, url) {
1035: return builder.load(frame, varname, url);
1.16 dom-ts-4 1036: }
1.15 dom-ts-4 1037:
1.17 dom-ts-4 1038: function getImplementationAttribute(attr) {
1039: return builder.getImplementationAttribute(attr);
1.15 dom-ts-4 1040: }
1.16 dom-ts-4 1041:
1.9 dom-ts-4 1042:
1.18 dom-ts-4 1043: function setImplementationAttribute(attribute, value) {
1044: builder.setImplementationAttribute(attribute, value);
1045: }
1046:
1.21 dom-ts-4 1047: function createXPathEvaluator(doc) {
1048: try {
1049: return doc.getFeature("XPath", null);
1050: }
1051: catch(ex) {
1052: }
1053: return doc;
1054: }
1055:
1.10 dom-ts-4 1056:
1.18 dom-ts-4 1057: function MSXMLBuilder_onreadystatechange() {
1058: if (builder.parser.readyState == 4) {
1059: loadComplete();
1060: }
1.19 dom-ts-4 1061: }
1062:
1063:
1064: var fileBase = location.href;
1065: if (fileBase.indexOf('?') != -1) {
1066: fileBase = fileBase.substring(0, fileBase.indexOf('?'));
1067: }
1.20 dom-ts-4 1068: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
1069:
1.23 dom-ts-4 1070: function getImplementation() {
1071: return builder.getImplementation();
1072: }
1.19 dom-ts-4 1073:
Webmaster