Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.31

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.30      dom-ts-4  189: function same(expected, actual)
                    190: {
                    191:   return expected === actual;
                    192: }
                    193: 
1.18      dom-ts-4  194: function getSuffix(contentType) {
                    195:     switch(contentType) {
                    196:         case "text/html":
                    197:         return ".html";
                    198: 
                    199:         case "text/xml":
                    200:         return ".xml";
                    201: 
                    202:         case "application/xhtml+xml":
                    203:         return ".xhtml";
                    204: 
                    205:         case "image/svg+xml":
                    206:         return ".svg";
                    207: 
                    208:         case "text/mathml":
                    209:         return ".mml";
                    210:     }
                    211:     return ".html";
                    212: }
                    213: 
1.17      dom-ts-4  214: function IFrameBuilder() {
1.18      dom-ts-4  215:     this.contentType = "text/html";
1.26      dom-ts-4  216:     this.supportedContentTypes = [ "text/html", 
                    217:         "text/xml", 
                    218:         "image/svg+xml", 
                    219:         "application/xhtml+xml",
                    220:         "text/mathml" ];    
1.18      dom-ts-4  221: 
                    222:     this.supportsAsyncChange = false;
1.26      dom-ts-4  223:     this.async = true;
1.18      dom-ts-4  224:     this.fixedAttributeNames = [
                    225:         "validating",  "expandEntityReferences", "coalescing", 
1.31    ! dom-ts-4  226:         "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments" ];
1.18      dom-ts-4  227: 
1.31    ! dom-ts-4  228:     this.fixedAttributeValues = [false,  true, false, true, true , false, false, true ];
1.18      dom-ts-4  229:     this.configurableAttributeNames = [ ];
                    230:     this.configurableAttributeValues = [ ];
1.19      dom-ts-4  231:     this.exception = null;
1.17      dom-ts-4  232: }
1.12      dom-ts-4  233: 
1.18      dom-ts-4  234: IFrameBuilder.prototype.hasFeature = function(feature, version) {
                    235:     return document.implementation.hasFeature(feature, version);
                    236: }
                    237: 
1.23      dom-ts-4  238: IFrameBuilder.prototype.getImplementation = function() {
                    239:     return document.implementation;
                    240: }
                    241: 
1.31    ! dom-ts-4  242: IFrameBuilder.prototype.setContentType = function(contentType) {
        !           243:     this.contentType = contentType;
        !           244:     if (contentType == "text/html") {
        !           245:        this.fixedAttributeValues[this.fixedAttributeValues.length - 1] = true;
        !           246:     } else {
        !           247:        this.fixedAttributeValues[this.fixedAttributeValues.length - 1] = false;
        !           248:     }
        !           249: }
        !           250: 
        !           251: 
