Annotation of 2001/DOM-Test-Suite/ecmascript/DOMTestCase.js, revision 1.42
1.42 ! dom-ts-4 1: /*
! 2: Copyright (c) 2001-2004 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: function assertSize(descr, expected, actual) {
! 13: var actualSize;
! 14: assertNotNull(descr, actual);
! 15: actualSize = actual.length;
! 16: assertEquals(descr, expected, actualSize);
! 17: }
! 18:
! 19: function assertEqualsAutoCase(context, descr, expected, actual) {
! 20: if (builder.contentType == "text/html") {
! 21: if(context == "attribute") {
! 22: assertEquals(descr, expected.toLowerCase(), actual.toLowerCase());
! 23: } else {
! 24: assertEquals(descr, expected.toUpperCase(), actual);
! 25: }
! 26: } else {
! 27: assertEquals(descr, expected, actual);
! 28: }
! 29: }
! 30:
! 31:
! 32: function assertEqualsCollectionAutoCase(context, descr, expected, actual) {
! 33: //
! 34: // if they aren't the same size, they aren't equal
! 35: assertEquals(descr, expected.length, actual.length);
! 36:
! 37: //
! 38: // if there length is the same, then every entry in the expected list
! 39: // must appear once and only once in the actual list
! 40: var expectedLen = expected.length;
! 41: var expectedValue;
! 42: var actualLen = actual.length;
! 43: var i;
! 44: var j;
! 45: var matches;
! 46: for(i = 0; i < expectedLen; i++) {
! 47: matches = 0;
! 48: expectedValue = expected[i];
! 49: for(j = 0; j < actualLen; j++) {
! 50: if (builder.contentType == "text/html") {
! 51: if (context == "attribute") {
! 52: if (expectedValue.toLowerCase() == actual[j].toLowerCase()) {
! 53: matches++;
! 54: }
! 55: } else {
! 56: if (expectedValue.toUpperCase() == actual[j]) {
! 57: matches++;
! 58: }
! 59: }
! 60: } else {
! 61: if(expectedValue == actual[j]) {
! 62: matches++;
! 63: }
! 64: }
! 65: }
! 66: if(matches == 0) {
! 67: assert(descr + ": No match found for " + expectedValue,false);
! 68: }
! 69: if(matches > 1) {
! 70: assert(descr + ": Multiple matches found for " + expectedValue, false);
! 71: }
! 72: }
! 73: }
! 74:
! 75: function assertEqualsCollection(descr, expected, actual) {
! 76: //
! 77: // if they aren't the same size, they aren't equal
! 78: assertEquals(descr, expected.length, actual.length);
! 79: //
! 80: // if there length is the same, then every entry in the expected list
! 81: // must appear once and only once in the actual list
! 82: var expectedLen = expected.length;
! 83: var expectedValue;
! 84: var actualLen = actual.length;
! 85: var i;
! 86: var j;
! 87: var matches;
! 88: for(i = 0; i < expectedLen; i++) {
! 89: matches = 0;
! 90: expectedValue = expected[i];
! 91: for(j = 0; j < actualLen; j++) {
! 92: if(expectedValue == actual[j]) {
! 93: matches++;
! 94: }
! 95: }
! 96: if(matches == 0) {
! 97: assert(descr + ": No match found for " + expectedValue,false);
! 98: }
! 99: if(matches > 1) {
! 100: assert(descr + ": Multiple matches found for " + expectedValue, false);
! 101: }
! 102: }
! 103: }
! 104:
! 105:
! 106: function assertEqualsListAutoCase(context, descr, expected, actual) {
! 107: var minLength = expected.length;
! 108: if (actual.length < minLength) {
! 109: minLength = actual.length;
! 110: }
! 111: //
! 112: for(var i = 0; i < minLength; i++) {
! 113: assertEqualsAutoCase(context, descr, expected[i], actual[i]);
! 114: }
! 115: //
! 116: // if they aren't the same size, they aren't equal
! 117: assertEquals(descr, expected.length, actual.length);
! 118: }
! 119:
! 120:
! 121: function assertEqualsList(descr, expected, actual) {
! 122: var minLength = expected.length;
! 123: if (actual.length < minLength) {
! 124: minLength = actual.length;
! 125: }
! 126: //
! 127: for(var i = 0; i < minLength; i++) {
! 128: if(expected[i] != actual[i]) {
! 129: assertEquals(descr, expected[i], actual[i]);
! 130: }
! 131: }
! 132: //
! 133: // if they aren't the same size, they aren't equal
! 134: assertEquals(descr, expected.length, actual.length);
! 135: }
! 136:
! 137: function assertInstanceOf(descr, type, obj) {
! 138: if(type == "Attr") {
! 139: assertEquals(descr,2,obj.nodeType);
! 140: var specd = obj.specified;
! 141: }
! 142: }
! 143:
! 144: function assertSame(descr, expected, actual) {
! 145: if(expected != actual) {
! 146: assertEquals(descr, expected.nodeType, actual.nodeType);
! 147: assertEquals(descr, expected.nodeValue, actual.nodeValue);
! 148: }
! 149: }
! 150:
! 151: function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
! 152: //
! 153: // URI must be non-null
! 154: assertNotNull(assertID, actual);
! 155:
! 156: var uri = actual;
! 157:
! 158: var lastPound = actual.lastIndexOf("#");
! 159: var actualFragment = "";
! 160: if(lastPound != -1) {
! 161: //
! 162: // substring before pound
! 163: //
! 164: uri = actual.substring(0,lastPound);
! 165: actualFragment = actual.substring(lastPound+1);
! 166: }
! 167: if(fragment != null) assertEquals(assertID,fragment, actualFragment);
! 168:
! 169: var lastQuestion = uri.lastIndexOf("?");
! 170: var actualQuery = "";
! 171: if(lastQuestion != -1) {
! 172: //
! 173: // substring before pound
! 174: //
! 175: uri = actual.substring(0,lastQuestion);
! 176: actualQuery = actual.substring(lastQuestion+1);
! 177: }
! 178: if(query != null) assertEquals(assertID, query, actualQuery);
! 179:
! 180: var firstColon = uri.indexOf(":");
! 181: var firstSlash = uri.indexOf("/");
! 182: var actualPath = uri;
! 183: var actualScheme = "";
! 184: if(firstColon != -1 && firstColon < firstSlash) {
! 185: actualScheme = uri.substring(0,firstColon);
! 186: actualPath = uri.substring(firstColon + 1);
! 187: }
! 188:
! 189: if(scheme != null) {
! 190: assertEquals(assertID, scheme, actualScheme);
! 191: }
! 192:
! 193: if(path != null) {
! 194: assertEquals(assertID, path, actualPath);
! 195: }
! 196:
! 197: if(host != null) {
! 198: var actualHost = "";
! 199: if(actualPath.substring(0,2) == "//") {
! 200: var termSlash = actualPath.substring(2).indexOf("/") + 2;
! 201: actualHost = actualPath.substring(0,termSlash);
! 202: }
! 203: assertEquals(assertID, host, actualHost);
! 204: }
! 205:
! 206: if(file != null || name != null) {
! 207: var actualFile = actualPath;
! 208: var finalSlash = actualPath.lastIndexOf("/");
! 209: if(finalSlash != -1) {
! 210: actualFile = actualPath.substring(finalSlash+1);
! 211: }
! 212: if (file != null) {
! 213: assertEquals(assertID, file, actualFile);
! 214: }
! 215: if (name != null) {
! 216: var actualName = actualFile;
! 217: var finalDot = actualFile.lastIndexOf(".");
! 218: if (finalDot != -1) {
! 219: actualName = actualName.substring(0, finalDot);
! 220: }
! 221: assertEquals(assertID, name, actualName);
! 222: }
! 223: }
! 224:
! 225: if(isAbsolute != null) {
! 226: assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
! 227: }
! 228: }
! 229:
! 230:
! 231: // size() used by assertSize element
! 232: function size(collection)
! 233: {
! 234: return collection.length;
! 235: }
! 236:
! 237: function same(expected, actual)
! 238: {
! 239: return expected === actual;
! 240: }
! 241:
! 242: function getSuffix(contentType) {
! 243: switch(contentType) {
! 244: case "text/html":
! 245: return ".html";
! 246:
! 247: case "text/xml":
! 248: return ".xml";
! 249:
! 250: case "application/xhtml+xml":
! 251: return ".xhtml";
! 252:
! 253: case "image/svg+xml":
! 254: return ".svg";
! 255:
! 256: case "text/mathml":
! 257: return ".mml";
! 258: }
! 259: return ".html";
! 260: }
! 261:
! 262: function equalsAutoCase(context, expected, actual) {
! 263: if (builder.contentType == "text/html") {
! 264: if (context == "attribute") {
! 265: return expected.toLowerCase() == actual;
! 266: }
! 267: return expected.toUpperCase() == actual;
! 268: }
! 269: return expected == actual;
! 270: }
! 271:
! 272: function catchInitializationError(blder, ex) {
! 273: blder.initializationError = ex;
! 274: blder.initializationFatalError = ex;
! 275: }
! 276:
! 277: function checkInitialization(blder, testname) {
! 278: if (blder.initializationError != null) {
! 279: if (blder.skipIncompatibleTests) {
! 280: info(testname + " not run:" + blder.initializationError);
! 281: return blder.initializationError;
! 282: } else {
! 283: //
! 284: // if an exception was thrown
! 285: // rethrow it and do not run the test
! 286: if (blder.initializationFatalError != null) {
! 287: throw blder.initializationFatalError;
! 288: } else {
! 289: //
! 290: // might be recoverable, warn but continue the test
! 291: warn(testname + ": " + blder.initializationError);
! 292: }
! 293: }
! 294: }
! 295: return null;
! 296: }
! 297: function createTempURI(scheme) {
! 298: if (scheme == "http") {
! 299: return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() * 100000) + ".xml";
! 300: }
! 301: return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml";
! 302: }
! 303:
! 304:
! 305: function EventMonitor() {
! 306: this.atEvents = new Array();
! 307: this.bubbledEvents = new Array();
! 308: this.capturedEvents = new Array();
! 309: this.allEvents = new Array();
! 310: }
! 311:
! 312: EventMonitor.prototype.handleEvent = function(evt) {
! 313: switch(evt.eventPhase) {
! 314: case 1:
! 315: monitor.capturedEvents[monitor.capturedEvents.length] = evt;
! 316: break;
! 317:
! 318: case 2:
! 319: monitor.atEvents[monitor.atEvents.length] = evt;
! 320: break;
! 321:
! 322: case 3:
! 323: monitor.bubbledEvents[monitor.bubbledEvents.length] = evt;
! 324: break;
! 325: }
! 326: monitor.allEvents[monitor.allEvents.length] = evt;
! 327: }
! 328:
! 329: function DOMErrorImpl(err) {
! 330: this.severity = err.severity;
! 331: this.message = err.message;
! 332: this.type = err.type;
! 333: this.relatedException = err.relatedException;
! 334: this.relatedData = err.relatedData;
! 335: this.location = err.location;
! 336: }
! 337:
! 338:
! 339:
! 340: function DOMErrorMonitor() {
! 341: this.allErrors = new Array();
! 342: }
! 343:
! 344: DOMErrorMonitor.prototype.handleError = function(err) {
! 345: errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err);
! 346: }
! 347:
! 348: DOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) {
! 349: var i;
! 350: for (i = 0; i < errorMonitor.allErrors.length; i++) {
! 351: if (errorMonitor.allErrors[i].severity >= severity) {
! 352: assertEquals(id, severity - 1, errorMonitor.allErrors[i].severity);
! 353: }
! 354: }
! 355: }
! 356:
! 357: function UserDataNotification(operation, key, data, src, dst) {
! 358: this.operation = operation;
! 359: this.key = key;
! 360: this.data = data;
! 361: this.src = src;
! 362: this.dst = dst;
! 363: }
! 364:
! 365: function UserDataMonitor() {
! 366: this.allNotifications = new Array();
! 367: }
! 368:
! 369: UserDataMonitor.prototype.handle = function(operation, key, data, src, dst) {
! 370: userDataMonitor.allNotifications[this.allNotifications.length] =
! 371: new UserDataNotification(operation, key, data, src, dst);
! 372: }
! 373:
! 374:
! 375:
! 376: function IFrameBuilder() {
! 377: this.contentType = "text/html";
! 378: this.supportedContentTypes = [ "text/html",
! 379: "text/xml",
! 380: "image/svg+xml",
! 381: "application/xhtml+xml" ];
! 382:
! 383: this.supportsAsyncChange = false;
! 384: this.async = true;
! 385: this.fixedAttributeNames = [
! 386: "validating", "expandEntityReferences", "coalescing",
! 387: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments", "schemaValidating"];
! 388:
! 389: this.fixedAttributeValues = [false, true, false, true, true , false, false, true, false ];
! 390: this.configurableAttributeNames = [ ];
! 391: this.configurableAttributeValues = [ ];
! 392: this.initializationError = null;
! 393: this.initializationFatalError = null;
! 394: this.skipIncompatibleTests = false;
! 395: }
! 396:
! 397: IFrameBuilder.prototype.hasFeature = function(feature, version) {
! 398: return document.implementation.hasFeature(feature, version);
! 399: }
! 400:
! 401: IFrameBuilder.prototype.getImplementation = function() {
! 402: return document.implementation;
! 403: }
! 404:
! 405: IFrameBuilder.prototype.setContentType = function(contentType) {
! 406: this.contentType = contentType;
! 407: if (contentType == "text/html") {
! 408: this.fixedAttributeValues[6] = false;
! 409: } else {
! 410: this.fixedAttributeValues[6] = true;
! 411: }
! 412: }
! 413:
! 414:
! 415:
! 416: IFrameBuilder.prototype.preload = function(frame, varname, url) {
! 417: if (this.contentType == "text/html" || this.contentType == "application/xhtml+xml") {
! 418: if (url.substring(0,5) == "staff" || url == "nodtdstaff" || url == "datatype_normalization") {
! 419: throw "Tests using staff or nodtdstaff are not supported by HTML processors";
! 420: }
! 421: }
! 422: var iframe = document.createElement("iframe");
! 423: var srcname = url + getSuffix(this.contentType);
! 424: iframe.setAttribute("name", srcname);
! 425: iframe.setAttribute("src", fileBase + srcname);
! 426: //
! 427: // HTML and XHTML have onload attributes that will invoke loadComplete
! 428: //
! 429: if (this.contentType != "text/html" && this.contentType != "application/xhtml+xml") {
! 430: iframe.addEventListener("load", loadComplete, false);
! 431: }
! 432: document.getElementsByTagName("body").item(0).appendChild(iframe);
! 433: return 0;
! 434: }
! 435:
! 436: IFrameBuilder.prototype.load = function(frame, varname, url) {
! 437: if (this.contentType == "text/html") {
! 438: return frame.document;
! 439: }
! 440: var name = url + getSuffix(this.contentType);
! 441: var iframes = document.getElementsByTagName("iframe");
! 442: for(var i = 0; i < iframes.length; i++) {
! 443: if (iframes.item(i).getAttribute("name") == name) {
! 444: var item = iframes.item(i);
! 445: if (typeof(item.contentDocument) != 'undefined') {
! 446: return item.contentDocument;
! 447: }
! 448: if (typeof(item.document) != 'undefined') {
! 449: return item.document;
! 450: }
! 451: return null;
! 452: }
! 453: }
! 454: return null;
! 455: }
! 456:
! 457: IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
! 458: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
! 459: if (this.fixedAttributeNames[i] == attr) {
! 460: return this.fixedAttributeValues[i];
! 461: }
! 462: }
! 463: throw "Unrecognized implementation attribute: " + attr;
! 464: }
! 465:
! 466:
! 467:
! 468: IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
! 469: var supported = this.getImplementationAttribute(attribute);
! 470: if (supported != value) {
! 471: this.initializationError = "IFrame loader does not support " + attribute + "=" + value;
! 472: }
! 473: }
! 474:
! 475:
! 476: IFrameBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 477: var supported = this.getImplementationAttribute(attribute);
! 478: return (supported == value);
! 479: }
! 480:
! 481:
! 482:
! 483: function SVGPluginBuilder() {
! 484: this.contentType = "image/svg+xml";
! 485: this.supportedContentTypes = [ "image/svg+xml" ];
! 486:
! 487: this.supportsAsyncChange = false;
! 488: this.async = true;
! 489: this.fixedAttributeNames = [
! 490: "validating", "expandEntityReferences", "coalescing",
! 491: "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments" , "schemaValidating"];
! 492:
! 493: this.fixedAttributeValues = [false, true, false, true, true , false, true, false, false ];
! 494: this.configurableAttributeNames = [ ];
! 495: this.configurableAttributeValues = [ ];
! 496: this.initializationError = null;
! 497: this.initializationFatalError = null;
! 498: this.skipIncompatibleTests = false;
! 499: }
! 500:
! 501: SVGPluginBuilder.prototype.hasFeature = function(feature, version) {
! 502: if (feature == "XML") {
! 503: if (version == null || version == "1.0" || version == "2.0") {
! 504: return true;
! 505: }
! 506: }
! 507: return false;
! 508: }
! 509:
! 510: SVGPluginBuilder.prototype.setContentType = function(contentType) {
! 511: this.contentType = contentType;
! 512: }
! 513:
! 514: SVGPluginBuilder.prototype.getImplementation = function() {
! 515: var embed = document.createElement("embed");
! 516: embed.src = fileBase + url + getSuffix(this.contentType);
! 517: embed.height = 100;
! 518: embed.width = 100;
! 519: embed.type = "image/svg+xml";
! 520: embed.id = varname;
! 521: var child = document.documentElement.firstChild;
! 522: while(child != null) {
! 523: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
! 524: child.appendChild(embed);
! 525: return child.getSVGDocument.implementation;
! 526: }
! 527: child = child.nextSibling;
! 528: }
! 529: return null;
! 530: }
! 531:
! 532: var svgloadcount = 0;
! 533: function SVGPluginBuilder_pollreadystate() {
! 534: var newCount = 0;
! 535: var child = document.documentElement.firstChild;
! 536: while(child != null) {
! 537: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
! 538: var grand = child.firstChild;
! 539: while (grand != null) {
! 540: if (grand.nodeName.toUpperCase() == 'EMBED' && grand.readystate == 4) {
! 541: newCount++;
! 542: }
! 543: grand = grand.nextSibling;
! 544: }
! 545: break;
! 546: }
! 547: child = child.nextSibling;
! 548: }
! 549: if (newCount > svgloadcount) {
! 550: svgloadcount++;
! 551: loadComplete();
! 552: if (setUpPageStatus == 'complete') {
! 553: return;
! 554: }
! 555: }
! 556: setTimeout(SVGPluginBuilder_pollreadystate, 100);
! 557: }
! 558:
! 559: SVGPluginBuilder.prototype.preload = function(frame, varname, url) {
! 560: var embed = document.createElement("embed");
! 561: embed.src = fileBase + url + getSuffix(this.contentType);
! 562: embed.height = 100;
! 563: embed.width = 100;
! 564: embed.type = "image/svg+xml";
! 565: embed.id = varname;
! 566: var child = document.documentElement.firstChild;
! 567: while(child != null) {
! 568: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
! 569: child.appendChild(embed);
! 570: break;
! 571: }
! 572: child = child.nextSibling;
! 573: }
! 574: //
! 575: // if unable to monitor ready state change then
! 576: // check if load is complete every in 0.1 second
! 577: setTimeout(SVGPluginBuilder_pollreadystate , 100);
! 578: return 0;
! 579: }
! 580:
! 581: SVGPluginBuilder.prototype.load = function(frame, varname, url) {
! 582: var child = document.documentElement.firstChild;
! 583: while(child != null) {
! 584: if (child.nodeName != null && child.nodeName.toUpperCase() == "BODY") {
! 585: var grand = child.firstChild;
! 586: while (grand != null) {
! 587: if (grand.id == varname) {
! 588: return grand.getSVGDocument();
! 589: }
! 590: grand = grand.nextSibling;
! 591: }
! 592: }
! 593: child = child.nextSibling;
! 594: }
! 595: return null;
! 596: }
! 597:
! 598: SVGPluginBuilder.prototype.getImplementationAttribute = function(attr) {
! 599: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
! 600: if (this.fixedAttributeNames[i] == attr) {
! 601: return this.fixedAttributeValues[i];
! 602: }
! 603: }
! 604: throw "Unrecognized implementation attribute: " + attr;
! 605: }
! 606:
! 607:
! 608: SVGPluginBuilder.prototype.setImplementationAttribute = function(attribute, value) {
! 609: var supported = this.getImplementationAttribute(attribute);
! 610: if (supported != value) {
! 611: this.initializationError = "SVG Plugin loader does not support " + attribute + "=" + value;
! 612: }
! 613: }
! 614:
! 615: SVGPluginBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 616: var supported = this.getImplementationAttribute(attribute);
! 617: return (supported == value);
! 618: }
! 619:
! 620:
! 621:
! 622:
! 623: function MSXMLBuilder(progID) {
! 624: this.progID = progID;
! 625: this.configurableAttributeNames = [
! 626: "validating", "ignoringElementContentWhitespace"];
! 627: this.configurableAttributeValues = [ false, false ];
! 628: this.fixedAttributeNames = [ "signed", "hasNullString",
! 629: "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments", "schemaValidating" ];
! 630: this.fixedAttributeValues = [ true, true, false, false, false, false, false ];
! 631:
! 632: this.contentType = "text/xml";
! 633: this.supportedContentTypes = [
! 634: "text/xml",
! 635: "image/svg+xml",
! 636: "application/xhtml+xml",
! 637: "text/mathml" ];
! 638:
! 639: this.async = false;
! 640: this.supportsAsyncChange = true;
! 641: this.parser = null;
! 642: this.initializationError = null;
! 643: this.initializationFatalError = null;
! 644: this.skipIncompatibleTests = false;
! 645: }
! 646:
! 647: MSXMLBuilder.prototype.createMSXML = function() {
! 648: var parser = new ActiveXObject(this.progID);
! 649: parser.async = this.async;
! 650: parser.preserveWhiteSpace = !this.configurableAttributeValues[1];
! 651: parser.validateOnParse = this.configurableAttributeValues[0];
! 652: return parser;
! 653: }
! 654:
! 655: MSXMLBuilder.prototype.setContentType = function(contentType) {
! 656: this.contentType = contentType;
! 657: }
! 658:
! 659:
! 660: MSXMLBuilder.prototype.preload = function(frame, varname, url) {
! 661: if (this.async) {
! 662: this.parser = this.createMSXML();
! 663: parser.async = true;
! 664: parser.onreadystatechange = MSXMLBuilder_onreadystatechange;
! 665: parser.load(fileBase + url + getSuffix(this.contentType));
! 666: if (parser.readystate != 4) {
! 667: return 0;
! 668: }
! 669: }
! 670: return 1;
! 671: }
! 672:
! 673: MSXMLBuilder.prototype.load = function(frame, varname, url) {
! 674: var parser = this.createMSXML();
! 675: if(!parser.load(fileBase + url + getSuffix(this.contentType))) {
! 676: throw parser.parseError.reason;
! 677: }
! 678: //
! 679: // if the first child of the document is a PI representing
! 680: // the XML Declaration, remove it from the tree.
! 681: //
! 682: // According to the DOM FAQ, this behavior is not wrong,
! 683: // but the tests are written assuming that it is not there.
! 684: //
! 685: var xmlDecl = parser.firstChild;
! 686: if(xmlDecl != null && xmlDecl.nodeType == 7 && xmlDecl.target.toLowerCase() == "xml") {
! 687: parser.removeChild(xmlDecl);
! 688: }
! 689: return parser;
! 690: }
! 691:
! 692: MSXMLBuilder.prototype.getImplementationAttribute = function(attr) {
! 693: var i;
! 694: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 695: if (this.fixedAttributeNames[i] == attr) {
! 696: return this.fixedAttributeValues[i];
! 697: }
! 698: }
! 699:
! 700: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 701: if (this.configurableAttributeNames[i] == attr) {
! 702: return this.configurableAttributeValues[i];
! 703: }
! 704: }
! 705:
! 706: throw "Unrecognized implementation attribute: " + attr;
! 707: }
! 708:
! 709:
! 710: MSXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
! 711: var i;
! 712: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 713: if (this.fixedAttributeNames[i] == attribute) {
! 714: if (this.fixedAttributeValues[i] != value) {
! 715: this.initializationError = "MSXML does not support " + attribute + "=" + value;
! 716: }
! 717: return;
! 718: }
! 719: }
! 720: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 721: if (this.configurableAttributeNames[i] == attribute) {
! 722: this.configurableAttributeValues[i] = value;
! 723: return;
! 724: }
! 725: }
! 726: this.initializationError = "Unrecognized implementation attribute: " + attr;
! 727: }
! 728:
! 729:
! 730: MSXMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 731: var i;
! 732: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 733: if (this.fixedAttributeNames[i] == attribute) {
! 734: return (this.fixedAttributeValues[i] == value);
! 735: }
! 736: }
! 737: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 738: if (this.configurableAttributeNames[i] == attribute) {
! 739: return true;
! 740: }
! 741: }
! 742: return false;
! 743: }
! 744:
! 745:
! 746: MSXMLBuilder.prototype.getImplementation = function() {
! 747: var doc = this.CreateMSXML();
! 748: return doc.implementation;
! 749: }
! 750:
! 751: //
! 752: // Only used to select tests compatible with implementation
! 753: // not used on tests that actually test hasFeature()
! 754: //
! 755: MSXMLBuilder.prototype.hasFeature = function(feature, version) {
! 756: //
! 757: // MSXML will take null, unfortunately
! 758: // there is no way to get it to there from script
! 759: // without a type mismatch error
! 760: if(version == null) {
! 761: switch(feature.toUpperCase()) {
! 762: case "XML":
! 763: case "CORE":
! 764: return true;
! 765:
! 766: case "HTML":
! 767: case "ORG.W3C.DOM":
! 768: return false;
! 769: }
! 770: if(this.getDOMImplementation().hasFeature(feature,"1.0")) {
! 771: return true;
! 772: }
! 773: if(this.getDOMImplementation().hasFeature(feature,"2.0")) {
! 774: return true;
! 775: }
! 776: if(this.getDOMImplementation().hasFeature(feature,"3.0")) {
! 777: return true;
! 778: }
! 779: }
! 780: return this.getDOMImplementation().hasFeature(feature,version);
! 781: }
! 782:
! 783:
! 784:
! 785: function MozillaXMLBuilder() {
! 786: this.contentType = "text/xml";
! 787:
! 788: this.configurableAttributeNames = [ ];
! 789: this.configurableAttributeValues = [ ];
! 790: this.fixedAttributeNames = [ "validating", "ignoringElementContentWhitespace", "signed",
! 791: "hasNullString", "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments", "schemaValidating" ];
! 792: this.fixedAttributeValues = [ false, false, true, true, false, false, false, false, false ];
! 793:
! 794: this.contentType = "text/xml";
! 795: this.supportedContentTypes = [
! 796: "text/xml",
! 797: "image/svg+xml",
! 798: "application/xhtml+xml",
! 799: "text/mathml" ];
! 800:
! 801: this.async = true;
! 802: this.supportsAsyncChange = false;
! 803:
! 804: this.docs = new Array();
! 805: this.docnames = new Array();
! 806: this.initializationError = null;
! 807: this.initializationFatalError = null;
! 808: this.skipIncompatibleTests = false;
! 809: }
! 810:
! 811: MozillaXMLBuilder.prototype.getImplementation = function() {
! 812: return document.implementation;
! 813: }
! 814:
! 815: MozillaXMLBuilder.prototype.setContentType = function(contentType) {
! 816: this.contentType = contentType;
! 817: }
! 818:
! 819:
! 820:
! 821: MozillaXMLBuilder.prototype.preload = function(frame, varname, url) {
! 822: var domimpl = document.implementation;
! 823: var doc = domimpl.createDocument("", "temp", null);
! 824: doc.addEventListener("load", loadComplete, false);
! 825: doc.load(fileBase + url + getSuffix(this.contentType));
! 826: this.docs[this.docs.length] = doc;
! 827: this.docnames[this.docnames.length] = varname;
! 828: return 0;
! 829: }
! 830:
! 831: MozillaXMLBuilder.prototype.load = function(frame, varname, url) {
! 832: for(i = 0; i < this.docnames.length; i++) {
! 833: if (this.docnames[i] == varname) {
! 834: return this.docs[i];
! 835: }
! 836: }
! 837: return null;
! 838: }
! 839:
! 840:
! 841: MozillaXMLBuilder.prototype.getImplementationAttribute = function(attr) {
! 842: for (var i = 0; i < this.fixedAttributeNames.length; i++) {
! 843: if (this.fixedAttributeNames[i] == attr) {
! 844: return this.fixedAttributeValues[i];
! 845: }
! 846: }
! 847: return false;
! 848: }
! 849:
! 850:
! 851: MozillaXMLBuilder.prototype.hasFeature = function(feature, version)
! 852: {
! 853: return this.getImplementation().hasFeature(feature, version);
! 854: }
! 855:
! 856: MozillaXMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
! 857: var supported = this.getImplementationAttribute(attribute);
! 858: if (supported != value) {
! 859: this.initializationError = "Mozilla XML loader does not support " + attribute + "=" + value;
! 860: }
! 861: }
! 862:
! 863:
! 864: MozillaXMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
! 865: var supported = this.getImplementationAttribute(attribute);
! 866: return (supported == value);
! 867: }
! 868:
! 869: function DOM3LSBuilder() {
! 870: this.contentType = "text/xml";
! 871:
! 872: this.fixedAttributeNames = [ signed, "hasNullString" ];
! 873: this.fixedAttributeValues = [ true, true ];
! 874: this.configurableAttributeNames = [ "validating", "ignoringElementContentWhitespace",
! 875: "expandEntityReferences", "coalescing", "namespaceAware", "ignoringComments", "schemaValidating" ];
! 876: this.configurableAttributeValues = [ false, false, true, true, false, false, true, false, false ];
! 877: this.domConfigNames = [ "validate", "element-content-whitespace",
! 878: "entities", "cdata-sections", "namespaces", "comments", "validate" ];
! 879: this.domConfigSense = [ true, false, false, false, true, false, true ];
! 880:
! 881: this.contentType = "text/xml";
! 882: this.supportedContentTypes = [
! 883: "text/xml",
! 884: "image/svg+xml",
! 885: "application/xhtml+xml",
! 886: "text/mathml" ];
! 887:
! 888: this.async = false;
! 889: this.supportsAsyncChange = true;
! 890:
! 891: this.docs = new Array();
! 892: this.docnames = new Array();
! 893: this.lsparser = null;
! 894: this.initializationError = null;
! 895: this.initializationFatalError = null;
! 896: this.skipIncompatibleTests = false;
! 897: }
! 898:
! 899: DOM3LSBuilder.prototype.getImplementation = function() {
! 900: return document.implementation;
! 901: }
! 902:
! 903:
! 904: DOM3LSBuilder.prototype.setContentType = function(contentType) {
! 905: this.contentType = contentType;
! 906: }
! 907:
! 908: DOM3LSBuilder.prototype.preload = function(frame, varname, url) {
! 909: if (!this.async) {
! 910: return 1;
! 911: }
! 912: var domimpl = document.implementation;
! 913: this.lsparser = domimpl.createLSParser(2, null);
! 914: this.lsparser.addEventListener("load", loadComplete, false);
! 915: var uri = fileBase + url + getSuffix(this.contentType);
! 916: var doc = this.lsparser.parseURI(uri);
! 917: this.docs[this.docs.length] = doc;
! 918: this.docnames[this.docnames.length] = varname;
! 919: return 0;
! 920: }
! 921:
! 922: DOM3LSBuilder.prototype.load = function(frame, varname, url) {
! 923: if (this.async) {
! 924: for(i = 0; i < this.docnames.length; i++) {
! 925: if (this.docnames[i] == varname) {
! 926: return this.docs[i];
! 927: }
! 928: }
! 929: return null;
! 930: }
! 931: this.lsparser = document.implementation.createLSParser(1, null);
! 932: var uri = fileBase + url + getSuffix(this.contentType);
! 933: return this.lsparser.parseURI(uri);
! 934: }
! 935:
! 936:
! 937: DOM3LSBuilder.prototype.getImplementationAttribute = function(attr) {
! 938: if (attr == "schemaValidating") {
! 939: return (this.lsparser.domConfig.getParameter("validate") &&
! 940: this.lsparser.domConfig.getParameter("schema-type") ==
! 941: "http://www.w3.org/2001/XMLSchema");
! 942: }
! 943: var i;
! 944: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 945: if (this.fixedAttributeNames[i] == attr) {
! 946: return this.fixedAttributeValues[i];
! 947: }
! 948: }
! 949: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 950: if (this.configurableAttributeNames[i] == attr) {
! 951: if(this.lsparser.domConfig.getParameter(this.domConfigNames[i])) {
! 952: return this.domConfigSense[i];
! 953: } else {
! 954: return !this.domConfigSense[i];
! 955: }
! 956: }
! 957: }
! 958: throw "unrecognized implementation attribute " + att;
! 959: }
! 960:
! 961: DOM3LSBuilder.prototype.hasFeature = function(feature, version) {
! 962: return document.implementation.hasFeature(feature, version);
! 963: }
! 964:
! 965:
! 966: DOM3LSBuilder.prototype.setImplementationAttribute = function(attr, value) {
! 967: if (attr == "schemaValidating") {
! 968: this.lsparser.domConfig.setParameter("validate", true);
! 969: this.lsparser.domConfig.setParameter("schema-type",
! 970: "http://www.w3.org/2001/XMLSchema");
! 971: return;
! 972: }
! 973: var i;
! 974: for (i = 0; i < this.fixedAttributeNames.length; i++) {
! 975: if (this.fixedAttributeNames[i] == attr) {
! 976: if (value != this.fixedAttributeValue) {
! 977: this.initializationError = "DOM3LS does not support " + attribute + " = " + value;
! 978: return;
! 979: }
! 980: }
! 981: }
! 982: for (i = 0; i < this.configurableAttributeNames.length; i++) {
! 983: if (this.configurableAttributeNames[i] == attr) {
! 984: if (this.domConfigSense[i]) {
! 985: this.lsparser.domConfig.setParameter(this.domConfigNames[i], value);
! 986: } else {
! 987: this.lsparser.domConfig.setParameter(this.domConfigNames[i], !value);
! 988: }
! 989: return;
! 990: }
! 991: }
! 992: throw "Unrecognized configuration attribute " + attr;
! 993: }
! 994:
! 995:
! 996:
! 997: function createBuilder(implementation) {
! 998: if (implementation == null) {
! 999: return new IFrameBuilder();
! 1000: }
! 1001: switch(implementation) {
! 1002: case "msxml3":
! 1003: return new MSXMLBuilder("Msxml2.DOMDocument.3.0");
! 1004:
! 1005: case "msxml4":
! 1006: return new MSXMLBuilder("Msxml2.DOMDocument.4.0");
! 1007:
! 1008: case "mozillaXML":
! 1009: return new MozillaXMLBuilder();
! 1010:
! 1011: case "svgplugin":
! 1012: return new SVGPluginBuilder();
! 1013:
! 1014: case "dom3ls":
! 1015: return new DOM3LSBuilder();
! 1016:
! 1017: case "iframe":
! 1018: return new IFrameBuilder();
! 1019:
! 1020: default:
! 1021: alert ("unrecognized implementation " + implementation);
! 1022: }
! 1023: return new IFrameBuilder();
! 1024: }
! 1025:
! 1026: function checkFeature(feature, version)
! 1027: {
! 1028: if (!builder.hasFeature(feature, version))
! 1029: {
! 1030: //
! 1031: // don't throw exception so that users can select to ignore the precondition
! 1032: //
! 1033: builder.initializationError = "builder does not support feature " + feature + " version " + version;
! 1034: }
! 1035: }
! 1036:
! 1037: function createConfiguredBuilder() {
! 1038: var builder = null;
! 1039: var contentType = null;
! 1040: var i;
! 1041: var contentTypeSet = false;
! 1042: var parm = null;
! 1043: if (top && typeof(top.jsUnitParmHash) != 'undefined') {
! 1044: builder = createBuilder(top.jsUnitGetParm('implementation'));
! 1045:
! 1046: parm = top.jsUnitGetParm("skipincompatibletests");
! 1047: if (parm) {
! 1048: if (parm == 'true') {
! 1049: builder.skipIncompatibleTests = true;
! 1050: } else {
! 1051: builder.skipIncompatibleTests = false;
! 1052: }
! 1053: }
! 1054:
! 1055: if (top.jsUnitGetParm('asynchronous') == 'true' && builder.supportAsync) {
! 1056: builder.async = true;
! 1057: }
! 1058: if (top.jsUnitGetParm('expandentityreferences')) {
! 1059: if (top.jsUnitGetParm('expandEntityReferences') == 'true') {
! 1060: builder.setImplementationAttribute('expandEntityReferences', true);
! 1061: } else {
! 1062: builder.setImplementationAttribute('expandEntityReferences', false);
! 1063: }
! 1064: }
! 1065: if (top.jsUnitGetParm('ignoringelementcontentwhitespace')) {
! 1066: if (top.jsUnitGetParm('ignoringElementContentWhitespace') == 'true') {
! 1067: builder.setImplementationAttribute('ignoringElementContentWhitespace', true);
! 1068: } else {
! 1069: builder.setImplementationAttribute('ignoringElementContentWhitespace', false);
! 1070: }
! 1071: }
! 1072: if (top.jsUnitGetParm('validating')) {
! 1073: if (top.jsUnitGetParm('validating') == 'true') {
! 1074: builder.setImplementationAttribute('validating', true);
! 1075: } else {
! 1076: builder.setImplementationAttribute('validating', false);
! 1077: }
! 1078: }
! 1079: if (top.jsUnitGetParm('coalescing')) {
! 1080: if (top.jsUnitGetParm('coalescing') == 'true') {
! 1081: builder.setImplementationAttribute('coalescing', true);
! 1082: } else {
! 1083: builder.setImplementationAttribute('coalescing', false);
! 1084: }
! 1085: }
! 1086: if (top.jsUnitGetParm('namespaceaware')) {
! 1087: if (top.jsUnitGetParm('namespaceaware') == 'true') {
! 1088: builder.setImplementationAttribute('namespaceAware', true);
! 1089: } else {
! 1090: builder.setImplementationAttribute('namespaceAware', false);
! 1091: }
! 1092: }
! 1093: contentType = top.jsUnitGetParm('contenttype');
! 1094: if (contentType != null) {
! 1095: contentTypeSet = false;
! 1096: for (i = 0; i < builder.supportedContentTypes.length; i++) {
! 1097: if (builder.supportedContentTypes[i] == contentType) {
! 1098: builder.setContentType(contentType);
! 1099: contentTypeSet = true;
! 1100: break;
! 1101: }
! 1102: }
! 1103: if (!contentTypeSet) {
! 1104: this.exception = "Builder does not support content type " + contentType;
! 1105: }
! 1106: }
! 1107: if (top.jsUnitGetParm('ignoringcomments')) {
! 1108: if (top.jsUnitGetParm('ignoringcomments') == 'true') {
! 1109: builder.setImplementationAttribute('ignoringComments', true);
! 1110: } else {
! 1111: builder.setImplementationAttribute('ignoringComments', false);
! 1112: }
! 1113: }
! 1114: } else {
! 1115: builder = new IFrameBuilder();
! 1116: }
! 1117: return builder;
! 1118: }
! 1119:
! 1120:
! 1121: function preload(frame, varname, url) {
! 1122: return builder.preload(frame, varname, url);
! 1123: }
! 1124:
! 1125: function load(frame, varname, url) {
! 1126: return builder.load(frame, varname, url);
! 1127: }
! 1128:
! 1129: function getImplementationAttribute(attr) {
! 1130: return builder.getImplementationAttribute(attr);
! 1131: }
! 1132:
! 1133:
! 1134: function setImplementationAttribute(attribute, value) {
! 1135: builder.setImplementationAttribute(attribute, value);
! 1136: }
! 1137:
! 1138: function createXPathEvaluator(doc) {
! 1139: try {
! 1140: return doc.getFeature("XPath", null);
! 1141: }
! 1142: catch(ex) {
! 1143: }
! 1144: return doc;
! 1145: }
! 1146:
! 1147: function toLowerArray(src) {
! 1148: var newArray = new Array();
! 1149: var i;
! 1150: for (i = 0; i < src.length; i++) {
! 1151: newArray[i] = src[i].toLowerCase();
! 1152: }
! 1153: return newArray;
! 1154: }
! 1155:
! 1156: function MSXMLBuilder_onreadystatechange() {
! 1157: if (builder.parser.readyState == 4) {
! 1158: loadComplete();
! 1159: }
! 1160: }
! 1161:
! 1162:
! 1163: var fileBase = location.href;
! 1164: if (fileBase.indexOf('?') != -1) {
! 1165: fileBase = fileBase.substring(0, fileBase.indexOf('?'));
! 1166: }
! 1167: fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
! 1168:
! 1169: function getImplementation() {
! 1170: return builder.getImplementation();
! 1171: }
! 1172:
Webmaster