[extra] Import Firefox 3.0 beta 5 tarball
[mozilla-extra.git] / extensions / schema-validation / tests / schema-complex-test.html
blob958befad1d0a147c93fa093cf069118fe0c99440
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3 <head>
4 <title></title>
5 <style>
6 .passed {background-color:lightgreen;}
7 .failed {background-color:red;}
9 td {
10 padding:3px;
12 </style>
13 <script>
14 var myValidator = null;
15 var counter;
16 var failCounter = 0;
17 var results;
18 var start;
19 var end;
20 var gXMLDoc;
22 function getValidator() {
23 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
24 if (!myValidator)
25 myValidator = Components.classes["@mozilla.org/xmlextras/schemas/schemavalidator;1"]
26 .getService(Components.interfaces.nsISchemaValidator);
27 return myValidator;
30 function validateComplexType(aID, aType, aIsValid){
31 var rv = false;
33 if (!gXMLDoc) {
34 var xmlHTTP = new XMLHttpRequest();
35 xmlHTTP.open("GET", document.URL + "/../schema-complex-test.xml", false);
36 xmlHTTP.send(null);
37 gXMLDoc = xmlHTTP.responseXML;
40 var elm = gXMLDoc.getElementById(aID);
41 if (!elm) {
42 alert("No element found!");
43 } else {
44 //elm.removeAttribute("id");
45 rv = getValidator().validate(elm);
48 counter++;
49 results[results.length] = {type: aType, nodevalue: aID, rv: rv, isvalid: aIsValid};
52 function validateFile(aFile, aSchema, aIsValid) {
53 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
55 try{
56 var myValidator = Components.classes["@mozilla.org/schemavalidator;1"].createInstance(Components.interfaces.nsISchemaValidator);
57 } catch(e){ alert(e) }
59 var schemaLoader = Components.classes["@mozilla.org/schemavalidator/schemaloader;1"]
60 .getService(Components.interfaces.nsISVSchemaLoader);
61 try {
62 schema = schemaLoader.load(aSchema);
63 myValidator.loadSchema(schema);
64 } catch(e){alert(e)}
66 var rv = false;
68 var xmlHTTP = new XMLHttpRequest();
69 xmlHTTP.open("GET", aFile, false);
70 xmlHTTP.send(null);
71 xmlDoc = xmlHTTP.responseXML;
73 xmlDoc.documentElement.removeAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
74 rv = getValidator().validate(xmlDoc.documentElement);
76 counter++;
77 results[results.length] = {type: "file", nodevalue: "", rv: rv, isvalid: aIsValid};
80 function displayResults(){
81 var tbody = document.createElement("tbody");
82 var tr, td, textNode;
83 for (var run = 0; run < results.length; run++){
84 tr = document.createElement("tr");
86 td = document.createElement("td");
87 textNode = document.createTextNode(run + 1);
88 td.appendChild(textNode);
89 tr.appendChild(td);
91 td = document.createElement("td");
92 textNode = document.createTextNode(results[run].type);
93 td.appendChild(textNode);
94 tr.appendChild(td);
96 td = document.createElement("td");
97 textNode = document.createTextNode(results[run].nodevalue);
98 td.appendChild(textNode);
99 tr.appendChild(td);
101 td = document.createElement("td");
102 textNode = document.createTextNode(results[run].rv);
103 td.appendChild(textNode);
104 tr.appendChild(td);
106 td = document.createElement("td");
107 textNode = document.createTextNode(results[run].isvalid);
108 td.appendChild(textNode);
109 tr.appendChild(td);
111 td = document.createElement("td");
112 textNode = document.createTextNode((results[run].rv == results[run].isvalid) ? "Passed" : "Failed");
113 td.appendChild(textNode);
114 td.className = (results[run].rv == results[run].isvalid) ? "passed" : "failed";
115 tr.appendChild(td);
117 tbody.appendChild(tr);
119 if (results[run].rv!=results[run].isvalid)
120 failCounter++;
122 document.getElementById("resultTable").replaceChild(tbody, document.getElementById("results"));
125 var dp = new DOMParser();
126 var schema;
128 function test() {
129 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
131 try{
132 myValidator = Components.classes["@mozilla.org/schemavalidator;1"].createInstance(Components.interfaces.nsISchemaValidator);
133 } catch(e){ alert(e) }
135 var schemaLoader = Components.classes["@mozilla.org/schemavalidator/schemaloader;1"]
136 .getService(Components.interfaces.nsISVSchemaLoader);
137 try {
138 // SchemaLoader.Load() wants a URI
139 schema = schemaLoader.load(document.URL + "/../schema.xsd");
140 //alert(schema.attributeFormDefaultQualified)
141 myValidator.loadSchema(schema);
142 } catch(e){alert(e)}
144 //schema collection
145 var schemaCollection = schema.collection;
147 document.getElementById("results").innerHTML = "";
148 counter = 0;
149 failCounter = 0;
150 results = new Array();
152 start = new Date();
154 if (1) {
155 validateComplexType("balance-1", "balance-1", true);
156 validateComplexType("balance-2", "balance-2", false);
157 validateComplexType("balance-3", "balance-3", false);
158 validateComplexType("balance-4", "balance-4", false);
159 validateComplexType("balance-5", "balance-5", true);
161 validateComplexType("balance2-1", "balance2-1", true);
162 validateComplexType("balance2-2", "balance2-2", false);
163 validateComplexType("balance2-3", "balance2-3", false);
164 validateComplexType("balance2-4", "balance2-4", false);
166 validateComplexType("balance3-1", "balance3-1", true);
167 validateComplexType("balance3-2", "balance3-2", true);
168 validateComplexType("balance3-3", "balance3-3", false);
169 validateComplexType("balance3-4", "balance3-4", true);
170 validateComplexType("balance3-5", "balance3-5", false);
172 validateComplexType("balance4-1", "balance4-1", true);
173 validateComplexType("balance4-2", "balance4-2", true);
174 validateComplexType("balance4-3", "balance4-3", false);
175 validateComplexType("balance4-4", "balance4-4", false);
177 validateComplexType("balance5-1", "balance5-1", true);
178 validateComplexType("balance5-2", "balance5-2", false);
179 validateComplexType("balance5-3", "balance5-3", true);
180 validateComplexType("balance5-4", "balance5-4", true);
181 validateComplexType("balance5-5", "balance5-5", false);
182 validateComplexType("balance5-6", "balance5-6", false);
184 validateComplexType("balance6-1", "balance6-1", true);
185 validateComplexType("balance6-2", "balance6-2", true);
186 validateComplexType("balance6-3", "balance6-3", true);
187 validateComplexType("balance6-4", "balance6-4", true);
188 validateComplexType("balance6-5", "balance6-5", false);
189 validateComplexType("balance6-6", "balance6-6", true);
190 validateComplexType("balance6-7", "balance6-7", true);
191 validateComplexType("balance6-8", "balance6-8", true);
192 validateComplexType("balance6-9", "balance6-9", false);
194 validateComplexType("balance7-1", "balance7-1", false);
195 validateComplexType("balance7-2", "balance7-2", true);
196 validateComplexType("balance7-3", "balance7-3", false);
197 validateComplexType("balance7-4", "balance7-4", true);
198 validateComplexType("balance7-5", "balance7-5", false);
199 validateComplexType("balance7-6", "balance7-6", true);
200 validateComplexType("balance7-7", "balance7-7", true);
201 validateComplexType("balance7-8", "balance7-8", true);
202 validateComplexType("balance7-9", "balance7-9", false);
203 validateComplexType("balance7-10", "balance7-10", false);
204 validateComplexType("balance7-11", "balance7-11", false);
206 validateComplexType("balance8-1", "balance8-1", true);
207 validateComplexType("balance8-2", "balance8-2", true);
208 validateComplexType("balance8-3", "balance8-3", false);
209 validateComplexType("balance8-4", "balance8-4", true);
210 validateComplexType("balance8-5", "balance8-5", true);
211 validateComplexType("balance8-6", "balance8-6", false);
212 validateComplexType("balance8-7", "balance8-7", false);
214 validateComplexType("balance9-1", "balance9-1", true);
215 validateComplexType("balance9-2", "balance9-2", false);
216 validateComplexType("balance9-3", "balance9-3", false);
217 validateComplexType("balance9-4", "balance9-4", true);
218 validateComplexType("balance9-5", "balance9-5", false);
219 validateComplexType("balance9-6", "balance9-6", false);
221 validateComplexType("balance10-1", "balance10-1", false);
222 validateComplexType("balance10-2", "balance10-2", false);
223 validateComplexType("balance10-3", "balance10-3", false);
225 validateComplexType("balance11-1", "balance11-1", true);
226 validateComplexType("balance11-2", "balance11-2", false);
228 validateComplexType("balance12-1", "balance12-1", true);
229 validateComplexType("balance12-2", "balance12-2", true);
230 validateComplexType("balance12-3", "balance12-3", false);
231 validateComplexType("balance12-4", "balance12-4", false);
232 validateComplexType("balance12-5", "balance12-5", false);
234 validateComplexType("t1", "t1", true);
235 validateComplexType("t2", "t2", false);
236 validateComplexType("t3", "t3", true);
237 validateComplexType("t4", "t4", false);
238 validateComplexType("t5", "t5", false);
239 validateComplexType("t6", "t6", true);
240 validateComplexType("t7", "t7", false);
241 validateComplexType("t8", "t8", false);
242 validateComplexType("t9", "t9", false);
243 validateComplexType("t10", "t10", false);
244 validateComplexType("t11", "t11", true);
245 validateComplexType("t12", "t12", true);
246 validateComplexType("t13", "t13", false);
248 validateComplexType("author-1", "author-1", true);
249 validateComplexType("author-2", "author-2", false);
250 validateComplexType("author-3", "author-3", false);
251 validateComplexType("author-4", "author-4", false);
252 validateComplexType("author-5", "author-5", true);
253 validateComplexType("author-6", "author-6", false);
254 validateComplexType("author-7", "author-7", false);
255 validateComplexType("author-8", "author-8", false);
257 validateComplexType("author-2-1", "author-2-1", true);
258 validateComplexType("author-2-2", "author-2-2", false);
259 validateComplexType("author-2-3", "author-2-3", false);
261 validateComplexType("author-3-1", "author-3-1", true);
262 validateComplexType("author-3-2", "author-3-2", true);
264 validateComplexType("author-4-1", "author-4-1", true);
266 validateComplexType("balance-attrgroup-1-1", "balance-attrgroup-1-1", true);
267 validateComplexType("balance-attrgroup-1-2", "balance-attrgroup-1-2", true);
268 validateComplexType("balance-attrgroup-1-3", "balance-attrgroup-1-3", false);
269 validateComplexType("balance-attrgroup-1-4", "balance-attrgroup-1-4", false);
271 validateComplexType("group-1", "group-1", true);
272 validateComplexType("group-2", "group-2", true);
273 validateComplexType("group-3", "group-3", false);
274 validateComplexType("group-4", "group-4", false);
276 validateComplexType("deriv-ext-1-1", "deriv-ext-1-1", true);
277 validateComplexType("deriv-ext-1-2", "deriv-ext-1-2", false);
278 validateComplexType("deriv-ext-1-3", "deriv-ext-1-3", false);
280 validateComplexType("deriv-res-1-1", "deriv-res-1-1", true);
281 validateComplexType("deriv-res-1-2", "deriv-res-1-2", false);
283 validateComplexType("deriv-res-2-1", "deriv-res-2-1", true);
284 validateComplexType("deriv-res-2-2", "deriv-res-2-2", false);
286 validateComplexType("deriv-ext-complex-1-1", "deriv-ext-complex-1-1", true);
287 validateComplexType("deriv-ext-complex-1-2", "deriv-ext-complex-1-2", false);
289 validateComplexType("deriv-ext-restriction-1-1", "deriv-ext-restriction-1-1", true);
290 validateComplexType("deriv-ext-restriction-1-2", "deriv-ext-restriction-1-2", false);
291 validateComplexType("deriv-ext-restriction-1-3", "deriv-ext-restriction-1-3", true);
293 validateComplexType("empty-complex-1-1", "empty-complex-1-1", true);
294 validateComplexType("empty-complex-1-2", "empty-complex-1-2", true);
295 validateComplexType("empty-complex-1-3", "empty-complex-1-3", false);
296 validateComplexType("empty-complex-1-4", "empty-complex-1-4", false);
298 validateComplexType("empty-complex-2-1", "empty-complex-2-1", true);
299 validateComplexType("empty-complex-2-2", "empty-complex-2-2", true);
302 end = new Date();
304 // final result
305 displayResults();
306 document.getElementById("finalResults").innerHTML = counter + " Tests Completed, with " + failCounter + " Failures" +
307 ". Seconds: " + ((end-start) / 1000);
309 </script>
310 </head>
311 <body>
313 <button onclick="test()">Do</button>
315 <div id="finalResults"></div>
317 <table border=1 cellpadding=0 cellspacing=0 width="100%" id="resultTable" style="font-size:0.8em;">
318 <thead>
319 <td>#</td>
320 <td>Type</td>
321 <td>Value</td>
322 <td>Is Valid?</td>
323 <td>Should be Valid?</td>
324 <td>Result</td>
325 </thead>
326 <tbody id="results" />
327 </table>
328 </body>
329 </html>