1.18      dom-ts-4  252: 
1.17      dom-ts-4  253: IFrameBuilder.prototype.preload = function(frame, varname, url) {
1.26      dom-ts-4  254:   if (this.contentType == "text/html") {
                    255:        if (url == "staff" || url == "nodtdstaff") {
                    256:        throw "Tests using staff or nodtdstaff are not supported by HTML processors";
                    257:        }  
                    258:        return 1;
1.18      dom-ts-4  259:   }
1.26      dom-ts-4  260:   var iframe = document.createElement("iframe");
                    261:   var srcname = url + getSuffix(this.contentType);
                    262:   iframe.setAttribute("name", srcname);
                    263:   iframe.setAttribute("src", fileBase + srcname);
                    264:   iframe.addEventListener("load", loadComplete, false);  
                    265:   document.getElementsByTagName("body").item(0).appendChild(iframe);
                    266:   return 0; 
1.17      dom-ts-4  267: }
1.9       dom-ts-4  268: 
1.17      dom-ts-4  269: IFrameBuilder.prototype.load = function(frame, varname, url) {
1.26      dom-ts-4  270:        if (this.contentType == "text/html") {
                    271:        return frame.document;
                    272:     }
                    273:     var name = url + getSuffix(this.contentType);
                    274:     var iframes = document.getElementsByTagName("iframe");
                    275:     for(var i = 0; i < iframes.length; i++) {
                    276:        if (iframes.item(i).getAttribute("name") == name) {
                    277:            return iframes.item(i).contentDocument;
                    278:        }
                    279:     }
                    280:     return null;
1.17      dom-ts-4  281: }
1.9       dom-ts-4  282: 
1.17      dom-ts-4  283: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
1.18      dom-ts-4  284:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
                    285:         if (this.fixedAttributeNames[i] == attr) {
                    286:             return this.fixedAttributeValues[i];
1.15      dom-ts-4  287:         }
1.9       dom-ts-4  288:     }
1.18      dom-ts-4  289:     throw "Unrecognized implementation attribute: " + attr;
1.17      dom-ts-4  290: }
1.9       dom-ts-4  291: 
1.5       dom-ts-4  292: 
1.17      dom-ts-4  293: IFrameBuilder.prototype.toAutoCase = function(s) {
1.20      dom-ts-4  294:     if (this.contentType == "text/html") {
                    295:         return s.toUpperCase();
                    296:     }
                    297:     return s;
1.17      dom-ts-4  298: }
1.5       dom-ts-4  299: 
1.17      dom-ts-4  300: IFrameBuilder.prototype.toAutoCaseArray = function(s) {
1.20      dom-ts-4  301:     if (this.contentType == "text/html") {
                    302:         return toUpperCaseArray(s);
                    303:     }
                    304:     return s;
1.17      dom-ts-4  305: }
1.1       dom-ts-4  306: 
1.18      dom-ts-4  307: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
                    308:     var supported = this.getImplementationAttribute(attribute);
                    309:     if (supported != value) {
                    310:         throw "IFrame loader does not support " + attribute + "=" + value;
                    311:     }
                    312: }
                    313: 
                    314: 
1.22      dom-ts-4  315: 
                    316: 
1.20      dom-ts-4  317: function SVGPluginBuilder() {
                    318:     this.contentType = "image/svg+xml";
                    319:     this.supportedContentTypes = [ "image/svg+xml" ];
                    320: 
                    321:     this.supportsAsyncChange = false;
                    322:     this.async = true;
                    323:     this.fixedAttributeNames = [
                    324:         "validating",  "expandEntityReferences", "coalescing", 
1.31    ! dom-ts-4  325:         "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments"];
1.20      dom-ts-4  326: 
1.31    ! dom-ts-4  327:     this.fixedAttributeValues = [false,  true, false, true, true , false, false, false ];
1.20      dom-ts-4  328:     this.configurableAttributeNames = [ ];
                    329:     this.configurableAttributeValues = [ ];
                    330:     this.exception = null;
                    331: }
                    332: 
                    333: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
                    334:     if (feature == "XML") {
                    335:         if (version == null || version == "1.0" || version == "2.0") {
                    336:             return true;
                    337:         }
                    338:     }
                    339: }
                    340: 
1.31    ! dom-ts-4  341: SVGPluginBuilder.prototype.setContentType = function(contentType) {
        !           342:     this.contentType = contentType;
        !           343: }
        !           344: 
1.23      dom-ts-4  345: SVGPluginBuilder.prototype.getImplementation = function() {
                    346:   var embed = document.createElement("embed");
                    347:   embed.src = fileBase + url + getSuffix(this.contentType);
                    348:   embed.height = 100;
                    349:   embed.width = 100;
                    350:   embed.type = "image/svg+xml";
                    351:   embed.id = varname;
                    352:   var child = document.documentElement.firstChild;
                    353:   while(child != null) {
                    354:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    355:           child.appendChild(embed);
                    356:           return child.getSVGDocument.implementation;
                    357:       }
                    358:       child = child.nextSibling;
                    359:   }
                    360:   return null;
                    361: }
                    362: 
