1901afcec28e282052ffa6542c21b025cead9b4c0Steve Block/*
2901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockCopyright (c) 2001-2005 World Wide Web Consortium,
3901afcec28e282052ffa6542c21b025cead9b4c0Steve Block(Massachusetts Institute of Technology, European Research Consortium
4901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfor Informatics and Mathematics, Keio University). All
5901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockRights Reserved. This work is distributed under the W3C(r) Software License [1] in the
6901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockhope that it will be useful, but WITHOUT ANY WARRANTY; without even
7901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockthe implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
9901afcec28e282052ffa6542c21b025cead9b4c0Steve Block[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
10901afcec28e282052ffa6542c21b025cead9b4c0Steve Block*/
11901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
12901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
13901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertSize(descr, expected, actual) {
14901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualSize;
15901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertNotNull(descr, actual);
16901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    actualSize = actual.length;
17901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertEquals(descr, expected, actualSize);
18901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
19901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
20901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertEqualsAutoCase(context, descr, expected, actual) {
21901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	if (builder.contentType == "text/html") {
22901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	    if(context == "attribute") {
23901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	    	assertEquals(descr, expected.toLowerCase(), actual.toLowerCase());
24901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	    } else {
25901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	        assertEquals(descr, expected.toUpperCase(), actual);
26901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	    }
27901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	} else {
28901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  		assertEquals(descr, expected, actual);
29901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	}
30901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
31901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
32901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
33901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertEqualsCollectionAutoCase(context, descr, expected, actual) {
34901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
35901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  if they aren't the same size, they aren't equal
36901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertEquals(descr, expected.length, actual.length);
37901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
38901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
39901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  if there length is the same, then every entry in the expected list
40901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //     must appear once and only once in the actual list
41901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var expectedLen = expected.length;
42901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var expectedValue;
43901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualLen = actual.length;
44901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var i;
45901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var j;
46901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var matches;
47901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    for(i = 0; i < expectedLen; i++) {
48901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        matches = 0;
49901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        expectedValue = expected[i];
50901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        for(j = 0; j < actualLen; j++) {
51901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        	if (builder.contentType == "text/html") {
52901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        		if (context == "attribute") {
53901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        			if (expectedValue.toLowerCase() == actual[j].toLowerCase()) {
54901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        				matches++;
55901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        			}
56901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        		} else {
57901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        			if (expectedValue.toUpperCase() == actual[j]) {
58901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        				matches++;
59901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        			}
60901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        		}
61901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        	} else {
62901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            	if(expectedValue == actual[j]) {
63901afcec28e282052ffa6542c21b025cead9b4c0Steve Block                	matches++;
64901afcec28e282052ffa6542c21b025cead9b4c0Steve Block                }
65901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            }
66901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
67901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(matches == 0) {
68901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            assert(descr + ": No match found for " + expectedValue,false);
69901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
70901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(matches > 1) {
71901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            assert(descr + ": Multiple matches found for " + expectedValue, false);
72901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
73901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
74901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
75901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
76901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertEqualsCollection(descr, expected, actual) {
77901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
78901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  if they aren't the same size, they aren't equal
79901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertEquals(descr, expected.length, actual.length);
80901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
81901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  if there length is the same, then every entry in the expected list
82901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //     must appear once and only once in the actual list
83901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var expectedLen = expected.length;
84901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var expectedValue;
85901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualLen = actual.length;
86901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var i;
87901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var j;
88901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var matches;
89901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    for(i = 0; i < expectedLen; i++) {
90901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        matches = 0;
91901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        expectedValue = expected[i];
92901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        for(j = 0; j < actualLen; j++) {
93901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            if(expectedValue == actual[j]) {
94901afcec28e282052ffa6542c21b025cead9b4c0Steve Block                matches++;
95901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            }
96901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
97901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(matches == 0) {
98901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            assert(descr + ": No match found for " + expectedValue,false);
99901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
100901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(matches > 1) {
101901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            assert(descr + ": Multiple matches found for " + expectedValue, false);
102901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
103901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
104901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
105901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
106901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
107901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertEqualsListAutoCase(context, descr, expected, actual) {
108901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	var minLength = expected.length;
109901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	if (actual.length < minLength) {
110901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    minLength = actual.length;
111901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	}
112901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
113901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    for(var i = 0; i < minLength; i++) {
114901afcec28e282052ffa6542c21b025cead9b4c0Steve Block		assertEqualsAutoCase(context, descr, expected[i], actual[i]);
115901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
116901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
117901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  if they aren't the same size, they aren't equal
118901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertEquals(descr, expected.length, actual.length);
119901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
120901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
121901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
122901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertEqualsList(descr, expected, actual) {
123901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	var minLength = expected.length;
124901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	if (actual.length < minLength) {
125901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    minLength = actual.length;
126901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	}
127901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
128901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    for(var i = 0; i < minLength; i++) {
129901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(expected[i] != actual[i]) {
130901afcec28e282052ffa6542c21b025cead9b4c0Steve Block			assertEquals(descr, expected[i], actual[i]);
131901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
132901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
133901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
134901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  if they aren't the same size, they aren't equal
135901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertEquals(descr, expected.length, actual.length);
136901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
137901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
138901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertInstanceOf(descr, type, obj) {
139901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(type == "Attr") {
140901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(descr,2,obj.nodeType);
141901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        var specd = obj.specified;
142901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
143901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
144901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
145901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertSame(descr, expected, actual) {
146901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(expected != actual) {
147901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(descr, expected.nodeType, actual.nodeType);
148901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(descr, expected.nodeValue, actual.nodeValue);
149901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
150901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
151901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
152901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  function assertURIEquals(assertID, scheme, path, host, file, name, query, fragment, isAbsolute, actual) {
153901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
154901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //  URI must be non-null
155901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    assertNotNull(assertID, actual);
156901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
157901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var uri = actual;
158901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
159901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var lastPound = actual.lastIndexOf("#");
160901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualFragment = "";
161901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(lastPound != -1) {
162901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        //
163901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        //   substring before pound
164901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        //
165901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        uri = actual.substring(0,lastPound);
166901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        actualFragment = actual.substring(lastPound+1);
167901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
168901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(fragment != null) assertEquals(assertID,fragment, actualFragment);
169901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
170901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var lastQuestion = uri.lastIndexOf("?");
171901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualQuery = "";
172901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(lastQuestion != -1) {
173901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        //
174901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        //   substring before pound
175901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        //
176901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        uri = actual.substring(0,lastQuestion);
177901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        actualQuery = actual.substring(lastQuestion+1);
178901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
179901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(query != null) assertEquals(assertID, query, actualQuery);
180901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
181901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var firstColon = uri.indexOf(":");
182901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var firstSlash = uri.indexOf("/");
183901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualPath = uri;
184901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var actualScheme = "";
185901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(firstColon != -1 && firstColon < firstSlash) {
186901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        actualScheme = uri.substring(0,firstColon);
187901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        actualPath = uri.substring(firstColon + 1);
188901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
189901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
190901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(scheme != null) {
191901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(assertID, scheme, actualScheme);
192901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
193901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
194901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(path != null) {
195901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(assertID, path, actualPath);
196901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
197901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
198901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(host != null) {
199901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        var actualHost = "";
200901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(actualPath.substring(0,2) == "//") {
201901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            var termSlash = actualPath.substring(2).indexOf("/") + 2;
202901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            actualHost = actualPath.substring(0,termSlash);
203901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
204901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(assertID, host, actualHost);
205901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
206901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
207901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(file != null || name != null) {
208901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        var actualFile = actualPath;
209901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        var finalSlash = actualPath.lastIndexOf("/");
210901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if(finalSlash != -1) {
211901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            actualFile = actualPath.substring(finalSlash+1);
212901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
213901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if (file != null) {
214901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            assertEquals(assertID, file, actualFile);
215901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
216901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if (name != null) {
217901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            var actualName = actualFile;
218901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            var finalDot = actualFile.lastIndexOf(".");
219901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            if (finalDot != -1) {
220901afcec28e282052ffa6542c21b025cead9b4c0Steve Block                actualName = actualName.substring(0, finalDot);
221901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            }
222901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            assertEquals(assertID, name, actualName);
223901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
224901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
225901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
226901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if(isAbsolute != null) {
227901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        assertEquals(assertID, isAbsolute, actualPath.substring(0,1) == "/");
228901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
229901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
230901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
231901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
232901afcec28e282052ffa6542c21b025cead9b4c0Steve Block// size() used by assertSize element
233901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction size(collection)
234901afcec28e282052ffa6542c21b025cead9b4c0Steve Block{
235901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  return collection.length;
236901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
237901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
238901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction same(expected, actual)
239901afcec28e282052ffa6542c21b025cead9b4c0Steve Block{
240901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  return expected === actual;
241901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
242901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
243901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction equalsAutoCase(context, expected, actual) {
244901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	if (builder.contentType == "text/html") {
245901afcec28e282052ffa6542c21b025cead9b4c0Steve Block		if (context == "attribute") {
246901afcec28e282052ffa6542c21b025cead9b4c0Steve Block			return expected.toLowerCase() == actual;
247901afcec28e282052ffa6542c21b025cead9b4c0Steve Block		}
248901afcec28e282052ffa6542c21b025cead9b4c0Steve Block		return expected.toUpperCase() == actual;
249901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	}
250901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	return expected == actual;
251901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
252901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
253901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction createTempURI(scheme) {
254901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (scheme == "http") {
255901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   	  return "http://localhost:8080/webdav/tmp" + Math.floor(Math.random() * 100000) + ".xml";
256901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
257901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   return "file:///tmp/domts" + Math.floor(Math.random() * 100000) + ".xml";
258901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
259901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
260901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
261901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
262901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction EventMonitor() {
263901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.atEvents = new Array();
264901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.bubbledEvents = new Array();
265901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.capturedEvents = new Array();
266901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.allEvents = new Array();
267901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
268901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
269901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockEventMonitor.prototype.handleEvent = function(evt) {
270901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    switch(evt.eventPhase) {
271901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       case 1:
272901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       monitor.capturedEvents[monitor.capturedEvents.length] = evt;
273901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       break;
274901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
275901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       case 2:
276901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       monitor.atEvents[monitor.atEvents.length] = evt;
277901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       break;
278901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
279901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       case 3:
280901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       monitor.bubbledEvents[monitor.bubbledEvents.length] = evt;
281901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       break;
282901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
283901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    monitor.allEvents[monitor.allEvents.length] = evt;
284901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
285901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
286901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction DOMErrorImpl(err) {
287901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.severity = err.severity;
288901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.message = err.message;
289901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.type = err.type;
290901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.relatedException = err.relatedException;
291901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.relatedData = err.relatedData;
292901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.location = err.location;
293901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
294901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
295901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
296901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
297901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction DOMErrorMonitor() {
298901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.allErrors = new Array();
299901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
300901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
301901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockDOMErrorMonitor.prototype.handleError = function(err) {
302901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    errorMonitor.allErrors[errorMonitor.allErrors.length] = new DOMErrorImpl(err);
303901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
304901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
305901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockDOMErrorMonitor.prototype.assertLowerSeverity = function(id, severity) {
306901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var i;
307901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    for (i = 0; i < this.allErrors.length; i++) {
308901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if (this.allErrors[i].severity >= severity) {
309901afcec28e282052ffa6542c21b025cead9b4c0Steve Block           assertEquals(id, severity - 1, this.allErrors[i].severity);
310901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
311901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
312901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
313901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
314901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction UserDataNotification(operation, key, data, src, dst) {
315901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.operation = operation;
316901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.key = key;
317901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.data = data;
318901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.src = src;
319901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.dst = dst;
320901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
321901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
322901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction UserDataMonitor() {
323901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	this.allNotifications = new Array();
324901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
325901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
326901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockUserDataMonitor.prototype.handle = function(operation, key, data, src, dst) {
327901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    userDataMonitor.allNotifications[userDataMonitor.allNotifications.length] =
328901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         new UserDataNotification(operation, key, data, src, dst);
329901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
330901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
331901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
332901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
333901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction HTMLBuilder() {
334901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.contentType = "text/html";
335901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.supportedContentTypes = [ "text/html" ];
336901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
337901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.supportsAsyncChange = false;
338901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.async = false;
339901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.fixedAttributeNames = [
340901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        "validating",  "expandEntityReferences", "coalescing",
341901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        "signed", "hasNullString", "ignoringElementContentWhitespace", "namespaceAware", "ignoringComments", "schemaValidating"];
342901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
343901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.fixedAttributeValues = [false,  true, false, true, true , false, false, false, false ];
344901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.configurableAttributeNames = [ ];
345901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.configurableAttributeValues = [ ];
346901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.initializationError = null;
347901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.initializationFatalError = null;
348901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.skipIncompatibleTests = true;
349901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.documentURLs = new Array();
350901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    this.documentVarnames = new Array();
351901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
352901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
353901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.hasFeature = function(feature, version) {
354901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return document.implementation.hasFeature(feature, version);
355901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
356901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
357901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.getImplementation = function() {
358901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  return document.implementation;
359901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
360901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
361901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.preload = function(frame, varname, url) {
362901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  var i;
363901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.documentVarnames[this.documentVarnames.length] = varname;
364901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  this.documentURLs[this.documentURLs.length] = url;
365901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  if (this.documentURLs.length > 1) {
366901afcec28e282052ffa6542c21b025cead9b4c0Steve Block     //
367901afcec28e282052ffa6542c21b025cead9b4c0Steve Block     //   if all the urls are not the same
368901afcec28e282052ffa6542c21b025cead9b4c0Steve Block     //
369901afcec28e282052ffa6542c21b025cead9b4c0Steve Block     for (i = 1; i < this.documentURLs.length; i++) {
370901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         if (this.documentURLs[i] != this.documentURLs[0]) {
371901afcec28e282052ffa6542c21b025cead9b4c0Steve Block             throw "Tests with multiple loads of different documents are not currently supported";
372901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         }
373901afcec28e282052ffa6542c21b025cead9b4c0Steve Block     }
374901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
375901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  return 1;
376901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
377901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
378901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.cloneNode = function(srcNode, doc) {
379901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   var clone = null;
380901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   switch(srcNode.nodeType) {
381901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      //
382901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      //  element
383901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      case 1:
384901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = doc.createElement(srcNode.nodeName.toLowerCase());
385901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      var attrs = srcNode.attributes;
386901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      for(var i = 0; i < attrs.length; i++) {
387901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          var srcAttr = attrs.item(i);
388901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          clone.setAttribute(srcAttr.nodeName, srcAttr.nodeValue);
389901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
390901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      var srcChild = srcNode.firstChild;
391901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      while(srcChild != null) {
392901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         var cloneChild = this.cloneNode(srcChild, doc);
393901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         if (cloneChild != null) {
394901afcec28e282052ffa6542c21b025cead9b4c0Steve Block             clone.appendChild(cloneChild);
395901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         }
396901afcec28e282052ffa6542c21b025cead9b4c0Steve Block         srcChild = srcChild.nextSibling;
397901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
398901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      break;
399901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
400901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      case 3:
401901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = doc.createTextNode(srcNode.nodeValue);
402901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      break;
403901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
404901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      case 4:
405901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = doc.createCDATASection(srcNode.nodeValue);
406901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      break;
407901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
408901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      case 7:
409901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = doc.createProcessingInstruction(srcNode.nodeValue);
410901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      break;
411901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
412901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      case 8:
413901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = doc.createComment(srcNode.nodeValue);
414901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      break;
415901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
416901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   return clone;
417901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
418901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
419901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
420901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
421901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.load = function(frame, varname, url) {
422901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  if (this.documentVarnames[0] == varname) {
423901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  	return document;
424901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
425901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //
426901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //
427901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //  not a perfect way to do this
428901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //    Document.cloneNode is implementation dependent but exists in L1
429901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //       and implemented in IE.  The alternative brute force copy
430901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //       only works in L2 or higher implementations and can't copy
431901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  //       entity and notation definitions, etc.
432901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  var clone = null;
433901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  try {
434901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = document.cloneNode(true);
435901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  } catch(ex) {
436901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
437901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  if (clone == null) {
438901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      clone = document.implementation.createDocument(
439901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          document.documentElement.namespaceURI,
440901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          document.documentElement.nodeName,
441901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          null);
442901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      //
443901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      //   Work-around since
444901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      //   Safari does not create document element
445901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      //      create document.
446901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      if (clone.documentElement == null) {
447901afcec28e282052ffa6542c21b025cead9b4c0Steve Block           clone.appendChild(clone.createElement(document.documentElement.nodeName));
448901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
449901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      var attrs = document.documentElement.attributes;
450901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      for(var i = 0; i < attrs.length; i++) {
451901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          var srcAttr = attrs.item(i);
452901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          clone.documentElement.setAttribute(srcAttr.nodeName, srcAttr.nodeValue);
453901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
454901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
455901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      var srcNode = document.firstChild;
456901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      while(srcNode != null && srcNode.nodeType != 1) {
457901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          if (srcNode.nodeType != 10) {
458901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          	 var cloneNode = this.cloneNode(srcNode, clone);
459901afcec28e282052ffa6542c21b025cead9b4c0Steve Block             clone.insertBefore(cloneNode, clone.documentElement);
460901afcec28e282052ffa6542c21b025cead9b4c0Steve Block           }
461901afcec28e282052ffa6542c21b025cead9b4c0Steve Block           srcNode = srcNode.nextSibling;
462901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
463901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      srcNode = document.documentElement.nextSibling;
464901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      while(srcNode != null) {
465901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          var cloneNode = this.cloneNode(srcNode, clone);
466901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          clone.appendChild(cloneNode);
467901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          srcNode = srcNode.nextSibling;
468901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
469901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      srcNode = document.documentElement.firstChild;
470901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      while(srcNode != null) {
471901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          var cloneNode = this.cloneNode(srcNode, clone);
472901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          if (cloneNode != null) {
473901afcec28e282052ffa6542c21b025cead9b4c0Steve Block             clone.documentElement.appendChild(cloneNode);
474901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          }
475901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          srcNode = srcNode.nextSibling;
476901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
477901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
478901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  return clone;
479901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
480901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
481901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.getImplementationAttribute = function(attr) {
482901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    for (var i = 0; i < this.fixedAttributeNames.length; i++) {
483901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        if (this.fixedAttributeNames[i] == attr) {
484901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            return this.fixedAttributeValues[i];
485901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
486901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
487901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    throw "Unrecognized implementation attribute: " + attr;
488901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
489901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
490901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
491901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.setImplementationAttribute = function(attribute, value) {
492901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var supported = this.getImplementationAttribute(attribute);
493901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if (supported != value) {
494901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        this.initializationError = "HTML loader does not support " + attribute + "=" + value;
495901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
496901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
497901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
498901afcec28e282052ffa6542c21b025cead9b4c0Steve BlockHTMLBuilder.prototype.canSetImplementationAttribute = function(attribute, value) {
499901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var supported = this.getImplementationAttribute(attribute);
500901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return (supported == value);
501901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
502901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
503901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
504901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
505901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
506901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction createConfiguredBuilder() {
507901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return new HTMLBuilder();
508901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
509901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
510901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction catchInitializationError(buildr, ex) {
511901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   buildr.initializationError = ex;
512901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   buildr.initializationFatalError = ex;
513901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
514901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
515901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction toLowerArray(src) {
516901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   var newArray = new Array();
517901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   var i;
518901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   for (i = 0; i < src.length; i++) {
519901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      newArray[i] = src[i].toLowerCase();
520901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
521901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   return newArray;
522901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
523901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
524901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
525901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction checkFeature(feature, version)
526901afcec28e282052ffa6542c21b025cead9b4c0Steve Block{
527901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  if (!builder.hasFeature(feature, version))
528901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  {
529901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
530901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //   don't throw exception so that users can select to ignore the precondition
531901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    //
532901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    builder.initializationError = "builder does not support feature " + feature + " version " + version;
533901afcec28e282052ffa6542c21b025cead9b4c0Steve Block  }
534901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
535901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
536901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction setResult(resultType, message) {
537901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   var testName = getTargetURI();
538901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.open();
539901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.writeln("<html><head>");
540901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.writeln("<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET=utf-8'>");
541901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.write("<title>");
542901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.write(testName + ":" + resultType);
543901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.write("</title></head><body><table width='100%' border='1' style='color:");
544901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (resultType == null) {
545901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      document.writeln("green'><tr><td>Test:</td><td>" + testName + "</td></tr><tr><td>Status:</td><td>Success</td></tr>");
546901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   } else {
547901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      if (resultType == "skip") {
548901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      	document.writeln("blue'><tr><td>Test:</td><td>" + testName + "</td></tr><tr><td>Status:</td><td>Skipped</td></tr>");
549901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      } else {
550901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        document.writeln("red'><tr><td>Test:</td><td>" + testName + "</td><td></tr><tr><td>Status:</td><td>" + resultType + "</td></tr>");
551901afcec28e282052ffa6542c21b025cead9b4c0Steve Block      }
552901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
553901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (message != null) {
554901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   		document.writeln("<tr><td>Detail:</td><td>" + message + "</td></tr>");
555901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
556901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.write("</table></body></html>");
557901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   document.close();
558901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (parent != window) {
559901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       parent.setResult(testName, resultType, message);
560901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
561901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
562901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
563901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction checkInitialization(buildr, testname) {
564901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   return buildr.initializationError;
565901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
566901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
567901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction preload(docRef, varname, href) {
568901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   return builder.preload(docRef, varname, href);
569901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
570901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
571901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
572901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction load(docRef, varname, href) {
573901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   return builder.load(docRef, varname, href);
574901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
575901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
576901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
577901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction getImplementationAttribute(attr) {
578901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return builder.getImplementationAttribute(attr);
579901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
580901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
581901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
582901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction setImplementationAttribute(attribute, value) {
583901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    builder.setImplementationAttribute(attribute, value);
584901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
585901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
586901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction createXPathEvaluator(doc) {
587901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    try {
588901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        return doc.getFeature("XPath", null);
589901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
590901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    catch(ex) {
591901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
592901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return doc;
593901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
594901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
595901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
596901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction getImplementation() {
597901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return builder.getImplementation();
598901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
599901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
600901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction assertEquals(id, expected, actual) {
601901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   var myActual;
602901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (expected != actual) {
603901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       myActual = actual;
604901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       if (actual == null) {
605901afcec28e282052ffa6542c21b025cead9b4c0Steve Block          myActual = "null";
606901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       }
607901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       throw "failure:" + id + ": assertEquals failed, actual " + myActual + ", expected " + expected + ".";
608901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
609901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
610901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
611901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction assertNull(id, actual) {
612901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (actual != null) {
613901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       throw "failure:" + id + ": assertNull failed, actual " + actual;
614901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
615901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
616901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
617901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
618901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction assertTrue(id, actual) {
619901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (!actual) {
620901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       throw "failure:" + id + ": assertTrue failed";
621901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
622901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
623901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
624901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
625901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction assertFalse(id, actual) {
626901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (actual) {
627901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       throw "failure:" + id +  ": assertTrue failed";
628901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
629901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
630901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
631901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction assertNotNull(id, actual) {
632901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   if (actual == null) {
633901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       throw "failure:" + id + ": assertNotNull failed";
634901afcec28e282052ffa6542c21b025cead9b4c0Steve Block   }
635901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
636901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
637901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction fail(id) {
638901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    throw "failure:" + id +  ": fail";
639901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
640901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
641901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
642901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
643901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction getSuffix(contentType) {
644901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    switch(contentType) {
645901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        case "text/xml":
646901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        return ".xml";
647901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
648901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        case "application/xhtml+xml":
649901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        return ".xhtml";
650901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
651901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        case "image/svg+xml":
652901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        return ".svg";
653901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
654901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        case "text/mathml":
655901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        return ".mml";
656901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
657901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return ".html";
658901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
659901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
660901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
661901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction getResourceURI(name, scheme, contentType) {
662901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    var base = document.documentURI;
663901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if (base == null) {
664901afcec28e282052ffa6542c21b025cead9b4c0Steve Block       base = "";
665901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    } else {
666901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	   base = base.substring(0, base.lastIndexOf('/') + 1) + "files/";
667901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
668901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    return base + name + getSuffix(contentType);
669901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
670901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
671901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
672901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
673901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockfunction startTest() {
674901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
675901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
676901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  WebKit modification: 18-August-2005
677901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
678901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  Inform the test controller that this test has a text-format result and so should
679901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  be dumped as text, and also that the dump should not occur automatically.
680901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
681901afcec28e282052ffa6542c21b025cead9b4c0Steve Blockif (window.layoutTestController) {
682901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    layoutTestController.dumpAsText();
683901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    layoutTestController.waitUntilDone();
684901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
685901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
686901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  End WebKit modification
687901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
688901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
689901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	//
690901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	//   invoke test setup
691901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	//
692901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	setUpPage();
693901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
694901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	try {
695901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    runTest();
696901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    if (builder.initializationError == null) {
697901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	       setResult(null, null);
698901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    } else {
699901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	       setResult("skip", builder.initializationError);
700901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    }
701901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	} catch(ex) {
702901afcec28e282052ffa6542c21b025cead9b4c0Steve Block	    if (typeof(ex.substring) != 'undefined' && ex.substring(0, 8) == "failure:") {
703901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            setResult("failure", ex.substring(8));
704901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        } else {
705901afcec28e282052ffa6542c21b025cead9b4c0Steve Block            setResult("error", ex);
706901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        }
707901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
708901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
709901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
710901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  WebKit modification: 18-August-2005
711901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
712901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  Inform the test controller that this test is complete, so it's time to dump.
713901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
714901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    if (window.layoutTestController) {
715901afcec28e282052ffa6542c21b025cead9b4c0Steve Block        layoutTestController.notifyDone();
716901afcec28e282052ffa6542c21b025cead9b4c0Steve Block    }
717901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
718901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//  End WebKit modification
719901afcec28e282052ffa6542c21b025cead9b4c0Steve Block//
720901afcec28e282052ffa6542c21b025cead9b4c0Steve Block
721901afcec28e282052ffa6542c21b025cead9b4c0Steve Block}
722