Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.29
1.1 dom-ts-4 1: /*
1.22 dom-ts-4 2: Copyright (c) 2001-2003 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.9 dom-ts-4 18:
1.13 dom-ts-4 19: function assertEqualsCollection(descr, expected, actual) {
1.3 dom-ts-4 20: //
21: // if they aren't the same size, they aren't equal
1.17 dom-ts-4 22: assertEquals(descr, expected.length, actual.length);
1.3 dom-ts-4 23: //
24: // if there length is the same, then every entry in the expected list
25: // must appear once and only once in the actual list
26: var expectedLen = expected.length;
27: var expectedValue;
28: var actualLen = actual.length;
29: var i;
30: var j;
31: var matches;
32: for(i = 0; i < expectedLen; i++) {
33: matches = 0;
34: expectedValue = expected[i];
35: for(j = 0; j < actualLen; j++) {
36: if(expectedValue == actual[j]) {
37: matches++;
38: }
39: }
40: if(matches == 0) {
1.17 dom-ts-4 41: assert(descr + ": No match found for " + expectedValue,false);
1.3 dom-ts-4 42: }
43: if(matches > 1) {
1.17 dom-ts-4 44: assert(descr + ": Multiple matches found for " + expectedValue, false);
1.3 dom-ts-4 45: }
46: }
47: }
48:
49:
1.13 dom-ts-4 50: function assertEqualsList(descr, expected, actual) {
1.27 dom-ts-4 51: var minLength = expected.length;
52: if (actual.length < minLength) {
53: minLength = actual.length;
54: }
1.3 dom-ts-4 55: //
1.27 dom-ts-4 56: for(var i = 0; i < minLength; i++) {
1.3 dom-ts-4 57: if(expected[i] != actual[i]) {
1.17 dom-ts-4 58: assertEquals(descr, expected[i], actual[i]);
1.3 dom-ts-4 59: }
60: }
1.27 dom-ts-4 61: //
62: // if they aren't the same size, they aren't equal
63: assertEquals(descr, expected.length, actual.length);
1.3 dom-ts-4 64: }
65:
66: function assertInstanceOf(descr, type, obj) {
67: if(type == "Attr") {
1.17 dom-ts-4 68: assertEquals(descr,2,obj.nodeType);
1.3 dom-ts-4 69: var specd = obj.specified;
70: }
71: }
72:
73: function assertSame(descr, expected, actual) {
74: if(expected != actual) {
1.17 dom-ts-4 75: assertEquals(descr, expected.nodeType, actual.nodeType);
76: assertEquals(descr, expected.nodeValue, actual.nodeValue);
1.3 dom-ts-4 77: }
78: }
79:
1.16 dom-ts-4 80: function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
1.7 dom-ts-4 81: //
82: // URI must be non-null
1.17 dom-ts-4 83: assertNotNull(assertID, actual);
1.7 dom-ts-4 84:
85: var uri = actual;
86:
87: var lastPound = actual.lastIndexOf("#");
88: var actualFragment = "";
89: if(lastPound != -1) {
90: //
91: // substring before pound
92: //
93: uri = actual.substring(0,lastPound);
94: actualFragment = actual.substring(lastPound+1);
95: }
1.17 dom-ts-4 96: if(fragment != null) assertEquals(assertID,fragment, actualFragment);
1.7 dom-ts-4 97:
98: var lastQuestion = uri.lastIndexOf("?");
99: var actualQuery = "";
100: if(lastQuestion != -1) {
101: //
102: // substring before pound
103: //
104: uri = actual.substring(0,lastQuestion);
105: actualQuery = actual.substring(lastQuestion+1);
106: }
1.17 dom-ts-4 107: if(query != null) assertEquals(assertID, query, actualQuery);
1.7 dom-ts-4 108:
109: var firstColon = uri.indexOf(":");
110: var firstSlash = uri.indexOf("/");
111: var actualPath = uri;
112: var actualScheme = "";
113: if(firstColon != -1 && firstColon < firstSlash) {
114: actualScheme = uri.substring(0,firstColon);
115: actualPath = uri.substring(firstColon + 1);
116: }
117:
118: if(scheme != null) {
1.17 dom-ts-4 119: assertEquals(assertID, scheme, actualScheme);
1.7 dom-ts-4 120: }
121:
122: if(path != null) {
1.17 dom-ts-4 123: assertEquals(assertID, path, actualPath);
1.7 dom-ts-4 124: }
125:
126: if(host != null) {
127: var actualHost = "";
1.16 dom-ts-4 128: if(actualPath.substring(0,2) == "//") {
1.8 dom-ts-4 129: var termSlash = actualPath.substring(2).indexOf("/") + 2;
1.7 dom-ts-4 130: actualHost = actualPath.substring(0,termSlash);
131: }
1.17 dom-ts-4 132: assertEquals(assertID, host, actualHost);
1.7 dom-ts-4 133: }
134:
1.16 dom-ts-4 135: if(file != null || name != null) {
1.7 dom-ts-4 136: var actualFile = actualPath;
137: var finalSlash = actualPath.lastIndexOf("/");
138: if(finalSlash != -1) {
139: actualFile = actualPath.substring(finalSlash+1);
140: }
1.16 dom-ts-4 141: if (file != null) {
1.17 dom-ts-4 142: assertEquals(assertID, file, actualFile);
1.16 dom-ts-4 143: }
144: if (name != null) {
145: var actualName = actualFile;
146: var finalDot = actualFile.lastIndexOf(".");
147: if (finalDot != -1) {
148: actualName = actualName.substring(0, finalDot);
149: }
1.17 dom-ts-4 150: assertEquals(assertID, name, actualName);
1.16 dom-ts-4 151: }
1.7 dom-ts-4 152: }
153:
154: if(isAbsolute != null) {
1.17 dom-ts-4 155: assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
1.13 dom-ts-4 156: }
157: }
158:
1.25 dom-ts-4 159: function toUpperCaseArray(expected) {
1.17 dom-ts-4 160: var upperCased = new Array(expected.length);
161: for(var i = 0; i < expected.length; i++) {
162: if (expected[i].substring(0,1) != "#") {
163: upperCased[i] = expected[i].toUpperCase();
1.15 dom-ts-4 164: } else {
1.17 dom-ts-4 165: upperCased[i] = expected[i];
1.12 dom-ts-4 166: }
1.15 dom-ts-4 167: }
1.17 dom-ts-4 168: return upperCased;
169: }
1.12 dom-ts-4 170:
1.29 ! dom-ts-4 171: function toLowerArray(expected) {
! 172: var lowerCased = new Array(expected.length);
! 173: for(var i = 0; i < expected.length; i++) {
! 174: if (expected[i].substring(0,1) != "#") {
! 175: lowerCased[i] = expected[i].toLowerCase();
! 176: } else {
! 177: lowerCased[i] = expected[i];
! 178: }
! 179: }
! 180: return lowerCased;
! 181: }
! 182:
! 183: // size() used by assertSize element
! 184: function size(collection)
! 185: {
! 186: return collection.length;
! 187: }
! 188:
1.18 dom-ts-4 189: function getSuffix(contentType) {
190: switch(contentType) {
191: case "text/html":
192: return ".html";
193:
194: case "text/xml":
195: return ".xml";
196:
197: case "application/xhtml+xml":
198: return ".xhtml";
199:
200: case "image/svg+xml":
201: return ".svg";
202:
203: case "text/mathml":
204: return ".mml";
205: }
206: return ".html";
207: }
208:
1.17 dom-ts-4 209: function IFrameBuilder() {
1.18 dom-ts-4 210: this.contentType = "text/html";
1.26 dom-ts-4 211: this.supportedContentTypes = [ "text/html",
212: "text/xml",
213: "image/svg+xml",
214: "application/xhtml+xml",
215: "text/mathml" ];
1.18 dom-ts-4 216:
217: this.supportsAsyncChange = false;
1.26 dom-ts-4 218: this.async = true;
1.18 dom-ts-4 219: this.fixedAttributeNames = [
220: "validating", "expandEntityReferences", "coalescing",
221: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware" ];
222:
223: this.fixedAttributeValues = [false, true, false, true, true , false, false ];
224: this.configurableAttributeNames = [ ];
225: this.configurableAttributeValues = [ ];
1.19 dom-ts-4 226: this.exception = null;
1.17 dom-ts-4 227: }
1.12 dom-ts-4 228:
1.18 dom-ts-4 229: IFrameBuilder.prototype.hasFeature = function(feature, version) {
230: return document.implementation.hasFeature(feature, version);
231: }
232:
1.23 dom-ts-4 233: IFrameBuilder.prototype.getImplementation = function() {
234: return document.implementation;
235: }
236:
1.18 dom-ts-4 237:
1.17 dom-ts-4 238: IFrameBuilder.prototype.preload = function(frame, varname, url) {
1.26 dom-ts-4 239: if (this.contentType == "text/html") {
240: if (url == "staff" || url == "nodtdstaff") {
241: throw "Tests using staff or nodtdstaff are not supported by HTML processors";
242: }
243: return 1;
1.18 dom-ts-4 244: }
1.26 dom-ts-4 245: var iframe = document.createElement("iframe");
246: var srcname = url + getSuffix(this.contentType);
247: iframe.setAttribute("name", srcname);
248: iframe.setAttribute("src", fileBase + srcname);
249: iframe.addEventListener("load", loadComplete, false);
250: document.getElementsByTagName("body").item(0).appendChild(iframe);
251: return 0;
1.17 dom-ts-4 252: }
1.9 dom-ts-4 253:
1.17 dom-ts-4 254: IFrameBuilder.prototype.load = function(frame, varname, url) {
1.26 dom-ts-4 255: if (this.contentType == "text/html") {
256: return frame.document;
257: }
258: var name = url + getSuffix(this.contentType);
259: var iframes = document.getElementsByTagName("iframe");
260: for(var i = 0; i < iframes.length; i++) {
261: if (iframes.item(i).getAttribute("name") == name) {
262: return iframes.item(i).contentDocument;
263: }
264: }
265: return null;
1.17 dom-ts-4 266: }
1.9 dom-ts-4 267:
1.17 dom-ts-4 268: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
1.18 dom-ts-4 269: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
270: if (this.fixedAttributeNames[i] == attr) {
271: return this.fixedAttributeValues[i];
1.15 dom-ts-4 272: }
1.9 dom-ts-4 273: }
1.18 dom-ts-4 274: throw "Unrecognized implementation attribute: " + attr;
1.17 dom-ts-4 275: }
1.9 dom-ts-4 276:
1.5 dom-ts-4 277:
1.17 dom-ts-4 278: IFrameBuilder.prototype.toAutoCase = function(s) {
1.20 dom-ts-4 279: if (this.contentType == "text/html") {
280: return s.toUpperCase();
281: }
282: return s;
1.17 dom-ts-4 283: }
1.5 dom-ts-4 284:
1.17 dom-ts-4 285: IFrameBuilder.prototype.toAutoCaseArray = function(s) {
1.20 dom-ts-4 286: if (this.contentType == "text/html") {
287: return toUpperCaseArray(s);
288: }
289: return s;
1.17 dom-ts-4 290: }
1.1 dom-ts-4 291:
1.18 dom-ts-4 292: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
293: var supported = this.getImplementationAttribute(attribute);
294: if (supported != value) {
295: throw "IFrame loader does not support " + attribute + "=" + value;
296: }
297: }
298:
299:
1.22 dom-ts-4 300:
301:
1.20 dom-ts-4 302: function SVGPluginBuilder() {
303: this.contentType = "image/svg+xml";
304: this.supportedContentTypes = [ "image/svg+xml" ];
305:
306: this.supportsAsyncChange = false;
307: this.async = true;
308: this.fixedAttributeNames = [
309: "validating", "expandEntityReferences", "coalescing",
310: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware" ];
311:
312: this.fixedAttributeValues = [false, true, false, true, true , false, false ];
313: this.configurableAttributeNames = [ ];
314: this.configurableAttributeValues = [ ];
315: this.exception = null;
316: }
317:
318: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
319: if (feature == "XML") {
320: if (version == null || version == "1.0" || version == "2.0") {
321: return true;
322: }
323: }
324: }
325:
1.23 dom-ts-4 326: SVGPluginBuilder.prototype.getImplementation = function() {
327: var embed = document.createElement("embed");
328: embed.src = fileBase + url + getSuffix(this.contentType);
329: embed.height = 100;
330: embed.width = 100;
331: embed.type = "image/svg+xml";
332: embed.id = varname;
333: var child = document.documentElement.firstChild;
334: while(child != null) {
335: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
336: child.appendChild(embed);
337: return child.getSVGDocument.implementation;
338: }
339: child = child.nextSibling;
340: }
341: return null;
342: }
343:
1.20 dom-ts-4 344: var svgloadcount = 0;
345: function SVGPluginBuilder_pollreadystate() {
346: var newCount = 0;
347: var child = document.documentElement.firstChild;
348: while(child != null) {
349: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
350: var grand = child.firstChild;
351: while (grand != null) {
352: if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
353: newCount++;
354: }
355: grand = grand.nextSibling;
356: }
357: break;
358: }
359: child = child.nextSibling;
360: }
361: if (newCount > svgloadcount) {
362: svgloadcount++;
363: loadComplete();
364: if (setUpPageStatus == 'complete') {
365: return;
366: }
367: }
368: setTimeout(SVGPluginBuilder_pollreadystate, 100);
369: }
370:
371: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
372: var embed = document.createElement("embed");
373: embed.src = fileBase + url + getSuffix(this.contentType);
374: embed.height = 100;
375: embed.width = 100;
376: embed.type = "image/svg+xml";
377: embed.id = varname;
378: var child = document.documentElement.firstChild;
379: while(child != null) {
380: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
381: child.appendChild(embed);
382: break;
383: }
384: child = child.nextSibling;
385: }
386: //
387: // if unable to monitor ready state change then
388: // check if load is complete every in 0.1 second
389: setTimeout(SVGPluginBuilder_pollreadystate , 100);
390: return 0;
391: }
392:
393: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
394: var child = document.documentElement.firstChild;
395: while(child != null) {
396: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
397: var grand = child.firstChild;
398: while (grand != null) {
399: if (grand.id == varname) {
400: return grand.getSVGDocument();
401: }
402: grand = grand.nextSibling;
403: }
404: }
405: child = child.nextSibling;
406: }
407: return null;
408: }
409:
410: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
411: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
412: if (this.fixedAttributeNames[i] == attr) {
413: return this.fixedAttributeValues[i];
414: }
415: }
416: throw "Unrecognized implementation attribute: " + attr;
417: }
418:
419:
420: SVGPluginBuilder.prototype.toAutoCase = function(s) {
421: return s;
422: }
423:
424: SVGPluginBuilder.prototype.toAutoCaseArray = function(s) {
425: return s;
426: }
427:
428: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
429: var supported = this.getImplementationAttribute(attribute);
430: if (supported != value) {
431: throw "SVG Plugin loader does not support " + attribute + "=" + value;
432: }
433: }
434:
435:
436:
1.22 dom-ts-4 437:
438:
1.18 dom-ts-4 439: function MSXMLBuilder(progID) {
440: this.progID = progID;
441: this.configurableAttributeNames = [
442: "validating", "ignoringElementContentWhitespace"];
443: this.configurableAttributeValues = [ false, false ];
444: this.fixedAttributeNames = [ "signed", "hasNullString",
445: "expandEntityReferences", "coalescing", "namespaceAware" ];
446: this.fixedAttributeValues = [ true, true, false, false, false ];
447:
448: this.contentType = "text/xml";
449: this.supportedContentTypes = [
450: "text/xml",
451: "image/svg+xml",
452: "application/xhtml+xml",
453: "text/mathml" ];
454:
455: this.async = false;
456: this.supportsAsyncChange = true;
457: this.parser = null;
1.19 dom-ts-4 458: this.exception = null;
1.18 dom-ts-4 459: }
460:
461: MSXMLBuilder.prototype.createMSXML = function() {
1.19 dom-ts-4 462: var parser = new ActiveXObject(this.progID);
1.18 dom-ts-4 463: parser.async = this.async;
464: parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
465: parser.validateOnParse = this.configurableAttributeValues[0];
466: return parser;
467: }
468:
469: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
470: if (this.async) {
471: this.parser = this.createMSXML();
472: parser.async = true;
473: parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
474: parser.load(fileBase + url + getSuffix(this.contentType));
475: if (parser.readystate != 4) {
476: return 0;
477: }
478: }
479: return 1;
480: }
481:
482: MSXMLBuilder.prototype.load = function(frame, varname, url) {
1.19 dom-ts-4 483: var parser = this.createMSXML();
1.18 dom-ts-4 484: if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
485: throw parser.parseError.reason;
486: }
487: //
488: // if the first child of the document is a PI representing
489: // the XML Declaration, remove it from the tree.
490: //
491: // According to the DOM FAQ, this behavior is not wrong,
492: // but the tests are written assuming that it is not there.
493: //
494: var xmlDecl = parser.firstChild;
495: if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
496: parser.removeChild(xmlDecl);
497: }
498: return parser;
499: }
500:
501: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
502: var i;
503: for (i = 0; i < this.fixedAttributeNames.length; i++) {
504: if (this.fixedAttributeNames[i] == attr) {
505: return this.fixedAttributeValues[i];
506: }
507: }
508:
509: for (i = 0; i < this.configurableAttributeNames.length; i++) {
510: if (this.configurableAttributeNames[i] == attr) {
511: return this.configurableAttributeValues[i];
512: }
513: }
514:
515: throw "Unrecognized implementation attribute: " + attr;
516: }
517:
518:
519: MSXMLBuilder.prototype.toAutoCase = function(s) {
520: return s;
521: }
522:
523: MSXMLBuilder.prototype.toAutoCaseArray = function(s) {
524: return s;
525: }
526:
527: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
528: var i;
529: for (i = 0; i < this.fixedAttributeNames.length; i++) {
1.19 dom-ts-4 530: if (this.fixedAttributeNames[i] == attribute) {
1.18 dom-ts-4 531: if (this.fixedAttributeValues[i] != value) {
532: throw "MSXML does not support " + attribute + "=" + value;
533: }
534: return;
535: }
536: }
537: for (i = 0; i < this.configurableAttributeNames.length; i++) {
538: if (this.configurableAttributeNames[i] == attribute) {
539: this.configurableAttributeValues[i] = value;
540: return;
541: }
542: }
543: throw "Unrecognized implementation attribute: " + attr;
544: }
545:
546:
1.23 dom-ts-4 547: MSXMLBuilder.prototype.getImplementation = function() {
548: var doc = this.CreateMSXML();
549: return doc.implementation;
550: }
1.18 dom-ts-4 551:
552: //
553: // Only used to select tests compatible with implementation
554: // not used on tests that actually test hasFeature()
555: //
556: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
557: //
558: // MSXML will take null, unfortunately
559: // there is no way to get it to there from script
560: // without a type mismatch error
561: if(version == null) {
562: switch(feature.toUpperCase()) {
563: case "XML":
564: case "CORE":
565: return true;
566:
567: case "HTML":
568: case "ORG.W3C.DOM":
569: return false;
570: }
571: if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
572: return true;
573: }
574: if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
575: return true;
576: }
577: if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
578: return true;
579: }
580: }
581: return this.getDOMImplementation().hasFeature(feature,version);
582: }
583:
584:
1.9 dom-ts-4 585:
1.17 dom-ts-4 586: function MozillaXMLBuilder() {
1.18 dom-ts-4 587: this.contentType = "text/xml";
588:
589: this.configurableAttributeNames = [ ];
590: this.configurableAttributeValues = [ ];
591: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
592: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware" ];
593: this.fixedAttributeValues = [ false, false, true, true, false, false, false ];
594:
595: this.contentType = "text/xml";
596: this.supportedContentTypes = [
597: "text/xml",
598: "image/svg+xml",
599: "application/xhtml+xml",
600: "text/mathml" ];
601:
602: this.async = true;
603: this.supportsAsyncChange = false;
604:
1.17 dom-ts-4 605: this.docs = new Array();
606: this.docnames = new Array();
1.19 dom-ts-4 607: this.exception = null;
1.17 dom-ts-4 608: }
1.1 dom-ts-4 609:
1.23 dom-ts-4 610: MozillaXMLBuilder.prototype.getImplementation = function() {
611: return document.implementation;
612: }
613:
614:
1.17 dom-ts-4 615: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
616: var domimpl = document.implementation;
617: var doc = domimpl.createDocument("", "temp", null);
618: doc.addEventListener("load", loadComplete, false);
1.18 dom-ts-4 619: doc.load(fileBase + url + getSuffix(this.contentType));
1.17 dom-ts-4 620: this.docs[this.docs.length] = doc;
621: this.docnames[this.docnames.length] = varname;
622: return 0;
623: }
1.1 dom-ts-4 624:
1.17 dom-ts-4 625: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
626: for(i = 0; i < this.docnames.length; i++) {
627: if (this.docnames[i] == varname) {
628: return this.docs[i];
1.9 dom-ts-4 629: }
630: }
1.17 dom-ts-4 631: return null;
632: }
1.1 dom-ts-4 633:
1.9 dom-ts-4 634:
1.17 dom-ts-4 635: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
1.22 dom-ts-4 636: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
637: if (this.fixedAttributeNames[i] == attr) {
638: return this.fixedAttributeValues[i];
639: }
640: }
1.17 dom-ts-4 641: return false;
642: }
1.1 dom-ts-4 643:
644:
1.17 dom-ts-4 645: MozillaXMLBuilder.prototype.toAutoCase = function(s) {
646: return s;
647: }
1.15 dom-ts-4 648:
1.17 dom-ts-4 649: MozillaXMLBuilder.prototype.toAutoCaseArray = function(s) {
650: return s;
1.16 dom-ts-4 651: }
652:
1.22 dom-ts-4 653:
654: function DOM3LSBuilder() {
655: this.contentType = "text/xml";
656:
657: this.configurableAttributeNames = [ ];
658: this.configurableAttributeValues = [ ];
659: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
660: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware" ];
661: this.fixedAttributeValues = [ false, false, true, true, false, false, true ];
662:
663: this.contentType = "text/xml";
664: this.supportedContentTypes = [
665: "text/xml",
666: "image/svg+xml",
667: "application/xhtml+xml",
668: "text/mathml" ];
669:
670: this.async = true;
671: this.supportsAsyncChange = true;
672:
673: this.docs = new Array();
674: this.docnames = new Array();
675: this.exception = null;
676: }
677:
1.23 dom-ts-4 678: DOM3LSBuilder.prototype.getImplementation = function() {
679: return document.implementation;
680: }
681:
682:
1.22 dom-ts-4 683: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
684: if (this.async) {
685: var domimpl = document.implementation;
686: var dombuilder = domimpl.createDOMBuilder(2, null);
687: dombuilder.addEventListener("load", loadComplete, false);
688: var uri = fileBase + url + getSuffix(this.contentType);
689: var doc = dombuilder.parseURI(uri);
690: this.docs[this.docs.length] = doc;
691: this.docnames[this.docnames.length] = varname;
692: return 0;
693: }
694: return 1;
695: }
696:
697: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
698: if (this.async) {
699: for(i = 0; i < this.docnames.length; i++) {
700: if (this.docnames[i] == varname) {
701: return this.docs[i];
702: }
703: }
704: return null;
705: }
706: var dombuilder = document.implementation.createDOMBuilder(1, null);
707: var uri = fileBase + url + getSuffix(this.contentType);
708: return dombuilder.parseURI(uri);
709: }
710:
711:
712: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
713: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
714: if (this.fixedAttributeNames[i] == attr) {
715: return this.fixedAttributeValues[i];
716: }
717: }
718: }
719:
720:
721: DOM3LSBuilder.prototype.toAutoCase = function(s) {
722: return s;
723: }
724:
725: DOM3LSBuilder.prototype.toAutoCaseArray = function(s) {
726: return s;
727: }
728:
1.28 dom-ts-4 729: DOM3LSBuilder.prototype.hasFeature = function(feature, version) {
730: return document.implementation.hasFeature(feature, version);
731: }
732:
733:
1.18 dom-ts-4 734: function createBuilder(implementation) {
735: switch(implementation) {
736: case "msxml3":
1.27 dom-ts-4 737: return new MSXMLBuilder("Msxml2.DOMDocument.3.0");
1.18 dom-ts-4 738:
739: case "msxml4":
740: return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
741:
742: case "mozilla":
743: return new MozillaXMLBuilder();
744:
1.20 dom-ts-4 745: case "svgplugin":
746: return new SVGPluginBuilder();
1.18 dom-ts-4 747:
748: case "dom3ls":
1.22 dom-ts-4 749: return new DOM3LSBuilder();
1.18 dom-ts-4 750: }
751: return new IFrameBuilder();
752: }
753:
754: var builder = null;
755:
756: if (top && top.jsUnitParmHash)
757: {
758: builder = createBuilder(top.jsUnitParmHash.implementation);
1.19 dom-ts-4 759: try {
760: if (top.jsUnitParmHash.asynchronous == 'true' && builder.supportAsync) {
761: builder.async = true;
762: }
763: if (top.jsUnitParmHash.expandentityreferences) {
764: if (top.jsUnitParmHash.expandEntityReferences == 'true') {
765: builder.setImplementationAttribute('expandEntityReferences', true);
766: } else {
767: builder.setImplementationAttribute('expandEntityReferences', false);
768: }
769: }
770: if (top.jsUnitParmHash.ignoringelementcontentwhitespace) {
771: if (top.jsUnitParmHash.ignoringElementContentWhitespace == 'true') {
772: builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
773: } else {
774: builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
775: }
776: }
777: if (top.jsUnitParmHash.validating) {
778: if (top.jsUnitParmHash.validating == 'true') {
779: builder.setImplementationAttribute('validating', true);
780: } else {
781: builder.setImplementationAttribute('validating', false);
782: }
783: }
784: if (top.jsUnitParmHash.coalescing) {
785: if (top.jsUnitParmHash.coalescing == 'true') {
786: builder.setImplementationAttribute('coalescing', true);
787: } else {
788: builder.setImplementationAttribute('coalescing', false);
789: }
790: }
791: if (top.jsUnitParmHash.namespaceaware) {
792: if (top.jsUnitParmHash.namespaceaware == 'true') {
793: builder.setImplementationAttribute('namespaceAware', true);
794: } else {
795: builder.setImplementationAttribute('namespaceAware', false);
796: }
797: }
798: var contentType = top.jsUnitParmHash.contenttype;
799: if (contentType != null) {
800: var contentTypeSet = false;
801: for (var i = 0; i < builder.supportedContentTypes.length; i++) {
802: if (builder.supportedContentTypes[i] == contentType) {
803: builder.contentType = contentType;
804: contentTypeSet = true;
805: break;
806: }
807: }
808: if (!contentTypeSet) {
809: builder.exception = "Builder does not support content type " + contentType;
810: }
811: }
812: }
813: catch(ex) {
814: builder.exception = ex;
815: }
1.18 dom-ts-4 816: } else {
817: builder = new IFrameBuilder();
818: }
1.16 dom-ts-4 819:
820:
1.17 dom-ts-4 821: function preload(frame, varname, url) {
822: return builder.preload(frame, varname, url);
1.15 dom-ts-4 823: }
824:
1.17 dom-ts-4 825: function load(frame, varname, url) {
826: return builder.load(frame, varname, url);
1.16 dom-ts-4 827: }
1.15 dom-ts-4 828:
1.17 dom-ts-4 829: function getImplementationAttribute(attr) {
830: return builder.getImplementationAttribute(attr);
1.15 dom-ts-4 831: }
1.16 dom-ts-4 832:
1.9 dom-ts-4 833:
1.17 dom-ts-4 834: function toAutoCase(s) {
835: return builder.toAutoCase(s);
836: }
1.1 dom-ts-4 837:
1.17 dom-ts-4 838: function toAutoCaseArray(s) {
839: return builder.toAutoCaseArray(s);
840: }
1.10 dom-ts-4 841:
1.18 dom-ts-4 842: function setImplementationAttribute(attribute, value) {
843: builder.setImplementationAttribute(attribute, value);
844: }
845:
1.21 dom-ts-4 846: function createXPathEvaluator(doc) {
847: try {
848: return doc.getFeature("XPath", null);
849: }
850: catch(ex) {
851: }
852: return doc;
853: }
854:
1.10 dom-ts-4 855:
1.18 dom-ts-4 856: function MSXMLBuilder_onreadystatechange() {
857: if (builder.parser.readyState == 4) {
858: loadComplete();
859: }
1.19 dom-ts-4 860: }
861:
862:
863: var fileBase = location.href;
864: if (fileBase.indexOf('?') != -1) {
865: fileBase = fileBase.substring(0, fileBase.indexOf('?'));
866: }
1.20 dom-ts-4 867: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
868:
1.23 dom-ts-4 869: function getImplementation() {
870: return builder.getImplementation();
871: }
1.19 dom-ts-4 872:
Webmaster