Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 4 | |
michael@0 | 5 | <!-- |
michael@0 | 6 | tests for templates with invalid syntax |
michael@0 | 7 | --> |
michael@0 | 8 | |
michael@0 | 9 | <window title="XUL Invalid Template Tests" width="500" height="600" |
michael@0 | 10 | onload="runTest();" |
michael@0 | 11 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 12 | <script type="application/javascript" |
michael@0 | 13 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 14 | |
michael@0 | 15 | <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> |
michael@0 | 16 | |
michael@0 | 17 | <script> |
michael@0 | 18 | <![CDATA[ |
michael@0 | 19 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 20 | |
michael@0 | 21 | var consoleService = Components.classes["@mozilla.org/consoleservice;1"]. |
michael@0 | 22 | getService(Components.interfaces.nsIConsoleService); |
michael@0 | 23 | |
michael@0 | 24 | function checkConsole(expectedError) |
michael@0 | 25 | { |
michael@0 | 26 | var message = consoleService.getMessageArray()[0].message; |
michael@0 | 27 | is(message, expectedError, "logged message " + expectedError); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | // each test consists of a pre function executed before the template build, an |
michael@0 | 31 | // expected error message, and a post function executed after the template build |
michael@0 | 32 | var tests = [ |
michael@0 | 33 | |
michael@0 | 34 | // <queryset> used in invalid location |
michael@0 | 35 | { |
michael@0 | 36 | pre: function(template) template.insertBefore(document.createElement("queryset"), template.lastChild), |
michael@0 | 37 | error: "Error parsing template: unexpected <queryset> element", |
michael@0 | 38 | post: function(queryset) queryset.parentNode.removeChild(queryset) |
michael@0 | 39 | }, |
michael@0 | 40 | |
michael@0 | 41 | // no member variable found |
michael@0 | 42 | { |
michael@0 | 43 | pre: function(template) $("action").firstChild.removeAttribute("uri"), |
michael@0 | 44 | error: "Error parsing template: no member variable found. Action body should have an element with uri attribute", |
michael@0 | 45 | post: function() $("action").firstChild.setAttribute("uri", "?child") |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | // bad binding subject |
michael@0 | 49 | { |
michael@0 | 50 | pre: function(template) $("binding").removeAttribute("subject"), |
michael@0 | 51 | error: "Error parsing template: <binding> requires a variable for its subject attribute", |
michael@0 | 52 | post: function() $("binding").setAttribute("subject", "?child"), |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | // bad binding predicate |
michael@0 | 56 | { |
michael@0 | 57 | pre: function(template) $("binding").removeAttribute("predicate"), |
michael@0 | 58 | error: "Error parsing template: <binding> element is missing a predicate attribute", |
michael@0 | 59 | post: function() $("binding").setAttribute("predicate", "http://www.some-fictitious-zoo.com/rdf#name"), |
michael@0 | 60 | }, |
michael@0 | 61 | |
michael@0 | 62 | // bad binding object |
michael@0 | 63 | { |
michael@0 | 64 | pre: function(template) $("binding").setAttribute("object", "blah"), |
michael@0 | 65 | error: "Error parsing template: <binding> requires a variable for its object attribute", |
michael@0 | 66 | post: function() $("binding").setAttribute("object", "?name"), |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | // where condition missing a subject |
michael@0 | 70 | { |
michael@0 | 71 | pre: function(template) { var rule = $("rule"); |
michael@0 | 72 | var where = document.createElement("where"); |
michael@0 | 73 | where.setAttribute("subject", ""); |
michael@0 | 74 | where.setAttribute("rel", "equals"); |
michael@0 | 75 | where.setAttribute("value", "Raven"); |
michael@0 | 76 | rule.appendChild(where); |
michael@0 | 77 | return where; }, |
michael@0 | 78 | error: "Error parsing template: <where> element is missing a subject attribute", |
michael@0 | 79 | post: function(where) { where.parentNode.removeChild(where); } |
michael@0 | 80 | }, |
michael@0 | 81 | |
michael@0 | 82 | // where condition missing a rel |
michael@0 | 83 | { |
michael@0 | 84 | pre: function(template) { var rule = $("rule"); |
michael@0 | 85 | var where = document.createElement("where"); |
michael@0 | 86 | where.setAttribute("subject", "?name"); |
michael@0 | 87 | where.setAttribute("rel", ""); |
michael@0 | 88 | where.setAttribute("value", "Raven"); |
michael@0 | 89 | rule.appendChild(where); |
michael@0 | 90 | return where; }, |
michael@0 | 91 | error: "Error parsing template: <where> element is missing a rel attribute", |
michael@0 | 92 | post: function(where) { where.parentNode.removeChild(where); } |
michael@0 | 93 | }, |
michael@0 | 94 | |
michael@0 | 95 | // where condition missing a value |
michael@0 | 96 | { |
michael@0 | 97 | pre: function(template) { var rule = $("rule"); |
michael@0 | 98 | var where = document.createElement("where"); |
michael@0 | 99 | where.setAttribute("subject", "?name"); |
michael@0 | 100 | where.setAttribute("rel", "equals"); |
michael@0 | 101 | where.setAttribute("value", ""); |
michael@0 | 102 | rule.appendChild(where); |
michael@0 | 103 | return where; }, |
michael@0 | 104 | error: "Error parsing template: <where> element is missing a value attribute", |
michael@0 | 105 | post: function(where) { where.parentNode.removeChild(where); } |
michael@0 | 106 | }, |
michael@0 | 107 | |
michael@0 | 108 | // where condition missing a variable |
michael@0 | 109 | { |
michael@0 | 110 | pre: function(template) { var rule = $("rule"); |
michael@0 | 111 | var where = document.createElement("where"); |
michael@0 | 112 | where.setAttribute("subject", "name"); |
michael@0 | 113 | where.setAttribute("rel", "equals"); |
michael@0 | 114 | where.setAttribute("value", "Raven"); |
michael@0 | 115 | rule.appendChild(where); |
michael@0 | 116 | return where; }, |
michael@0 | 117 | error: "Error parsing template: <where> element must have at least one variable as a subject or value", |
michael@0 | 118 | post: function(where) { where.parentNode.removeChild(where); } |
michael@0 | 119 | }, |
michael@0 | 120 | |
michael@0 | 121 | // bad member container |
michael@0 | 122 | { |
michael@0 | 123 | pre: function(template) $("member").setAttribute("container", "blah"), |
michael@0 | 124 | error: "Error parsing template: <member> requires a variable for its container attribute", |
michael@0 | 125 | post: function() $("member").setAttribute("container", "?uri"), |
michael@0 | 126 | }, |
michael@0 | 127 | |
michael@0 | 128 | // bad member child |
michael@0 | 129 | { |
michael@0 | 130 | pre: function(template) $("member").setAttribute("child", "blah"), |
michael@0 | 131 | error: "Error parsing template: <member> requires a variable for its child attribute", |
michael@0 | 132 | post: function() $("member").setAttribute("child", "?child"), |
michael@0 | 133 | }, |
michael@0 | 134 | |
michael@0 | 135 | // bad triple subject |
michael@0 | 136 | { |
michael@0 | 137 | pre: function(template) $("triple").removeAttribute("subject"), |
michael@0 | 138 | error: "Error parsing template: <triple> requires a variable for its subject attribute", |
michael@0 | 139 | post: function() $("triple").setAttribute("subject", "?child"), |
michael@0 | 140 | }, |
michael@0 | 141 | |
michael@0 | 142 | // missing triple predicate |
michael@0 | 143 | { |
michael@0 | 144 | pre: function(template) $("triple").removeAttribute("predicate"), |
michael@0 | 145 | error: "Error parsing template: <triple> should have a non-variable value as a predicate", |
michael@0 | 146 | post: function() $("triple").setAttribute("predicate", "http://www.some-fictitious-zoo.com/rdf#name"), |
michael@0 | 147 | }, |
michael@0 | 148 | |
michael@0 | 149 | // bad triple predicate |
michael@0 | 150 | { |
michael@0 | 151 | pre: function(template) $("triple").setAttribute("predicate", "?predicate"), |
michael@0 | 152 | error: "Error parsing template: <triple> should have a non-variable value as a predicate", |
michael@0 | 153 | post: function() $("triple").setAttribute("predicate", "http://www.some-fictitious-zoo.com/rdf#name"), |
michael@0 | 154 | }, |
michael@0 | 155 | |
michael@0 | 156 | // bad triple object |
michael@0 | 157 | { |
michael@0 | 158 | pre: function(template) $("triple").removeAttribute("object"), |
michael@0 | 159 | error: "Error parsing template: <triple> requires a variable for its object attribute", |
michael@0 | 160 | post: function() $("triple").setAttribute("object", "?name"), |
michael@0 | 161 | }, |
michael@0 | 162 | |
michael@0 | 163 | // content not first element in query |
michael@0 | 164 | { |
michael@0 | 165 | pre: function(template) { var content = $("content"); content.parentNode.appendChild(content); return content; }, |
michael@0 | 166 | error: "Error parsing template: expected <content> to be first", |
michael@0 | 167 | post: function(content) content.parentNode.insertBefore(content, content.parentNode.firstChild), |
michael@0 | 168 | }, |
michael@0 | 169 | |
michael@0 | 170 | // member container variable not bound |
michael@0 | 171 | { |
michael@0 | 172 | pre: function(template) $("member").removeAttribute("container"), |
michael@0 | 173 | error: "Error parsing template: neither container or child variables of <member> has a value", |
michael@0 | 174 | post: function() $("member").setAttribute("container", "?uri"), |
michael@0 | 175 | }, |
michael@0 | 176 | |
michael@0 | 177 | // neither triple subject or object variable are bound |
michael@0 | 178 | { |
michael@0 | 179 | pre: function(template) $("triple").setAttribute("subject", "?blah"), |
michael@0 | 180 | error: "Error parsing template: neither subject or object variables of <triple> has a value", |
michael@0 | 181 | post: function() $("triple").setAttribute("subject", "?child"), |
michael@0 | 182 | }, |
michael@0 | 183 | |
michael@0 | 184 | // neither triple subject or object variable are bound |
michael@0 | 185 | { |
michael@0 | 186 | pre: function(template) { var triple = $("triple"); triple.setAttribute("subject", "blah"); |
michael@0 | 187 | triple.setAttribute("object", "blah"); }, |
michael@0 | 188 | error: "Error parsing template: <triple> should have at least one variable as a subject or object", |
michael@0 | 189 | post: function() { var triple = $("triple"); triple.setAttribute("subject", "?uri"); |
michael@0 | 190 | triple.setAttribute("object", "?uri") } |
michael@0 | 191 | }, |
michael@0 | 192 | |
michael@0 | 193 | // could not parse xml query expression |
michael@0 | 194 | { |
michael@0 | 195 | firstXMLTest: true, |
michael@0 | 196 | pre: function(template) { $("query").setAttribute("expr", "something()"); }, |
michael@0 | 197 | error: "Error parsing template: XPath expression in query could not be parsed", |
michael@0 | 198 | post: function() { } |
michael@0 | 199 | }, |
michael@0 | 200 | |
michael@0 | 201 | // could not parse xml assign expression |
michael@0 | 202 | { |
michael@0 | 203 | pre: function(template) { var query = $("query"); |
michael@0 | 204 | query.setAttribute("expr", "*"); |
michael@0 | 205 | var assign = document.createElement("assign"); |
michael@0 | 206 | assign.setAttribute("var", "?name"); |
michael@0 | 207 | assign.setAttribute("expr", "something()"); |
michael@0 | 208 | query.appendChild(assign); |
michael@0 | 209 | return assign; }, |
michael@0 | 210 | error: "Error parsing template: XPath expression in <assign> could not be parsed", |
michael@0 | 211 | post: function(assign) { assign.parentNode.removeChild(assign); } |
michael@0 | 212 | }, |
michael@0 | 213 | |
michael@0 | 214 | // could not parse xml binding expression |
michael@0 | 215 | { |
michael@0 | 216 | pre: function(template) { $("binding").setAttribute("predicate", "something()"); }, |
michael@0 | 217 | error: "Error parsing template: XPath expression in <binding> could not be parsed", |
michael@0 | 218 | post: function() { $("binding").setAttribute("predicate", "[name]"); }, |
michael@0 | 219 | }, |
michael@0 | 220 | |
michael@0 | 221 | ]; |
michael@0 | 222 | |
michael@0 | 223 | function runTest() |
michael@0 | 224 | { |
michael@0 | 225 | var root = $("root"); |
michael@0 | 226 | var template = $("template"); |
michael@0 | 227 | while (test = tests.shift()) { |
michael@0 | 228 | consoleService.reset(); |
michael@0 | 229 | var context = test.pre(template); |
michael@0 | 230 | root.builder.rebuild(); |
michael@0 | 231 | checkConsole(test.error); |
michael@0 | 232 | test.post(context); |
michael@0 | 233 | |
michael@0 | 234 | // preload and set up for the xml datasource query error tests |
michael@0 | 235 | if (tests.length && tests[0].firstXMLTest) { |
michael@0 | 236 | var src = window.location.href.replace(/test_tmpl.*xul/, "animals.xml"); |
michael@0 | 237 | xmlDoc = new XMLHttpRequest(); |
michael@0 | 238 | xmlDoc.open("get", src, false); |
michael@0 | 239 | xmlDoc.send(null); |
michael@0 | 240 | |
michael@0 | 241 | var root = $("root"); |
michael@0 | 242 | root.setAttribute("querytype", "xml"); |
michael@0 | 243 | root.setAttribute("datasources", "animals.xml"); |
michael@0 | 244 | $("binding").setAttribute("predicate", "[name]"); |
michael@0 | 245 | |
michael@0 | 246 | function waitForDatasource() { |
michael@0 | 247 | // wait for the datasource to be available before continuing the test |
michael@0 | 248 | if (root.builder.datasource instanceof XMLDocument) |
michael@0 | 249 | runTest(); |
michael@0 | 250 | else |
michael@0 | 251 | setTimeout(waitForDatasource, 100); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | setTimeout(waitForDatasource, 0); |
michael@0 | 255 | return; |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | SimpleTest.finish(); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | ]]> |
michael@0 | 262 | </script> |
michael@0 | 263 | |
michael@0 | 264 | <vbox id="root" datasources="animals.rdf" ref="http://www.some-fictitious-zoo.com/birds"> |
michael@0 | 265 | <template id="template"> |
michael@0 | 266 | <query id="query"> |
michael@0 | 267 | <content id="content" uri="?uri"/> |
michael@0 | 268 | <member id="member" container="?uri" child="?child"/> |
michael@0 | 269 | <triple id="triple" subject="?child" predicate="http://www.some-fictitious-zoo.com/rdf#name" object="?name"/> |
michael@0 | 270 | </query> |
michael@0 | 271 | <rule id="rule"> |
michael@0 | 272 | <binding id="binding" subject="?child" predicate="http://www.some-fictitious-zoo.com/rdf#name" object="?name"/> |
michael@0 | 273 | <action id="action"> |
michael@0 | 274 | <label uri="?child" value="?name"/> |
michael@0 | 275 | </action> |
michael@0 | 276 | </rule> |
michael@0 | 277 | </template> |
michael@0 | 278 | </vbox> |
michael@0 | 279 | |
michael@0 | 280 | </window> |