1.20      dom-ts-4  363: var svgloadcount = 0;
                    364: function SVGPluginBuilder_pollreadystate() {
                    365:   var newCount = 0;
                    366:   var child = document.documentElement.firstChild;
                    367:   while(child != null) {
                    368:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    369:           var grand = child.firstChild;
                    370:           while (grand != null) {
                    371:              if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
                    372:                 newCount++;
                    373:              }
                    374:              grand = grand.nextSibling;
                    375:           }
                    376:           break;
                    377:       }
                    378:       child = child.nextSibling;
                    379:   }
                    380:   if (newCount > svgloadcount) {
                    381:     svgloadcount++;
                    382:     loadComplete();
                    383:     if (setUpPageStatus == 'complete') {
                    384:         return;
                    385:     }
                    386:   }
                    387:   setTimeout(SVGPluginBuilder_pollreadystate, 100);
                    388: }
                    389: 
                    390: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
                    391:   var embed = document.createElement("embed");
                    392:   embed.src = fileBase + url + getSuffix(this.contentType);
                    393:   embed.height = 100;
                    394:   embed.width = 100;
                    395:   embed.type = "image/svg+xml";
                    396:   embed.id = varname;
                    397:   var child = document.documentElement.firstChild;
                    398:   while(child != null) {
                    399:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    400:           child.appendChild(embed);
                    401:           break;
                    402:       }
                    403:       child = child.nextSibling;
                    404:   }
                    405:   //
                    406:   //   if unable to monitor ready state change then
                    407:   //     check if load is complete every in 0.1 second
                    408:   setTimeout(SVGPluginBuilder_pollreadystate , 100);
                    409:   return 0;
                    410: }
                    411: 
                    412: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
                    413:   var child = document.documentElement.firstChild;
                    414:   while(child != null) {
                    415:       if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
                    416:                  var grand = child.firstChild;
                    417:                  while (grand != null) {
                    418:                        if (grand.id == varname) {
                    419:                                return grand.getSVGDocument();
                    420:                        }
                    421:                        grand = grand.nextSibling;
                    422:                  }
                    423:          }
                    424:       child = child.nextSibling;
                    425:    }
                    426:    return null;
                    427: }
                    428: 
                    429: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
                    430:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
                    431:         if (this.fixedAttributeNames[i] == attr) {
                    432:             return this.fixedAttributeValues[i];
                    433:         }
                    434:     }
                    435:     throw "Unrecognized implementation attribute: " + attr;
                    436: }
                    437: 
                    438: 
                    439: SVGPluginBuilder.prototype.toAutoCase = function(s) {
                    440:     return s;
                    441: }
                    442: 
                    443: SVGPluginBuilder.prototype.toAutoCaseArray = function(s) {
                    444:     return s;
                    445: }
                    446: 
                    447: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
                    448:     var supported = this.getImplementationAttribute(attribute);
                    449:     if (supported != value) {
                    450:         throw "SVG Plugin loader does not support " + attribute + "=" + value;
                    451:     }
                    452: }
                    453: 
                    454: 
                    455: 
1.22      dom-ts-4  456: 
                    457: 
