Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.10
1.1 dom-ts-4 1: /*
2: Copyright (c) 2001 World Wide Web Consortium,
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: */
12:
1.3 dom-ts-4 13: function assertSize(descr, expected, actual) {
14: var actualSize;
15: actualSize = actual.length;
16: assertEquals(descr, expected, actualSize);
17: }
1.9 dom-ts-4 18:
19: function assertStringEquals(descr, expected, actual, ignoreCase) {
20: if(expected != actual) {
21: if(ignoreCase && actual != null) {
22: if(expected.toLowerCase() != actual.toLowerCase()) {
23: assertEquals(descr,expected,actual);
24: }
25: }
26: else {
27: assertEquals(descr,expected,actual);
28: }
29: }
30: }
31:
32:
33: function assertStringNotEquals(descr, expected, actual, ignoreCase) {
34: if(expected == actual) {
35: assertNotEquals(descr,expected,actual);
36: }
37: if(ignoreCase && actual != null && expected.toLowerCase() == actual.toLowerCase()) {
38: assertNotEquals(descr,expected,actual);
39: }
40: }
41:
42: function assertEqualsCollection(descr, expected, actual,ignoreCase) {
1.3 dom-ts-4 43: //
44: // if they aren't the same size, they aren't equal
45: assertEquals(descr, expected.length, actual.length);
46: //
47: // if there length is the same, then every entry in the expected list
48: // must appear once and only once in the actual list
49: var expectedLen = expected.length;
50: var expectedValue;
51: var actualLen = actual.length;
52: var i;
53: var j;
54: var matches;
55: for(i = 0; i < expectedLen; i++) {
56: matches = 0;
57: expectedValue = expected[i];
58: for(j = 0; j < actualLen; j++) {
59: if(expectedValue == actual[j]) {
60: matches++;
61: }
1.9 dom-ts-4 62: else {
63: if(ignoreCase && expectedValue.toLowerCase() == actual[j].toLowerCase()) {
64: matches++;
65: }
66: }
1.3 dom-ts-4 67: }
68: if(matches == 0) {
69: assert(descr + ": No match found for " + expectedValue,false);
70: }
71: if(matches > 1) {
72: assert(descr + ": Multiple matches found for " + expectedValue, false);
73: }
74: }
75: }
76:
77:
1.9 dom-ts-4 78: function assertEqualsList(descr, expected, actual, ignoreCase) {
1.3 dom-ts-4 79: //
80: // if they aren't the same size, they aren't equal
81: assertEquals(descr, expected.length, actual.length);
82: //
83: var actualLen = actual.length;
84: var i;
85: for(i = 0; i < actualLen; i++) {
86: if(expected[i] != actual[i]) {
1.9 dom-ts-4 87: if(!ignoreCase || (expected[i].toLowerCase() != actual[i].toLowerCase())) {
88: assertEquals(descr, expected[i], actual[i]);
89: }
1.3 dom-ts-4 90: }
91: }
92: }
93:
94: function assertInstanceOf(descr, type, obj) {
95: if(type == "Attr") {
96: assertEquals(descr,2,obj.nodeType);
97: var specd = obj.specified;
98: }
99: }
100:
101: function assertSame(descr, expected, actual) {
102: if(expected != actual) {
103: assertEquals(descr, expected.nodeType, actual.nodeType);
104: assertEquals(descr, expected.nodeValue, actual.nodeValue);
105: }
106: }
107:
1.7 dom-ts-4 108: function assertURIEquals(assertID, scheme, path, host, file, query, fragment, isAbsolute, actual) {
109: //
110: // URI must be non-null
111: assertNotNull(assertID, actual);
112:
113: var uri = actual;
114:
115: var lastPound = actual.lastIndexOf("#");
116: var actualFragment = "";
117: if(lastPound != -1) {
118: //
119: // substring before pound
120: //
121: uri = actual.substring(0,lastPound);
122: actualFragment = actual.substring(lastPound+1);
123: }
124: if(fragment != null) assertEquals(assertID,fragment, actualFragment);
125:
126: var lastQuestion = uri.lastIndexOf("?");
127: var actualQuery = "";
128: if(lastQuestion != -1) {
129: //
130: // substring before pound
131: //
132: uri = actual.substring(0,lastQuestion);
133: actualQuery = actual.substring(lastQuestion+1);
134: }
135: if(query != null) assertEquals(assertID, query, actualQuery);
136:
137: var firstColon = uri.indexOf(":");
138: var firstSlash = uri.indexOf("/");
139: var actualPath = uri;
140: var actualScheme = "";
141: if(firstColon != -1 && firstColon < firstSlash) {
142: actualScheme = uri.substring(0,firstColon);
143: actualPath = uri.substring(firstColon + 1);
144: }
145:
146: if(scheme != null) {
147: assertEquals(assertID, scheme, actualScheme);
148: }
149:
150: if(path != null) {
151: assertEquals(assertID, path, actualPath);
152: }
153:
154: if(host != null) {
155: var actualHost = "";
156: if(actualPath.startsWith("//")) {
1.8 dom-ts-4 157: var termSlash = actualPath.substring(2).indexOf("/") + 2;
1.7 dom-ts-4 158: actualHost = actualPath.substring(0,termSlash);
159: }
160: assertEquals(assertID, host, actualHost);
161: }
162:
163: if(file != null) {
164: var actualFile = actualPath;
165: var finalSlash = actualPath.lastIndexOf("/");
166: if(finalSlash != -1) {
167: actualFile = actualPath.substring(finalSlash+1);
168: }
169: assertEquals(assertID, file, actualFile);
170: }
171:
172: if(isAbsolute != null) {
173: assertEquals(assertID, isAbsolute.booleanValue(), actualPath.startsWith("/"));
174: }
175: }
176:
177:
1.3 dom-ts-4 178: var factory = null;
1.9 dom-ts-4 179: var defaultContentType = "text/xml";
1.3 dom-ts-4 180:
181:
1.9 dom-ts-4 182: function MozHTMLApplyParserAttributes(parser, attrNames, attrValues) {
183: if(attrNames != null) {
184: var i;
185: for(i = 0; i < attrNames.length; i++) {
186: if(attrNames[i] == "expandEntityReferences") {
187: if(attrValues[i] == true) {
188: throw "Mozilla does not support expanding entity references";
189: }
190: }
191: }
192: }
193: }
194:
195: function MozHTMLDocumentBuilder_checkAvailability(sourceURL) {
196: switch(sourceURL)
197: {
198: case "staff":
199: case "staffNS":
200: case "staff.xml":
201: case "staffNS.xml":
202: throw sourceURL + " not available for HTML";
203: }
204: }
205:
206:
207: function MozHTMLDocumentBuilder_load(sourceURL, willBeModified) {
208: //
209: // resolve full URL
210: //
211: var absURL = location.href;
212: absURL = absURL.substring(0,absURL.lastIndexOf("/")+1) + sourceURL + ".html";
213: //
214: // see if there is an available copy around
215: //
216: var newDoc = checkCache(willBeModified, this.cache, absURL);
217: //
218: // if not create a new window
219: //
220: if(newDoc == null) {
221: var newWindow = window.open(absURL);
222: newDoc = newWindow.document;
223: if(!willBeModified) {
224: this.cache[this.cache.length] = new DocumentBuilderCacheEntry(absURL, newDoc);
225: }
226: }
227: return newDoc;
228: }
229:
230: function MozHTMLDocumentBuilder_getDOMImplementation() {
231: return document.implementation;
232: }
233:
234: //
235: // This function checks the exception raised in the test
236: // If this function returns true, then the exception is
237: // consistent with the exception code parameter
238: //
239: // This code attempts to determine the reason for the exception
240: // to reduce the chance that an unrelated exception causes
241: // the test to pass.
242: function MozHTMLDocumentBuilder_isDOMExceptionCode(ex, code) {
243: return true;
1.3 dom-ts-4 244: }
245:
1.9 dom-ts-4 246: function MozHTMLDocumentBuilder_getImplementationAttribute(attr) {
247: return false;
248: }
249:
250: function MozHTMLDocumentBuilder_close(testdoc) {
251: testdoc.close();
252: }
253:
254: function MozHTMLDocumentBuilder_checkAttributes(attrNames, attrValues) {
255: //
256: // if no attributes were specified,
257: // the document builder can be reused
258: if(this.attrNames == null) {
259: if(attrNames == null) {
260: return true;
261: }
262: }
263: return false;
264:
265: }
266:
267: function MozHTMLDocumentBuilder_hasFeature(feature, version) {
268: var upfeature = feature.toUpperCase();
269: switch(upfeature) {
270: case "HTML":
271: case "CORE":
272: case "EVENTS":
273: return true;
274: }
275: return false;
276: }
277:
1.3 dom-ts-4 278:
1.9 dom-ts-4 279: function MozHTMLDocumentBuilder(attrNames, attrValues) {
280: this.attrNames = attrNames;
281: this.attrValues = attrValues;
282: this.cache = new Array();
283: this.load = MozHTMLDocumentBuilder_load;
284: this.checkAvailability = MozHTMLDocumentBuilder_checkAvailability;
285: this.isDOMExceptionCode = MozHTMLDocumentBuilder_isDOMExceptionCode;
286: this.getDOMImplementation = MozHTMLDocumentBuilder_getDOMImplementation;
287: this.getImplementationAttribute = MozHTMLDocumentBuilder_getImplementationAttribute;
288: this.close = MozHTMLDocumentBuilder_close;
289: this.checkAttributes = MozHTMLDocumentBuilder_checkAttributes;
290: this.hasFeature = MozHTMLDocumentBuilder_hasFeature;
291: this.ignoreCase = true;
1.3 dom-ts-4 292: }
293:
294:
1.9 dom-ts-4 295: function MozXMLApplyParserAttributes(parser, attrNames, attrValues) {
296: }
297:
298:
1.3 dom-ts-4 299: //
300: // get a document ready for the next test
301: //
1.9 dom-ts-4 302: function MozXMLLoad(sourceURL) {
1.3 dom-ts-4 303: var doc = document.implementation.createDocument("","temp",null);
1.9 dom-ts-4 304: doc.load(sourceURL + ".xml");
305: return doc;
1.3 dom-ts-4 306: }
307:
1.9 dom-ts-4 308: function MozXMLDocumentBuilder_load(sourceURL, willBeModified) {
309: for(i = 0; i < this.cache.length; i++) {
310: if(this.cache[i].url == sourceURL) {
311: var testdoc = this.cache[i].testdoc;
312: if(testdoc.documentElement.nodeName != "temp") {
313: //
314: // if it will be modified, start loading its replacement
315: //
316: if(willBeModified) {
317: this.cache[i].testdoc = MozXMLLoad(sourceURL);
318: }
319: return testdoc;
320: }
321: }
322: }
1.3 dom-ts-4 323: doc = document.implementation.createDocument("","temp",null);
1.9 dom-ts-4 324: doc.load(sourceURL + ".xml");
1.3 dom-ts-4 325: for(var i = 0; i < 5; i++) {
1.9 dom-ts-4 326: if(doc.documentElement != null && doc.documentElement.nodeName != "temp") break;
327: alert("Load attempt " + i.toString() + ": Press OK continue.");
1.3 dom-ts-4 328: }
1.9 dom-ts-4 329:
330: if(willBeModified) {
331: //
332: // if it will be modified, get another copy started
333: //
1.10 ! dom-ts-4 334: this.cache[this.cache.length] = new DocumentBuilderCacheEntry(sourceURL, MozXMLLoad(sourceURL));
1.9 dom-ts-4 335: }
336: //
337: // if not going to be modified, then we can keep this around
338: // for another iteration
339: else {
340: this.cache[this.cache.length] = new DocumentBuilderCacheEntry(sourceURL,doc);
341: }
1.3 dom-ts-4 342:
343: return doc;
344: }
345:
1.9 dom-ts-4 346: function MozXMLDocumentBuilder_getDOMImplementation() {
1.3 dom-ts-4 347: return document.implementation;
348: }
349:
1.9 dom-ts-4 350: function MozXMLDocumentBuilder_isDOMExceptionCode(ex, code) {
1.3 dom-ts-4 351: return true;
352: }
353:
1.9 dom-ts-4 354: function MozXMLDocumentBuilder_getImplementationAttribute(attr) {
1.4 dom-ts-4 355: if(attr == "expandEntityReferences") {
356: return true;
357: }
1.3 dom-ts-4 358: return false;
359: }
360:
1.9 dom-ts-4 361: function MozXMLDocumentBuilder_checkAttributes(attrNames, attrValues) {
362: if(this.attrNames == null) {
363: if(attrNames == null) {
364: return true;
365: }
366: }
367: return false;
368: }
369:
370: function MozXMLDocumentBuilder_checkAvailability(sourceURL) {
371: return true;
372: }
373:
374: function MozXMLDocumentBuilder_hasFeature(feature, version) {
375: var upfeature = feature.toUpperCase();
376: if(version == null) {
377: switch(upfeature) {
378: case "XML":
379: case "ORG.W3C.DOM":
380: case "CORE":
381: case "EVENTS":
382: case "HTML":
383: return true;
384:
385: }
386: }
387: return this.getDOMImplementation().hasFeature(feature,version);
388: }
389:
390: function MozXMLDocumentBuilder_close(testdoc) {
391: }
392:
393:
394: function MozXMLDocumentBuilder(attrNames, attrValues) {
1.3 dom-ts-4 395: this.attrNames = attrNames;
396: this.attrValues = attrValues;
1.9 dom-ts-4 397: this.cache = new Array();
398: this.load = MozXMLDocumentBuilder_load;
399: this.isDOMExceptionCode = MozXMLDocumentBuilder_isDOMExceptionCode;
400: this.getDOMImplementation = MozXMLDocumentBuilder_getDOMImplementation;
401: this.getImplementationAttribute = MozXMLDocumentBuilder_getImplementationAttribute;
402: this.checkAttributes = MozXMLDocumentBuilder_checkAttributes;
403: this.checkAvailability = MozXMLDocumentBuilder_checkAvailability;
404: this.close = MozXMLDocumentBuilder_close;
405: this.hasFeature = MozXMLDocumentBuilder_hasFeature;
406: this.ignoreCase = false;
1.4 dom-ts-4 407: //
408: // check if expandEntityReferences is false
409: // and throw an excpetion since that behavior is not supported
410: //
411: if(attrNames != null) {
412: for(var i = 0; i < attrNames.length; i++) {
413: if(attrNames[i] == "expandEntityReferences" && attrValues[i] == false) {
414: throw "Mozilla doesn't support entity preservation";
415: }
416: }
417: }
1.3 dom-ts-4 418: }
419:
1.9 dom-ts-4 420: var defaultMozHTMLDocumentBuilder = null;
421: var defaultMozXMLDocumentBuilder = null;
422: var defaultMozSVGDocumentBuilder = null;
423:
424: function MozDocumentBuilderFactory_newDocumentBuilder(attrNames, attrValues,contentType) {
425: if(contentType != null) {
426: switch(contentType)
427: {
428: case "image/xml+svg":
429: if(defaultMozSVGDocumentBuilder.checkAttributes(attrNames, attrValues)) {
430: return defaultMozSVGDocumentBuilder;
431: }
432: return new ASVDocumentBuilder(attrNames, attrValues);
433:
434: case "text/html":
435: if(defaultMozHTMLDocumentBuilder.checkAttributes(attrNames, attrValues)) {
436: return defaultMozHTMLDocumentBuilder;
437: }
438: return new MozHTMLDocumentBuilder(attrNames, attrValues);
439:
440: }
1.3 dom-ts-4 441: }
1.9 dom-ts-4 442: if(defaultMozXMLDocumentBuilder.checkAttributes(attrNames, attrValues)) {
443: return defaultMozXMLDocumentBuilder;
444: }
445: return new MozXMLDocumentBuilder(attrNames, attrValues);
1.3 dom-ts-4 446: }
447:
448: function MozDocumentBuilderFactory() {
449: this.newDocumentBuilder = MozDocumentBuilderFactory_newDocumentBuilder;
450: }
451:
1.9 dom-ts-4 452: //
453: // If application name contains Netscape
454: // set up Mozilla factories
455: //
1.3 dom-ts-4 456: if(navigator.appName.indexOf("Netscape") != -1) {
1.9 dom-ts-4 457: defaultMozXMLDocumentBuilder = new MozXMLDocumentBuilder(null,null);
458: defaultMozHTMLDocumentBuilder = new MozHTMLDocumentBuilder(null, null);
459: defaultMozSVGDocumentBuilder = new ASVDocumentBuilder(null,null);
460: defaultContentType = "image/xml";
1.3 dom-ts-4 461: factory = new MozDocumentBuilderFactory();
462: }
1.5 dom-ts-4 463:
464:
465: //
466: // Adobe SVG Viewer support
467: //
468: //
469: //
1.3 dom-ts-4 470:
1.5 dom-ts-4 471: //
472: // get a document ready for the next test
473: //
474: function ASVStartLoad(sourceURL) {
475: //
476: // must create embed element in containing HTML
477: //
478: var embed = document.createElement("embed");
479: embed.src = sourceURL + ".svg";
480: embed.height= 100;
481: embed.width = 100;
482: embed.type = "image/svg+xml";
483: var htmlelem = document.documentElement;
484: var child = htmlelem.firstChild;
485: while(child != null) {
486: if(child.nodeName == "BODY") {
487: child.appendChild(embed);
488: break;
489: }
490: child = child.nextSibling;
491: }
492: return embed;
493: }
494:
495: function ASVDocumentBuilder_load(sourceURL, willBeModified) {
1.9 dom-ts-4 496: var embed = null;
497: for(var i = 0; i < this.cache.length; i++) {
498: if(this.cache[i].URL == sourceURL) {
499: embed = this.cache[i].testdoc;
500: if(embed != null && embed.readyState == "complete") {
501: if(willBeModified) {
502: this.cache[i].testdoc = ASVStartLoad(sourceURL);
503: }
504: return embed.getSVGDocument();
505: }
1.5 dom-ts-4 506: }
507: }
1.9 dom-ts-4 508: embed = ASVStartLoad(sourceURL);
509: //
510: // if the current doc will be modified, start loading another
511: //
512: if(willBeModified) {
513: this.cache[this.cache.length] = new DocumentBuilderCacheEntry(sourceURL, ASVStartLoad(sourceURL));
514: }
1.5 dom-ts-4 515: for(var i = 0; i < 5; i++) {
1.9 dom-ts-4 516:
1.5 dom-ts-4 517: alert("Document loading: Press OK continue.");
518: if(embed.readyState == "complete") break;
519: }
520:
521: doc = embed.getSVGDocument();
522:
1.9 dom-ts-4 523: //
524: // if the document will be modified
525: // start another SVG load on the same document
526: // to be ready for next time
527: if(willBeModified) {
528: this.dirty[this.dirty.length] = embed;
529: }
530: //
531: // if this document will not be modified
532: // add it to the cache
533: else {
534: this.cache[this.cache.length] = new DocumentBuilderCacheEntry(sourceURL, embed);
535: }
536:
1.5 dom-ts-4 537: return doc;
538: }
539:
540: function ASVDocumentBuilder_getDOMImplementation() {
1.9 dom-ts-4 541: for(var i = 0; i < this.cache.length; i++) {
542: if(this.cache[i].testdoc.readyState == "complete") {
543: return this.cache[i].testdoc.getSVGDocument().implementation;
544: }
545: }
546: var testdoc = load("staff",false);
547: return testdoc.implementation;
548: }
1.5 dom-ts-4 549:
550: function ASVDocumentBuilder_isDOMExceptionCode(ex, code) {
551: return true;
552: }
553:
554: function ASVDocumentBuilder_getImplementationAttribute(attr) {
555: if(attr == "expandEntityReferences") {
556: return true;
557: }
558: return false;
559: }
1.9 dom-ts-4 560:
561: //
562: // dispose of modified documents by removing their
563: // embed section
564: //
565: function ASVDocumentBuilder_close(testdoc) {
566: for(i = 0; i < this.dirty.length; i++) {
567: var embed = this.dirty[i];
568: if(embed.getSVGDocument() == testdoc) {
569: embed.parentNode.removeChild(embed);
570: break;
571: }
572: }
573: }
574:
575: function ASVDocumentBuilder_checkAttributes(attrNames, attrValues) {
576: if(this.attrNames == null) {
577: if(attrNames == null) {
578: return true;
579: }
580: }
581: return false;
582: }
583:
584: function ASVDocumentBuilder_checkAvailability(sourceURL) {
585: return true;
586: }
587:
588: function ASVDocumentBuilder_hasFeature(feature, version) {
589: var upfeature = feature.toUpperCase();
590: if(version == null) {
591: switch(upfeature) {
592: case "XML":
593: case "ORG.W3C.DOM":
594: case "CORE":
595: case "EVENTS":
596: return true;
597:
598: case "HTML":
599: return false;
600: }
601: }
602: return this.getDOMImplementation().hasFeature(feature,version);
603: }
604:
1.5 dom-ts-4 605:
606: function ASVDocumentBuilder(attrNames, attrValues) {
607: this.attrNames = attrNames;
608: this.attrValues = attrValues;
1.9 dom-ts-4 609: this.cache = new Array();
610: this.dirty = new Array();
1.5 dom-ts-4 611: this.load = ASVDocumentBuilder_load;
612: this.isDOMExceptionCode = ASVDocumentBuilder_isDOMExceptionCode;
613: this.getDOMImplementation = ASVDocumentBuilder_getDOMImplementation;
614: this.getImplementationAttribute = ASVDocumentBuilder_getImplementationAttribute;
1.9 dom-ts-4 615: this.checkAttributes = ASVDocumentBuilder_checkAttributes;
616: this.checkAvailability = ASVDocumentBuilder_checkAvailability;
617: this.close = ASVDocumentBuilder_close;
618: this.hasFeature = ASVDocumentBuilder_hasFeature;
619: this.ignoreCase = false;
1.5 dom-ts-4 620: if(attrNames != null) {
621: for(var i = 0; i < attrNames.length; i++) {
622: if(attrNames[i] == "expandEntityReferences" && attrValues[i] == false) {
623: throw "Adobe SVG Viewer can not preserve entities";
624: }
625: if(attrNames[i] == "ignoringElementContentWhitespace" && attrValues[i] == true) {
626: throw "Adobe SVG Viewer can not preserve ignorable whitespace";
627: }
628: }
629: }
630: }
631:
632:
633:
634:
1.9 dom-ts-4 635: function MSXMLApplyParserAttributes(parser, attrNames, attrValues) {
1.1 dom-ts-4 636: if(attrNames != null) {
637: var i;
638: for(i = 0; i < attrNames.length; i++) {
639: if(attrNames[i] == "expandEntityReferences") {
640: if(attrValues[i] == true) {
641: throw "MSXML does not support expanding entity references";
642: }
643: }
644: if(attrNames[i] == "validate") {
645: parser.validateOnParse = attrValues[i];
646: }
647: if(attrNames[i] == "ignoreElementContentWhitespace") {
648: parser.preserveWhiteSpace = !attrValues[i];
649: }
650: }
651: }
652: }
653:
1.9 dom-ts-4 654: function MSXMLDocumentBuilder_checkAvailability(sourceURL) {
655: return true;
656: }
657:
658: function DocumentBuilderCacheEntry(url, testdoc) {
659: this.url = url;
660: this.testdoc = testdoc;
661: }
662:
663: function checkCache(willBeModified,cache, sourceURL) {
664: //
665: // return any previously loaded instance
666: for(i = 0; i < cache.length; i++) {
667: if(cache[i] != null && cache[i].url == sourceURL) {
668: var testdoc = cache[i].testdoc;
669: //
670: // if it will be modified then
671: // remove it from the cache
672: if(willBeModified) {
673: cache[i] = null;
674: }
675: return testdoc;
676: }
677: }
678: return null;
679: }
680:
681:
682: function MSXMLDocumentBuilder_load(sourceURL, willBeModified) {
683: if(!this.parser.load(sourceURL + ".xml")) {
1.1 dom-ts-4 684: throw this.parser.parseError.reason;
685: }
686: //
687: // if the first child of the document is a PI representing
688: // the XML Declaration, remove it from the tree.
689: //
690: // According to the DOM FAQ, this behavior is not wrong,
1.9 dom-ts-4 691: // but the tests are written assuming that it is not there.
1.1 dom-ts-4 692: //
693: var xmlDecl = this.parser.firstChild;
694: if(xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
695: this.parser.removeChild(xmlDecl);
696: }
697: return this.parser;
698: }
699:
1.9 dom-ts-4 700: function MSXMLDocumentBuilder_getDOMImplementation() {
1.1 dom-ts-4 701: return this.parser.domImplementation;
702: }
703:
1.5 dom-ts-4 704: //
705: // This function checks the exception raised in the test
706: // If this function returns true, then the exception is
707: // consistent with the exception code parameter
708: //
709: // This code attempts to determine the reason for the exception
710: // to reduce the chance that an unrelated exception causes
711: // the test to pass.
1.9 dom-ts-4 712: function MSXMLDocumentBuilder_isDOMExceptionCode(ex, code) {
1.2 dom-ts-4 713: var retval;
714: switch(code) {
715: //
716: // INDEX_SIZE_ERR
717: case 1:
718: retval = (ex.number == -2147024809);
719: break;
720:
721: //
722: // HIERARCHY_REQUEST_ERR
723: case 3:
724: retval = (ex.number == -2147467259);
725: break;
726:
727:
728: //
729: // INVALID_CHARACTER_ERR
730: case 5:
731: retval = (ex.description.search(".*may not contain.*") >= 0);
732: break;
733:
734: //
735: // NO_MODIFICATION_ALLOWED_ERR
736: case 7:
1.1 dom-ts-4 737: retval = (ex.description.search(".*read.*only.*") >= 0);
1.2 dom-ts-4 738: break;
739:
740: //
741: // NOT_FOUND_ERR
742: //
743: case 8:
744: retval = (ex.number == -2147024809 || ex.number == -2147467259);
745: break;
746:
747: //
748: // INUSE_ATTRIBUTE_ERR
749: case 10:
750: retval = (ex.description.search(".*must be removed.*") >= 0);
751: break;
1.1 dom-ts-4 752: }
753: return retval;
754: }
755:
1.9 dom-ts-4 756: function MSXMLDocumentBuilder_getImplementationAttribute(attr) {
1.1 dom-ts-4 757: if(attr == "ignoringElementContentWhitespace") {
758: return !this.parser.preserveWhiteSpace;
759: }
760: return false;
761: }
1.9 dom-ts-4 762:
763: function MSXMLDocumentBuilder_close(testdoc) {
764: }
765:
766: function MSXMLDocumentBuilder_checkAttributes(attrNames, attrValues) {
767: if(this.attrNames == null) {
768: if(attrNames == null) {
769: return true;
770: }
771: }
772: return false;
773: }
774:
775: function MSXMLDocumentBuilder_hasFeature(feature, version) {
776: //
777: // MSXML will take null, unfortunately
778: // there is no way to get it to there from script
779: // without a type mismatch error
780: if(version == null) {
781: switch(feature.toUpperCase()) {
782: case "XML":
783: case "CORE":
784: return true;
785:
786: case "HTML":
787: case "ORG.W3C.DOM":
788: return false;
789: }
790: if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
791: return true;
792: }
793: if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
794: return true;
795: }
796: if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
797: return true;
798: }
799: }
800: return this.getDOMImplementation().hasFeature(feature,version);
801: }
1.1 dom-ts-4 802:
1.9 dom-ts-4 803: function MSXMLDocumentBuilder(attrNames, attrValues) {
1.1 dom-ts-4 804: this.attrNames = attrNames;
805: this.attrValues = attrValues;
1.9 dom-ts-4 806:
807: this.load = MSXMLDocumentBuilder_load;
808: this.checkAvailability = MSXMLDocumentBuilder_checkAvailability;
809: this.isDOMExceptionCode = MSXMLDocumentBuilder_isDOMExceptionCode;
810: this.getDOMImplementation = MSXMLDocumentBuilder_getDOMImplementation;
811: this.getImplementationAttribute = MSXMLDocumentBuilder_getImplementationAttribute;
812: this.close = MSXMLDocumentBuilder_close;
813: this.checkAttributes = MSXMLDocumentBuilder_checkAttributes;
814: this.hasFeature = MSXMLDocumentBuilder_hasFeature;
815: this.ignoreCase = false;
816:
1.1 dom-ts-4 817: this.parser = new ActiveXObject("MSXML2.DOMDocument.3.0");
818: this.parser.async = false;
819: this.parser.preserveWhiteSpace = true;
1.9 dom-ts-4 820: MSXMLApplyParserAttributes(this.parser,this.attrNames, this.attrValues);
821: }
822:
823:
824: function MSHTMLApplyParserAttributes(parser, attrNames, attrValues) {
825: if(attrNames != null) {
826: var i;
827: for(i = 0; i < attrNames.length; i++) {
828: if(attrNames[i] == "expandEntityReferences") {
829: if(attrValues[i] == true) {
830: throw "MSHTML does not support expanding entity references";
831: }
832: }
833: if(attrNames[i] == "validate") {
834: parser.validateOnParse = attrValues[i];
835: }
836: if(attrNames[i] == "ignoreElementContentWhitespace") {
837: parser.preserveWhiteSpace = !attrValues[i];
838: }
839: }
840: }
1.1 dom-ts-4 841: }
842:
1.9 dom-ts-4 843: function MSHTMLDocumentBuilder_checkAvailability(sourceURL) {
844: switch(sourceURL)
845: {
846: case "staff":
847: case "staffNS":
848: case "staff.xml":
849: case "staffNS.xml":
850: throw sourceURL + " not available for HTML";
851: }
852: }
1.1 dom-ts-4 853:
1.9 dom-ts-4 854:
855: function MSHTMLDocumentBuilder_load(sourceURL, willBeModified) {
856: //
857: // resolve full URL
858: //
859: var absURL = location.href;
860: absURL = absURL.substring(0,absURL.lastIndexOf("/")+1) + sourceURL + ".html";
861: //
862: // see if there is an available copy around
863: //
864: var newDoc = checkCache(willBeModified, this.cache, absURL);
865: //
866: // if not create a new window
867: //
868: if(newDoc == null) {
869: var newWindow = window.open(absURL);
870: newDoc = newWindow.document;
871: if(!willBeModified) {
872: this.cache[this.cache.length] = new DocumentBuilderCacheEntry(absURL, newDoc);
873: }
874: }
875: return newDoc;
876: }
877:
878: function MSHTMLDocumentBuilder_getDOMImplementation() {
879: return document.implementation;
880: }
881:
882: //
883: // This function checks the exception raised in the test
884: // If this function returns true, then the exception is
885: // consistent with the exception code parameter
886: //
887: // This code attempts to determine the reason for the exception
888: // to reduce the chance that an unrelated exception causes
889: // the test to pass.
890: function MSHTMLDocumentBuilder_isDOMExceptionCode(ex, code) {
891: return true;
892: }
893:
894: function MSHTMLDocumentBuilder_getImplementationAttribute(attr) {
895: return false;
896: }
897:
898: function MSHTMLDocumentBuilder_close(testdoc) {
899: testdoc.close();
900: }
901:
902: function MSHTMLDocumentBuilder_checkAttributes(attrNames, attrValues) {
903: //
904: // if no attributes were specified,
905: // the document builder can be reused
906: if(this.attrNames == null) {
907: if(attrNames == null) {
908: return true;
909: }
910: }
911: return false;
912:
913: }
914:
915: function MSHTMLDocumentBuilder_hasFeature(feature, version) {
916: var upfeature = feature.toUpperCase();
917: switch(upfeature) {
918: case "HTML":
919: case "CORE":
920: return true;
921: }
922: return false;
923: }
924:
925:
926: function MSHTMLDocumentBuilder(attrNames, attrValues) {
927: this.attrNames = attrNames;
928: this.attrValues = attrValues;
929: this.cache = new Array();
930: this.load = MSHTMLDocumentBuilder_load;
931: this.checkAvailability = MSHTMLDocumentBuilder_checkAvailability;
932: this.isDOMExceptionCode = MSHTMLDocumentBuilder_isDOMExceptionCode;
933: this.getDOMImplementation = MSHTMLDocumentBuilder_getDOMImplementation;
934: this.getImplementationAttribute = MSHTMLDocumentBuilder_getImplementationAttribute;
935: this.close = MSHTMLDocumentBuilder_close;
936: this.checkAttributes = MSHTMLDocumentBuilder_checkAttributes;
937: this.hasFeature = MSHTMLDocumentBuilder_hasFeature;
938: this.ignoreCase = true;
939: }
940:
941: var defaultMSHTMLDocumentBuilder = null;
942: var defaultMSXMLDocumentBuilder = null;
943: var defaultASVDocumentBuilder = null;
944:
945:
946: function IE5DocumentBuilderFactory_newDocumentBuilder(attrNames, attrValues,contentType) {
947: if(contentType != null) {
948: switch(contentType) {
949: case "image/xml+svg":
950: if(defaultASVDocumentBuilder.checkAttributes(attrNames,attrValues)) {
951: return defaultASVDocumentBuilder;
952: }
953: return new ASVDocumentBuilder(attrNames, attrValues);
954:
955: case "text/html":
956: if(defaultMSHTMLDocumentBuilder.checkAttributes(attrNames, attrValues)) {
957: return defaultMSHTMLDocumentBuilder;
958: }
959: return new MSHTMLDocumentBuilder(attrNames, attrValues);
960: }
961: }
962: if(defaultMSXMLDocumentBuilder.checkAttributes(attrNames, attrValues)) {
963: return defaultMSXMLDocumentBuilder;
964: }
965: return new MSXMLDocumentBuilder(attrNames, attrValues);
1.1 dom-ts-4 966: }
967:
968: function IE5DocumentBuilderFactory() {
969: this.newDocumentBuilder = IE5DocumentBuilderFactory_newDocumentBuilder;
970: }
971:
1.3 dom-ts-4 972: if(factory == null && navigator.appName.indexOf("Microsoft") != -1) {
973: factory = new IE5DocumentBuilderFactory();
1.9 dom-ts-4 974: defaultContentType = "text/xml";
975: defaultMSXMLDocumentBuilder = new MSXMLDocumentBuilder(null,null);
976: defaultMSHTMLDocumentBuilder = new MSHTMLDocumentBuilder(null,null);
977: defaultASVDocumentBuilder = new ASVDocumentBuilder(null,null);
978: }
979:
980: if(factory == null) {
981: alert("Unrecognized browser: " + navigator.appName);
1.1 dom-ts-4 982: }
983:
1.10 ! dom-ts-4 984:
! 985: var isTestPageLoaded=false;
! 986:
! 987: function isLoaded() {
! 988: return isTestPageLoaded;
! 989: }
! 990: function newOnLoadEvent() {
! 991: isTestPageLoaded=true;
! 992: }
! 993:
! 994: window.onload=newOnLoadEvent;
Webmaster