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

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial