Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
michael@0 | 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
michael@0 | 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
michael@0 | 4 | <head> |
michael@0 | 5 | <title>script.aculo.us Unit test file</title> |
michael@0 | 6 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
michael@0 | 7 | <script src="../../lib/prototype.js" type="text/javascript"></script> |
michael@0 | 8 | <script src="../../src/scriptaculous.js" type="text/javascript"></script> |
michael@0 | 9 | <script src="../../src/unittest.js" type="text/javascript"></script> |
michael@0 | 10 | <link rel="stylesheet" href="../test.css" type="text/css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <h1>script.aculo.us Unit test file</h1> |
michael@0 | 14 | <p> |
michael@0 | 15 | Tests for builder.js |
michael@0 | 16 | </p> |
michael@0 | 17 | |
michael@0 | 18 | <!-- Log output --> |
michael@0 | 19 | <div id="testlog"> </div> |
michael@0 | 20 | |
michael@0 | 21 | <div id="result"></div> |
michael@0 | 22 | |
michael@0 | 23 | <!-- Tests follow --> |
michael@0 | 24 | <script type="text/javascript" language="javascript" charset="utf-8"> |
michael@0 | 25 | // <![CDATA[ |
michael@0 | 26 | |
michael@0 | 27 | // Serializes a node and its contents to plain old HTML |
michael@0 | 28 | // IMPORTANT: style attributes can't be correctly serialized cross-browser wise, |
michael@0 | 29 | // so the contents of style attributes must match what IE thinks is correct |
michael@0 | 30 | function serializeNode(node){ |
michael@0 | 31 | if(node.nodeType == 3) return node.nodeValue; |
michael@0 | 32 | node = $(node); |
michael@0 | 33 | var tag = node.tagName.toLowerCase(); |
michael@0 | 34 | return '<' + ([tag].concat($A(node.attributes).map(function(attr){ |
michael@0 | 35 | // Filter out stuff that we don't need |
michael@0 | 36 | if(attr.nodeName == '_extended' || attr.nodeName == '_counted' || |
michael@0 | 37 | typeof attr.nodeValue == 'function' ||!Element.hasAttribute(node, attr.nodeName)) return; |
michael@0 | 38 | // remove trailing ; in style attributes on Firefox |
michael@0 | 39 | var value = node.readAttribute(attr.nodeName); |
michael@0 | 40 | if(attr.nodeName == 'style' && value.endsWith(';')) |
michael@0 | 41 | value = value.substr(0, value.length-1); |
michael@0 | 42 | return attr.nodeName + '="' + value + '"' |
michael@0 | 43 | }).compact().sort())).join(' ') + '>' + $A(node.childNodes).map(serializeNode).join('') + |
michael@0 | 44 | '</' + tag + '>'; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | new Test.Unit.Runner({ |
michael@0 | 48 | |
michael@0 | 49 | setup: function() { |
michael@0 | 50 | $('result').innerHTML = ''; |
michael@0 | 51 | }, |
michael@0 | 52 | |
michael@0 | 53 | testBuilderBasics: function() { with(this) { |
michael@0 | 54 | var element = Builder.node('div'); |
michael@0 | 55 | assertEqual('DIV', element.nodeName); |
michael@0 | 56 | |
michael@0 | 57 | var element = Builder.node('div',{id:'mydiv'}) |
michael@0 | 58 | assertEqual('mydiv', element.id); |
michael@0 | 59 | |
michael@0 | 60 | var element = Builder.node('div',{id:'mydiv',className:'one two'}) |
michael@0 | 61 | assertEqual('mydiv', element.id); |
michael@0 | 62 | assertEqual('one two', element.className); |
michael@0 | 63 | |
michael@0 | 64 | var element = Builder.node('span','text 123 <blah>'); |
michael@0 | 65 | assertEqual('SPAN', element.nodeName); |
michael@0 | 66 | assertEqual('text 123 <blah>', element.innerHTML); |
michael@0 | 67 | |
michael@0 | 68 | var element = Builder.node('span',123); |
michael@0 | 69 | assertEqual('SPAN', element.nodeName); |
michael@0 | 70 | assertEqual('123', element.innerHTML); |
michael@0 | 71 | |
michael@0 | 72 | var element = Builder.node('span',['test']); |
michael@0 | 73 | assertEqual('SPAN', element.nodeName); |
michael@0 | 74 | assertEqual('test', element.innerHTML); |
michael@0 | 75 | |
michael@0 | 76 | var element = Builder.node('span',['test',123]); |
michael@0 | 77 | assertEqual('SPAN', element.nodeName); |
michael@0 | 78 | assertEqual('test123', element.innerHTML); |
michael@0 | 79 | |
michael@0 | 80 | var element = Builder.node('span',{},['test',123]); |
michael@0 | 81 | assertEqual('SPAN', element.nodeName); |
michael@0 | 82 | assertEqual('test123', element.innerHTML); |
michael@0 | 83 | |
michael@0 | 84 | var element = Builder.node('span',{id:'myspan'},['test',123]); |
michael@0 | 85 | assertEqual('SPAN', element.nodeName); |
michael@0 | 86 | assertEqual('myspan', element.id); |
michael@0 | 87 | assertEqual('test123', element.innerHTML); |
michael@0 | 88 | |
michael@0 | 89 | var element = Builder.node('div',[1,2,[3],[[[4],5],6],7,8,[[[[9]]],0]]); |
michael@0 | 90 | assertEqual('1234567890',element.innerHTML); |
michael@0 | 91 | |
michael@0 | 92 | var element = Builder.node('div',[1,'2',['3'],[[[4],'5'],6],7,'8',[[[['9']]],0]]); |
michael@0 | 93 | assertEqual('1234567890',element.innerHTML); |
michael@0 | 94 | |
michael@0 | 95 | var element = Builder.node('div',{id:'mydiv'},[1,2,[3],[[[4],5],6],7,8,[[[[9]]],0]]); |
michael@0 | 96 | assertEqual('1234567890',element.innerHTML); |
michael@0 | 97 | |
michael@0 | 98 | var element = Builder.node('div',{id:'mydiv'},[1,'2',['3'],[[[4],'5'],6],7,'8',[[[['9']]],0]]); |
michael@0 | 99 | assertEqual('1234567890',element.innerHTML); |
michael@0 | 100 | assertEqual(10, element.childNodes.length); |
michael@0 | 101 | |
michael@0 | 102 | var element = Builder.node('div', Builder.node('span')); |
michael@0 | 103 | assertEqual(1, element.childNodes.length); |
michael@0 | 104 | assertEqual('SPAN', element.childNodes[0].tagName); |
michael@0 | 105 | |
michael@0 | 106 | var element = Builder.node('div', {id:'mydiv'}, Builder.node('span')); |
michael@0 | 107 | assertEqual(1, element.childNodes.length); |
michael@0 | 108 | assertEqual('mydiv', element.id); |
michael@0 | 109 | assertEqual('SPAN', element.childNodes[0].tagName); |
michael@0 | 110 | }}, |
michael@0 | 111 | |
michael@0 | 112 | testBuilderClassAndFor: function() { with(this) { |
michael@0 | 113 | var elt = Builder.node('div', { className: 'demoClass' }); |
michael@0 | 114 | assertEqual('demoClass', elt.className); |
michael@0 | 115 | var elt = Builder.node('label', { htmlFor: 'mydiv' }); |
michael@0 | 116 | assertEqual('mydiv', elt.htmlFor); |
michael@0 | 117 | }}, |
michael@0 | 118 | |
michael@0 | 119 | testBuilderAllXHTMLTags: function() { with(this) { |
michael@0 | 120 | var XHTML_TAGS = [ |
michael@0 | 121 | 'a','abbr','acronym','address','applet','area', |
michael@0 | 122 | 'b','bdo','big','blockquote','br','button', |
michael@0 | 123 | 'caption','cite','code','col','colgroup', |
michael@0 | 124 | 'dd','del','dfn','div','dl','dt', |
michael@0 | 125 | 'em', |
michael@0 | 126 | 'fieldset','form', |
michael@0 | 127 | 'h1','h2','h3','h4','h5','h6','hr', |
michael@0 | 128 | 'i','iframe','img','input','ins', |
michael@0 | 129 | 'kbd', |
michael@0 | 130 | 'label','legend','li', |
michael@0 | 131 | 'map', |
michael@0 | 132 | 'object','ol','optgroup','option', |
michael@0 | 133 | 'p','param','pre', |
michael@0 | 134 | 'q', |
michael@0 | 135 | 'samp','script','select','small','span','strong','style','sub','sup', |
michael@0 | 136 | 'table','tbody','td','textarea','tfoot','th','thead','tr','tt', |
michael@0 | 137 | 'ul','var'] |
michael@0 | 138 | |
michael@0 | 139 | XHTML_TAGS.each(function(tag) { |
michael@0 | 140 | try { |
michael@0 | 141 | var element = Builder.node(tag); |
michael@0 | 142 | assertNotNull(element, 'Tag "'+tag+'" expected, but was null.'); |
michael@0 | 143 | assertEqual(tag.toUpperCase(), element.nodeName); |
michael@0 | 144 | |
michael@0 | 145 | var element = Builder.node(tag,{id:'tag_'+tag+'_test_id'}); |
michael@0 | 146 | assertEqual(tag.toUpperCase(), element.nodeName); |
michael@0 | 147 | assertEqual('tag_'+tag+'_test_id', element.id, 'Setting id attribute for "'+tag+'" failed!'); |
michael@0 | 148 | } catch(e) { |
michael@0 | 149 | assert(false, 'Error while creating node of type '+tag+'. Note: Firefox bug in 1.0.X on option and optgroup, fixed in 1.5b1. Internet Explorer 6 doesn\'t support the ABBR tag and has no standard DOM implementation for tables.'); |
michael@0 | 150 | } |
michael@0 | 151 | }); |
michael@0 | 152 | }}, |
michael@0 | 153 | |
michael@0 | 154 | // special case, because requires workarounds on IE and Firefox < 1.5 |
michael@0 | 155 | testBuilderOptionTag: function() { with(this) { |
michael@0 | 156 | assertEqual('', Builder.node('option').innerHTML); |
michael@0 | 157 | assertEqual('test', Builder.node('option','test').innerHTML); |
michael@0 | 158 | assertEqual('', Builder.node('option',{className:'test'}).innerHTML); |
michael@0 | 159 | assertEqual('test', Builder.node('option',{className:'test'},'test').innerHTML); |
michael@0 | 160 | assertEqual('test', Builder.node('option',{},'test').innerHTML); |
michael@0 | 161 | |
michael@0 | 162 | var selectElement = Builder.node('select'); |
michael@0 | 163 | var optionElement = Builder.node('option',{className:'test',id:'option_123'},123); |
michael@0 | 164 | selectElement.appendChild(optionElement); |
michael@0 | 165 | document.body.appendChild(selectElement); |
michael@0 | 166 | assertEqual('123', $('option_123').innerHTML); |
michael@0 | 167 | }}, |
michael@0 | 168 | |
michael@0 | 169 | testBuilderContatenation: function() { with(this) { |
michael@0 | 170 | var element = Builder.node('div', [Builder.node('span')]); |
michael@0 | 171 | assertEqual('DIV', element.nodeName); |
michael@0 | 172 | assertEqual(1, element.childNodes.length); |
michael@0 | 173 | assertEqual('SPAN', element.firstChild.nodeName); |
michael@0 | 174 | |
michael@0 | 175 | var element = Builder.node('div', [Builder.node('span'),'text']); |
michael@0 | 176 | assertEqual(2, element.childNodes.length); |
michael@0 | 177 | assertEqual(0, element.firstChild.childNodes.length); |
michael@0 | 178 | assertEqual('DIV', element.nodeName); |
michael@0 | 179 | assertEqual('SPAN', element.firstChild.nodeName); |
michael@0 | 180 | assertEqual(3, element.firstChild.nextSibling.nodeType); |
michael@0 | 181 | |
michael@0 | 182 | var element = Builder.node('div', [Builder.node('span',[Builder.node('strong','blah')]),'text']); |
michael@0 | 183 | assertEqual(2, element.childNodes.length); |
michael@0 | 184 | assertEqual(1, element.firstChild.childNodes.length); |
michael@0 | 185 | assertEqual('DIV', element.nodeName); |
michael@0 | 186 | assertEqual('SPAN', element.firstChild.nodeName); |
michael@0 | 187 | assertEqual('STRONG', element.firstChild.firstChild.nodeName); |
michael@0 | 188 | assertEqual('blah', element.firstChild.firstChild.innerHTML); |
michael@0 | 189 | assertEqual(3, element.firstChild.nextSibling.nodeType); |
michael@0 | 190 | }}, |
michael@0 | 191 | |
michael@0 | 192 | testBuilderComplexExample: function() { with(this) { |
michael@0 | 193 | var element = Builder.node('div',{id:'ghosttrain'},[ |
michael@0 | 194 | Builder.node('div',{style:'font-weight: bold; font-size: 11px'},[ |
michael@0 | 195 | Builder.node('h1','Ghost Train'), |
michael@0 | 196 | "testtext", 2, 3, 4, |
michael@0 | 197 | Builder.node('ul',[ |
michael@0 | 198 | Builder.node('li',{onclick:'alert(\'test\')'},'click me') |
michael@0 | 199 | ]), |
michael@0 | 200 | ]), |
michael@0 | 201 | ]); |
michael@0 | 202 | assertEqual('DIV', element.nodeName); |
michael@0 | 203 | |
michael@0 | 204 | $('result').appendChild(element); |
michael@0 | 205 | |
michael@0 | 206 | // browsers aren't sure about upper and lower case on elements |
michael@0 | 207 | assertEqual( |
michael@0 | 208 | '<div id="ghosttrain"><div style="font-weight: bold; font-size: 11px">' + |
michael@0 | 209 | '<h1>Ghost Train</h1>testtext234<ul><li onclick="alert(\'test\')">click me</li></ul></div></div>', |
michael@0 | 210 | serializeNode($('result').childNodes[0])); |
michael@0 | 211 | }}, |
michael@0 | 212 | |
michael@0 | 213 | testBuilderShortcuts: function() { with(this) { |
michael@0 | 214 | Builder.dump(); |
michael@0 | 215 | |
michael@0 | 216 | var element = DIV(SPAN()); |
michael@0 | 217 | assertEqual('SPAN', element.childNodes[0].tagName); |
michael@0 | 218 | |
michael@0 | 219 | var element = DIV({id:'test'},SPAN()); |
michael@0 | 220 | assertEqual('SPAN', element.childNodes[0].tagName); |
michael@0 | 221 | |
michael@0 | 222 | var element = DIV({id:'ghosttrain'},[ |
michael@0 | 223 | DIV({style:'font-weight: bold; font-size: 11px'},[ |
michael@0 | 224 | H1('Ghost Train'), |
michael@0 | 225 | "testtext", 2, 3, 4, |
michael@0 | 226 | UL([ |
michael@0 | 227 | LI({onclick:'alert(\'test\')'},'click me') |
michael@0 | 228 | ]), |
michael@0 | 229 | ]), |
michael@0 | 230 | ]); |
michael@0 | 231 | assertEqual('DIV', element.nodeName); |
michael@0 | 232 | |
michael@0 | 233 | $('result').appendChild(element); |
michael@0 | 234 | |
michael@0 | 235 | assertEqual( |
michael@0 | 236 | '<div id="ghosttrain"><div style="font-weight: bold; font-size: 11px">' + |
michael@0 | 237 | '<h1>Ghost Train</h1>testtext234<ul><li onclick="alert(\'test\')">click me</li></ul></div></div>', |
michael@0 | 238 | serializeNode($('result').childNodes[0])); |
michael@0 | 239 | }}, |
michael@0 | 240 | |
michael@0 | 241 | testBuilderBuild: function() { with(this) { |
michael@0 | 242 | ['<span>this is <b>neat!</b></span>',' \n<span>this is <b>neat!</b></span>\n '].each( |
michael@0 | 243 | function(html){ |
michael@0 | 244 | var node = Builder.build(html); |
michael@0 | 245 | assertEqual('<span>this is <b>neat!</b></span>', serializeNode(node)); |
michael@0 | 246 | }); |
michael@0 | 247 | }}, |
michael@0 | 248 | |
michael@0 | 249 | testBuilderAttributeEscaping: function() { with(this) { |
michael@0 | 250 | var element = Builder.node('div',{blah:"<foo'bar&baz\"bat>"}); |
michael@0 | 251 | assertEqual("<foo'bar&baz\"bat>", $(element).readAttribute('blah')); |
michael@0 | 252 | }} |
michael@0 | 253 | |
michael@0 | 254 | }); |
michael@0 | 255 | // ]]> |
michael@0 | 256 | </script> |
michael@0 | 257 | </body> |
michael@0 | 258 | </html> |