1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<BASE HREF="about:blank">
5<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
6<TITLE>NIST DOM HTML Test - Base</TITLE>
7<script type='text/javascript'>/*
8Copyright (c) 2001-2005 World Wide Web Consortium, 
9(Massachusetts Institute of Technology, European Research Consortium 
10for Informatics and Mathematics, Keio University). All 
11Rights Reserved. This work is distributed under the W3C(r) Software License [1] in the 
12hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
13the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
14
15[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
16*/
17
18//
19//   Webkit modification:  11-August-2005
20//
21if (window.layoutTestController)
22    layoutTestController.dumpAsText();
23//
24//   End modification
25//
26
27
28  function assertSize(descr, expected, actual) {
29    var actualSize;
30    assertNotNull(descr, actual);
31    actualSize = actual.length;
32    assertEquals(descr, expected, actualSize);
33  }
34
35  function assertEqualsAutoCase(context, descr, expected, actual) {
36  	if (builder.contentType == "text/html") {
37  	    if(context == "attribute") {
38  	    	assertEquals(descr, expected.toLowerCase(), actual.toLowerCase());
39  	    } else {
40  	        assertEquals(descr, expected.toUpperCase(), actual);
41  	    }
42  	} else {
43  		assertEquals(descr, expected, actual); 
44  	}
45  }
46  
47
48  function assertEqualsCollectionAutoCase(context, descr, expected, actual) {
49    //
50    //  if they aren't the same size, they aren't equal
51    assertEquals(descr, expected.length, actual.length);
52    
53    //
54    //  if there length is the same, then every entry in the expected list
55    //     must appear once and only once in the actual list
56    var expectedLen = expected.length;
57    var expectedValue;
58    var actualLen = actual.length;
59    var i;
60    var j;
61    var matches;
62    for(i = 0; i < expectedLen; i++) {
63        matches = 0;
64        expectedValue = expected[i];
65        for(j = 0; j < actualLen; j++) {
66        	if (builder.contentType == "text/html") {
67        		if (context == "attribute") {
68        			if (expectedValue.toLowerCase() == actual[j].toLowerCase()) {
69        				matches++;
70        			}
71        		} else {
72        			if (expectedValue.toUpperCase() == actual[j]) {
73        				matches++;
74        			}
75        		}
76        	} else {
77            	if(expectedValue == actual[j]) {
78                	matches++;
79                }
80            }
81        }
82        if(matches == 0) {
83            assert(descr + ": No match found for " + expectedValue,false);
84        }
85        if(matches > 1) {
86            assert(descr + ": Multiple matches found for " + expectedValue, false);
87        }
88    }
89  }
90
91  function assertEqualsCollection(descr, expected, actual) {
92    //
93    //  if they aren't the same size, they aren't equal
94    assertEquals(descr, expected.length, actual.length);
95    //
96    //  if there length is the same, then every entry in the expected list
97    //     must appear once and only once in the actual list
98    var expectedLen = expected.length;
99    var expectedValue;
100    var actualLen = actual.length;
101    var i;
102    var j;
103    var matches;
104    for(i = 0; i < expectedLen; i++) {
105        matches = 0;
106        expectedValue = expected[i];
107        for(j = 0; j < actualLen; j++) {
108            if(expectedValue == actual[j]) {
109                matches++;
110            }
111        }
112        if(matches == 0) {
113            assert(descr + ": No match found for " + expectedValue,false);
114        }
115        if(matches > 1) {
116            assert(descr + ": Multiple matches found for " + expectedValue, false);
117        }
118    }
119  }
120
121
122  function assertEqualsListAutoCase(context, descr, expected, actual) {
123	var minLength = expected.length;
124	if (actual.length < minLength) {
125	    minLength = actual.length;
126	}
127    //
128    for(var i = 0; i < minLength; i++) {
129		assertEqualsAutoCase(context, descr, expected[i], actual[i]);
130    }
131    //
132    //  if they aren't the same size, they aren't equal
133    assertEquals(descr, expected.length, actual.length);
134  }
135
136
137  function assertEqualsList(descr, expected, actual) {
138	var minLength = expected.length;
139	if (actual.length < minLength) {
140	    minLength = actual.length;
141	}
142    //
143    for(var i = 0; i < minLength; i++) {
144        if(expected[i] != actual[i]) {
145			assertEquals(descr, expected[i], actual[i]);
146        }
147    }
148    //
149    //  if they aren't the same size, they aren't equal
150    assertEquals(descr, expected.length, actual.length);
151  }
152
153  function assertInstanceOf(descr, type, obj) {
154    if(type == "Attr") {
155        assertEquals(descr,2,obj.nodeType);
156        var specd = obj.specified;
157    }
158  }
159
160  function assertSame(descr, expected, actual) {
161    if(expected != actual) {
162        assertEquals(descr, expected.nodeType, actual.nodeType);
163        assertEquals(descr, expected.nodeValue, actual.nodeValue);
164    }
165  }
166
167  function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
168    //
169    //  URI must be non-null
170    assertNotNull(assertID, actual);
171
172    var uri = actual;
173
174    var lastPound = actual.lastIndexOf("#");
175    var actualFragment = "";
176    if(lastPound != -1) {
177        //
178        //   substring before pound
179        //
180        uri = actual.substring(0,lastPound);
181        actualFragment = actual.substring(lastPound+1);
182    }
183    if(fragment != null) assertEquals(assertID,fragment, actualFragment);
184
185    var lastQuestion = uri.lastIndexOf("?");
186    var actualQuery = "";
187    if(lastQuestion != -1) {
188        //
189        //   substring before pound
190        //
191        uri = actual.substring(0,lastQuestion);
192        actualQuery = actual.substring(lastQuestion+1);
193    }
194    if(query != null) assertEquals(assertID, query, actualQuery);
195
196    var firstColon = uri.indexOf(":");
197    var firstSlash = uri.indexOf("/");
198    var actualPath = uri;
199    var actualScheme = "";
200    if(firstColon != -1 && firstColon < firstSlash) {
201        actualScheme = uri.substring(0,firstColon);
202        actualPath = uri.substring(firstColon + 1);
203    }
204
205    if(scheme != null) {
206        assertEquals(assertID, scheme, actualScheme);
207    }
208
209    if(path != null) {
210        assertEquals(assertID, path, actualPath);
211    }
212
213    if(host != null) {
214        var actualHost = "";
215        if(actualPath.substring(0,2) == "//") {
216            var termSlash = actualPath.substring(2).indexOf("/") + 2;
217            actualHost = actualPath.substring(0,termSlash);
218        }
219        assertEquals(assertID, host, actualHost);
220    }
221
222    if(file != null || name != null) {
223        var actualFile = actualPath;
224        var finalSlash = actualPath.lastIndexOf("/");
225        if(finalSlash != -1) {
226            actualFile = actualPath.substring(finalSlash+1);
227        }
228        if (file != null) {
229            assertEquals(assertID, file, actualFile);
230        }
231        if (name != null) {
232            var actualName = actualFile;
233            var finalDot = actualFile.lastIndexOf(".");
234            if (finalDot != -1) {
235                actualName = actualName.substring(0, finalDot);
236            }
237            assertEquals(assertID, name, actualName);
238        }
239    }
240
241    if(isAbsolute != null) {
242        assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
243    }
244  }
245
246
247// size() used by assertSize element
248function size(collection)
249{
250  return collection.length;
251}
252
253function same(expected, actual)
254{
255  return expected === actual;
256}
257
258function equalsAutoCase(context, expected, actual) {
259	if (builder.contentType == "text/html") {
260		if (context == "attribute") {
261			return expected.toLowerCase() == actual;
262		}
263		return expected.toUpperCase() == actual;
264	}
265	return expected == actual;
266}
267
268function createTempURI(scheme) {
269   if (scheme == "http") {
270   	  return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() * 100000) + ".xml";
271   }
272   return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml";
273}
274
275
276
277function EventMonitor() {
278  this.atEvents = new Array();
279  this.bubbledEvents = new Array();
280  this.capturedEvents = new Array();
281  this.allEvents = new Array();
282}
283
284EventMonitor.prototype.handleEvent = function(evt) {
285    switch(evt.eventPhase) {
286       case 1:
287       monitor.capturedEvents[monitor.capturedEvents.length] = evt;
288       break;
289       
290       case 2:
291       monitor.atEvents[monitor.atEvents.length] = evt;
292       break;
293
294       case 3:
295       monitor.bubbledEvents[monitor.bubbledEvents.length] = evt;
296       break;
297    }
298    monitor.allEvents[monitor.allEvents.length] = evt;
299}
300
301function DOMErrorImpl(err) {
302  this.severity = err.severity;
303  this.message = err.message;
304  this.type = err.type;
305  this.relatedException = err.relatedException;
306  this.relatedData = err.relatedData;
307  this.location = err.location;
308}
309
310
311
312function DOMErrorMonitor() {
313  this.allErrors = new Array();
314}
315
316DOMErrorMonitor.prototype.handleError = function(err) {
317    errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err);
318}
319
320DOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) {
321    var i;
322    for (i = 0; i < this.allErrors.length; i++) {
323        if (this.allErrors[i].severity >= severity) {
324           assertEquals(id, severity - 1, this.allErrors[i].severity);
325        }
326    }
327}
328
329function UserDataNotification(operation, key, data, src, dst) {
330    this.operation = operation;
331    this.key = key;
332    this.data = data;
333    this.src = src;
334    this.dst = dst;
335}
336
337function UserDataMonitor() {
338	this.allNotifications = new Array();
339}
340
341UserDataMonitor.prototype.handle = function(operation, key, data, src, dst) {
342    userDataMonitor.allNotifications[userDataMonitor.allNotifications.length] =
343         new UserDataNotification(operation, key, data, src, dst);
344}
345
346
347
348function HTMLBuilder() {
349    this.contentType = "text/html";
350    this.supportedContentTypes = [ "text/html" ];
351
352    this.supportsAsyncChange = false;
353    this.async = false;
354    this.fixedAttributeNames = [
355        "validating",  "expandEntityReferences", "coalescing", 
356        "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments", "schemaValidating"];
357
358    this.fixedAttributeValues = [false,  true, false, true, true , false, false, false, false ];
359    this.configurableAttributeNames = [ ];
360    this.configurableAttributeValues = [ ];
361    this.initializationError = null;
362    this.initializationFatalError = null;
363    this.skipIncompatibleTests = true;
364    this.documentURLs = new Array();
365    this.documentVarnames = new Array();
366}
367
368HTMLBuilder.prototype.hasFeature = function(feature, version) {
369    return document.implementation.hasFeature(feature, version);
370}
371
372HTMLBuilder.prototype.getImplementation = function() {
373  return document.implementation;
374}
375
376HTMLBuilder.prototype.preload = function(frame, varname, url) {
377  var i;
378  this.documentVarnames[this.documentVarnames.length] = varname;
379  this.documentURLs[this.documentURLs.length] = url;
380  if (this.documentURLs.length > 1) {
381     //
382     //   if all the urls are not the same
383     //
384     for (i = 1; i < this.documentURLs.length; i++) {
385         if (this.documentURLs[i] != this.documentURLs[0]) {
386             throw "Tests with multiple loads of different documents are not currently supported";
387         }
388     }
389  }
390  return 1;
391}
392
393HTMLBuilder.prototype.cloneNode = function(srcNode, doc) {
394   var clone = null;
395   switch(srcNode.nodeType) {
396      //
397      //  element
398      case 1:
399      clone = doc.createElement(srcNode.nodeName.toLowerCase());
400      var attrs = srcNode.attributes;
401      for(var i = 0; i < attrs.length; i++) {
402          var srcAttr = attrs.item(i);
403          clone.setAttribute(srcAttr.nodeName, srcAttr.nodeValue);
404      }
405      var srcChild = srcNode.firstChild;
406      while(srcChild != null) {
407         var cloneChild = this.cloneNode(srcChild, doc);
408         if (cloneChild != null) {
409             clone.appendChild(cloneChild);
410         }
411         srcChild = srcChild.nextSibling;
412      }
413      break;
414      
415      case 3:
416      clone = doc.createTextNode(srcNode.nodeValue);
417      break;
418      
419      case 4:
420      clone = doc.createCDATASection(srcNode.nodeValue);
421      break;
422            
423      case 7:
424      clone = doc.createProcessingInstruction(srcNode.nodeValue);
425      break;
426      
427      case 8:
428      clone = doc.createComment(srcNode.nodeValue);
429      break;
430   }
431   return clone;
432      
433}
434
435HTMLBuilder.prototype.load = function(frame, varname, url) {
436  if (this.documentVarnames[0] == varname) {
437  	return document;
438  }
439  //
440  //
441  //  not a perfect way to do this
442  //    Document.cloneNode is implementation dependent but exists in L1
443  //       and implemented in IE.  The alternative brute force copy
444  //       only works in L2 or higher implementations and can't copy
445  //       entity and notation definitions, etc.
446  var clone = null;
447  try {
448      clone = document.cloneNode(true);
449  } catch(ex) {
450  }
451  if (clone == null) {
452      clone = document.implementation.createDocument(
453          document.documentElement.namespaceURI,
454          document.documentElement.nodeName,
455          null);
456      //
457      //   Work-around since
458      //   Safari does not create document element 
459      //      create document.      
460      if (clone.documentElement == null) {
461           clone.appendChild(clone.createElement(document.documentElement.nodeName));
462      }
463      var attrs = document.documentElement.attributes;
464      for(var i = 0; i < attrs.length; i++) {
465          var srcAttr = attrs.item(i);
466          clone.documentElement.setAttribute(srcAttr.nodeName, srcAttr.nodeValue);
467      }
468
469      var srcNode = document.firstChild;
470      while(srcNode != null && srcNode.nodeType != 1) {
471          if (srcNode.nodeType != 10) {
472          	 var cloneNode = this.cloneNode(srcNode, clone);
473             clone.insertBefore(cloneNode, clone.documentElement);
474           }
475           srcNode = srcNode.nextSibling; 
476      }
477      srcNode = document.documentElement.nextSibling;
478      while(srcNode != null) {
479          var cloneNode = this.cloneNode(srcNode, clone);
480          clone.appendChild(cloneNode);
481          srcNode = srcNode.nextSibling;
482      }
483      srcNode = document.documentElement.firstChild;
484      while(srcNode != null) {
485          var cloneNode = this.cloneNode(srcNode, clone);
486          if (cloneNode != null) {
487             clone.documentElement.appendChild(cloneNode);
488          }
489          srcNode = srcNode.nextSibling;
490      }
491  }
492  return clone;
493}
494
495HTMLBuilder.prototype.getImplementationAttribute = function(attr) {
496    for (var i = 0; i < this.fixedAttributeNames.length; i++) {
497        if (this.fixedAttributeNames[i] == attr) {
498            return this.fixedAttributeValues[i];
499        }
500    }
501    throw "Unrecognized implementation attribute: " + attr;
502}
503
504
505HTMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
506    var supported = this.getImplementationAttribute(attribute);
507    if (supported != value) {
508        this.initializationError = "HTML loader does not support " + attribute + "=" + value;
509    }
510}
511
512HTMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
513    var supported = this.getImplementationAttribute(attribute);
514    return (supported == value);
515}
516
517
518
519
520function createConfiguredBuilder() {
521    return new HTMLBuilder();
522}
523
524function catchInitializationError(buildr, ex) {
525   buildr.initializationError = ex;
526   buildr.initializationFatalError = ex;
527}
528
529function toLowerArray(src) {
530   var newArray = new Array();
531   var i;
532   for (i = 0; i < src.length; i++) {
533      newArray[i] = src[i].toLowerCase();
534   }
535   return newArray;
536}
537
538
539function checkFeature(feature, version)
540{
541  if (!builder.hasFeature(feature, version))
542  {
543    //
544    //   don't throw exception so that users can select to ignore the precondition
545    //
546    builder.initializationError = "builder does not support feature " + feature + " version " + version;
547  }
548}
549
550function setResult(resultType, message) {
551   var testName = getTargetURI();
552   document.open();
553   document.writeln("<html><head>");
554   document.writeln("<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET=utf-8'>");    
555   document.write("<title>");
556   document.write(testName + ":" + resultType);
557   document.write("<\/title><\/head><body><table width='100%' border='1' style='color:");
558   if (resultType == null) {
559      document.writeln("green'><tr><td>Test:<\/td><td>" + testName + "<\/td><\/tr><tr><td>Status:<\/td><td>Success<\/td><\/tr>");
560   } else {
561      if (resultType == "skip") {
562      	document.writeln("blue'><tr><td>Test:<\/td><td>" + testName + "<\/td><\/tr><tr><td>Status:<\/td><td>Skipped<\/td><\/tr>");
563      } else {
564        document.writeln("red'><tr><td>Test:<\/td><td>" + testName + "<\/td><td><\/tr><tr><td>Status:<\/td><td>" + resultType + "<\/td><\/tr>");
565      }
566   }
567   if (message != null) {
568   		document.writeln("<tr><td>Detail:<\/td><td>" + message + "<\/td><\/tr>");
569   }
570   document.write("<\/table><\/body><\/html>");
571   document.close();
572   if (parent != window) {
573       parent.setResult(testName, resultType, message);
574   }
575}
576
577function checkInitialization(buildr, testname) {
578   return buildr.initializationError;
579}
580
581function preload(docRef, varname, href) {
582   return builder.preload(docRef, varname, href);
583}
584
585
586function load(docRef, varname, href) {
587   return builder.load(docRef, varname, href);
588}
589
590
591function getImplementationAttribute(attr) {
592    return builder.getImplementationAttribute(attr);
593}
594
595
596function setImplementationAttribute(attribute, value) {
597    builder.setImplementationAttribute(attribute, value);
598}
599
600function createXPathEvaluator(doc) {
601    try {
602        return doc.getFeature("XPath", null);
603    }
604    catch(ex) {
605    }
606    return doc;
607}
608
609
610function getImplementation() {
611    return builder.getImplementation();
612}
613
614function assertEquals(id, expected, actual) {
615   var myActual;
616   if (expected != actual) {
617       myActual = actual;
618       if (actual == null) {
619          myActual = "null";
620       }
621       throw "failure:" + id + ": assertEquals failed, actual " + myActual + ", expected " + expected + "."; 
622   }
623}
624
625function assertNull(id, actual) {
626   if (actual != null) {
627       throw "failure:" + id + ": assertNull failed, actual " + actual;
628   }
629}
630
631
632function assertTrue(id, actual) {
633   if (!actual) {
634       throw "failure:" + id + ": assertTrue failed";
635   }
636}
637
638
639function assertFalse(id, actual) {
640   if (actual) {
641       throw "failure:" + id +  ": assertTrue failed";
642   }
643}
644
645function assertNotNull(id, actual) {
646   if (actual == null) {
647       throw "failure:" + id + ": assertNotNull failed";
648   }
649}
650
651function fail(id) {
652    throw "failure:" + id +  ": fail";
653}
654
655
656
657function getSuffix(contentType) {
658    switch(contentType) {
659        case "text/xml":
660        return ".xml";
661
662        case "application/xhtml+xml":
663        return ".xhtml";
664
665        case "image/svg+xml":
666        return ".svg";
667
668        case "text/mathml":
669        return ".mml";
670    }
671    return ".html";
672}
673
674
675function getResourceURI(name, scheme, contentType) {
676    var base = document.documentURI;
677    if (base == null) {
678       base = "";
679    } else {
680	   base = base.substring(0, base.lastIndexOf('/') + 1) + "files/";
681    }
682    return base + name + getSuffix(contentType);
683}
684
685
686
687function startTest() {
688	//
689	//   invoke test setup
690	//
691	setUpPage();
692
693	try {
694	    runTest();
695	    if (builder.initializationError == null) {
696	       setResult(null, null);
697	    } else {
698	       setResult("skip", builder.initializationError);
699	    }
700	} catch(ex) {
701	    if (typeof(ex.substring) != 'undefined' && ex.substring(0, 8) == "failure:") {
702            setResult("failure", ex.substring(8));
703        } else {
704            setResult("error", ex);
705        }
706    }
707}</script><script charset='UTF-8' type='text/javascript'>
708/*
709Copyright é 2001-2004 World Wide Web Consortium, 
710(Massachusetts Institute of Technology, European Research Consortium 
711for Informatics and Mathematics, Keio University). All 
712Rights Reserved. This work is distributed under the W3Cî Software License [1] in the 
713hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
714the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
715
716[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
717*/
718
719
720
721   /**
722    *  Gets URI that identifies the test.
723    *  @return uri identifier of test
724    */
725function getTargetURI() {
726      return "http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLBaseElement01";
727   }
728
729var docsLoaded = -1000000;
730var builder = null;
731
732//
733//   This function is called by the testing framework before
734//      running the test suite.
735//
736//   If there are no configuration exceptions, asynchronous
737//        document loading is started.  Otherwise, the status
738//        is set to complete and the exception is immediately
739//        raised when entering the body of the test.
740//
741function setUpPage() {
742   setUpPageStatus = 'running';
743   try {
744     //
745     //   creates test document builder, may throw exception
746     //
747     builder = createConfiguredBuilder();
748
749      docsLoaded = 0;
750      
751      var docRef = null;
752      if (typeof(this.doc) != 'undefined') {
753        docRef = this.doc;
754      }
755      docsLoaded += preload(docRef, "doc", "base");
756        
757       if (docsLoaded == 1) {
758          setUpPageStatus = 'complete';
759       }
760    } catch(ex) {
761    	catchInitializationError(builder, ex);
762        setUpPageStatus = 'complete';
763    }
764}
765
766
767
768//
769//   This method is called on the completion of 
770//      each asychronous load started in setUpTests.
771//
772//   When every synchronous loaded document has completed,
773//      the page status is changed which allows the
774//      body of the test to be executed.
775function loadComplete() {
776    if (++docsLoaded == 1) {
777        setUpPageStatus = 'complete';
778    }
779}
780
781
782/**
783* 
784    The href attribute specifies the base URI. 
785
786    Retrieve the href attribute and examine its value.  
787
788* @author NIST
789* @author Mary Brady
790* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-65382887
791*/
792function HTMLBaseElement01() {
793   var success;
794    if(checkInitialization(builder, "HTMLBaseElement01") != null) return;
795    var nodeList;
796      var testNode;
797      var vhref;
798      var doc;
799      
800      var docRef = null;
801      if (typeof(this.doc) != 'undefined') {
802        docRef = this.doc;
803      }
804      doc = load(docRef, "doc", "base");
805      nodeList = doc.getElementsByTagName("base");
806      assertSize("Asize",1,nodeList);
807testNode = nodeList.item(0);
808      vhref = testNode.href;
809
810      assertEquals("hrefLink","about:blank",vhref);
811       
812}
813
814
815
816
817function runTest() {
818   HTMLBaseElement01();
819}
820</script><script type='text/javascript'>function loadComplete() { startTest(); }</script></HEAD>
821<BODY onload="loadComplete()">
822<P>Some Text</P>
823</BODY>
824</HTML>
825