dom/tests/mochitest/dom-level2-core/DOMTestCase.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 Copyright (c) 2001-2005 World Wide Web Consortium,
michael@0 3 (Massachusetts Institute of Technology, Institut National de
michael@0 4 Recherche en Informatique et en Automatique, Keio University). All
michael@0 5 Rights Reserved. This program is distributed under the W3C's Software
michael@0 6 Intellectual Property License. This program is distributed in the
michael@0 7 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
michael@0 8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
michael@0 9 PURPOSE.
michael@0 10 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
michael@0 11 */
michael@0 12
michael@0 13 function assertNull(descr, actual) {
michael@0 14 return ok(actual === null, descr);
michael@0 15 }
michael@0 16
michael@0 17
michael@0 18 function assertNotNull(descr, actual) {
michael@0 19 return ok(actual !== null, descr);
michael@0 20 }
michael@0 21
michael@0 22 function assertTrue(descr, actual) {
michael@0 23 return ok(actual === true, descr);
michael@0 24 }
michael@0 25
michael@0 26 function assertFalse(descr, actual) {
michael@0 27 return ok(actual === false, descr);
michael@0 28 }
michael@0 29
michael@0 30 function assertEquals(descr, expected, actual) {
michael@0 31 return is(expected, actual, descr);
michael@0 32 }
michael@0 33
michael@0 34 function assertSize(descr, expected, actual) {
michael@0 35 ok(actual !== null, descr);
michael@0 36 /*
michael@0 37 // Work around too strict checks.
michael@0 38 if (!actual) {
michael@0 39 ok(actual, "[assertSize()] 'actual' has a value");
michael@0 40 return;
michael@0 41 }
michael@0 42 */
michael@0 43
michael@0 44 is(actual.length, expected, descr);
michael@0 45 }
michael@0 46
michael@0 47 function assertEqualsAutoCase(context, descr, expected, actual) {
michael@0 48 if (builder.contentType == "text/html") {
michael@0 49 if(context == "attribute") {
michael@0 50 is(actual.toLowerCase(), expected.toLowerCase(), descr);
michael@0 51 } else {
michael@0 52 is(actual, expected.toUpperCase(), descr);
michael@0 53 }
michael@0 54 } else {
michael@0 55 is(expected, actual, descr);
michael@0 56 }
michael@0 57 }
michael@0 58
michael@0 59
michael@0 60 function assertEqualsCollectionAutoCase(context, descr, expected, actual) {
michael@0 61 //
michael@0 62 // if they aren't the same size, they aren't equal
michael@0 63 is(actual.length, expected.length, descr);
michael@0 64
michael@0 65 //
michael@0 66 // if there length is the same, then every entry in the expected list
michael@0 67 // must appear once and only once in the actual list
michael@0 68 var expectedLen = expected.length;
michael@0 69 var expectedValue;
michael@0 70 var actualLen = actual.length;
michael@0 71 var i;
michael@0 72 var j;
michael@0 73 var matches;
michael@0 74 for(i = 0; i < expectedLen; i++) {
michael@0 75 matches = 0;
michael@0 76 expectedValue = expected[i];
michael@0 77 for(j = 0; j < actualLen; j++) {
michael@0 78 if (builder.contentType == "text/html") {
michael@0 79 if (context == "attribute") {
michael@0 80 if (expectedValue.toLowerCase() == actual[j].toLowerCase()) {
michael@0 81 matches++;
michael@0 82 }
michael@0 83 } else {
michael@0 84 if (expectedValue.toUpperCase() == actual[j]) {
michael@0 85 matches++;
michael@0 86 }
michael@0 87 }
michael@0 88 } else {
michael@0 89 if(expectedValue == actual[j]) {
michael@0 90 matches++;
michael@0 91 }
michael@0 92 }
michael@0 93 }
michael@0 94 if(matches == 0) {
michael@0 95 ok(false, descr + ": No match found for " + expectedValue);
michael@0 96 }
michael@0 97 if(matches > 1) {
michael@0 98 ok(false, descr + ": Multiple matches found for " + expectedValue);
michael@0 99 }
michael@0 100 }
michael@0 101 }
michael@0 102
michael@0 103 function assertEqualsCollection(descr, expected, actual) {
michael@0 104 //
michael@0 105 // if they aren't the same size, they aren't equal
michael@0 106 is(actual.length, expected.length, descr);
michael@0 107 //
michael@0 108 // if there length is the same, then every entry in the expected list
michael@0 109 // must appear once and only once in the actual list
michael@0 110 var expectedLen = expected.length;
michael@0 111 var expectedValue;
michael@0 112 var actualLen = actual.length;
michael@0 113 var i;
michael@0 114 var j;
michael@0 115 var matches;
michael@0 116 for(i = 0; i < expectedLen; i++) {
michael@0 117 matches = 0;
michael@0 118 expectedValue = expected[i];
michael@0 119 for(j = 0; j < actualLen; j++) {
michael@0 120 if(expectedValue == actual[j]) {
michael@0 121 matches++;
michael@0 122 }
michael@0 123 }
michael@0 124 if(matches == 0) {
michael@0 125 ok(false, descr + ": No match found for " + expectedValue);
michael@0 126 }
michael@0 127 if(matches > 1) {
michael@0 128 ok(false, descr + ": Multiple matches found for " + expectedValue);
michael@0 129 }
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133
michael@0 134 function assertEqualsListAutoCase(context, descr, expected, actual) {
michael@0 135 var minLength = expected.length;
michael@0 136 if (actual.length < minLength) {
michael@0 137 minLength = actual.length;
michael@0 138 }
michael@0 139 //
michael@0 140 for(var i = 0; i < minLength; i++) {
michael@0 141 assertEqualsAutoCase(context, descr, expected[i], actual[i]);
michael@0 142 }
michael@0 143 //
michael@0 144 // if they aren't the same size, they aren't equal
michael@0 145 is(actual.length, expected.length, descr);
michael@0 146 }
michael@0 147
michael@0 148
michael@0 149 function assertEqualsList(descr, expected, actual) {
michael@0 150 var minLength = expected.length;
michael@0 151 if (actual.length < minLength) {
michael@0 152 minLength = actual.length;
michael@0 153 }
michael@0 154 //
michael@0 155 for(var i = 0; i < minLength; i++) {
michael@0 156 if(expected[i] != actual[i]) {
michael@0 157 is(actual[i], expected[i], descr);
michael@0 158 }
michael@0 159 }
michael@0 160 //
michael@0 161 // if they aren't the same size, they aren't equal
michael@0 162 is(actual.length, expected.length, descr);
michael@0 163 }
michael@0 164
michael@0 165 function assertInstanceOf(descr, type, obj) {
michael@0 166 if(type == "Attr") {
michael@0 167 is(2, obj.nodeType, descr);
michael@0 168 var specd = obj.specified;
michael@0 169 }
michael@0 170 /*
michael@0 171 else {
michael@0 172 // Ensure at least one SimpleTest check is reported. (Bug 483992)
michael@0 173 todo_is(type, "Attr", "[DOMTestCase.assertInstanceOf()] Fake default check.");
michael@0 174 }
michael@0 175 */
michael@0 176 }
michael@0 177
michael@0 178 function assertSame(descr, expected, actual) {
michael@0 179 if(expected != actual) {
michael@0 180 is(expected.nodeType, actual.nodeType, descr);
michael@0 181 is(expected.nodeValue, actual.nodeValue, descr);
michael@0 182 }
michael@0 183 /*
michael@0 184 else {
michael@0 185 // Ensure at least one SimpleTest check is reported. (Bug 483992)
michael@0 186 todo_isnot(expected, actual, "[DOMTestCase.assertSame()] Fake default check." +
michael@0 187 " (Type=" + actual.nodeType + ", Value=" + actual.nodeValue + ")");
michael@0 188 }
michael@0 189 */
michael@0 190 }
michael@0 191
michael@0 192 function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
michael@0 193 //
michael@0 194 // URI must be non-null
michael@0 195 ok(assertID, "[assertURIEquals()] 'assertID' has a value");
michael@0 196 ok(actual, "[assertURIEquals()] 'actual' has a value");
michael@0 197 /*
michael@0 198 // Add missing early return.
michael@0 199 if (!actual)
michael@0 200 return;
michael@0 201 */
michael@0 202
michael@0 203 var uri = actual;
michael@0 204
michael@0 205 var lastPound = actual.lastIndexOf("#");
michael@0 206 var actualFragment = "";
michael@0 207 if(lastPound != -1) {
michael@0 208 //
michael@0 209 // substring before pound
michael@0 210 //
michael@0 211 uri = actual.substring(0,lastPound);
michael@0 212 actualFragment = actual.substring(lastPound+1);
michael@0 213 }
michael@0 214 if(fragment != null) is(actualFragment, fragment, assertID);
michael@0 215
michael@0 216 var lastQuestion = uri.lastIndexOf("?");
michael@0 217 var actualQuery = "";
michael@0 218 if(lastQuestion != -1) {
michael@0 219 //
michael@0 220 // substring before pound
michael@0 221 //
michael@0 222 uri = actual.substring(0,lastQuestion);
michael@0 223 actualQuery = actual.substring(lastQuestion+1);
michael@0 224 }
michael@0 225 if(query != null) is(actualQuery, query, assertID);
michael@0 226
michael@0 227 var firstColon = uri.indexOf(":");
michael@0 228 var firstSlash = uri.indexOf("/");
michael@0 229 var actualPath = uri;
michael@0 230 var actualScheme = "";
michael@0 231 if(firstColon != -1 && firstColon < firstSlash) {
michael@0 232 actualScheme = uri.substring(0,firstColon);
michael@0 233 actualPath = uri.substring(firstColon + 1);
michael@0 234 }
michael@0 235
michael@0 236 if(scheme != null) {
michael@0 237 is(scheme, actualScheme, assertID);
michael@0 238 }
michael@0 239
michael@0 240 if(path != null) {
michael@0 241 is(path, actualPath, assertID);
michael@0 242 }
michael@0 243
michael@0 244 if(host != null) {
michael@0 245 var actualHost = "";
michael@0 246 if(actualPath.substring(0,2) == "//") {
michael@0 247 var termSlash = actualPath.substring(2).indexOf("/") + 2;
michael@0 248 actualHost = actualPath.substring(0,termSlash);
michael@0 249 }
michael@0 250 is(actualHost, host, assertID);
michael@0 251 }
michael@0 252
michael@0 253 if(file != null || name != null) {
michael@0 254 var actualFile = actualPath;
michael@0 255 var finalSlash = actualPath.lastIndexOf("/");
michael@0 256 if(finalSlash != -1) {
michael@0 257 actualFile = actualPath.substring(finalSlash+1);
michael@0 258 }
michael@0 259 if (file != null) {
michael@0 260 is(actualFile, file, assertID);
michael@0 261 }
michael@0 262 if (name != null) {
michael@0 263 var actualName = actualFile;
michael@0 264 var finalDot = actualFile.lastIndexOf(".");
michael@0 265 if (finalDot != -1) {
michael@0 266 actualName = actualName.substring(0, finalDot);
michael@0 267 }
michael@0 268 is(actualName, name, assertID);
michael@0 269 }
michael@0 270 }
michael@0 271
michael@0 272 if(isAbsolute != null) {
michael@0 273 is(actualPath.substring(0,1) == "/", isAbsolute, assertID);
michael@0 274 }
michael@0 275 }
michael@0 276
michael@0 277
michael@0 278 // size() used by assertSize element
michael@0 279 function size(collection)
michael@0 280 {
michael@0 281 return collection.length;
michael@0 282 }
michael@0 283
michael@0 284 function same(expected, actual)
michael@0 285 {
michael@0 286 return expected === actual;
michael@0 287 }
michael@0 288
michael@0 289 function getSuffix(contentType) {
michael@0 290 switch(contentType) {
michael@0 291 case "text/html":
michael@0 292 return ".html";
michael@0 293
michael@0 294 case "text/xml":
michael@0 295 return ".xml";
michael@0 296
michael@0 297 case "application/xhtml+xml":
michael@0 298 return ".xhtml";
michael@0 299
michael@0 300 case "image/svg+xml":
michael@0 301 return ".svg";
michael@0 302
michael@0 303 case "text/mathml":
michael@0 304 return ".mml";
michael@0 305 }
michael@0 306 return ".html";
michael@0 307 }
michael@0 308
michael@0 309 function equalsAutoCase(context, expected, actual) {
michael@0 310 if (builder.contentType == "text/html") {
michael@0 311 if (context == "attribute") {
michael@0 312 return expected.toLowerCase() == actual;
michael@0 313 }
michael@0 314 return expected.toUpperCase() == actual;
michael@0 315 }
michael@0 316 return expected == actual;
michael@0 317 }
michael@0 318
michael@0 319 function catchInitializationError(blder, ex) {
michael@0 320 if (blder == null) {
michael@0 321 alert(ex);
michael@0 322 } else {
michael@0 323 blder.initializationError = ex;
michael@0 324 blder.initializationFatalError = ex;
michael@0 325 }
michael@0 326 }
michael@0 327
michael@0 328 function checkInitialization(blder, testname) {
michael@0 329 if (blder.initializationError != null) {
michael@0 330 // Fake a "warn()" function, as it was missing :-|
michael@0 331 function warn(msg) {
michael@0 332 info("[checkInitialization() warning] " + msg);
michael@0 333 }
michael@0 334
michael@0 335 if (blder.skipIncompatibleTests) {
michael@0 336 warn(testname + " not run:" + blder.initializationError);
michael@0 337 return blder.initializationError;
michael@0 338 } else {
michael@0 339 //
michael@0 340 // if an exception was thrown
michael@0 341 // rethrow it and do not run the test
michael@0 342 if (blder.initializationFatalError != null) {
michael@0 343 throw blder.initializationFatalError;
michael@0 344 } else {
michael@0 345 //
michael@0 346 // might be recoverable, warn but continue the test
michael@0 347 warn(testname + ": " + blder.initializationError);
michael@0 348 }
michael@0 349 }
michael@0 350 }
michael@0 351 return null;
michael@0 352 }
michael@0 353 function createTempURI(scheme) {
michael@0 354 if (scheme == "http") {
michael@0 355 return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() * 100000) + ".xml";
michael@0 356 }
michael@0 357 return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml";
michael@0 358 }
michael@0 359
michael@0 360
michael@0 361 function EventMonitor() {
michael@0 362 this.atEvents = new Array();
michael@0 363 this.bubbledEvents = new Array();
michael@0 364 this.capturedEvents = new Array();
michael@0 365 this.allEvents = new Array();
michael@0 366 }
michael@0 367
michael@0 368 EventMonitor.prototype.handleEvent = function(evt) {
michael@0 369 switch(evt.eventPhase) {
michael@0 370 case 1:
michael@0 371 monitor.capturedEvents[monitor.capturedEvents.length] = evt;
michael@0 372 break;
michael@0 373
michael@0 374 case 2:
michael@0 375 monitor.atEvents[monitor.atEvents.length] = evt;
michael@0 376 break;
michael@0 377
michael@0 378 case 3:
michael@0 379 monitor.bubbledEvents[monitor.bubbledEvents.length] = evt;
michael@0 380 break;
michael@0 381 }
michael@0 382 monitor.allEvents[monitor.allEvents.length] = evt;
michael@0 383 }
michael@0 384
michael@0 385 function DOMErrorImpl(err) {
michael@0 386 this.severity = err.severity;
michael@0 387 this.message = err.message;
michael@0 388 this.type = err.type;
michael@0 389 this.relatedException = err.relatedException;
michael@0 390 this.relatedData = err.relatedData;
michael@0 391 this.location = err.location;
michael@0 392 }
michael@0 393
michael@0 394
michael@0 395
michael@0 396 function DOMErrorMonitor() {
michael@0 397 this.allErrors = new Array();
michael@0 398 }
michael@0 399
michael@0 400 DOMErrorMonitor.prototype.handleError = function(err) {
michael@0 401 errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err);
michael@0 402 }
michael@0 403
michael@0 404 DOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) {
michael@0 405 var i;
michael@0 406 for (i = 0; i < errorMonitor.allErrors.length; i++) {
michael@0 407 if (errorMonitor.allErrors[i].severity >= severity) {
michael@0 408 assertEquals(id, severity - 1, errorMonitor.allErrors[i].severity);
michael@0 409 }
michael@0 410 }
michael@0 411 }
michael@0 412
michael@0 413 function UserDataNotification(operation, key, data, src, dst) {
michael@0 414 this.operation = operation;
michael@0 415 this.key = key;
michael@0 416 this.data = data;
michael@0 417 this.src = src;
michael@0 418 this.dst = dst;
michael@0 419 }
michael@0 420
michael@0 421 function UserDataMonitor() {
michael@0 422 this.allNotifications = new Array();
michael@0 423 }
michael@0 424
michael@0 425 UserDataMonitor.prototype.handle = function(operation, key, data, src, dst) {
michael@0 426 userDataMonitor.allNotifications[this.allNotifications.length] =
michael@0 427 new UserDataNotification(operation, key, data, src, dst);
michael@0 428 }
michael@0 429
michael@0 430
michael@0 431
michael@0 432 function IFrameBuilder() {
michael@0 433 this.contentType = "text/html";
michael@0 434 this.supportedContentTypes = [ "text/html",
michael@0 435 "text/xml",
michael@0 436 "image/svg+xml",
michael@0 437 "application/xhtml+xml" ];
michael@0 438
michael@0 439 this.supportsAsyncChange = false;
michael@0 440 this.async = true;
michael@0 441 this.fixedAttributeNames = [
michael@0 442 "validating", "expandEntityReferences", "coalescing",
michael@0 443 "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments", "schemaValidating"];
michael@0 444
michael@0 445 this.fixedAttributeValues = [false, true, false, true, true , false, false, true, false ];
michael@0 446 this.configurableAttributeNames = [ ];
michael@0 447 this.configurableAttributeValues = [ ];
michael@0 448 this.initializationError = null;
michael@0 449 this.initializationFatalError = null;
michael@0 450 this.skipIncompatibleTests = false;
michael@0 451 }
michael@0 452
michael@0 453 IFrameBuilder.prototype.hasFeature = function(feature, version) {
michael@0 454 return document.implementation.hasFeature(feature, version);
michael@0 455 }
michael@0 456
michael@0 457 IFrameBuilder.prototype.getImplementation = function() {
michael@0 458 return document.implementation;
michael@0 459 }
michael@0 460
michael@0 461 IFrameBuilder.prototype.setContentType = function(contentType) {
michael@0 462 this.contentType = contentType;
michael@0 463 if (contentType == "text/html") {
michael@0 464 this.fixedAttributeValues[6] = false;
michael@0 465 } else {
michael@0 466 this.fixedAttributeValues[6] = true;
michael@0 467 }
michael@0 468 }
michael@0 469
michael@0 470
michael@0 471
michael@0 472 IFrameBuilder.prototype.preload = function(frame, varname, url) {
michael@0 473 var suffix;
michael@0 474 if (this.contentType == "text/html" ||
michael@0 475 this.contentType == "application/xhtml+xml") {
michael@0 476 if (url.substring(0,5) == "staff" || url == "nodtdstaff" ||
michael@0 477 url == "datatype_normalization") {
michael@0 478 suffix = ".xml";
michael@0 479 }
michael@0 480 }
michael@0 481
michael@0 482 if (!suffix) suffix = getSuffix(this.contentType);
michael@0 483
michael@0 484 var iframe = document.createElement("iframe");
michael@0 485 var srcname = url + suffix;
michael@0 486 iframe.setAttribute("name", srcname);
michael@0 487 iframe.setAttribute("src", fileBase + srcname);
michael@0 488 //
michael@0 489 // HTML and XHTML have onload attributes that will invoke loadComplete
michael@0 490 //
michael@0 491 if (suffix.indexOf("html") < 0) {
michael@0 492 iframe.addEventListener("load", loadComplete, false);
michael@0 493 }
michael@0 494 document.getElementsByTagName("body").item(0).appendChild(iframe);
michael@0 495 return 0;
michael@0 496 }
michael@0 497
michael@0 498 IFrameBuilder.prototype.load = function(frame, varname, url) {
michael@0 499 var suffix;
michael@0 500 if (url.substring(0,5) == "staff" || url == "nodtdstaff" || url == "datatype_normalization") {
michael@0 501 suffix = ".xml";
michael@0 502 }
michael@0 503 if (!suffix) suffix = getSuffix(this.contentType);
michael@0 504 var name = url + suffix;
michael@0 505 var iframes = document.getElementsByTagName("iframe");
michael@0 506 for(var i = 0; i < iframes.length; i++) {
michael@0 507 if (iframes.item(i).getAttribute("name") == name) {
michael@0 508 var item = iframes.item(i);
michael@0 509 if (typeof(item.contentDocument) != 'undefined') {
michael@0 510 return item.contentDocument;
michael@0 511 }
michael@0 512 if (typeof(item.document) != 'undefined') {
michael@0 513 return item.document;
michael@0 514 }
michael@0 515 return null;
michael@0 516 }
michael@0 517 }
michael@0 518 return null;
michael@0 519 }
michael@0 520
michael@0 521 IFrameBuilder.prototype.getImplementationAttribute = function(attr) {
michael@0 522 for (var i = 0; i < this.fixedAttributeNames.length; i++) {
michael@0 523 if (this.fixedAttributeNames[i] == attr) {
michael@0 524 return this.fixedAttributeValues[i];
michael@0 525 }
michael@0 526 }
michael@0 527 throw "Unrecognized implementation attribute: " + attr;
michael@0 528 }
michael@0 529
michael@0 530
michael@0 531
michael@0 532 IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) {
michael@0 533 var supported = this.getImplementationAttribute(attribute);
michael@0 534 if (supported != value) {
michael@0 535 this.initializationError = "IFrame loader does not support " + attribute + "=" + value;
michael@0 536 }
michael@0 537 }
michael@0 538
michael@0 539
michael@0 540 IFrameBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
michael@0 541 var supported = this.getImplementationAttribute(attribute);
michael@0 542 return (supported == value);
michael@0 543 }
michael@0 544
michael@0 545
michael@0 546 function createBuilder(implementation) {
michael@0 547 if (implementation == null) {
michael@0 548 return new IFrameBuilder();
michael@0 549 }
michael@0 550 switch(implementation) {
michael@0 551 /* case "msxml3":
michael@0 552 return new MSXMLBuilder("Msxml2.DOMDocument.3.0");
michael@0 553
michael@0 554 case "msxml4":
michael@0 555 return new MSXMLBuilder("Msxml2.DOMDocument.4.0");*/
michael@0 556
michael@0 557 case "mozillaXML":
michael@0 558 return new MozillaXMLBuilder();
michael@0 559 /*
michael@0 560 case "svgplugin":
michael@0 561 return new SVGPluginBuilder();
michael@0 562
michael@0 563 case "dom3ls":
michael@0 564 return new DOM3LSBuilder(); */
michael@0 565
michael@0 566 case "iframe":
michael@0 567 return new IFrameBuilder();
michael@0 568
michael@0 569 case "xmlhttprequest":
michael@0 570 return new XMLHttpRequestBuilder();
michael@0 571
michael@0 572 default:
michael@0 573 alert ("unrecognized implementation " + implementation);
michael@0 574 }
michael@0 575 return new IFrameBuilder();
michael@0 576 }
michael@0 577
michael@0 578 function checkFeature(feature, version)
michael@0 579 {
michael@0 580 if (!builder.hasFeature(feature, version))
michael@0 581 {
michael@0 582 //
michael@0 583 // don't throw exception so that users can select to ignore the precondition
michael@0 584 //
michael@0 585 builder.initializationError = "builder does not support feature " + feature + " version " + version;
michael@0 586 }
michael@0 587 }
michael@0 588
michael@0 589 function createConfiguredBuilder() {
michael@0 590 var builder = null;
michael@0 591 var contentType = null;
michael@0 592 var i;
michael@0 593 var contentTypeSet = false;
michael@0 594 var parm = null;
michael@0 595 builder = new IFrameBuilder();
michael@0 596 return builder;
michael@0 597 }
michael@0 598
michael@0 599
michael@0 600 function preload(frame, varname, url) {
michael@0 601 return builder.preload(frame, varname, url);
michael@0 602 }
michael@0 603
michael@0 604 function load(frame, varname, url) {
michael@0 605 return builder.load(frame, varname, url);
michael@0 606 }
michael@0 607
michael@0 608 function getImplementationAttribute(attr) {
michael@0 609 return builder.getImplementationAttribute(attr);
michael@0 610 }
michael@0 611
michael@0 612
michael@0 613 function setImplementationAttribute(attribute, value) {
michael@0 614 builder.setImplementationAttribute(attribute, value);
michael@0 615 }
michael@0 616
michael@0 617 function setAsynchronous(value) {
michael@0 618 if (builder.supportsAsyncChange) {
michael@0 619 builder.async = value;
michael@0 620 } else {
michael@0 621 update();
michael@0 622 }
michael@0 623 }
michael@0 624
michael@0 625
michael@0 626 function createXPathEvaluator(doc) {
michael@0 627 try {
michael@0 628 return doc.getFeature("XPath", null);
michael@0 629 }
michael@0 630 catch(ex) {
michael@0 631 }
michael@0 632 return doc;
michael@0 633 }
michael@0 634
michael@0 635 function toLowerArray(src) {
michael@0 636 var newArray = new Array();
michael@0 637 var i;
michael@0 638 for (i = 0; i < src.length; i++) {
michael@0 639 newArray[i] = src[i].toLowerCase();
michael@0 640 }
michael@0 641 return newArray;
michael@0 642 }
michael@0 643
michael@0 644 function MSXMLBuilder_onreadystatechange() {
michael@0 645 if (builder.parser.readyState == 4) {
michael@0 646 loadComplete();
michael@0 647 }
michael@0 648 }
michael@0 649
michael@0 650
michael@0 651
michael@0 652 var fileBase = location.href;
michael@0 653 if (fileBase.indexOf('?') != -1) {
michael@0 654 fileBase = fileBase.substring(0, fileBase.indexOf('?'));
michael@0 655 }
michael@0 656 fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/";
michael@0 657
michael@0 658 function getResourceURI(name, scheme, contentType) {
michael@0 659 return fileBase + name + getSuffix(contentType);
michael@0 660 }
michael@0 661
michael@0 662
michael@0 663 function getImplementation() {
michael@0 664 return builder.getImplementation();
michael@0 665 }
michael@0 666
michael@0 667 // Count of failures overridden as todos.
michael@0 668 var gFailuresAsTodos = 0;
michael@0 669
michael@0 670 // Override SimpleTest result logger.
michael@0 671 var ST_logResult = SimpleTest._logResult;
michael@0 672 SimpleTest._logResult = function overrideSTlR(test, passString, failString) {
michael@0 673 if (todoTests[docName] && !test.result && !test.todo) {
michael@0 674 test.name = "[failure as todo] " + test.name;
michael@0 675 test.todo = true;
michael@0 676 failString = "TEST-KNOWN-FAIL";
michael@0 677
michael@0 678 ++gFailuresAsTodos;
michael@0 679 }
michael@0 680
michael@0 681 ST_logResult(test, passString, failString);
michael@0 682 }
michael@0 683
michael@0 684 window.doc = window;
michael@0 685 SimpleTest.waitForExplicitFinish();
michael@0 686 addLoadEvent(function(){ setUpPage(); });
michael@0 687
michael@0 688 // Actual marking code is in overrideSTlR() now.
michael@0 689 function markTodos() {
michael@0 690 if (todoTests[docName]) {
michael@0 691 isnot(gFailuresAsTodos, 0, "test marked todo should have failed somewhere");
michael@0 692 }
michael@0 693 }
michael@0 694
michael@0 695 function runJSUnitTests() {
michael@0 696 builder = createConfiguredBuilder();
michael@0 697 try {
michael@0 698 var tests = exposeTestFunctionNames();
michael@0 699 for (var i = 0; i < tests.length; i++) {
michael@0 700 window[tests[i]]();
michael@0 701 }
michael@0 702 } catch (ex) {
michael@0 703 if (todoTests[docName]) {
michael@0 704 todo(false, "[failure as todo] Test threw exception: " + ex);
michael@0 705 ++gFailuresAsTodos;
michael@0 706 } else {
michael@0 707 ok(false, "Test threw exception: " + ex);
michael@0 708 }
michael@0 709 }
michael@0 710 }

mercurial