dom/tests/browser/browser_bug396843.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 function test() {
michael@0 2 /** Test for Bug 396843 **/
michael@0 3 waitForExplicitFinish();
michael@0 4
michael@0 5 function testInDocument(doc, documentID) {
michael@0 6
michael@0 7 var allNodes = [];
michael@0 8 var XMLNodes = [];
michael@0 9
michael@0 10 // HTML
michael@0 11 function HTML_TAG(name) {
michael@0 12 allNodes.push(doc.createElement(name));
michael@0 13 }
michael@0 14
michael@0 15 /* List copy/pasted from nsHTMLTagList.h */
michael@0 16 HTML_TAG("a", "Anchor")
michael@0 17 HTML_TAG("abbr", "Span")
michael@0 18 HTML_TAG("acronym", "Span")
michael@0 19 HTML_TAG("address", "Span")
michael@0 20 HTML_TAG("applet", "SharedObject")
michael@0 21 HTML_TAG("area", "Area")
michael@0 22 HTML_TAG("b", "Span")
michael@0 23 HTML_TAG("base", "Shared")
michael@0 24 HTML_TAG("basefont", "Span")
michael@0 25 HTML_TAG("bdo", "Span")
michael@0 26 HTML_TAG("bgsound", "Span")
michael@0 27 HTML_TAG("big", "Span")
michael@0 28 HTML_TAG("blockquote", "Shared")
michael@0 29 HTML_TAG("body", "Body")
michael@0 30 HTML_TAG("br", "BR")
michael@0 31 HTML_TAG("button", "Button")
michael@0 32 HTML_TAG("canvas", "Canvas")
michael@0 33 HTML_TAG("caption", "TableCaption")
michael@0 34 HTML_TAG("center", "Span")
michael@0 35 HTML_TAG("cite", "Span")
michael@0 36 HTML_TAG("code", "Span")
michael@0 37 HTML_TAG("col", "TableCol")
michael@0 38 HTML_TAG("colgroup", "TableCol")
michael@0 39 HTML_TAG("dd", "Span")
michael@0 40 HTML_TAG("del", "Mod")
michael@0 41 HTML_TAG("dfn", "Span")
michael@0 42 HTML_TAG("dir", "Shared")
michael@0 43 HTML_TAG("div", "Div")
michael@0 44 HTML_TAG("dl", "SharedList")
michael@0 45 HTML_TAG("dt", "Span")
michael@0 46 HTML_TAG("em", "Span")
michael@0 47 HTML_TAG("embed", "SharedObject")
michael@0 48 HTML_TAG("fieldset", "FieldSet")
michael@0 49 HTML_TAG("font", "Font")
michael@0 50 HTML_TAG("form", "Form")
michael@0 51 HTML_TAG("frame", "Frame")
michael@0 52 HTML_TAG("frameset", "FrameSet")
michael@0 53 HTML_TAG("h1", "Heading")
michael@0 54 HTML_TAG("h2", "Heading")
michael@0 55 HTML_TAG("h3", "Heading")
michael@0 56 HTML_TAG("h4", "Heading")
michael@0 57 HTML_TAG("h5", "Heading")
michael@0 58 HTML_TAG("h6", "Heading")
michael@0 59 HTML_TAG("head", "Head")
michael@0 60 HTML_TAG("hr", "HR")
michael@0 61 HTML_TAG("html", "Html")
michael@0 62 HTML_TAG("i", "Span")
michael@0 63 HTML_TAG("iframe", "IFrame")
michael@0 64 HTML_TAG("image", "")
michael@0 65 HTML_TAG("img", "Image")
michael@0 66 HTML_TAG("input", "Input")
michael@0 67 HTML_TAG("ins", "Mod")
michael@0 68 HTML_TAG("isindex", "Unknown")
michael@0 69 HTML_TAG("kbd", "Span")
michael@0 70 HTML_TAG("keygen", "Span")
michael@0 71 HTML_TAG("label", "Label")
michael@0 72 HTML_TAG("legend", "Legend")
michael@0 73 HTML_TAG("li", "LI")
michael@0 74 HTML_TAG("link", "Link")
michael@0 75 HTML_TAG("listing", "Span")
michael@0 76 HTML_TAG("map", "Map")
michael@0 77 HTML_TAG("marquee", "Div")
michael@0 78 HTML_TAG("menu", "Shared")
michael@0 79 HTML_TAG("meta", "Meta")
michael@0 80 HTML_TAG("multicol", "Unknown")
michael@0 81 HTML_TAG("nobr", "Span")
michael@0 82 HTML_TAG("noembed", "Div")
michael@0 83 HTML_TAG("noframes", "Div")
michael@0 84 HTML_TAG("noscript", "Div")
michael@0 85 HTML_TAG("object", "Object")
michael@0 86 HTML_TAG("ol", "SharedList")
michael@0 87 HTML_TAG("optgroup", "OptGroup")
michael@0 88 HTML_TAG("option", "Option")
michael@0 89 HTML_TAG("p", "Paragraph")
michael@0 90 HTML_TAG("param", "Shared")
michael@0 91 HTML_TAG("plaintext", "Span")
michael@0 92 HTML_TAG("pre", "Pre")
michael@0 93 HTML_TAG("q", "Shared")
michael@0 94 HTML_TAG("s", "Span")
michael@0 95 HTML_TAG("samp", "Span")
michael@0 96 HTML_TAG("script", "Script")
michael@0 97 HTML_TAG("select", "Select")
michael@0 98 HTML_TAG("small", "Span")
michael@0 99 HTML_TAG("spacer", "Unknown")
michael@0 100 HTML_TAG("span", "Span")
michael@0 101 HTML_TAG("strike", "Span")
michael@0 102 HTML_TAG("strong", "Span")
michael@0 103 HTML_TAG("style", "Style")
michael@0 104 HTML_TAG("sub", "Span")
michael@0 105 HTML_TAG("sup", "Span")
michael@0 106 HTML_TAG("table", "Table")
michael@0 107 HTML_TAG("tbody", "TableSection")
michael@0 108 HTML_TAG("td", "TableCell")
michael@0 109 HTML_TAG("textarea", "TextArea")
michael@0 110 HTML_TAG("tfoot", "TableSection")
michael@0 111 HTML_TAG("th", "TableCell")
michael@0 112 HTML_TAG("thead", "TableSection")
michael@0 113 HTML_TAG("template", "Template")
michael@0 114 HTML_TAG("title", "Title")
michael@0 115 HTML_TAG("tr", "TableRow")
michael@0 116 HTML_TAG("tt", "Span")
michael@0 117 HTML_TAG("u", "Span")
michael@0 118 HTML_TAG("ul", "SharedList")
michael@0 119 HTML_TAG("var", "Span")
michael@0 120 HTML_TAG("wbr", "Shared")
michael@0 121 HTML_TAG("xmp", "Span")
michael@0 122
michael@0 123 function SVG_TAG(name) {
michael@0 124 allNodes.push(doc.createElementNS("http://www.w3.org/2000/svg", name));
michael@0 125 }
michael@0 126
michael@0 127 // List sorta stolen from SVG element factory.
michael@0 128 SVG_TAG("a")
michael@0 129 SVG_TAG("polyline")
michael@0 130 SVG_TAG("polygon")
michael@0 131 SVG_TAG("circle")
michael@0 132 SVG_TAG("ellipse")
michael@0 133 SVG_TAG("line")
michael@0 134 SVG_TAG("rect")
michael@0 135 SVG_TAG("svg")
michael@0 136 SVG_TAG("g")
michael@0 137 SVG_TAG("foreignObject")
michael@0 138 SVG_TAG("path")
michael@0 139 SVG_TAG("text")
michael@0 140 SVG_TAG("tspan")
michael@0 141 SVG_TAG("image")
michael@0 142 SVG_TAG("style")
michael@0 143 SVG_TAG("linearGradient")
michael@0 144 SVG_TAG("metadata")
michael@0 145 SVG_TAG("radialGradient")
michael@0 146 SVG_TAG("stop")
michael@0 147 SVG_TAG("defs")
michael@0 148 SVG_TAG("desc")
michael@0 149 SVG_TAG("script")
michael@0 150 SVG_TAG("use")
michael@0 151 SVG_TAG("symbol")
michael@0 152 SVG_TAG("marker")
michael@0 153 SVG_TAG("title")
michael@0 154 SVG_TAG("clipPath")
michael@0 155 SVG_TAG("textPath")
michael@0 156 SVG_TAG("filter")
michael@0 157 SVG_TAG("feBlend")
michael@0 158 SVG_TAG("feColorMatrix")
michael@0 159 SVG_TAG("feComponentTransfer")
michael@0 160 SVG_TAG("feComposite")
michael@0 161 SVG_TAG("feFuncR")
michael@0 162 SVG_TAG("feFuncG")
michael@0 163 SVG_TAG("feFuncB")
michael@0 164 SVG_TAG("feFuncA")
michael@0 165 SVG_TAG("feGaussianBlur")
michael@0 166 SVG_TAG("feMerge")
michael@0 167 SVG_TAG("feMergeNode")
michael@0 168 SVG_TAG("feMorphology")
michael@0 169 SVG_TAG("feOffset")
michael@0 170 SVG_TAG("feFlood")
michael@0 171 SVG_TAG("feTile")
michael@0 172 SVG_TAG("feTurbulence")
michael@0 173 SVG_TAG("feConvolveMatrix")
michael@0 174 SVG_TAG("feDistantLight")
michael@0 175 SVG_TAG("fePointLight")
michael@0 176 SVG_TAG("feSpotLight")
michael@0 177 SVG_TAG("feDiffuseLighting")
michael@0 178 SVG_TAG("feSpecularLighting")
michael@0 179 SVG_TAG("feDisplacementMap")
michael@0 180 SVG_TAG("feImage")
michael@0 181 SVG_TAG("pattern")
michael@0 182 SVG_TAG("mask")
michael@0 183 SVG_TAG("svgSwitch")
michael@0 184
michael@0 185 // Toss in some other namespaced stuff too, for good measure
michael@0 186 // XUL stuff might not be creatable in content documents
michael@0 187 try {
michael@0 188 allNodes.push(doc.createElementNS(
michael@0 189 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
michael@0 190 "window"));
michael@0 191 } catch (e) {}
michael@0 192 allNodes.push(doc.createElementNS("http://www.w3.org/1998/Math/MathML",
michael@0 193 "math"));
michael@0 194 allNodes.push(doc.createElementNS("http://www.w3.org/2001/xml-events",
michael@0 195 "testname"));
michael@0 196 allNodes.push(doc.createElementNS("bogus.namespace", "testname"));
michael@0 197
michael@0 198 var XMLDoc = doc.implementation.createDocument("", "", null);
michael@0 199
michael@0 200 // And non-elements
michael@0 201 allNodes.push(doc.createTextNode("some text"));
michael@0 202 allNodes.push(doc.createComment("some text"));
michael@0 203 allNodes.push(doc.createDocumentFragment());
michael@0 204 XMLNodes.push(XMLDoc.createCDATASection("some text"));
michael@0 205 XMLNodes.push(XMLDoc.createProcessingInstruction("PI", "data"));
michael@0 206
michael@0 207 function runTestUnwrapped() {
michael@0 208 if (!("wrappedJSObject" in doc)) {
michael@0 209 return;
michael@0 210 }
michael@0 211 ok(doc.wrappedJSObject.nodePrincipal === undefined,
michael@0 212 "Must not have document principal for " + documentID);
michael@0 213 ok(doc.wrappedJSObject.baseURIObject === undefined,
michael@0 214 "Must not have document base URI for " + documentID);
michael@0 215 ok(doc.wrappedJSObject.documentURIObject === undefined,
michael@0 216 "Must not have document URI for " + documentID);
michael@0 217
michael@0 218 for (var i = 0; i < allNodes.length; ++i) {
michael@0 219 ok(allNodes[i].wrappedJSObject.nodePrincipal === undefined,
michael@0 220 "Unexpected principal appears for " + allNodes[i].nodeName +
michael@0 221 " in " + documentID);
michael@0 222 ok(allNodes[i].wrappedJSObject.baseURIObject === undefined,
michael@0 223 "Unexpected base URI appears for " + allNodes[i].nodeName +
michael@0 224 " in " + documentID);
michael@0 225 }
michael@0 226 }
michael@0 227
michael@0 228 function runTestProps() {
michael@0 229 isnot(doc.nodePrincipal, null,
michael@0 230 "Must have document principal in " + documentID);
michael@0 231 is(doc.nodePrincipal instanceof Components.interfaces.nsIPrincipal,
michael@0 232 true, "document principal must be a principal in " + documentID);
michael@0 233 isnot(doc.baseURIObject, null,
michael@0 234 "Must have document base URI in" + documentID);
michael@0 235 is(doc.baseURIObject instanceof Components.interfaces.nsIURI,
michael@0 236 true, "document base URI must be a URI in " + documentID);
michael@0 237 isnot(doc.documentURIObject, null,
michael@0 238 "Must have document URI " + documentID);
michael@0 239 is(doc.documentURIObject instanceof Components.interfaces.nsIURI,
michael@0 240 true, "document URI must be a URI in " + documentID);
michael@0 241 is(doc.documentURIObject.spec, doc.documentURI,
michael@0 242 "document URI must be the right URI in " + documentID);
michael@0 243
michael@0 244 for (var i = 0; i < allNodes.length; ++i) {
michael@0 245 is(allNodes[i].nodePrincipal, doc.nodePrincipal,
michael@0 246 "Unexpected principal for " + allNodes[i].nodeName +
michael@0 247 " in " + documentID);
michael@0 248 is(allNodes[i].baseURIObject, doc.baseURIObject,
michael@0 249 "Unexpected base URI for " + allNodes[i].nodeName +
michael@0 250 " in " + documentID);
michael@0 251 }
michael@0 252
michael@0 253 for (i = 0; i < XMLNodes.length; ++i) {
michael@0 254 is(XMLNodes[i].nodePrincipal, doc.nodePrincipal,
michael@0 255 "Unexpected principal for " + XMLNodes[i].nodeName +
michael@0 256 " in " + documentID);
michael@0 257 is(XMLNodes[i].baseURIObject.spec, "about:blank",
michael@0 258 "Unexpected base URI for " + XMLNodes[i].nodeName +
michael@0 259 " in " + documentID);
michael@0 260 }
michael@0 261 }
michael@0 262
michael@0 263 runTestUnwrapped();
michael@0 264 runTestProps();
michael@0 265 runTestUnwrapped();
michael@0 266 }
michael@0 267
michael@0 268 var testsRunning = 2;
michael@0 269
michael@0 270 testInDocument(document, "browser window");
michael@0 271
michael@0 272 function newTabTest(url) {
michael@0 273 var newTab = gBrowser.addTab();
michael@0 274 var newBrowser = gBrowser.getBrowserForTab(newTab);
michael@0 275 newBrowser.contentWindow.location.href = url;
michael@0 276 function testBrowser(event) {
michael@0 277 newBrowser.removeEventListener("load", testBrowser, true);
michael@0 278 is(event.target, newBrowser.contentDocument,
michael@0 279 "Unexpected target in " + url);
michael@0 280 testInDocument(newBrowser.contentDocument, url);
michael@0 281
michael@0 282 gBrowser.removeTab(newTab);
michael@0 283
michael@0 284 --testsRunning;
michael@0 285 if (testsRunning == 0) {
michael@0 286 finish();
michael@0 287 }
michael@0 288 }
michael@0 289 newBrowser.addEventListener("load", testBrowser, true);
michael@0 290 }
michael@0 291
michael@0 292 newTabTest("about:blank");
michael@0 293 newTabTest("about:config");
michael@0 294 }

mercurial