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

1.1     ! dom-ts-4    1: /*
        !             2: Copyright (c) 2001 World Wide Web Consortium,
        !             3: (Massachusetts Institute of Technology, Institut National de
        !             4: Recherche en Informatique et en Automatique, Keio University). All
        !             5: Rights Reserved. This program is distributed under the W3C's Software
        !             6: Intellectual Property License. This program is distributed in the
        !             7: hope that it will be useful, but WITHOUT ANY WARRANTY; without even
        !             8: the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
        !             9: PURPOSE.
        !            10: See W3C License http://www.w3.org/Consortium/Legal/ for more details.
        !            11: */
        !            12: 
        !            13:   function IE5ApplyParserAttributes(parser, attrNames, attrValues) {
        !            14:        if(attrNames != null) {
        !            15:            var i;
        !            16:                for(i = 0; i < attrNames.length; i++) {
        !            17:                        if(attrNames[i] == "expandEntityReferences") {
        !            18:                                if(attrValues[i] == true) {
        !            19:                                        throw "MSXML does not support expanding entity references";
        !            20:                                }
        !            21:                        }
        !            22:                        if(attrNames[i] == "validate") {
        !            23:                                parser.validateOnParse = attrValues[i];
        !            24:                        }
        !            25:                        if(attrNames[i] == "ignoreElementContentWhitespace") {
        !            26:                                parser.preserveWhiteSpace = !attrValues[i];
        !            27:                        }
        !            28:                }
        !            29:         }
        !            30:   }
        !            31: 
        !            32:   function IE5DocumentBuilder_load(sourceURL, willBeModified) {
        !            33:        var actualURL = "file:///d:/domts/2001/DOM-Test-Suite/tests/level1/core/files/" + sourceURL;
        !            34:        if(!this.parser.load(actualURL)) {
        !            35:                throw this.parser.parseError.reason;
        !            36:        }
        !            37:     //
        !            38:     //   if the first child of the document is a PI representing
        !            39:     //      the XML Declaration, remove it from the tree.
        !            40:     //
        !            41:     //   According to the DOM FAQ, this behavior is not wrong,
        !            42:     //      but the tests are written assumming that it is not there.
        !            43:     //
        !            44:     var xmlDecl = this.parser.firstChild;
        !            45:     if(xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
        !            46:         this.parser.removeChild(xmlDecl);
        !            47:     }
        !            48:        return this.parser;
        !            49:   }
        !            50: 
        !            51:    function IE5DocumentBuilder_getDOMImplementation() {
        !            52:         return this.parser.domImplementation;
        !            53:    }
        !            54: 
        !            55:   function IE5DocumentBuilder_isDOMExceptionCode(ex, code) {
        !            56:        var retval = false;
        !            57:        if(code == 7) {
        !            58:                retval = (ex.description.search(".*read.*only.*") >= 0);
        !            59:        }
        !            60:        return retval;
        !            61:   }
        !            62: 
        !            63:   function IE5DocumentBuilder_getImplementationAttribute(attr) {
        !            64:     if(attr == "ignoringElementContentWhitespace") {
        !            65:         return !this.parser.preserveWhiteSpace;
        !            66:     }
        !            67:     return false;
        !            68:   }
        !            69: 
        !            70:   function IE5DocumentBuilder(attrNames, attrValues) {
        !            71:     this.attrNames = attrNames;
        !            72:     this.attrValues = attrValues;
        !            73:     this.load = IE5DocumentBuilder_load;
        !            74:     this.isDOMExceptionCode = IE5DocumentBuilder_isDOMExceptionCode;
        !            75:     this.getDOMImplementation = IE5DocumentBuilder_getDOMImplementation;
        !            76:     this.getImplementationAttribute = IE5DocumentBuilder_getImplementationAttribute;
        !            77:     this.parser = new ActiveXObject("MSXML2.DOMDocument.3.0");
        !            78:     this.parser.async = false;
        !            79:     this.parser.preserveWhiteSpace = true;
        !            80:     IE5ApplyParserAttributes(this.parser,this.attrNames, this.attrValues);    
        !            81:   }
        !            82: 
        !            83:   var IE5DefaultBuilder = new IE5DocumentBuilder(null,null);
        !            84: 
        !            85:   function IE5DocumentBuilderFactory_newDocumentBuilder(attrNames, attrValues) {
        !            86:     if(attrNames == null && attrValues == null) {
        !            87:         return IE5DefaultBuilder;
        !            88:     }
        !            89:     return new IE5DocumentBuilder(attrNames, attrValues);
        !            90:   }
        !            91: 
        !            92:   function IE5DocumentBuilderFactory() {
        !            93:     this.newDocumentBuilder = IE5DocumentBuilderFactory_newDocumentBuilder;
        !            94:   }
        !            95: 
        !            96:   var factory = new IE5DocumentBuilderFactory();
        !            97: 
        !            98:   function assertTrue(descr, actual) {
        !            99:     assert(descr,actual);
        !           100:   }
        !           101: 
        !           102:   function assertFalse(descr, actual) {
        !           103:     assert(descr, !actual);
        !           104:   }
        !           105: 
        !           106:   function assertSize(descr, expected, actual) {
        !           107:     var actualSize;
        !           108:     actualSize = actual.length;
        !           109:     assertEquals(descr, expected, actualSize);
        !           110:   }
        !           111:  
        !           112:   function assertEqualsCollection(descr, expected, actual) {
        !           113:     //
        !           114:     //  if they aren't the same size, they aren't equal
        !           115:     assertEquals(descr, expected.length, actual.length);
        !           116:     //
        !           117:     //  if there length is the same, then every entry in the expected list
        !           118:     //     must appear once and only once in the actual list
        !           119:     var expectedLen = expected.length;
        !           120:     var expectedValue;
        !           121:     var actualLen = actual.length;
        !           122:     var i;
        !           123:     var j;
        !           124:     var matches;
        !           125:     for(i = 0; i < expectedLen; i++) {
        !           126:         matches = 0;
        !           127:         expectedValue = expected[i];
        !           128:         for(j = 0; j < actualLen; j++) {
        !           129:             if(expectedValue == actual[j]) {
        !           130:                 matches++;
        !           131:             }
        !           132:         }
        !           133:         if(matches == 0) {
        !           134:             assert(descr + ": No match found for " + expectedValue,false);
        !           135:         }
        !           136:         if(matches > 1) {
        !           137:             assert(descr + ": Multiple matches found for " + expectedValue, false);
        !           138:         }
        !           139:     }
        !           140:   }
        !           141: 
        !           142: 
        !           143:   function assertEqualsList(descr, expected, actual) {
        !           144:     //
        !           145:     //  if they aren't the same size, they aren't equal
        !           146:     assertEquals(descr, expected.length, actual.length);
        !           147:     //
        !           148:     var actualLen = actual.length;
        !           149:     var i;
        !           150:     for(i = 0; i < actualLen; i++) {
        !           151:         if(expected[i] != actual[i]) {
        !           152:             assertEquals(descr, expected[i], actual[i]);
        !           153:         }
        !           154:     }
        !           155:   }
        !           156: 
        !           157:   function assertInstanceOf(descr, type, obj) {
        !           158:     if(type == "Attr") {
        !           159:         assertEquals(descr,2,obj.nodeType);
        !           160:         var specd = obj.specified;
        !           161:     }
        !           162:   }
        !           163: 
        !           164:   function assertSame(descr, expected, actual) {
        !           165:     if(expected != actual) {
        !           166:         assertEquals(descr, expected.nodeType, actual.nodeType);
        !           167:         assertEquals(descr, expected.nodeValue, actual.nodeValue);
        !           168:     }
        !           169:   }

Webmaster