1.18      dom-ts-4  458: function MSXMLBuilder(progID) {
                    459:     this.progID = progID;
                    460:     this.configurableAttributeNames = [
                    461:         "validating", "ignoringElementContentWhitespace"];
                    462:     this.configurableAttributeValues = [ false, false ];
                    463:     this.fixedAttributeNames = [ "signed", "hasNullString", 
1.31    ! dom-ts-4  464:         "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
        !           465:     this.fixedAttributeValues = [ true, true, false, false, false, false ];
1.18      dom-ts-4  466: 
                    467:     this.contentType = "text/xml";
                    468:     this.supportedContentTypes = [ 
                    469:         "text/xml", 
                    470:         "image/svg+xml", 
                    471:         "application/xhtml+xml",
                    472:         "text/mathml" ];
                    473: 
                    474:     this.async = false;
                    475:     this.supportsAsyncChange = true;
                    476:     this.parser = null;
1.19      dom-ts-4  477:     this.exception = null;
1.18      dom-ts-4  478: }
                    479: 
                    480: MSXMLBuilder.prototype.createMSXML = function() {
1.19      dom-ts-4  481:     var parser = new ActiveXObject(this.progID);
1.18      dom-ts-4  482:     parser.async = this.async;
                    483:     parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
                    484:     parser.validateOnParse = this.configurableAttributeValues[0];
                    485:     return parser;
                    486:   }
1.31    ! dom-ts-4  487:   
        !           488: MSXMLBuilder.prototype.setContentType = function(contentType) {
        !           489:     this.contentType = contentType;
        !           490: }
        !           491:   
1.18      dom-ts-4  492: 
                    493: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
                    494:   if (this.async) {
                    495:      this.parser = this.createMSXML();
                    496:      parser.async = true;
                    497:      parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
                    498:      parser.load(fileBase + url + getSuffix(this.contentType));
                    499:      if (parser.readystate != 4) {
                    500:         return 0;
                    501:      }
                    502:   }
                    503:   return 1;
                    504: }
                    505: 
                    506: MSXMLBuilder.prototype.load = function(frame, varname, url) {
1.19      dom-ts-4  507:     var parser = this.createMSXML();
1.18      dom-ts-4  508:        if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
                    509:                throw parser.parseError.reason;
                    510:        }
                    511:     //
                    512:     //   if the first child of the document is a PI representing
                    513:     //      the XML Declaration, remove it from the tree.
                    514:     //
                    515:     //   According to the DOM FAQ, this behavior is not wrong,
                    516:     //      but the tests are written assuming that it is not there.
                    517:     //
                    518:     var xmlDecl = parser.firstChild;
                    519:     if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
                    520:         parser.removeChild(xmlDecl);
                    521:     }
                    522:        return parser;
                    523: }
                    524: 
                    525: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
                    526:     var i;
                    527:     for (i = 0; i < this.fixedAttributeNames.length; i++) {
                    528:         if (this.fixedAttributeNames[i] == attr) {
                    529:             return this.fixedAttributeValues[i];
                    530:         }
                    531:     }
                    532: 
                    533:     for (i = 0; i < this.configurableAttributeNames.length; i++) {
                    534:         if (this.configurableAttributeNames[i] == attr) {
                    535:             return this.configurableAttributeValues[i];
                    536:         }
                    537:     }
                    538: 
                    539:     throw "Unrecognized implementation attribute: " + attr;
                    540: }
                    541: 
                    542: 
                    543: MSXMLBuilder.prototype.toAutoCase = function(s) {
                    544:     return s;
                    545: }
                    546: 
                    547: MSXMLBuilder.prototype.toAutoCaseArray = function(s) {
                    548:     return s;
                    549: }
                    550: 
                    551: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
                    552:     var i;
                    553:     for (i = 0; i < this.fixedAttributeNames.length; i++) {
1.19      dom-ts-4  554:         if (this.fixedAttributeNames[i] == attribute) {
1.18      dom-ts-4  555:             if (this.fixedAttributeValues[i] != value) {
                    556:                 throw "MSXML does not support " + attribute + "=" + value;
                    557:             }
                    558:             return;
                    559:         }
                    560:     }
                    561:     for (i = 0; i < this.configurableAttributeNames.length; i++) {
                    562:         if (this.configurableAttributeNames[i] == attribute) {
                    563:             this.configurableAttributeValues[i] = value;
                    564:             return;
                    565:         }
                    566:     }
                    567:     throw "Unrecognized implementation attribute: " + attr;
                    568: }
                    569:             
                    570: 
1.23      dom-ts-4  571: MSXMLBuilder.prototype.getImplementation = function() {
                    572:     var doc = this.CreateMSXML();
                    573:     return doc.implementation;
                    574: }
1.18      dom-ts-4  575: 
                    576: //
                    577: //   Only used to select tests compatible with implementation
                    578: //      not used on tests that actually test hasFeature()
                    579: //
                    580: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
                    581:     //
                    582:     //   MSXML will take null, unfortunately 
                    583:     //      there is no way to get it to there from script
                    584:     //      without a type mismatch error
                    585:     if(version == null) {
                    586:                switch(feature.toUpperCase()) {
                    587:                   case "XML":
                    588:                   case "CORE":
                    589:                   return true;
                    590:                   
                    591:                   case "HTML":
                    592:                   case "ORG.W3C.DOM":
                    593:                   return false;
                    594:                }
                    595:                if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
                    596:                   return true;
                    597:                }
                    598:                if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
                    599:                   return true;
                    600:                }
                    601:                if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
                    602:                   return true;
                    603:                }
                    604:     }
                    605:        return this.getDOMImplementation().hasFeature(feature,version);
                    606:   }
                    607: 
                    608: 
1.9       dom-ts-4  609: 
1.17      dom-ts-4  610: function MozillaXMLBuilder() {
1.18      dom-ts-4  611:     this.contentType = "text/xml";
                    612: 
                    613:     this.configurableAttributeNames = [ ];
                    614:     this.configurableAttributeValues = [ ];
                    615:     this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed", 
1.31    ! dom-ts-4  616:         "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
        !           617:     this.fixedAttributeValues = [ false, false, true, true, false, false, false, false ];
1.18      dom-ts-4  618: 
                    619:     this.contentType = "text/xml";
                    620:     this.supportedContentTypes = [ 
                    621:         "text/xml", 
                    622:         "image/svg+xml", 
                    623:         "application/xhtml+xml",
                    624:         "text/mathml" ];
                    625: 
                    626:     this.async = true;
                    627:     this.supportsAsyncChange = false;
                    628: 
1.17      dom-ts-4  629:     this.docs = new Array();
                    630:     this.docnames = new Array();
1.19      dom-ts-4  631:     this.exception = null;
1.17      dom-ts-4  632: }
1.1       dom-ts-4  633: 
1.23      dom-ts-4  634: MozillaXMLBuilder.prototype.getImplementation = function() {
                    635:     return document.implementation;
                    636: }
                    637: 
1.31    ! dom-ts-4  638: MozillaXMLBuilder.prototype.setContentType = function(contentType) {
        !           639:     this.contentType = contentType;
        !           640: }
        !           641: 
        !           642: 
1.23      dom-ts-4  643: 
1.17      dom-ts-4  644: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
                    645:   var domimpl = document.implementation;
                    646:   var doc = domimpl.createDocument("", "temp", null);
                    647:   doc.addEventListener("load", loadComplete, false);
1.18      dom-ts-4  648:   doc.load(fileBase + url + getSuffix(this.contentType));
1.17      dom-ts-4  649:   this.docs[this.docs.length] = doc;
                    650:   this.docnames[this.docnames.length] = varname;
                    651:   return 0;
                    652: }
1.1       dom-ts-4  653: 
1.17      dom-ts-4  654: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
                    655:     for(i = 0; i < this.docnames.length; i++) {
                    656:         if (this.docnames[i] == varname) {
                    657:             return this.docs[i];
1.9       dom-ts-4  658:         }
                    659:     }
1.17      dom-ts-4  660:     return null;
                    661: }
1.1       dom-ts-4  662: 
1.9       dom-ts-4  663: 
1.17      dom-ts-4  664: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
1.22      dom-ts-4  665:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
                    666:         if (this.fixedAttributeNames[i] == attr) {
                    667:             return this.fixedAttributeValues[i];
                    668:         }
                    669:     }
1.17      dom-ts-4  670:     return false;
                    671: }
1.1       dom-ts-4  672: 
                    673: 
1.17      dom-ts-4  674: MozillaXMLBuilder.prototype.toAutoCase = function(s) {
                    675:     return s;
                    676: }
1.15      dom-ts-4  677: 
1.17      dom-ts-4  678: MozillaXMLBuilder.prototype.toAutoCaseArray = function(s) {
                    679:     return s;
1.16      dom-ts-4  680: }
                    681: 
1.22      dom-ts-4  682: 
                    683: function DOM3LSBuilder() {
                    684:     this.contentType = "text/xml";
                    685: 
                    686:     this.configurableAttributeNames = [ ];
                    687:     this.configurableAttributeValues = [ ];
                    688:     this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed", 
1.31    ! dom-ts-4  689:         "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments" ];
        !           690:     this.fixedAttributeValues = [ false, false, true, true, false, false, true, false ];
1.22      dom-ts-4  691: 
                    692:     this.contentType = "text/xml";
                    693:     this.supportedContentTypes = [ 
                    694:         "text/xml", 
                    695:         "image/svg+xml", 
                    696:         "application/xhtml+xml",
                    697:         "text/mathml" ];
                    698: 
                    699:     this.async = true;
                    700:     this.supportsAsyncChange = true;
                    701: 
                    702:     this.docs = new Array();
                    703:     this.docnames = new Array();
                    704:     this.exception = null;
                    705: }
                    706: 
1.23      dom-ts-4  707: DOM3LSBuilder.prototype.getImplementation = function() {
                    708:     return document.implementation;
                    709: }
                    710: 
                    711: 
1.31    ! dom-ts-4  712: DOM3LSBuilder.prototype.setContentType = function(contentType) {
        !           713:     this.contentType = contentType;
        !           714: }
        !           715: 
1.22      dom-ts-4  716: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
                    717:   if (this.async) {
                    718:       var domimpl = document.implementation;
                    719:       var dombuilder = domimpl.createDOMBuilder(2, null);
                    720:       dombuilder.addEventListener("load", loadComplete, false);
                    721:       var uri = fileBase + url + getSuffix(this.contentType);
                    722:       var doc = dombuilder.parseURI(uri);
                    723:       this.docs[this.docs.length] = doc;
                    724:       this.docnames[this.docnames.length] = varname;
                    725:       return 0;
                    726:    }
                    727:    return 1;
                    728: }
                    729: 
                    730: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
                    731:     if (this.async) {
                    732:         for(i = 0; i < this.docnames.length; i++) {
                    733:             if (this.docnames[i] == varname) {
                    734:                 return this.docs[i];
                    735:             }
                    736:         }
                    737:         return null;
                    738:     }
                    739:     var dombuilder = document.implementation.createDOMBuilder(1, null);
                    740:     var uri = fileBase + url + getSuffix(this.contentType);
                    741:     return dombuilder.parseURI(uri);
                    742: }
                    743: 
                    744: 
                    745: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
                    746:     for (var i = 0; i < this.fixedAttributeNames.length; i++) {
                    747:         if (this.fixedAttributeNames[i] == attr) {
                    748:             return this.fixedAttributeValues[i];
                    749:         }
                    750:     }
                    751: }
                    752: 
                    753: 
                    754: DOM3LSBuilder.prototype.toAutoCase = function(s) {
                    755:     return s;
                    756: }
                    757: 
                    758: DOM3LSBuilder.prototype.toAutoCaseArray = function(s) {
                    759:     return s;
                    760: }
                    761: 
1.28      dom-ts-4  762: DOM3LSBuilder.prototype.hasFeature = function(feature, version) {
                    763:     return document.implementation.hasFeature(feature, version);
                    764: }
                    765: 
                    766: 
1.18      dom-ts-4  767: function createBuilder(implementation) {
                    768:   switch(implementation) {
                    769:     case "msxml3":
1.27      dom-ts-4  770:     return new MSXMLBuilder("Msxml2.DOMDocument.3.0");
1.18      dom-ts-4  771:     
                    772:     case "msxml4":
                    773:     return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
                    774: 
                    775:     case "mozilla":
                    776:     return new MozillaXMLBuilder();
                    777: 
1.20      dom-ts-4  778:     case "svgplugin":
                    779:     return new SVGPluginBuilder();
1.18      dom-ts-4  780: 
                    781:     case "dom3ls":
1.22      dom-ts-4  782:     return new DOM3LSBuilder();
1.18      dom-ts-4  783:   }
                    784:   return new IFrameBuilder();
                    785: }
                    786: 
1.30      dom-ts-4  787: function checkFeature(feature, version)
                    788: {
                    789:   if (!builder.hasFeature(feature, version))
                    790:   {
                    791:     throw "builder does not support feature " + feature + " version " + version;
                    792:   }
                    793: }
                    794: 
1.18      dom-ts-4  795: var builder = null;
                    796: 
                    797: if (top && top.jsUnitParmHash)
                    798: {
                    799:     builder = createBuilder(top.jsUnitParmHash.implementation);
1.19      dom-ts-4  800:     try {
                    801:         if (top.jsUnitParmHash.asynchronous == 'true' && builder.supportAsync) {
                    802:             builder.async = true;
                    803:         }
                    804:         if (top.jsUnitParmHash.expandentityreferences) {
                    805:             if (top.jsUnitParmHash.expandEntityReferences == 'true') {
                    806:                 builder.setImplementationAttribute('expandEntityReferences', true);
                    807:             } else {
                    808:                 builder.setImplementationAttribute('expandEntityReferences', false);
                    809:             }
                    810:         }
                    811:         if (top.jsUnitParmHash.ignoringelementcontentwhitespace) {
                    812:             if (top.jsUnitParmHash.ignoringElementContentWhitespace == 'true') {
                    813:                 builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
                    814:             } else {
                    815:                 builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
                    816:             }
                    817:         }
                    818:         if (top.jsUnitParmHash.validating) {
                    819:             if (top.jsUnitParmHash.validating == 'true') {
                    820:                 builder.setImplementationAttribute('validating', true);
                    821:             } else {
                    822:                 builder.setImplementationAttribute('validating', false);
                    823:             }
                    824:         }
                    825:         if (top.jsUnitParmHash.coalescing) {
                    826:             if (top.jsUnitParmHash.coalescing == 'true') {
                    827:                 builder.setImplementationAttribute('coalescing', true);
                    828:             } else {
                    829:                 builder.setImplementationAttribute('coalescing', false);
                    830:             }
                    831:         }
                    832:         if (top.jsUnitParmHash.namespaceaware) {
                    833:             if (top.jsUnitParmHash.namespaceaware == 'true') {
                    834:                 builder.setImplementationAttribute('namespaceAware', true);
                    835:             } else {
                    836:                 builder.setImplementationAttribute('namespaceAware', false);
                    837:             }
                    838:         }
                    839:         var contentType = top.jsUnitParmHash.contenttype;
                    840:         if (contentType != null) {
                    841:             var contentTypeSet = false;
                    842:             for (var i = 0; i < builder.supportedContentTypes.length; i++) {
                    843:                 if (builder.supportedContentTypes[i] == contentType) {
1.31    ! dom-ts-4  844:                     builder.setContentType(contentType);
1.19      dom-ts-4  845:                     contentTypeSet = true;
                    846:                     break;
                    847:                 }
                    848:             }
                    849:             if (!contentTypeSet) {
                    850:                 builder.exception = "Builder does not support content type " + contentType;
                    851:             }
                    852:         }
1.31    ! dom-ts-4  853:         if (top.jsUnitParmHash.ignoringcomments) {
        !           854:             if (top.jsUnitParmHash.ignoringcomments == 'true') {
        !           855:                 builder.setImplementationAttribute('ignoringComments', true);
        !           856:             } else {
        !           857:                 builder.setImplementationAttribute('ignoringComments', false);
        !           858:             }
        !           859:         }
        !           860:         
1.19      dom-ts-4  861:     }
                    862:     catch(ex) {
                    863:         builder.exception = ex;
                    864:     }
1.18      dom-ts-4  865: } else {
                    866:     builder = new IFrameBuilder();
                    867: }
1.16      dom-ts-4  868: 
                    869: 
1.17      dom-ts-4  870: function preload(frame, varname, url) {
                    871:   return builder.preload(frame, varname, url);
1.15      dom-ts-4  872: }
                    873: 
1.17      dom-ts-4  874: function load(frame, varname, url) {
                    875:     return builder.load(frame, varname, url);
1.16      dom-ts-4  876: }
1.15      dom-ts-4  877: 
1.17      dom-ts-4  878: function getImplementationAttribute(attr) {
                    879:     return builder.getImplementationAttribute(attr);
1.15      dom-ts-4  880: }
1.16      dom-ts-4  881: 
1.9       dom-ts-4  882: 
1.17      dom-ts-4  883: function toAutoCase(s) {
                    884:     return builder.toAutoCase(s);
                    885: }
1.1       dom-ts-4  886: 
1.17      dom-ts-4  887: function toAutoCaseArray(s) {
                    888:     return builder.toAutoCaseArray(s);
                    889: }
1.10      dom-ts-4  890: 
1.18      dom-ts-4  891: function setImplementationAttribute(attribute, value) {
                    892:     builder.setImplementationAttribute(attribute, value);
                    893: }
                    894: 
1.21      dom-ts-4  895: function createXPathEvaluator(doc) {
                    896:     try {
                    897:         return doc.getFeature("XPath", null);
                    898:     }
                    899:     catch(ex) {
                    900:     }
                    901:     return doc;
                    902: }
                    903: 
1.10      dom-ts-4  904: 
1.18      dom-ts-4  905: function MSXMLBuilder_onreadystatechange() {
                    906:     if (builder.parser.readyState == 4) {
                    907:         loadComplete();
                    908:     }
1.19      dom-ts-4  909: }
                    910: 
                    911: 
                    912: var fileBase = location.href;
                    913: if (fileBase.indexOf('?') != -1) {
                    914:    fileBase = fileBase.substring(0, fileBase.indexOf('?'));
                    915: }
1.20      dom-ts-4  916: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
                    917: 
1.23      dom-ts-4  918: function getImplementation() {
                    919:     return builder.getImplementation();
                    920: }
1.19      dom-ts-4  921: 

Webmaster