1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/dom-level1-core/DOMTestCase.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,699 @@ 1.4 +/* 1.5 +Copyright (c) 2001-2005 World Wide Web Consortium, 1.6 +(Massachusetts Institute of Technology, Institut National de 1.7 +Recherche en Informatique et en Automatique, Keio University). All 1.8 +Rights Reserved. This program is distributed under the W3C's Software 1.9 +Intellectual Property License. This program is distributed in the 1.10 +hope that it will be useful, but WITHOUT ANY WARRANTY; without even 1.11 +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 1.12 +PURPOSE. 1.13 +See W3C License http://www.w3.org/Consortium/Legal/ for more details. 1.14 +*/ 1.15 + 1.16 +function assertNull(descr, actual) { 1.17 + return ok(actual === null, descr); 1.18 +} 1.19 + 1.20 + 1.21 +function assertNotNull(descr, actual) { 1.22 + return ok(actual !== null, descr); 1.23 +} 1.24 + 1.25 +function assertTrue(descr, actual) { 1.26 + return ok(actual === true, descr); 1.27 +} 1.28 + 1.29 +function assertFalse(descr, actual) { 1.30 + return ok(actual === false, descr); 1.31 +} 1.32 + 1.33 +function assertEquals(descr, expected, actual) { 1.34 + return is(expected, actual, descr); 1.35 +} 1.36 + 1.37 + function assertSize(descr, expected, actual) { 1.38 + ok(actual !== null, descr); 1.39 + // Work around too strict checks. 1.40 + if (!actual) { 1.41 + ok(actual, "[assertSize()] 'actual' has a value"); 1.42 + return; 1.43 + } 1.44 + 1.45 + is(actual.length, expected, descr); 1.46 + } 1.47 + 1.48 + function assertEqualsAutoCase(context, descr, expected, actual) { 1.49 + if (builder.contentType == "text/html") { 1.50 + if(context == "attribute") { 1.51 + is(actual.toLowerCase(), expected.toLowerCase(), descr); 1.52 + } else { 1.53 + is(actual, expected.toUpperCase(), descr); 1.54 + } 1.55 + } else { 1.56 + is(expected, actual, descr); 1.57 + } 1.58 + } 1.59 + 1.60 + 1.61 + function assertEqualsCollectionAutoCase(context, descr, expected, actual) { 1.62 + // 1.63 + // if they aren't the same size, they aren't equal 1.64 + is(actual.length, expected.length, descr); 1.65 + 1.66 + // 1.67 + // if there length is the same, then every entry in the expected list 1.68 + // must appear once and only once in the actual list 1.69 + var expectedLen = expected.length; 1.70 + var expectedValue; 1.71 + var actualLen = actual.length; 1.72 + var i; 1.73 + var j; 1.74 + var matches; 1.75 + for(i = 0; i < expectedLen; i++) { 1.76 + matches = 0; 1.77 + expectedValue = expected[i]; 1.78 + for(j = 0; j < actualLen; j++) { 1.79 + if (builder.contentType == "text/html") { 1.80 + if (context == "attribute") { 1.81 + if (expectedValue.toLowerCase() == actual[j].toLowerCase()) { 1.82 + matches++; 1.83 + } 1.84 + } else { 1.85 + if (expectedValue.toUpperCase() == actual[j]) { 1.86 + matches++; 1.87 + } 1.88 + } 1.89 + } else { 1.90 + if(expectedValue == actual[j]) { 1.91 + matches++; 1.92 + } 1.93 + } 1.94 + } 1.95 + if(matches == 0) { 1.96 + ok(false, descr + ": No match found for " + expectedValue); 1.97 + } 1.98 + if(matches > 1) { 1.99 + ok(false, descr + ": Multiple matches found for " + expectedValue); 1.100 + } 1.101 + } 1.102 + } 1.103 + 1.104 + function assertEqualsCollection(descr, expected, actual) { 1.105 + // 1.106 + // if they aren't the same size, they aren't equal 1.107 + is(actual.length, expected.length, descr); 1.108 + // 1.109 + // if there length is the same, then every entry in the expected list 1.110 + // must appear once and only once in the actual list 1.111 + var expectedLen = expected.length; 1.112 + var expectedValue; 1.113 + var actualLen = actual.length; 1.114 + var i; 1.115 + var j; 1.116 + var matches; 1.117 + for(i = 0; i < expectedLen; i++) { 1.118 + matches = 0; 1.119 + expectedValue = expected[i]; 1.120 + for(j = 0; j < actualLen; j++) { 1.121 + if(expectedValue == actual[j]) { 1.122 + matches++; 1.123 + } 1.124 + } 1.125 + if(matches == 0) { 1.126 + ok(false, descr + ": No match found for " + expectedValue); 1.127 + } 1.128 + if(matches > 1) { 1.129 + ok(false, descr + ": Multiple matches found for " + expectedValue); 1.130 + } 1.131 + } 1.132 + } 1.133 + 1.134 + 1.135 + function assertEqualsListAutoCase(context, descr, expected, actual) { 1.136 + var minLength = expected.length; 1.137 + if (actual.length < minLength) { 1.138 + minLength = actual.length; 1.139 + } 1.140 + // 1.141 + for(var i = 0; i < minLength; i++) { 1.142 + assertEqualsAutoCase(context, descr, expected[i], actual[i]); 1.143 + } 1.144 + // 1.145 + // if they aren't the same size, they aren't equal 1.146 + is(actual.length, expected.length, descr); 1.147 + } 1.148 + 1.149 + 1.150 + function assertEqualsList(descr, expected, actual) { 1.151 + var minLength = expected.length; 1.152 + if (actual.length < minLength) { 1.153 + minLength = actual.length; 1.154 + } 1.155 + // 1.156 + for(var i = 0; i < minLength; i++) { 1.157 + if(expected[i] != actual[i]) { 1.158 + is(actual[i], expected[i], descr); 1.159 + } 1.160 + } 1.161 + // 1.162 + // if they aren't the same size, they aren't equal 1.163 + is(actual.length, expected.length, descr); 1.164 + } 1.165 + 1.166 + function assertInstanceOf(descr, type, obj) { 1.167 + if(type == "Attr") { 1.168 + is(2, obj.nodeType, descr); 1.169 + var specd = obj.specified; 1.170 + } 1.171 +/* 1.172 + else { 1.173 + // Ensure at least one SimpleTest check is reported. (Bug 483992) 1.174 + todo_is(type, "Attr", "[DOMTestCase.assertInstanceOf()] Fake default check."); 1.175 + } 1.176 +*/ 1.177 + } 1.178 + 1.179 + function assertSame(descr, expected, actual) { 1.180 + if(expected != actual) { 1.181 + is(expected.nodeType, actual.nodeType, descr); 1.182 + is(expected.nodeValue, actual.nodeValue, descr); 1.183 + } 1.184 + else { 1.185 + // Ensure at least one SimpleTest check is reported. (Bug 483992) 1.186 + todo_isnot(expected, actual, "[DOMTestCase.assertSame()] Fake default check." + 1.187 + " (Type=" + actual.nodeType + ", Value=" + actual.nodeValue + ")"); 1.188 + } 1.189 + } 1.190 + 1.191 + function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) { 1.192 + // 1.193 + // URI must be non-null 1.194 + ok(assertID, "[assertURIEquals()] 'assertID' has a value"); 1.195 + ok(actual, "[assertURIEquals()] 'actual' has a value"); 1.196 +/* 1.197 + // Add missing early return. 1.198 + if (!actual) 1.199 + return; 1.200 +*/ 1.201 + 1.202 + var uri = actual; 1.203 + 1.204 + var lastPound = actual.lastIndexOf("#"); 1.205 + var actualFragment = ""; 1.206 + if(lastPound != -1) { 1.207 + // 1.208 + // substring before pound 1.209 + // 1.210 + uri = actual.substring(0,lastPound); 1.211 + actualFragment = actual.substring(lastPound+1); 1.212 + } 1.213 + if(fragment != null) is(actualFragment, fragment, assertID); 1.214 + 1.215 + var lastQuestion = uri.lastIndexOf("?"); 1.216 + var actualQuery = ""; 1.217 + if(lastQuestion != -1) { 1.218 + // 1.219 + // substring before pound 1.220 + // 1.221 + uri = actual.substring(0,lastQuestion); 1.222 + actualQuery = actual.substring(lastQuestion+1); 1.223 + } 1.224 + if(query != null) is(actualQuery, query, assertID); 1.225 + 1.226 + var firstColon = uri.indexOf(":"); 1.227 + var firstSlash = uri.indexOf("/"); 1.228 + var actualPath = uri; 1.229 + var actualScheme = ""; 1.230 + if(firstColon != -1 && firstColon < firstSlash) { 1.231 + actualScheme = uri.substring(0,firstColon); 1.232 + actualPath = uri.substring(firstColon + 1); 1.233 + } 1.234 + 1.235 + if(scheme != null) { 1.236 + is(scheme, actualScheme, assertID); 1.237 + } 1.238 + 1.239 + if(path != null) { 1.240 + is(path, actualPath, assertID); 1.241 + } 1.242 + 1.243 + if(host != null) { 1.244 + var actualHost = ""; 1.245 + if(actualPath.substring(0,2) == "//") { 1.246 + var termSlash = actualPath.substring(2).indexOf("/") + 2; 1.247 + actualHost = actualPath.substring(0,termSlash); 1.248 + } 1.249 + is(actualHost, host, assertID); 1.250 + } 1.251 + 1.252 + if(file != null || name != null) { 1.253 + var actualFile = actualPath; 1.254 + var finalSlash = actualPath.lastIndexOf("/"); 1.255 + if(finalSlash != -1) { 1.256 + actualFile = actualPath.substring(finalSlash+1); 1.257 + } 1.258 + if (file != null) { 1.259 + is(actualFile, file, assertID); 1.260 + } 1.261 + if (name != null) { 1.262 + var actualName = actualFile; 1.263 + var finalDot = actualFile.lastIndexOf("."); 1.264 + if (finalDot != -1) { 1.265 + actualName = actualName.substring(0, finalDot); 1.266 + } 1.267 + is(actualName, name, assertID); 1.268 + } 1.269 + } 1.270 + 1.271 + if(isAbsolute != null) { 1.272 + is(actualPath.substring(0,1) == "/", isAbsolute, assertID); 1.273 + } 1.274 + } 1.275 + 1.276 + 1.277 +// size() used by assertSize element 1.278 +function size(collection) 1.279 +{ 1.280 + return collection.length; 1.281 +} 1.282 + 1.283 +function same(expected, actual) 1.284 +{ 1.285 + return expected === actual; 1.286 +} 1.287 + 1.288 +function getSuffix(contentType) { 1.289 + switch(contentType) { 1.290 + case "text/html": 1.291 + return ".html"; 1.292 + 1.293 + case "text/xml": 1.294 + return ".xml"; 1.295 + 1.296 + case "application/xhtml+xml": 1.297 + return ".xhtml"; 1.298 + 1.299 + case "image/svg+xml": 1.300 + return ".svg"; 1.301 + 1.302 + case "text/mathml": 1.303 + return ".mml"; 1.304 + } 1.305 + return ".html"; 1.306 +} 1.307 + 1.308 +function equalsAutoCase(context, expected, actual) { 1.309 + if (builder.contentType == "text/html") { 1.310 + if (context == "attribute") { 1.311 + return expected.toLowerCase() == actual; 1.312 + } 1.313 + return expected.toUpperCase() == actual; 1.314 + } 1.315 + return expected == actual; 1.316 +} 1.317 + 1.318 +function catchInitializationError(blder, ex) { 1.319 + if (blder == null) { 1.320 + alert(ex); 1.321 + } else { 1.322 + blder.initializationError = ex; 1.323 + blder.initializationFatalError = ex; 1.324 + } 1.325 +} 1.326 + 1.327 +function checkInitialization(blder, testname) { 1.328 + if (blder.initializationError != null) { 1.329 + // Fake a "warn()" function, as it was missing :-| 1.330 + function warn(msg) { 1.331 + info("[checkInitialization() warning] " + msg); 1.332 + } 1.333 + 1.334 + if (blder.skipIncompatibleTests) { 1.335 + warn(testname + " not run:" + blder.initializationError); 1.336 + return blder.initializationError; 1.337 + } else { 1.338 + // 1.339 + // if an exception was thrown 1.340 + // rethrow it and do not run the test 1.341 + if (blder.initializationFatalError != null) { 1.342 + throw blder.initializationFatalError; 1.343 + } else { 1.344 + // 1.345 + // might be recoverable, warn but continue the test 1.346 + warn(testname + ": " + blder.initializationError); 1.347 + } 1.348 + } 1.349 + } 1.350 + return null; 1.351 +} 1.352 +function createTempURI(scheme) { 1.353 + if (scheme == "http") { 1.354 + return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() * 100000) + ".xml"; 1.355 + } 1.356 + return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml"; 1.357 +} 1.358 + 1.359 + 1.360 +function EventMonitor() { 1.361 + this.atEvents = new Array(); 1.362 + this.bubbledEvents = new Array(); 1.363 + this.capturedEvents = new Array(); 1.364 + this.allEvents = new Array(); 1.365 +} 1.366 + 1.367 +EventMonitor.prototype.handleEvent = function(evt) { 1.368 + switch(evt.eventPhase) { 1.369 + case 1: 1.370 + monitor.capturedEvents[monitor.capturedEvents.length] = evt; 1.371 + break; 1.372 + 1.373 + case 2: 1.374 + monitor.atEvents[monitor.atEvents.length] = evt; 1.375 + break; 1.376 + 1.377 + case 3: 1.378 + monitor.bubbledEvents[monitor.bubbledEvents.length] = evt; 1.379 + break; 1.380 + } 1.381 + monitor.allEvents[monitor.allEvents.length] = evt; 1.382 +} 1.383 + 1.384 +function DOMErrorImpl(err) { 1.385 + this.severity = err.severity; 1.386 + this.message = err.message; 1.387 + this.type = err.type; 1.388 + this.relatedException = err.relatedException; 1.389 + this.relatedData = err.relatedData; 1.390 + this.location = err.location; 1.391 +} 1.392 + 1.393 + 1.394 + 1.395 +function DOMErrorMonitor() { 1.396 + this.allErrors = new Array(); 1.397 +} 1.398 + 1.399 +DOMErrorMonitor.prototype.handleError = function(err) { 1.400 + errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err); 1.401 +} 1.402 + 1.403 +DOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) { 1.404 + var i; 1.405 + for (i = 0; i < errorMonitor.allErrors.length; i++) { 1.406 + if (errorMonitor.allErrors[i].severity >= severity) { 1.407 + assertEquals(id, severity - 1, errorMonitor.allErrors[i].severity); 1.408 + } 1.409 + } 1.410 +} 1.411 + 1.412 +function UserDataNotification(operation, key, data, src, dst) { 1.413 + this.operation = operation; 1.414 + this.key = key; 1.415 + this.data = data; 1.416 + this.src = src; 1.417 + this.dst = dst; 1.418 +} 1.419 + 1.420 +function UserDataMonitor() { 1.421 + this.allNotifications = new Array(); 1.422 +} 1.423 + 1.424 +UserDataMonitor.prototype.handle = function(operation, key, data, src, dst) { 1.425 + userDataMonitor.allNotifications[this.allNotifications.length] = 1.426 + new UserDataNotification(operation, key, data, src, dst); 1.427 +} 1.428 + 1.429 + 1.430 + 1.431 +function IFrameBuilder() { 1.432 + this.contentType = "text/html"; 1.433 + this.supportedContentTypes = [ "text/html", 1.434 + "text/xml", 1.435 + "image/svg+xml", 1.436 + "application/xhtml+xml" ]; 1.437 + 1.438 + this.supportsAsyncChange = false; 1.439 + this.async = true; 1.440 + this.fixedAttributeNames = [ 1.441 + "validating", "expandEntityReferences", "coalescing", 1.442 + "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments", "schemaValidating"]; 1.443 + 1.444 + this.fixedAttributeValues = [false, true, false, true, true , false, false, true, false ]; 1.445 + this.configurableAttributeNames = [ ]; 1.446 + this.configurableAttributeValues = [ ]; 1.447 + this.initializationError = null; 1.448 + this.initializationFatalError = null; 1.449 + this.skipIncompatibleTests = false; 1.450 +} 1.451 + 1.452 +IFrameBuilder.prototype.hasFeature = function(feature, version) { 1.453 + return document.implementation.hasFeature(feature, version); 1.454 +} 1.455 + 1.456 +IFrameBuilder.prototype.getImplementation = function() { 1.457 + return document.implementation; 1.458 +} 1.459 + 1.460 +IFrameBuilder.prototype.setContentType = function(contentType) { 1.461 + this.contentType = contentType; 1.462 + if (contentType == "text/html") { 1.463 + this.fixedAttributeValues[6] = false; 1.464 + } else { 1.465 + this.fixedAttributeValues[6] = true; 1.466 + } 1.467 +} 1.468 + 1.469 + 1.470 + 1.471 +IFrameBuilder.prototype.preload = function(frame, varname, url) { 1.472 + var suffix; 1.473 + if (this.contentType == "text/html" || this.contentType == "application/xhtml+xml") { 1.474 + if (url.substring(0,5) == "staff" || url == "nodtdstaff" || url == "datatype_normalization") { 1.475 + suffix = ".xml"; 1.476 + } 1.477 + } 1.478 + 1.479 + if (!suffix) suffix = getSuffix(this.contentType); 1.480 + 1.481 + var iframe = document.createElement("iframe"); 1.482 + var srcname = url + suffix; 1.483 + iframe.setAttribute("name", srcname); 1.484 + iframe.setAttribute("src", fileBase + srcname); 1.485 + // 1.486 + // HTML and XHTML have onload attributes that will invoke loadComplete 1.487 + // 1.488 + if (suffix.indexOf("html") < 0) { 1.489 + iframe.addEventListener("load", loadComplete, false); 1.490 + } 1.491 + document.getElementsByTagName("body").item(0).appendChild(iframe); 1.492 + return 0; 1.493 +} 1.494 + 1.495 +IFrameBuilder.prototype.load = function(frame, varname, url) { 1.496 + var suffix; 1.497 + if (url.substring(0,5) == "staff" || url == "nodtdstaff" || url == "datatype_normalization") { 1.498 + suffix = ".xml"; 1.499 + } 1.500 + if (!suffix) suffix = getSuffix(this.contentType); 1.501 + var name = url + suffix; 1.502 + var iframes = document.getElementsByTagName("iframe"); 1.503 + for(var i = 0; i < iframes.length; i++) { 1.504 + if (iframes.item(i).getAttribute("name") == name) { 1.505 + var item = iframes.item(i); 1.506 + if (typeof(item.contentDocument) != 'undefined') { 1.507 + return item.contentDocument; 1.508 + } 1.509 + if (typeof(item.document) != 'undefined') { 1.510 + return item.document; 1.511 + } 1.512 + return null; 1.513 + } 1.514 + } 1.515 + return null; 1.516 +} 1.517 + 1.518 +IFrameBuilder.prototype.getImplementationAttribute = function(attr) { 1.519 + for (var i = 0; i < this.fixedAttributeNames.length; i++) { 1.520 + if (this.fixedAttributeNames[i] == attr) { 1.521 + return this.fixedAttributeValues[i]; 1.522 + } 1.523 + } 1.524 + throw "Unrecognized implementation attribute: " + attr; 1.525 +} 1.526 + 1.527 + 1.528 + 1.529 +IFrameBuilder.prototype.setImplementationAttribute = function(attribute, value) { 1.530 + var supported = this.getImplementationAttribute(attribute); 1.531 + if (supported != value) { 1.532 + this.initializationError = "IFrame loader does not support " + attribute + "=" + value; 1.533 + } 1.534 +} 1.535 + 1.536 + 1.537 +IFrameBuilder.prototype.canSetImplementationAttribute = function(attribute, value) { 1.538 + var supported = this.getImplementationAttribute(attribute); 1.539 + return (supported == value); 1.540 +} 1.541 + 1.542 + 1.543 +function createBuilder(implementation) { 1.544 + if (implementation == null) { 1.545 + return new IFrameBuilder(); 1.546 + } 1.547 + switch(implementation) { 1.548 +/* case "msxml3": 1.549 + return new MSXMLBuilder("Msxml2.DOMDocument.3.0"); 1.550 + 1.551 + case "msxml4": 1.552 + return new MSXMLBuilder("Msxml2.DOMDocument.4.0");*/ 1.553 + 1.554 + case "mozillaXML": 1.555 + return new MozillaXMLBuilder(); 1.556 +/* 1.557 + case "svgplugin": 1.558 + return new SVGPluginBuilder(); 1.559 + 1.560 + case "dom3ls": 1.561 + return new DOM3LSBuilder(); */ 1.562 + 1.563 + case "iframe": 1.564 + return new IFrameBuilder(); 1.565 + 1.566 + case "xmlhttprequest": 1.567 + return new XMLHttpRequestBuilder(); 1.568 + 1.569 + default: 1.570 + alert ("unrecognized implementation " + implementation); 1.571 + } 1.572 + return new IFrameBuilder(); 1.573 +} 1.574 + 1.575 +function checkFeature(feature, version) 1.576 +{ 1.577 + if (!builder.hasFeature(feature, version)) 1.578 + { 1.579 + // 1.580 + // don't throw exception so that users can select to ignore the precondition 1.581 + // 1.582 + builder.initializationError = "builder does not support feature " + feature + " version " + version; 1.583 + } 1.584 +} 1.585 + 1.586 +function createConfiguredBuilder() { 1.587 + var builder = null; 1.588 + var contentType = null; 1.589 + var i; 1.590 + var contentTypeSet = false; 1.591 + var parm = null; 1.592 + builder = new IFrameBuilder(); 1.593 + return builder; 1.594 +} 1.595 + 1.596 + 1.597 +function preload(frame, varname, url) { 1.598 + return builder.preload(frame, varname, url); 1.599 +} 1.600 + 1.601 +function load(frame, varname, url) { 1.602 + return builder.load(frame, varname, url); 1.603 +} 1.604 + 1.605 +function getImplementationAttribute(attr) { 1.606 + return builder.getImplementationAttribute(attr); 1.607 +} 1.608 + 1.609 + 1.610 +function setImplementationAttribute(attribute, value) { 1.611 + builder.setImplementationAttribute(attribute, value); 1.612 +} 1.613 + 1.614 +function setAsynchronous(value) { 1.615 + if (builder.supportsAsyncChange) { 1.616 + builder.async = value; 1.617 + } else { 1.618 + update(); 1.619 + } 1.620 +} 1.621 + 1.622 + 1.623 +function createXPathEvaluator(doc) { 1.624 + try { 1.625 + return doc.getFeature("XPath", null); 1.626 + } 1.627 + catch(ex) { 1.628 + } 1.629 + return doc; 1.630 +} 1.631 + 1.632 +function toLowerArray(src) { 1.633 + var newArray = new Array(); 1.634 + var i; 1.635 + for (i = 0; i < src.length; i++) { 1.636 + newArray[i] = src[i].toLowerCase(); 1.637 + } 1.638 + return newArray; 1.639 +} 1.640 + 1.641 +function MSXMLBuilder_onreadystatechange() { 1.642 + if (builder.parser.readyState == 4) { 1.643 + loadComplete(); 1.644 + } 1.645 +} 1.646 + 1.647 + 1.648 + 1.649 +var fileBase = location.href; 1.650 +if (fileBase.indexOf('?') != -1) { 1.651 + fileBase = fileBase.substring(0, fileBase.indexOf('?')); 1.652 +} 1.653 +fileBase = fileBase.substring(0, fileBase.lastIndexOf('/') + 1) + "files/"; 1.654 + 1.655 +function getResourceURI(name, scheme, contentType) { 1.656 + return fileBase + name + getSuffix(contentType); 1.657 +} 1.658 + 1.659 + 1.660 +function getImplementation() { 1.661 + return builder.getImplementation(); 1.662 +} 1.663 + 1.664 +// Count of failures overridden as todos. 1.665 +var gFailuresAsTodos = 0; 1.666 + 1.667 +// Override SimpleTest result logger. 1.668 +var ST_logResult = SimpleTest._logResult; 1.669 +SimpleTest._logResult = function overrideSTlR(test, passString, failString) { 1.670 + if (todoTests[docName] && !test.result && !test.todo) { 1.671 + test.name = "[failure as todo] " + test.name; 1.672 + test.todo = true; 1.673 + failString = "TEST-KNOWN-FAIL"; 1.674 + 1.675 + ++gFailuresAsTodos; 1.676 + } 1.677 + 1.678 + ST_logResult(test, passString, failString); 1.679 +} 1.680 + 1.681 +// Actual marking code is in overrideSTlR() now. 1.682 +function markTodos() { 1.683 + if (todoTests[docName]) { 1.684 + isnot(gFailuresAsTodos, 0, "test marked todo should have failed somewhere"); 1.685 + } 1.686 +} 1.687 + 1.688 +function runJSUnitTests() { 1.689 + try { 1.690 + var tests = exposeTestFunctionNames(); 1.691 + for (var i = 0; i < tests.length; i++) { 1.692 + window[tests[i]](); 1.693 + } 1.694 + } catch (ex) { 1.695 + if (todoTests[docName]) { 1.696 + todo(false, "[failure as todo] Test threw exception: " + ex); 1.697 + ++gFailuresAsTodos; 1.698 + } else { 1.699 + ok(false, "Test threw exception: " + ex); 1.700 + } 1.701 + } 1.702 +}