Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
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> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=389797 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 389797</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=389797">Mozilla Bug 389797</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 389797 **/ |
michael@0 | 21 | var allTags = []; |
michael@0 | 22 | var classInfos = {}; |
michael@0 | 23 | var interfaces = {}; |
michael@0 | 24 | var interfacesNonClassinfo = {}; |
michael@0 | 25 | |
michael@0 | 26 | function getClassName(tag) { |
michael@0 | 27 | return "HTML" + classInfos[tag] + "Element"; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function HTML_TAG(aTagName, aImplClass) { |
michael@0 | 31 | allTags.push(aTagName); |
michael@0 | 32 | classInfos[aTagName] = aImplClass; |
michael@0 | 33 | interfaces[aTagName] = |
michael@0 | 34 | [ "nsIDOMEventTarget", |
michael@0 | 35 | "nsIDOMElementCSSInlineStyle" ]; |
michael@0 | 36 | |
michael@0 | 37 | // Some interfaces don't appear in classinfo because other interfaces that |
michael@0 | 38 | // inherit from them do. |
michael@0 | 39 | interfacesNonClassinfo[aTagName] = |
michael@0 | 40 | [ "nsIDOMNode", |
michael@0 | 41 | "nsIDOMElement" ]; |
michael@0 | 42 | |
michael@0 | 43 | var interfaceName = "nsIDOM" + getClassName(aTagName); |
michael@0 | 44 | if (interfaceName in SpecialPowers.Ci) { // no nsIDOMHTMLSpanElement |
michael@0 | 45 | interfaces[aTagName].push(interfaceName); |
michael@0 | 46 | interfacesNonClassinfo[aTagName].push("nsIDOMHTMLElement"); |
michael@0 | 47 | } else { |
michael@0 | 48 | // Inherits directly from nsIDOMHTMLElement. |
michael@0 | 49 | interfaces[aTagName].push("nsIDOMHTMLElement"); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | var interfaceNameNS = "nsIDOMNS" + getClassName(aTagName); |
michael@0 | 53 | if (interfaceNameNS in SpecialPowers.Ci) { |
michael@0 | 54 | interfaces[aTagName].push(interfaceNameNS); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if (arguments.length > 2) { |
michael@0 | 58 | for (var i = 0; i < arguments[2].length; ++i) { |
michael@0 | 59 | interfaces[aTagName].push(arguments[2][i]); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | if (arguments.length > 3) { |
michael@0 | 64 | for (i = 0; i < arguments[3].length; ++i) { |
michael@0 | 65 | interfacesNonClassinfo[aTagName].push(arguments[3][i]); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | const objectIfaces = [ |
michael@0 | 71 | "imgINotificationObserver", "nsIRequestObserver", "nsIStreamListener", |
michael@0 | 72 | "nsIFrameLoaderOwner", "nsIObjectLoadingContent", "nsIChannelEventSink" |
michael@0 | 73 | ]; |
michael@0 | 74 | |
michael@0 | 75 | var objectIfaces2 = []; |
michael@0 | 76 | for (var iface of objectIfaces) { |
michael@0 | 77 | objectIfaces2.push(iface); |
michael@0 | 78 | } |
michael@0 | 79 | objectIfaces2.push("nsIImageLoadingContent"); |
michael@0 | 80 | |
michael@0 | 81 | /* List copy/pasted from nsHTMLTagList.h, with the second field modified to the |
michael@0 | 82 | correct classinfo (instead of the impl class) in the following cases: |
michael@0 | 83 | |
michael@0 | 84 | applet |
michael@0 | 85 | base |
michael@0 | 86 | blockquote |
michael@0 | 87 | dir |
michael@0 | 88 | dl |
michael@0 | 89 | embed |
michael@0 | 90 | menu |
michael@0 | 91 | ol |
michael@0 | 92 | param |
michael@0 | 93 | q |
michael@0 | 94 | ul |
michael@0 | 95 | wbr |
michael@0 | 96 | head |
michael@0 | 97 | html |
michael@0 | 98 | */ |
michael@0 | 99 | |
michael@0 | 100 | HTML_TAG("a", "Anchor"); |
michael@0 | 101 | HTML_TAG("abbr", ""); |
michael@0 | 102 | HTML_TAG("acronym", ""); |
michael@0 | 103 | HTML_TAG("address", ""); |
michael@0 | 104 | HTML_TAG("applet", "Applet", [], objectIfaces); |
michael@0 | 105 | HTML_TAG("area", "Area"); |
michael@0 | 106 | HTML_TAG("article", ""); |
michael@0 | 107 | HTML_TAG("aside", ""); |
michael@0 | 108 | HTML_TAG("b", ""); |
michael@0 | 109 | HTML_TAG("base", "Base"); |
michael@0 | 110 | HTML_TAG("bdo", ""); |
michael@0 | 111 | HTML_TAG("bgsound", "Unknown"); |
michael@0 | 112 | HTML_TAG("big", ""); |
michael@0 | 113 | HTML_TAG("blockquote", "Quote"); |
michael@0 | 114 | HTML_TAG("body", "Body"); |
michael@0 | 115 | HTML_TAG("br", "BR"); |
michael@0 | 116 | HTML_TAG("button", "Button"); |
michael@0 | 117 | HTML_TAG("canvas", "Canvas"); |
michael@0 | 118 | HTML_TAG("caption", "TableCaption"); |
michael@0 | 119 | HTML_TAG("center", ""); |
michael@0 | 120 | HTML_TAG("cite", ""); |
michael@0 | 121 | HTML_TAG("code", ""); |
michael@0 | 122 | HTML_TAG("col", "TableCol"); |
michael@0 | 123 | HTML_TAG("colgroup", "TableCol"); |
michael@0 | 124 | HTML_TAG("data", "Data"); |
michael@0 | 125 | HTML_TAG("datalist", "DataList"); |
michael@0 | 126 | HTML_TAG("dd", ""); |
michael@0 | 127 | HTML_TAG("del", "Mod"); |
michael@0 | 128 | HTML_TAG("dfn", ""); |
michael@0 | 129 | HTML_TAG("dir", "Directory"); |
michael@0 | 130 | HTML_TAG("div", "Div"); |
michael@0 | 131 | HTML_TAG("dl", "DList"); |
michael@0 | 132 | HTML_TAG("dt", ""); |
michael@0 | 133 | HTML_TAG("em", ""); |
michael@0 | 134 | HTML_TAG("embed", "Embed", [], objectIfaces); |
michael@0 | 135 | HTML_TAG("fieldset", "FieldSet"); |
michael@0 | 136 | HTML_TAG("figcaption", "") |
michael@0 | 137 | HTML_TAG("figure", "") |
michael@0 | 138 | HTML_TAG("font", "Font"); |
michael@0 | 139 | HTML_TAG("footer", "") |
michael@0 | 140 | HTML_TAG("form", "Form", [], [ "nsIWebProgressListener" ]); |
michael@0 | 141 | HTML_TAG("frame", "Frame", [ "nsIDOMMozBrowserFrame" ], [ "nsIFrameLoaderOwner" ]); |
michael@0 | 142 | HTML_TAG("frameset", "FrameSet"); |
michael@0 | 143 | HTML_TAG("h1", "Heading"); |
michael@0 | 144 | HTML_TAG("h2", "Heading"); |
michael@0 | 145 | HTML_TAG("h3", "Heading"); |
michael@0 | 146 | HTML_TAG("h4", "Heading"); |
michael@0 | 147 | HTML_TAG("h5", "Heading"); |
michael@0 | 148 | HTML_TAG("h6", "Heading"); |
michael@0 | 149 | HTML_TAG("head", "Head"); |
michael@0 | 150 | HTML_TAG("header", "") |
michael@0 | 151 | HTML_TAG("hgroup", "") |
michael@0 | 152 | HTML_TAG("hr", "HR"); |
michael@0 | 153 | HTML_TAG("html", "Html"); |
michael@0 | 154 | HTML_TAG("i", ""); |
michael@0 | 155 | HTML_TAG("iframe", "IFrame", [ "nsIDOMMozBrowserFrame" ], |
michael@0 | 156 | [ "nsIFrameLoaderOwner" ]); |
michael@0 | 157 | HTML_TAG("image", ""); |
michael@0 | 158 | HTML_TAG("img", "Image", [ "nsIImageLoadingContent" ], []); |
michael@0 | 159 | HTML_TAG("input", "Input", [], [ "imgINotificationObserver", |
michael@0 | 160 | "nsIImageLoadingContent", |
michael@0 | 161 | "nsIDOMNSEditableElement" ]); |
michael@0 | 162 | HTML_TAG("ins", "Mod"); |
michael@0 | 163 | HTML_TAG("kbd", ""); |
michael@0 | 164 | HTML_TAG("keygen", "Span"); |
michael@0 | 165 | HTML_TAG("label", "Label"); |
michael@0 | 166 | HTML_TAG("legend", "Legend"); |
michael@0 | 167 | HTML_TAG("li", "LI"); |
michael@0 | 168 | HTML_TAG("link", "Link"); |
michael@0 | 169 | HTML_TAG("listing", ""); |
michael@0 | 170 | HTML_TAG("main", ""); |
michael@0 | 171 | HTML_TAG("map", "Map"); |
michael@0 | 172 | HTML_TAG("mark", ""); |
michael@0 | 173 | HTML_TAG("marquee", "Div"); |
michael@0 | 174 | HTML_TAG("menu", "Menu"); |
michael@0 | 175 | HTML_TAG("meta", "Meta"); |
michael@0 | 176 | HTML_TAG("meter", "Meter"); |
michael@0 | 177 | HTML_TAG("multicol", "Unknown"); |
michael@0 | 178 | HTML_TAG("nav", "") |
michael@0 | 179 | HTML_TAG("nobr", ""); |
michael@0 | 180 | HTML_TAG("noembed", ""); |
michael@0 | 181 | HTML_TAG("noframes", ""); |
michael@0 | 182 | HTML_TAG("noscript", ""); |
michael@0 | 183 | HTML_TAG("object", "Object", [], |
michael@0 | 184 | objectIfaces.concat([ "nsIImageLoadingContent" ])); |
michael@0 | 185 | HTML_TAG("ol", "OList"); |
michael@0 | 186 | HTML_TAG("optgroup", "OptGroup"); |
michael@0 | 187 | HTML_TAG("option", "Option"); |
michael@0 | 188 | HTML_TAG("p", "Paragraph"); |
michael@0 | 189 | HTML_TAG("param", "Param"); |
michael@0 | 190 | HTML_TAG("plaintext", ""); |
michael@0 | 191 | HTML_TAG("pre", "Pre"); |
michael@0 | 192 | HTML_TAG("q", "Quote"); |
michael@0 | 193 | HTML_TAG("s", ""); |
michael@0 | 194 | HTML_TAG("samp", ""); |
michael@0 | 195 | HTML_TAG("script", "Script", [ "nsIScriptLoaderObserver" ], []); |
michael@0 | 196 | HTML_TAG("section", "") |
michael@0 | 197 | HTML_TAG("select", "Select", ["nsIDOMHTMLSelectElement"]); |
michael@0 | 198 | HTML_TAG("small", ""); |
michael@0 | 199 | HTML_TAG("span", "Span"); |
michael@0 | 200 | HTML_TAG("strike", ""); |
michael@0 | 201 | HTML_TAG("strong", ""); |
michael@0 | 202 | HTML_TAG("style", "Style"); |
michael@0 | 203 | HTML_TAG("sub", ""); |
michael@0 | 204 | HTML_TAG("sup", ""); |
michael@0 | 205 | HTML_TAG("table", "Table"); |
michael@0 | 206 | HTML_TAG("tbody", "TableSection"); |
michael@0 | 207 | HTML_TAG("td", "TableCell"); |
michael@0 | 208 | HTML_TAG("textarea", "TextArea", [], [ "nsIDOMNSEditableElement" ]); |
michael@0 | 209 | HTML_TAG("tfoot", "TableSection"); |
michael@0 | 210 | HTML_TAG("th", "TableCell"); |
michael@0 | 211 | HTML_TAG("thead", "TableSection"); |
michael@0 | 212 | HTML_TAG("template", "Template"); |
michael@0 | 213 | HTML_TAG("time", "Time"); |
michael@0 | 214 | HTML_TAG("title", "Title"); |
michael@0 | 215 | HTML_TAG("tr", "TableRow"); |
michael@0 | 216 | HTML_TAG("tt", ""); |
michael@0 | 217 | HTML_TAG("u", ""); |
michael@0 | 218 | HTML_TAG("ul", "UList"); |
michael@0 | 219 | HTML_TAG("var", ""); |
michael@0 | 220 | HTML_TAG("wbr", ""); |
michael@0 | 221 | HTML_TAG("xmp", ""); |
michael@0 | 222 | |
michael@0 | 223 | function tagName(aTag) { |
michael@0 | 224 | return "<" + aTag + ">"; |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | for (var tag of allTags) { |
michael@0 | 228 | var node = document.createElement(tag); |
michael@0 | 229 | |
michael@0 | 230 | // Have to use the proto's toString(), since HTMLAnchorElement and company |
michael@0 | 231 | // override toString(). |
michael@0 | 232 | var nodeString = HTMLElement.prototype.toString.apply(node); |
michael@0 | 233 | |
michael@0 | 234 | // Debug builds have extra info, so chop off after "Element" if it's followed |
michael@0 | 235 | // by ' ' or ']' |
michael@0 | 236 | nodeString = nodeString.replace(/Element[\] ].*/, "Element"); |
michael@0 | 237 | |
michael@0 | 238 | var classInfoString = getClassName(tag); |
michael@0 | 239 | is(nodeString, "[object " + classInfoString, |
michael@0 | 240 | "Unexpected classname for " + tagName(tag)); |
michael@0 | 241 | is(node instanceof window[classInfoString], true, |
michael@0 | 242 | tagName(tag) + " not an instance of " + classInfos[tag]); |
michael@0 | 243 | |
michael@0 | 244 | if (classInfoString != 'HTMLUnknownElement') { |
michael@0 | 245 | is(node instanceof HTMLUnknownElement, false, |
michael@0 | 246 | tagName(tag) + " is an instance of HTMLUnknownElement"); |
michael@0 | 247 | } else { |
michael@0 | 248 | is(node instanceof HTMLUnknownElement, true, |
michael@0 | 249 | tagName(tag) + " is an instance of HTMLUnknownElement"); |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | // Check that each node QIs to all the things we expect it to QI to |
michael@0 | 253 | for (var iface of interfaces[tag].concat(interfacesNonClassinfo[tag])) { |
michael@0 | 254 | is(iface in SpecialPowers.Ci, true, |
michael@0 | 255 | iface + " not in Components.interfaces"); |
michael@0 | 256 | is(node instanceof SpecialPowers.Ci[iface], true, |
michael@0 | 257 | tagName(tag) + " does not QI to " + iface); |
michael@0 | 258 | } |
michael@0 | 259 | } |
michael@0 | 260 | </script> |
michael@0 | 261 | </pre> |
michael@0 | 262 | </body> |
michael@0 | 263 | </html> |
michael@0 | 264 |