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

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

Webmaster