Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.34
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.17 dom-ts-4 298: function IFrameBuilder() {
1.18 dom-ts-4 299: this.contentType = "text/html";
1.26 dom-ts-4 300: this.supportedContentTypes = [ "text/html",
301: "text/xml",
302: "image/svg+xml",
303: "application/xhtml+xml",
304: "text/mathml" ];
1.18 dom-ts-4 305:
306: this.supportsAsyncChange = false;
1.26 dom-ts-4 307: this.async = true;
1.18 dom-ts-4 308: this.fixedAttributeNames = [
309: "validating", "expandEntityReferences", "coalescing",
1.34 ! dom-ts-4 310: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments"];
1.18 dom-ts-4 311:
1.31 dom-ts-4 312: this.fixedAttributeValues = [false, true, false, true, true , false, false, true ];
1.18 dom-ts-4 313: this.configurableAttributeNames = [ ];
314: this.configurableAttributeValues = [ ];
1.34 ! dom-ts-4 315: this.initializationError = null;
! 316: this.initializationFatalError = null;
! 317: this.skipIncompatibleTests = false;
1.17 dom-ts-4 318: }
1.12 dom-ts-4 319:
1.18 dom-ts-4 320: IFrameBuilder.prototype.hasFeature = function(feature, version) {
321: return document.implementation.hasFeature(feature, version);
322: }
323:
1.23 dom-ts-4 324: IFrameBuilder.prototype.getImplementation = function() {
325: return document.implementation;
326: }
327:
1.31 dom-ts-4 328: IFrameBuilder.prototype.setContentType = function(contentType) {
329: this.contentType = contentType;
330: if (contentType == "text/html") {
1.34 ! dom-ts-4 331: this.fixedAttributeValues[6] = false;
1.31 dom-ts-4 332: } else {
1.34 ! dom-ts-4 333: this.fixedAttributeValues[6] = true;
1.31 dom-ts-4 334: }
335: }
336:
337:
1.18 dom-ts-4 338:
1.17 dom-ts-4 339: IFrameBuilder.prototype.preload = function(frame, varname, url) {
1.34 ! dom-ts-4 340: if (this.contentType == "text/html" || this.contentType == "application/xhtml+xml") {
! 341: if (url.substring(0,5) == "staff" || url == "nodtdstaff" || url == "datatype_normalization") {
1.26 dom-ts-4 342: throw "Tests using staff or nodtdstaff are not supported by HTML processors";
343: }
344: return 1;
1.18 dom-ts-4 345: }
1.26 dom-ts-4 346: var iframe = document.createElement("iframe");
347: var srcname = url + getSuffix(this.contentType);
348: iframe.setAttribute("name", srcname);
349: iframe.setAttribute("src", fileBase + srcname);
1.33 dom-ts-4 350: jsUnitSetOnLoad(iframe, loadComplete);
1.26 dom-ts-4 351: document.getElementsByTagName("body").item(0).appendChild(iframe);
352: return 0;
1.17 dom-ts-4 353: }
1.9 dom-ts-4 354:
1.17 dom-ts-4 355: IFrameBuilder.prototype.load = function(frame, varname, url) {
1.26 dom-ts-4 356: if (this.contentType == "text/html") {
357: return frame.document;
358: }
359: var name = url + getSuffix(this.contentType);
360: var iframes = document.getElementsByTagName("iframe");
361: for(var i = 0; i < iframes.length; i++) {
362: if (iframes.item(i).getAttribute("name") == name) {
1.33 dom-ts-4 363: var item = iframes.item(i);
364: if (typeof(item.contentDocument) != 'undefined') {
365: return item.contentDocument;
366: }
367: if (typeof(item.document) != 'undefined') {
368: return item.document;
369: }
370: return null;
1.26 dom-ts-4 371: }
372: }
373: return null;
1.17 dom-ts-4 374: }
1.9 dom-ts-4 375:
1.17 dom-ts-4 376: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
1.18 dom-ts-4 377: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
378: if (this.fixedAttributeNames[i] == attr) {
379: return this.fixedAttributeValues[i];
1.15 dom-ts-4 380: }
1.9 dom-ts-4 381: }
1.18 dom-ts-4 382: throw "Unrecognized implementation attribute: " + attr;
1.17 dom-ts-4 383: }
1.9 dom-ts-4 384:
1.5 dom-ts-4 385:
1.1 dom-ts-4 386:
1.18 dom-ts-4 387: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
388: var supported = this.getImplementationAttribute(attribute);
389: if (supported != value) {
1.34 ! dom-ts-4 390: this.initializationError = "IFrame loader does not support " + attribute + "=" + value;
1.18 dom-ts-4 391: }
392: }
393:
394:
1.34 ! dom-ts-4 395: IFrameBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 396: var supported = this.getImplementationAttribute(attribute);
! 397: return (supported == value);
! 398: }
! 399:
1.22 dom-ts-4 400:
401:
1.20 dom-ts-4 402: function SVGPluginBuilder() {
403: this.contentType = "image/svg+xml";
404: this.supportedContentTypes = [ "image/svg+xml" ];
405:
406: this.supportsAsyncChange = false;
407: this.async = true;
408: this.fixedAttributeNames = [
409: "validating", "expandEntityReferences", "coalescing",
1.31 dom-ts-4 410: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments"];
1.20 dom-ts-4 411:
1.34 ! dom-ts-4 412: this.fixedAttributeValues = [false, true, false, true, true , false, true, false ];
1.20 dom-ts-4 413: this.configurableAttributeNames = [ ];
414: this.configurableAttributeValues = [ ];
1.34 ! dom-ts-4 415: this.initializationError = null;
! 416: this.initializationFatalError = null;
! 417: this.skipIncompatibleTests = false;
1.20 dom-ts-4 418: }
419:
420: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
421: if (feature == "XML") {
422: if (version == null || version == "1.0" || version == "2.0") {
423: return true;
424: }
425: }
1.33 dom-ts-4 426: return false;
1.20 dom-ts-4 427: }
428:
1.31 dom-ts-4 429: SVGPluginBuilder.prototype.setContentType = function(contentType) {
430: this.contentType = contentType;
431: }
432:
1.23 dom-ts-4 433: SVGPluginBuilder.prototype.getImplementation = function() {
434: var embed = document.createElement("embed");
435: embed.src = fileBase + url + getSuffix(this.contentType);
436: embed.height = 100;
437: embed.width = 100;
438: embed.type = "image/svg+xml";
439: embed.id = varname;
440: var child = document.documentElement.firstChild;
441: while(child != null) {
442: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
443: child.appendChild(embed);
444: return child.getSVGDocument.implementation;
445: }
446: child = child.nextSibling;
447: }
448: return null;
449: }
450:
1.20 dom-ts-4 451: var svgloadcount = 0;
452: function SVGPluginBuilder_pollreadystate() {
453: var newCount = 0;
454: var child = document.documentElement.firstChild;
455: while(child != null) {
456: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
457: var grand = child.firstChild;
458: while (grand != null) {
459: if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
460: newCount++;
461: }
462: grand = grand.nextSibling;
463: }
464: break;
465: }
466: child = child.nextSibling;
467: }
468: if (newCount > svgloadcount) {
469: svgloadcount++;
470: loadComplete();
471: if (setUpPageStatus == 'complete') {
472: return;
473: }
474: }
475: setTimeout(SVGPluginBuilder_pollreadystate, 100);
476: }
477:
478: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
479: var embed = document.createElement("embed");
480: embed.src = fileBase + url + getSuffix(this.contentType);
481: embed.height = 100;
482: embed.width = 100;
483: embed.type = "image/svg+xml";
484: embed.id = varname;
485: var child = document.documentElement.firstChild;
486: while(child != null) {
487: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
488: child.appendChild(embed);
489: break;
490: }
491: child = child.nextSibling;
492: }
493: //
494: // if unable to monitor ready state change then
495: // check if load is complete every in 0.1 second
496: setTimeout(SVGPluginBuilder_pollreadystate , 100);
497: return 0;
498: }
499:
500: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
501: var child = document.documentElement.firstChild;
502: while(child != null) {
503: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
504: var grand = child.firstChild;
505: while (grand != null) {
506: if (grand.id == varname) {
507: return grand.getSVGDocument();
508: }
509: grand = grand.nextSibling;
510: }
511: }
512: child = child.nextSibling;
513: }
514: return null;
515: }
516:
517: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
518: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
519: if (this.fixedAttributeNames[i] == attr) {
520: return this.fixedAttributeValues[i];
521: }
522: }
523: throw "Unrecognized implementation attribute: " + attr;
524: }
525:
526:
527: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
528: var supported = this.getImplementationAttribute(attribute);
529: if (supported != value) {
1.34 ! dom-ts-4 530: this.initializationError = "SVG Plugin loader does not support " + attribute + "=" + value;
1.20 dom-ts-4 531: }
532: }
533:
1.34 ! dom-ts-4 534: SVGPluginBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 535: var supported = this.getImplementationAttribute(attribute);
! 536: return (supported == value);
! 537: }
1.20 dom-ts-4 538:
539:
1.22 dom-ts-4 540:
541:
1.18 dom-ts-4 542: function MSXMLBuilder(progID) {
543: this.progID = progID;
544: this.configurableAttributeNames = [
545: "validating", "ignoringElementContentWhitespace"];
546: this.configurableAttributeValues = [ false, false ];
547: this.fixedAttributeNames = [ "signed", "hasNullString",
1.31 dom-ts-4 548: "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
549: this.fixedAttributeValues = [ true, true, false, false, false, false ];
1.18 dom-ts-4 550:
551: this.contentType = "text/xml";
552: this.supportedContentTypes = [
553: "text/xml",
554: "image/svg+xml",
555: "application/xhtml+xml",
556: "text/mathml" ];
557:
558: this.async = false;
559: this.supportsAsyncChange = true;
560: this.parser = null;
1.34 ! dom-ts-4 561: this.initializationError = null;
! 562: this.initializationFatalError = null;
! 563: this.skipIncompatibleTests = false;
1.18 dom-ts-4 564: }
565:
566: MSXMLBuilder.prototype.createMSXML = function() {
1.19 dom-ts-4 567: var parser = new ActiveXObject(this.progID);
1.18 dom-ts-4 568: parser.async = this.async;
569: parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
570: parser.validateOnParse = this.configurableAttributeValues[0];
571: return parser;
572: }
1.31 dom-ts-4 573:
574: MSXMLBuilder.prototype.setContentType = function(contentType) {
575: this.contentType = contentType;
576: }
577:
1.18 dom-ts-4 578:
579: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
580: if (this.async) {
581: this.parser = this.createMSXML();
582: parser.async = true;
583: parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
584: parser.load(fileBase + url + getSuffix(this.contentType));
585: if (parser.readystate != 4) {
586: return 0;
587: }
588: }
589: return 1;
590: }
591:
592: MSXMLBuilder.prototype.load = function(frame, varname, url) {
1.19 dom-ts-4 593: var parser = this.createMSXML();
1.18 dom-ts-4 594: if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
595: throw parser.parseError.reason;
596: }
597: //
598: // if the first child of the document is a PI representing
599: // the XML Declaration, remove it from the tree.
600: //
601: // According to the DOM FAQ, this behavior is not wrong,
602: // but the tests are written assuming that it is not there.
603: //
604: var xmlDecl = parser.firstChild;
605: if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
606: parser.removeChild(xmlDecl);
607: }
608: return parser;
609: }
610:
611: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
612: var i;
613: for (i = 0; i < this.fixedAttributeNames.length; i++) {
614: if (this.fixedAttributeNames[i] == attr) {
615: return this.fixedAttributeValues[i];
616: }
617: }
618:
619: for (i = 0; i < this.configurableAttributeNames.length; i++) {
620: if (this.configurableAttributeNames[i] == attr) {
621: return this.configurableAttributeValues[i];
622: }
623: }
624:
625: throw "Unrecognized implementation attribute: " + attr;
626: }
627:
628:
629: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
630: var i;
631: for (i = 0; i < this.fixedAttributeNames.length; i++) {
1.19 dom-ts-4 632: if (this.fixedAttributeNames[i] == attribute) {
1.18 dom-ts-4 633: if (this.fixedAttributeValues[i] != value) {
1.34 ! dom-ts-4 634: this.initializationError = "MSXML does not support " + attribute + "=" + value;
1.18 dom-ts-4 635: }
636: return;
637: }
638: }
639: for (i = 0; i < this.configurableAttributeNames.length; i++) {
640: if (this.configurableAttributeNames[i] == attribute) {
641: this.configurableAttributeValues[i] = value;
642: return;
643: }
644: }
1.34 ! dom-ts-4 645: this.initializationError = "Unrecognized implementation attribute: " + attr;
1.18 dom-ts-4 646: }
647:
648:
1.34 ! dom-ts-4 649: MSXMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 650: var i;
! 651: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 652: if (this.fixedAttributeNames[i] == attribute) {
! 653: return (this.fixedAttributeValues[i] == value);
! 654: }
! 655: }
! 656: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 657: if (this.configurableAttributeNames[i] == attribute) {
! 658: return true;
! 659: }
! 660: }
! 661: return false;
! 662: }
! 663:
! 664:
1.23 dom-ts-4 665: MSXMLBuilder.prototype.getImplementation = function() {
666: var doc = this.CreateMSXML();
667: return doc.implementation;
668: }
1.18 dom-ts-4 669:
670: //
671: // Only used to select tests compatible with implementation
672: // not used on tests that actually test hasFeature()
673: //
674: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
675: //
676: // MSXML will take null, unfortunately
677: // there is no way to get it to there from script
678: // without a type mismatch error
679: if(version == null) {
680: switch(feature.toUpperCase()) {
681: case "XML":
682: case "CORE":
683: return true;
684:
685: case "HTML":
686: case "ORG.W3C.DOM":
687: return false;
688: }
689: if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
690: return true;
691: }
692: if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
693: return true;
694: }
695: if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
696: return true;
697: }
698: }
699: return this.getDOMImplementation().hasFeature(feature,version);
700: }
701:
702:
1.9 dom-ts-4 703:
1.17 dom-ts-4 704: function MozillaXMLBuilder() {
1.18 dom-ts-4 705: this.contentType = "text/xml";
706:
707: this.configurableAttributeNames = [ ];
708: this.configurableAttributeValues = [ ];
709: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
1.31 dom-ts-4 710: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
711: this.fixedAttributeValues = [ false, false, true, true, false, false, false, false ];
1.18 dom-ts-4 712:
713: this.contentType = "text/xml";
714: this.supportedContentTypes = [
715: "text/xml",
716: "image/svg+xml",
717: "application/xhtml+xml",
718: "text/mathml" ];
719:
720: this.async = true;
721: this.supportsAsyncChange = false;
722:
1.17 dom-ts-4 723: this.docs = new Array();
724: this.docnames = new Array();
1.34 ! dom-ts-4 725: this.initializationError = null;
! 726: this.initializationFatalError = null;
! 727: this.skipIncompatibleTests = false;
1.17 dom-ts-4 728: }
1.1 dom-ts-4 729:
1.23 dom-ts-4 730: MozillaXMLBuilder.prototype.getImplementation = function() {
731: return document.implementation;
732: }
733:
1.31 dom-ts-4 734: MozillaXMLBuilder.prototype.setContentType = function(contentType) {
735: this.contentType = contentType;
736: }
737:
738:
1.23 dom-ts-4 739:
1.17 dom-ts-4 740: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
741: var domimpl = document.implementation;
742: var doc = domimpl.createDocument("", "temp", null);
743: doc.addEventListener("load", loadComplete, false);
1.18 dom-ts-4 744: doc.load(fileBase + url + getSuffix(this.contentType));
1.17 dom-ts-4 745: this.docs[this.docs.length] = doc;
746: this.docnames[this.docnames.length] = varname;
747: return 0;
748: }
1.1 dom-ts-4 749:
1.17 dom-ts-4 750: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
751: for(i = 0; i < this.docnames.length; i++) {
752: if (this.docnames[i] == varname) {
753: return this.docs[i];
1.9 dom-ts-4 754: }
755: }
1.17 dom-ts-4 756: return null;
757: }
1.1 dom-ts-4 758:
1.9 dom-ts-4 759:
1.17 dom-ts-4 760: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
1.22 dom-ts-4 761: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
762: if (this.fixedAttributeNames[i] == attr) {
763: return this.fixedAttributeValues[i];
764: }
765: }
1.17 dom-ts-4 766: return false;
767: }
1.1 dom-ts-4 768:
769:
1.33 dom-ts-4 770: MozillaXMLBuilder.prototype.hasFeature = function(feature, version)
771: {
772: return this.getImplementation().hasFeature(feature, version);
773: }
774:
775: MozillaXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
776: var supported = this.getImplementationAttribute(attribute);
777: if (supported != value) {
1.34 ! dom-ts-4 778: this.initializationError = "Mozilla XML loader does not support " + attribute + "=" + value;
1.33 dom-ts-4 779: }
780: }
1.22 dom-ts-4 781:
1.34 ! dom-ts-4 782:
! 783: MozillaXMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 784: var supported = this.getImplementationAttribute(attribute);
! 785: return (supported == value);
! 786: }
! 787:
1.22 dom-ts-4 788: function DOM3LSBuilder() {
789: this.contentType = "text/xml";
790:
1.34 ! dom-ts-4 791: this.fixedAttributeNames = [ signed, "hasNullString" ];
! 792: this.fixedAttributeValues = [ true, true ];
! 793: this.configurableAttributeNames = [ "validating", "ignoringElementContentWhitespace",
! 794: "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
! 795: this.configurableAttributeValues = [ false, false, true, true, false, false, true, false ];
! 796: this.domConfigNames = [ "validate", "element-content-whitespace",
! 797: "entities", "cdata-sections", "namespaces", "comments" ];
! 798: this.domConfigSense = [ true, false, false, false, true, false ];
1.22 dom-ts-4 799:
800: this.contentType = "text/xml";
801: this.supportedContentTypes = [
802: "text/xml",
803: "image/svg+xml",
804: "application/xhtml+xml",
805: "text/mathml" ];
806:
1.34 ! dom-ts-4 807: this.async = false;
1.22 dom-ts-4 808: this.supportsAsyncChange = true;
809:
810: this.docs = new Array();
811: this.docnames = new Array();
1.34 ! dom-ts-4 812: this.lsparser = null;
! 813: this.initializationError = null;
! 814: this.initializationFatalError = null;
! 815: this.skipIncompatibleTests = false;
1.22 dom-ts-4 816: }
817:
1.23 dom-ts-4 818: DOM3LSBuilder.prototype.getImplementation = function() {
819: return document.implementation;
820: }
821:
822:
1.31 dom-ts-4 823: DOM3LSBuilder.prototype.setContentType = function(contentType) {
824: this.contentType = contentType;
825: }
826:
1.22 dom-ts-4 827: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
1.34 ! dom-ts-4 828: if (!this.async) {
! 829: return 1;
! 830: }
! 831: var domimpl = document.implementation;
! 832: this.lsparser = domimpl.createLSParser(2, null);
! 833: this.lsparser.addEventListener("load", loadComplete, false);
! 834: var uri = fileBase + url + getSuffix(this.contentType);
! 835: var doc = this.lsparser.parseURI(uri);
! 836: this.docs[this.docs.length] = doc;
! 837: this.docnames[this.docnames.length] = varname;
! 838: return 0;
1.22 dom-ts-4 839: }
840:
841: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
842: if (this.async) {
843: for(i = 0; i < this.docnames.length; i++) {
844: if (this.docnames[i] == varname) {
845: return this.docs[i];
846: }
847: }
848: return null;
849: }
1.34 ! dom-ts-4 850: this.lsparser = document.implementation.createLSParser(1, null);
1.22 dom-ts-4 851: var uri = fileBase + url + getSuffix(this.contentType);
1.34 ! dom-ts-4 852: return this.lsparser.parseURI(uri);
1.22 dom-ts-4 853: }
854:
855:
856: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
1.34 ! dom-ts-4 857: var i;
! 858: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 859: if (this.fixedAttributeNames[i] == attr) {
! 860: return this.fixedAttributeValues[i];
! 861: }
! 862: }
! 863: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 864: if (this.configurableAttributeNames[i] == attr) {
! 865: if(this.lsparser.domConfig.getParameter(this.domConfigNames[i])) {
! 866: return this.domConfigSense[i];
! 867: } else {
! 868: return !this.domConfigSense[i];
! 869: }
1.22 dom-ts-4 870: }
871: }
1.34 ! dom-ts-4 872: throw "unrecognized implementation attribute " + att;
1.22 dom-ts-4 873: }
874:
1.28 dom-ts-4 875: DOM3LSBuilder.prototype.hasFeature = function(feature, version) {
876: return document.implementation.hasFeature(feature, version);
877: }
878:
879:
1.34 ! dom-ts-4 880:
1.18 dom-ts-4 881: function createBuilder(implementation) {
1.34 ! dom-ts-4 882: if (implementation == null) {
! 883: return new IFrameBuilder();
! 884: }
1.18 dom-ts-4 885: switch(implementation) {
886: case "msxml3":
1.27 dom-ts-4 887: return new MSXMLBuilder("Msxml2.DOMDocument.3.0");
1.18 dom-ts-4 888:
889: case "msxml4":
890: return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
891:
1.33 dom-ts-4 892: case "mozillaXML":
1.18 dom-ts-4 893: return new MozillaXMLBuilder();
894:
1.20 dom-ts-4 895: case "svgplugin":
896: return new SVGPluginBuilder();
1.18 dom-ts-4 897:
898: case "dom3ls":
1.22 dom-ts-4 899: return new DOM3LSBuilder();
1.33 dom-ts-4 900:
901: case "iframe":
902: return new IFrameBuilder();
1.34 ! dom-ts-4 903:
! 904: default:
! 905: alert ("unrecognized implementation " + implementation);
1.18 dom-ts-4 906: }
1.34 ! dom-ts-4 907: return new IFrameBuilder();
1.18 dom-ts-4 908: }
909:
1.30 dom-ts-4 910: function checkFeature(feature, version)
911: {
912: if (!builder.hasFeature(feature, version))
913: {
1.34 ! dom-ts-4 914: //
! 915: // don't throw exception so that users can select to ignore the precondition
! 916: //
! 917: builder.initializationError = "builder does not support feature " + feature + " version " + version;
1.30 dom-ts-4 918: }
919: }
920:
1.34 ! dom-ts-4 921: function createConfiguredBuilder() {
! 922: var builder = null;
! 923: var contentType = null;
! 924: var i;
! 925: var contentTypeSet = false;
! 926: var parm = null;
! 927: if (top && typeof(top.jsUnitParmHash) != 'undefined') {
! 928: builder = createBuilder(top.jsUnitGetParm('implementation'));
! 929:
! 930: parm = top.jsUnitGetParm("skipincompatibletests");
! 931: if (parm) {
! 932: if (parm == 'true') {
! 933: builder.skipIncompatibleTests = true;
! 934: } else {
! 935: builder.skipIncompatibleTests = false;
! 936: }
! 937: }
! 938:
! 939: if (top.jsUnitGetParm('asynchronous') == 'true' && builder.supportAsync) {
! 940: builder.async = true;
! 941: }
! 942: if (top.jsUnitGetParm('expandentityreferences')) {
! 943: if (top.jsUnitGetParm('expandEntityReferences') == 'true') {
! 944: builder.setImplementationAttribute('expandEntityReferences', true);
! 945: } else {
! 946: builder.setImplementationAttribute('expandEntityReferences', false);
! 947: }
! 948: }
! 949: if (top.jsUnitGetParm('ignoringelementcontentwhitespace')) {
! 950: if (top.jsUnitGetParm('ignoringElementContentWhitespace') == 'true') {
! 951: builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
! 952: } else {
! 953: builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
1.19 dom-ts-4 954: }
955: }
1.34 ! dom-ts-4 956: if (top.jsUnitGetParm('validating')) {
! 957: if (top.jsUnitGetParm('validating') == 'true') {
! 958: builder.setImplementationAttribute('validating', true);
! 959: } else {
! 960: builder.setImplementationAttribute('validating', false);
! 961: }
! 962: }
! 963: if (top.jsUnitGetParm('coalescing')) {
! 964: if (top.jsUnitGetParm('coalescing') == 'true') {
! 965: builder.setImplementationAttribute('coalescing', true);
! 966: } else {
! 967: builder.setImplementationAttribute('coalescing', false);
! 968: }
! 969: }
! 970: if (top.jsUnitGetParm('namespaceaware')) {
! 971: if (top.jsUnitGetParm('namespaceaware') == 'true') {
! 972: builder.setImplementationAttribute('namespaceAware', true);
! 973: } else {
! 974: builder.setImplementationAttribute('namespaceAware', false);
! 975: }
! 976: }
! 977: contentType = top.jsUnitGetParm('contenttype');
! 978: if (contentType != null) {
! 979: contentTypeSet = false;
! 980: for (i = 0; i < builder.supportedContentTypes.length; i++) {
! 981: if (builder.supportedContentTypes[i] == contentType) {
! 982: builder.setContentType(contentType);
! 983: contentTypeSet = true;
! 984: break;
! 985: }
! 986: }
! 987: if (!contentTypeSet) {
! 988: this.exception = "Builder does not support content type " + contentType;
! 989: }
! 990: }
! 991: if (top.jsUnitGetParm('ignoringcomments')) {
! 992: if (top.jsUnitGetParm('ignoringcomments') == 'true') {
! 993: builder.setImplementationAttribute('ignoringComments', true);
! 994: } else {
! 995: builder.setImplementationAttribute('ignoringComments', false);
! 996: }
! 997: }
! 998: } else {
! 999: builder = new IFrameBuilder();
! 1000: }
! 1001: return builder;
1.18 dom-ts-4 1002: }
1.16 dom-ts-4 1003:
1004:
1.17 dom-ts-4 1005: function preload(frame, varname, url) {
1006: return builder.preload(frame, varname, url);
1.15 dom-ts-4 1007: }
1008:
1.17 dom-ts-4 1009: function load(frame, varname, url) {
1010: return builder.load(frame, varname, url);
1.16 dom-ts-4 1011: }
1.15 dom-ts-4 1012:
1.17 dom-ts-4 1013: function getImplementationAttribute(attr) {
1014: return builder.getImplementationAttribute(attr);
1.15 dom-ts-4 1015: }
1.16 dom-ts-4 1016:
1.9 dom-ts-4 1017:
1.18 dom-ts-4 1018: function setImplementationAttribute(attribute, value) {
1019: builder.setImplementationAttribute(attribute, value);
1020: }
1021:
1.21 dom-ts-4 1022: function createXPathEvaluator(doc) {
1023: try {
1024: return doc.getFeature("XPath", null);
1025: }
1026: catch(ex) {
1027: }
1028: return doc;
1029: }
1030:
1.10 dom-ts-4 1031:
1.18 dom-ts-4 1032: function MSXMLBuilder_onreadystatechange() {
1033: if (builder.parser.readyState == 4) {
1034: loadComplete();
1035: }
1.19 dom-ts-4 1036: }
1037:
1038:
1039: var fileBase = location.href;
1040: if (fileBase.indexOf('?') != -1) {
1041: fileBase = fileBase.substring(0, fileBase.indexOf('?'));
1042: }
1.20 dom-ts-4 1043: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
1044:
1.23 dom-ts-4 1045: function getImplementation() {
1046: return builder.getImplementation();
1047: }
1.19 dom-ts-4 1048:
Webmaster