| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 Copyright (c) 2001-2005 World Wide Web Consortium, | |
| 3 (Massachusetts Institute of Technology, European Research Consortium | |
| 4 for Informatics and Mathematics, Keio University). All | |
| 5 Rights Reserved. This work is distributed under the W3C(r) Software License [1]
in the | |
| 6 hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 7 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 8 | |
| 9 [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 | |
| 10 */ | |
| 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 function assertEqualsCollectionAutoCase(context, descr, expected, actual) { | |
| 32 // | |
| 33 // if they aren't the same size, they aren't equal | |
| 34 assertEquals(descr, expected.length, actual.length); | |
| 35 | |
| 36 // | |
| 37 // if there length is the same, then every entry in the expected list | |
| 38 // must appear once and only once in the actual list | |
| 39 var expectedLen = expected.length; | |
| 40 var expectedValue; | |
| 41 var actualLen = actual.length; | |
| 42 var i; | |
| 43 var j; | |
| 44 var matches; | |
| 45 for(i = 0; i < expectedLen; i++) { | |
| 46 matches = 0; | |
| 47 expectedValue = expected[i]; | |
| 48 for(j = 0; j < actualLen; j++) { | |
| 49 if (builder.contentType == "text/html") { | |
| 50 if (context == "attribute") { | |
| 51 if (expectedValue.toLowerCase() == actual[j].toLowerCase())
{ | |
| 52 matches++; | |
| 53 } | |
| 54 } else { | |
| 55 if (expectedValue.toUpperCase() == actual[j]) { | |
| 56 matches++; | |
| 57 } | |
| 58 } | |
| 59 } else { | |
| 60 if(expectedValue == actual[j]) { | |
| 61 matches++; | |
| 62 } | |
| 63 } | |
| 64 } | |
| 65 if(matches == 0) { | |
| 66 assert(descr + ": No match found for " + expectedValue,false); | |
| 67 } | |
| 68 if(matches > 1) { | |
| 69 assert(descr + ": Multiple matches found for " + expectedValue, fals
e); | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 function assertEqualsCollection(descr, expected, actual) { | |
| 75 // | |
| 76 // if they aren't the same size, they aren't equal | |
| 77 assertEquals(descr, expected.length, actual.length); | |
| 78 // | |
| 79 // if there length is the same, then every entry in the expected list | |
| 80 // must appear once and only once in the actual list | |
| 81 var expectedLen = expected.length; | |
| 82 var expectedValue; | |
| 83 var actualLen = actual.length; | |
| 84 var i; | |
| 85 var j; | |
| 86 var matches; | |
| 87 for(i = 0; i < expectedLen; i++) { | |
| 88 matches = 0; | |
| 89 expectedValue = expected[i]; | |
| 90 for(j = 0; j < actualLen; j++) { | |
| 91 if(expectedValue == actual[j]) { | |
| 92 matches++; | |
| 93 } | |
| 94 } | |
| 95 if(matches == 0) { | |
| 96 assert(descr + ": No match found for " + expectedValue,false); | |
| 97 } | |
| 98 if(matches > 1) { | |
| 99 assert(descr + ": Multiple matches found for " + expectedValue, fals
e); | |
| 100 } | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 function assertEqualsListAutoCase(context, descr, expected, actual) { | |
| 105 var minLength = expected.length; | |
| 106 if (actual.length < minLength) { | |
| 107 minLength = actual.length; | |
| 108 } | |
| 109 // | |
| 110 for(var i = 0; i < minLength; i++) { | |
| 111 assertEqualsAutoCase(context, descr, expected[i], actual[i]); | |
| 112 } | |
| 113 // | |
| 114 // if they aren't the same size, they aren't equal | |
| 115 assertEquals(descr, expected.length, actual.length); | |
| 116 } | |
| 117 | |
| 118 function assertEqualsList(descr, expected, actual) { | |
| 119 var minLength = expected.length; | |
| 120 if (actual.length < minLength) { | |
| 121 minLength = actual.length; | |
| 122 } | |
| 123 // | |
| 124 for(var i = 0; i < minLength; i++) { | |
| 125 if(expected[i] != actual[i]) { | |
| 126 assertEquals(descr, expected[i], actual[i]); | |
| 127 } | |
| 128 } | |
| 129 // | |
| 130 // if they aren't the same size, they aren't equal | |
| 131 assertEquals(descr, expected.length, actual.length); | |
| 132 } | |
| 133 | |
| 134 function assertInstanceOf(descr, type, obj) { | |
| 135 if(type == "Attr") { | |
| 136 assertEquals(descr,2,obj.nodeType); | |
| 137 var specd = obj.specified; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 function assertSame(descr, expected, actual) { | |
| 142 if(expected != actual) { | |
| 143 assertEquals(descr, expected.nodeType, actual.nodeType); | |
| 144 assertEquals(descr, expected.nodeValue, actual.nodeValue); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 function assertURIEquals(assertID, scheme, path, host, file, name, query, frag
ment, isAbsolute, actual) { | |
| 149 // | |
| 150 // URI must be non-null | |
| 151 assertNotNull(assertID, actual); | |
| 152 | |
| 153 var uri = actual; | |
| 154 | |
| 155 var lastPound = actual.lastIndexOf("#"); | |
| 156 var actualFragment = ""; | |
| 157 if(lastPound != -1) { | |
| 158 // | |
| 159 // substring before pound | |
| 160 // | |
| 161 uri = actual.substring(0,lastPound); | |
| 162 actualFragment = actual.substring(lastPound+1); | |
| 163 } | |
| 164 if(fragment != null) assertEquals(assertID,fragment, actualFragment); | |
| 165 | |
| 166 var lastQuestion = uri.lastIndexOf("?"); | |
| 167 var actualQuery = ""; | |
| 168 if(lastQuestion != -1) { | |
| 169 // | |
| 170 // substring before pound | |
| 171 // | |
| 172 uri = actual.substring(0,lastQuestion); | |
| 173 actualQuery = actual.substring(lastQuestion+1); | |
| 174 } | |
| 175 if(query != null) assertEquals(assertID, query, actualQuery); | |
| 176 | |
| 177 var firstColon = uri.indexOf(":"); | |
| 178 var firstSlash = uri.indexOf("/"); | |
| 179 var actualPath = uri; | |
| 180 var actualScheme = ""; | |
| 181 if(firstColon != -1 && firstColon < firstSlash) { | |
| 182 actualScheme = uri.substring(0,firstColon); | |
| 183 actualPath = uri.substring(firstColon + 1); | |
| 184 } | |
| 185 | |
| 186 if(scheme != null) { | |
| 187 assertEquals(assertID, scheme, actualScheme); | |
| 188 } | |
| 189 | |
| 190 if(path != null) { | |
| 191 assertEquals(assertID, path, actualPath); | |
| 192 } | |
| 193 | |
| 194 if(host != null) { | |
| 195 var actualHost = ""; | |
| 196 if(actualPath.substring(0,2) == "//") { | |
| 197 var termSlash = actualPath.substring(2).indexOf("/") + 2; | |
| 198 actualHost = actualPath.substring(0,termSlash); | |
| 199 } | |
| 200 assertEquals(assertID, host, actualHost); | |
| 201 } | |
| 202 | |
| 203 if(file != null || name != null) { | |
| 204 var actualFile = actualPath; | |
| 205 var finalSlash = actualPath.lastIndexOf("/"); | |
| 206 if(finalSlash != -1) { | |
| 207 actualFile = actualPath.substring(finalSlash+1); | |
| 208 } | |
| 209 if (file != null) { | |
| 210 assertEquals(assertID, file, actualFile); | |
| 211 } | |
| 212 if (name != null) { | |
| 213 var actualName = actualFile; | |
| 214 var finalDot = actualFile.lastIndexOf("."); | |
| 215 if (finalDot != -1) { | |
| 216 actualName = actualName.substring(0, finalDot); | |
| 217 } | |
| 218 assertEquals(assertID, name, actualName); | |
| 219 } | |
| 220 } | |
| 221 | |
| 222 if(isAbsolute != null) { | |
| 223 assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/"); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 // size() used by assertSize element | |
| 228 function size(collection) | |
| 229 { | |
| 230 return collection.length; | |
| 231 } | |
| 232 | |
| 233 function same(expected, actual) | |
| 234 { | |
| 235 return expected === actual; | |
| 236 } | |
| 237 | |
| 238 function equalsAutoCase(context, expected, actual) { | |
| 239 if (builder.contentType == "text/html") { | |
| 240 if (context == "attribute") { | |
| 241 return expected.toLowerCase() == actual; | |
| 242 } | |
| 243 return expected.toUpperCase() == actual; | |
| 244 } | |
| 245 return expected == actual; | |
| 246 } | |
| 247 | |
| 248 function toLowerArray(src) { | |
| 249 var newArray = new Array(); | |
| 250 var i; | |
| 251 for (i = 0; i < src.length; i++) { | |
| 252 newArray[i] = src[i].toLowerCase(); | |
| 253 } | |
| 254 return newArray; | |
| 255 } | |
| 256 | |
| 257 function createTempURI(scheme) { | |
| 258 if (scheme == "http") { | |
| 259 return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() *
100000) + ".xml"; | |
| 260 } | |
| 261 return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml"; | |
| 262 } | |
| 263 | |
| 264 function EventMonitor() { | |
| 265 this.atEvents = new Array(); | |
| 266 this.bubbledEvents = new Array(); | |
| 267 this.capturedEvents = new Array(); | |
| 268 this.allEvents = new Array(); | |
| 269 } | |
| 270 | |
| 271 EventMonitor.prototype.handleEvent = function(evt) { | |
| 272 switch(evt.eventPhase) { | |
| 273 case 1: | |
| 274 monitor.capturedEvents[monitor.capturedEvents.length] = evt; | |
| 275 break; | |
| 276 | |
| 277 case 2: | |
| 278 monitor.atEvents[monitor.atEvents.length] = evt; | |
| 279 break; | |
| 280 | |
| 281 case 3: | |
| 282 monitor.bubbledEvents[monitor.bubbledEvents.length] = evt; | |
| 283 break; | |
| 284 } | |
| 285 monitor.allEvents[monitor.allEvents.length] = evt; | |
| 286 } | |
| 287 | |
| 288 function DOMErrorImpl(err) { | |
| 289 this.severity = err.severity; | |
| 290 this.message = err.message; | |
| 291 this.type = err.type; | |
| 292 this.relatedException = err.relatedException; | |
| 293 this.relatedData = err.relatedData; | |
| 294 this.location = err.location; | |
| 295 } | |
| 296 | |
| 297 function DOMErrorMonitor() { | |
| 298 this.allErrors = new Array(); | |
| 299 } | |
| 300 | |
| 301 DOMErrorMonitor.prototype.handleError = function(err) { | |
| 302 errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err
); | |
| 303 } | |
| 304 | |
| 305 DOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) { | |
| 306 var i; | |
| 307 for (i = 0; i < this.allErrors.length; i++) { | |
| 308 if (this.allErrors[i].severity >= severity) { | |
| 309 assertEquals(id, severity - 1, this.allErrors[i].severity); | |
| 310 } | |
| 311 } | |
| 312 } | |
| 313 | |
| 314 function UserDataNotification(operation, key, data, src, dst) { | |
| 315 this.operation = operation; | |
| 316 this.key = key; | |
| 317 this.data = data; | |
| 318 this.src = src; | |
| 319 this.dst = dst; | |
| 320 } | |
| 321 | |
| 322 function UserDataMonitor() { | |
| 323 this.allNotifications = new Array(); | |
| 324 } | |
| 325 | |
| 326 UserDataMonitor.prototype.handle = function(operation, key, data, src, dst) { | |
| 327 userDataMonitor.allNotifications[userDataMonitor.allNotifications.length] = | |
| 328 new UserDataNotification(operation, key, data, src, dst); | |
| 329 } | |
| 330 | |
| 331 function HTMLBuilder() { | |
| 332 this.contentType = "application/xhtml+xml"; | |
| 333 this.supportedContentTypes = [ "application/xhtml+xml" ]; | |
| 334 | |
| 335 this.supportsAsyncChange = false; | |
| 336 this.async = false; | |
| 337 this.fixedAttributeNames = [ | |
| 338 "validating", "expandEntityReferences", "coalescing", | |
| 339 "signed", "hasNullString", "ignoringElementContentWhitespace", "namespac
eAware", "ignoringComments", "schemaValidating"]; | |
| 340 | |
| 341 this.fixedAttributeValues = [false, true, false, true, true , false, true,
false, false ]; | |
| 342 this.configurableAttributeNames = [ ]; | |
| 343 this.configurableAttributeValues = [ ]; | |
| 344 this.initializationError = null; | |
| 345 this.initializationFatalError = null; | |
| 346 this.skipIncompatibleTests = true; | |
| 347 this.documentURLs = new Array(); | |
| 348 this.documentVarnames = new Array(); | |
| 349 } | |
| 350 | |
| 351 HTMLBuilder.prototype.hasFeature = function(feature, version) { | |
| 352 return document.implementation.hasFeature(feature, version); | |
| 353 } | |
| 354 | |
| 355 HTMLBuilder.prototype.getImplementation = function() { | |
| 356 return document.implementation; | |
| 357 } | |
| 358 | |
| 359 HTMLBuilder.prototype.preload = function(frame, varname, url) { | |
| 360 var i; | |
| 361 this.documentVarnames[this.documentVarnames.length] = varname; | |
| 362 this.documentURLs[this.documentURLs.length] = url; | |
| 363 if (this.documentURLs.length > 1) { | |
| 364 // | |
| 365 // if all the urls are not the same | |
| 366 // | |
| 367 for (i = 1; i < this.documentURLs.length; i++) { | |
| 368 if (this.documentURLs[i] != this.documentURLs[0]) { | |
| 369 throw "Tests with multiple loads of different documents are not cur
rently supported"; | |
| 370 } | |
| 371 } | |
| 372 } | |
| 373 return 1; | |
| 374 } | |
| 375 | |
| 376 HTMLBuilder.prototype.cloneNode = function(srcNode, doc) { | |
| 377 var clone = null; | |
| 378 switch(srcNode.nodeType) { | |
| 379 // | |
| 380 // element | |
| 381 case 1: | |
| 382 clone = doc.createElementNS(srcNode.namespaceURI, srcNode.nodeName); | |
| 383 var attrs = srcNode.attributes; | |
| 384 for(var i = 0; i < attrs.length; i++) { | |
| 385 var srcAttr = attrs.item(i); | |
| 386 clone.setAttributeNS(srcAttr.namespaceURI, srcAttr.nodeName, srcAttr.n
odeValue); | |
| 387 } | |
| 388 var srcChild = srcNode.firstChild; | |
| 389 while(srcChild != null) { | |
| 390 var cloneChild = this.cloneNode(srcChild, doc); | |
| 391 if (cloneChild != null) { | |
| 392 clone.appendChild(cloneChild); | |
| 393 } | |
| 394 srcChild = srcChild.nextSibling; | |
| 395 } | |
| 396 break; | |
| 397 | |
| 398 case 3: | |
| 399 clone = doc.createTextNode(srcNode.nodeValue); | |
| 400 break; | |
| 401 | |
| 402 case 4: | |
| 403 clone = doc.createCDATASection(srcNode.nodeValue); | |
| 404 break; | |
| 405 | |
| 406 case 5: | |
| 407 clone = doc.createEntityReference(srcNode.nodeName); | |
| 408 break; | |
| 409 | |
| 410 case 7: | |
| 411 clone = doc.createProcessingInstruction(srcNode.target, srcNode.data); | |
| 412 break; | |
| 413 | |
| 414 case 8: | |
| 415 clone = doc.createComment(srcNode.nodeValue); | |
| 416 break; | |
| 417 } | |
| 418 return clone; | |
| 419 | |
| 420 } | |
| 421 | |
| 422 HTMLBuilder.prototype.load = function(frame, varname, url) { | |
| 423 if (this.documentVarnames[0] == varname) { | |
| 424 return document; | |
| 425 } | |
| 426 // | |
| 427 // | |
| 428 // not a perfect way to do this | |
| 429 // Document.cloneNode is implementation dependent but exists in L1 | |
| 430 // and implemented in IE. The alternative brute force copy | |
| 431 // only works in L2 or higher implementations and can't copy | |
| 432 // entity and notation definitions, etc. | |
| 433 var clone = null; | |
| 434 try { | |
| 435 clone = document.cloneNode(true); | |
| 436 } catch(ex) { | |
| 437 } | |
| 438 if (clone == null) { | |
| 439 clone = document.implementation.createDocument( | |
| 440 document.documentElement.namespaceURI, | |
| 441 document.documentElement.nodeName, | |
| 442 null); | |
| 443 // | |
| 444 // Work-around since | |
| 445 // Safari does not create document element | |
| 446 // create document. | |
| 447 if (clone.documentElement == null) { | |
| 448 clone.appendChild(clone.createElementNS( | |
| 449 document.documentElement.namespaceURI, | |
| 450 document.documentElement.nodeName)); | |
| 451 } | |
| 452 var attrs = document.documentElement.attributes; | |
| 453 for(var i = 0; i < attrs.length; i++) { | |
| 454 var srcAttr = attrs.item(i); | |
| 455 clone.documentElement.setAttributeNS( | |
| 456 srcAttr.namespaceURI, srcAttr.nodeName, srcAttr.nodeValue); | |
| 457 } | |
| 458 | |
| 459 var srcNode = document.firstChild; | |
| 460 while(srcNode != null && srcNode.nodeType != 1) { | |
| 461 if (srcNode.nodeType != 10) { | |
| 462 var cloneNode = this.cloneNode(srcNode, clone); | |
| 463 clone.insertBefore(cloneNode, clone.documentElement); | |
| 464 } | |
| 465 srcNode = srcNode.nextSibling; | |
| 466 } | |
| 467 srcNode = document.documentElement.nextSibling; | |
| 468 while(srcNode != null) { | |
| 469 var cloneNode = this.cloneNode(srcNode, clone); | |
| 470 clone.appendChild(cloneNode); | |
| 471 srcNode = srcNode.nextSibling; | |
| 472 } | |
| 473 srcNode = document.documentElement.firstChild; | |
| 474 while(srcNode != null) { | |
| 475 var cloneNode = this.cloneNode(srcNode, clone); | |
| 476 if (cloneNode != null) { | |
| 477 clone.documentElement.appendChild(cloneNode); | |
| 478 } | |
| 479 srcNode = srcNode.nextSibling; | |
| 480 } | |
| 481 } | |
| 482 return clone; | |
| 483 } | |
| 484 | |
| 485 HTMLBuilder.prototype.getImplementationAttribute = function(attr) { | |
| 486 for (var i = 0; i < this.fixedAttributeNames.length; i++) { | |
| 487 if (this.fixedAttributeNames[i] == attr) { | |
| 488 return this.fixedAttributeValues[i]; | |
| 489 } | |
| 490 } | |
| 491 throw "Unrecognized implementation attribute: " + attr; | |
| 492 } | |
| 493 | |
| 494 HTMLBuilder.prototype.setImplementationAttribute = function(attribute, value) { | |
| 495 var supported = this.getImplementationAttribute(attribute); | |
| 496 if (supported != value) { | |
| 497 this.initializationError = "HTML loader does not support " + attribute +
"=" + value; | |
| 498 } | |
| 499 } | |
| 500 | |
| 501 HTMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value)
{ | |
| 502 var supported = this.getImplementationAttribute(attribute); | |
| 503 return (supported == value); | |
| 504 } | |
| 505 | |
| 506 function createConfiguredBuilder() { | |
| 507 return new HTMLBuilder(); | |
| 508 } | |
| 509 | |
| 510 function catchInitializationError(buildr, ex) { | |
| 511 buildr.initializationError = ex; | |
| 512 buildr.initializationFatalError = ex; | |
| 513 } | |
| 514 | |
| 515 function checkFeature(feature, version) | |
| 516 { | |
| 517 if (!builder.hasFeature(feature, version)) | |
| 518 { | |
| 519 // | |
| 520 // don't throw exception so that users can select to ignore the preconditi
on | |
| 521 // | |
| 522 builder.initializationError = "builder does not support feature " + feature
+ " version " + version; | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 function setResult(resultType, message) { | |
| 527 var testName = getTargetURI(); | |
| 528 document.title = testName + ":" + resultType; | |
| 529 var xhtmlNS = "http://www.w3.org/1999/xhtml"; | |
| 530 var newBody = document.createElementNS(xhtmlNS, "body"); | |
| 531 var newTable = document.createElementNS(xhtmlNS, "table"); | |
| 532 newTable.width = "100%"; | |
| 533 newTable.border = "1"; | |
| 534 newBody.appendChild(newTable); | |
| 535 var testRow = newTable.insertRow(-1); | |
| 536 var testDiv1 = testRow.insertCell(-1); | |
| 537 testDiv1.appendChild(document.createTextNode("Test")); | |
| 538 var testDiv2 = testRow.insertCell(-1); | |
| 539 testDiv2.appendChild(document.createTextNode(testName)); | |
| 540 var statusRow = newTable.insertRow(-1); | |
| 541 var statusDiv1 = statusRow.insertCell(-1); | |
| 542 statusDiv1.appendChild(document.createTextNode("Status")); | |
| 543 var statusDiv2 = statusRow.insertCell(-1); | |
| 544 var style = "color:green"; | |
| 545 if (resultType == null) { | |
| 546 statusDiv2.appendChild(document.createTextNode("Success")); | |
| 547 } else { | |
| 548 statusDiv2.appendChild(document.createTextNode(resultType)); | |
| 549 if (resultType == "skip") { | |
| 550 style = "color:blue"; | |
| 551 } else { | |
| 552 style = "color:red"; | |
| 553 } | |
| 554 } | |
| 555 newTable.setAttributeNS(null, "style", style); | |
| 556 if (message != null) { | |
| 557 var messageRow = newTable.insertRow(-1); | |
| 558 var messageDiv1 = messageRow.insertCell(-1); | |
| 559 messageDiv1.appendChild(document.createTextNode("Message")); | |
| 560 var messageDiv2 = messageRow.insertCell(-1); | |
| 561 messageDiv2.appendChild(document.createTextNode(message)); | |
| 562 } | |
| 563 var oldBody = document.getElementsByTagName("body")[0]; | |
| 564 oldBody.parentNode.replaceChild(newBody, oldBody); | |
| 565 if (parent != window && typeof(parent.setResult) != 'undefined') { | |
| 566 parent.setResult(testName, resultType, message); | |
| 567 } | |
| 568 } | |
| 569 | |
| 570 function checkInitialization(buildr, testname) { | |
| 571 return buildr.initializationError; | |
| 572 } | |
| 573 | |
| 574 function preload(docRef, varname, href) { | |
| 575 return builder.preload(docRef, varname, href); | |
| 576 } | |
| 577 | |
| 578 function load(docRef, varname, href) { | |
| 579 return builder.load(docRef, varname, href); | |
| 580 } | |
| 581 | |
| 582 function getImplementationAttribute(attr) { | |
| 583 return builder.getImplementationAttribute(attr); | |
| 584 } | |
| 585 | |
| 586 function setImplementationAttribute(attribute, value) { | |
| 587 builder.setImplementationAttribute(attribute, value); | |
| 588 } | |
| 589 | |
| 590 function createXPathEvaluator(doc) { | |
| 591 try { | |
| 592 return doc.getFeature("XPath", null); | |
| 593 } | |
| 594 catch(ex) { | |
| 595 } | |
| 596 return doc; | |
| 597 } | |
| 598 | |
| 599 function getImplementation() { | |
| 600 return builder.getImplementation(); | |
| 601 } | |
| 602 | |
| 603 function assertEquals(id, expected, actual) { | |
| 604 var myActual; | |
| 605 if (expected != actual) { | |
| 606 myActual = actual; | |
| 607 if (actual == null) { | |
| 608 myActual = "null"; | |
| 609 } | |
| 610 throw "failure:" + id + ": assertEquals failed, actual " + myActual + ",
expected " + expected + "."; | |
| 611 } | |
| 612 } | |
| 613 | |
| 614 function assertNull(id, actual) { | |
| 615 if (actual != null) { | |
| 616 throw "failure:" + id + ": assertNull failed, actual " + actual; | |
| 617 } | |
| 618 } | |
| 619 | |
| 620 function assertTrue(id, actual) { | |
| 621 if (!actual) { | |
| 622 throw "failure:" + id + ": assertTrue failed"; | |
| 623 } | |
| 624 } | |
| 625 | |
| 626 function assertFalse(id, actual) { | |
| 627 if (actual) { | |
| 628 throw "failure:" + id + ": assertTrue failed"; | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 function assertNotNull(id, actual) { | |
| 633 if (actual == null) { | |
| 634 throw "failure:" + id + ": assertNotNull failed"; | |
| 635 } | |
| 636 } | |
| 637 | |
| 638 function fail(id) { | |
| 639 throw "failure:" + id + ": fail"; | |
| 640 } | |
| 641 | |
| 642 function getSuffix(contentType) { | |
| 643 switch(contentType) { | |
| 644 case "text/html": | |
| 645 return ".html"; | |
| 646 | |
| 647 case "text/xml": | |
| 648 return ".xml"; | |
| 649 | |
| 650 case "image/svg+xml": | |
| 651 return ".svg"; | |
| 652 | |
| 653 case "text/mathml": | |
| 654 return ".mml"; | |
| 655 } | |
| 656 return ".xhtml"; | |
| 657 } | |
| 658 | |
| 659 function getResourceURI(name, scheme, contentType) { | |
| 660 var base = document.documentURI; | |
| 661 if (base == null) { | |
| 662 base = ""; | |
| 663 } else { | |
| 664 base = base.substring(0, base.lastIndexOf('/') + 1) + "files/"; | |
| 665 } | |
| 666 return base + name + getSuffix(contentType); | |
| 667 } | |
| 668 | |
| 669 function startTest() { | |
| 670 | |
| 671 // | |
| 672 // WebKit modification: 18-August-2005 | |
| 673 // | |
| 674 // Inform the test controller that this test has a text-format result and so sh
ould | |
| 675 // be dumped as text, and also that the dump should not occur automatically. | |
| 676 // | |
| 677 if (window.testRunner) { | |
| 678 testRunner.dumpAsText(); | |
| 679 testRunner.waitUntilDone(); | |
| 680 } | |
| 681 // | |
| 682 // End WebKit modification | |
| 683 // | |
| 684 | |
| 685 // | |
| 686 // invoke test setup | |
| 687 // | |
| 688 setUpPage(); | |
| 689 try { | |
| 690 runTest(); | |
| 691 if (builder.initializationError == null) { | |
| 692 setResult(null, null); | |
| 693 } else { | |
| 694 setResult("skip", builder.initializationError); | |
| 695 } | |
| 696 } catch(ex) { | |
| 697 if (typeof(ex.substring) != 'undefined' && ex.substring(0, 8) == "failur
e:") { | |
| 698 setResult("failure", ex.substring(8)); | |
| 699 } else { | |
| 700 setResult("error", ex); | |
| 701 } | |
| 702 } | |
| 703 | |
| 704 // | |
| 705 // WebKit modification: 18-August-2005 | |
| 706 // | |
| 707 // Inform the test controller that this test is complete, so it's time to dump. | |
| 708 // | |
| 709 if (window.testRunner) { | |
| 710 testRunner.notifyDone(); | |
| 711 } | |
| 712 // | |
| 713 // End WebKit modification | |
| 714 // | |
| 715 | |
| 716 } | |
| OLD | NEW |