content/xul/templates/tests/chrome/test_tmpl_errors.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial