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> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=411103 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 411103</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=411103">Mozilla Bug 411103</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"></div> |
michael@0 | 15 | |
michael@0 | 16 | <!-- XML's createElement and createElementNS aren't HTML's, of course --> |
michael@0 | 17 | <iframe src="data:application/xml,%3Cfoo%3EXML%3C/foo%3E" name="xmlWindow"></iframe> |
michael@0 | 18 | |
michael@0 | 19 | <!-- for good measure... --> |
michael@0 | 20 | <iframe src="data:application/xhtml+xml,%3Chtml%20xmlns=%22http://www.w3.org/1999/xhtml%22%3E%3Cbody%3E%3Cp%3EXHTML%3C/p%3E%3C/body%3E%3C/html%3E" |
michael@0 | 21 | name="xhtmlWindow"></iframe> |
michael@0 | 22 | |
michael@0 | 23 | <pre id="test"> |
michael@0 | 24 | <script class="testbody" type="text/javascript"> |
michael@0 | 25 | |
michael@0 | 26 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 27 | |
michael@0 | 28 | /** Test for Bug 411103 **/ |
michael@0 | 29 | var allNSTests = |
michael@0 | 30 | [ |
michael@0 | 31 | { args: [undefined, undefined] }, |
michael@0 | 32 | { args: [null, undefined] }, |
michael@0 | 33 | { args: [undefined, null] }, |
michael@0 | 34 | { args: [null, null] }, |
michael@0 | 35 | { args: [null, ""], code: 5 }, |
michael@0 | 36 | { args: ["", null] }, |
michael@0 | 37 | { args: ["", ""], code: 5 }, |
michael@0 | 38 | { args: [null, "<div>"], code: 5 }, |
michael@0 | 39 | { args: [null, "0div"], code: 5 }, |
michael@0 | 40 | { args: [null, "di v"], code: 5 }, |
michael@0 | 41 | { args: [null, "di<v"], code: 5 }, |
michael@0 | 42 | { args: [null, "-div"], code: 5 }, |
michael@0 | 43 | { args: [null, ".div"], code: 5 }, |
michael@0 | 44 | { args: ["http://example.com/", "<div>"], code: 5 }, |
michael@0 | 45 | { args: ["http://example.com/", "0div"], code: 5 }, |
michael@0 | 46 | { args: ["http://example.com/", "di<v"], code: 5 }, |
michael@0 | 47 | { args: ["http://example.com/", "-div"], code: 5 }, |
michael@0 | 48 | { args: ["http://example.com/", ".div"], code: 5 }, |
michael@0 | 49 | { args: [null, ":div"], code: 14 }, |
michael@0 | 50 | { args: [null, "div:"], code: 14 }, |
michael@0 | 51 | { args: ["http://example.com/", ":div"], code: 14 }, |
michael@0 | 52 | { args: ["http://example.com/", "div:"], code: 14 }, |
michael@0 | 53 | { args: [null, "d:iv"], code: 14 }, |
michael@0 | 54 | { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" }, |
michael@0 | 55 | { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name, invalid QName" }, |
michael@0 | 56 | { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" }, |
michael@0 | 57 | { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name, invalid QName" }, |
michael@0 | 58 | { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, not a valid QName" }, |
michael@0 | 59 | { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes it not a valid XML name" }, |
michael@0 | 60 | { args: ["http://example.com/", "a:_"] }, |
michael@0 | 61 | { args: ["http://example.com/", "a:\u0BC6"], code: 14, |
michael@0 | 62 | message: "non-ASCII character after colon is CombiningChar, which is " + |
michael@0 | 63 | "NCNameChar but not (Letter | \"_\") so invalid at start of " + |
michael@0 | 64 | "NCName (but still a valid XML name, hence not 5)" }, |
michael@0 | 65 | { args: ["http://example.com/", "\u0BC6:a"], code: 14, |
michael@0 | 66 | message: "non-ASCII character after colon is CombiningChar, which is " + |
michael@0 | 67 | "NCNameChar but not (Letter | \"_\") so invalid at start of " + |
michael@0 | 68 | "NCName (Gecko chooses to throw 14 here, but either is valid " + |
michael@0 | 69 | "as this is both an invalid XML name and an invalid QName)" }, |
michael@0 | 70 | { args: ["http://example.com/", "a:a\u0BC6"] }, |
michael@0 | 71 | { args: ["http://example.com/", "a\u0BC6:a"] }, |
michael@0 | 72 | { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml prefix wrong" }, |
michael@0 | 73 | { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xmlns prefix wrong" }, |
michael@0 | 74 | { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "binding namespace namespace to wrong prefix" }, |
michael@0 | 75 | { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] }, |
michael@0 | 76 | { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] }, |
michael@0 | 77 | { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] }, |
michael@0 | 78 | ]; |
michael@0 | 79 | |
michael@0 | 80 | var allNoNSTests = |
michael@0 | 81 | [ |
michael@0 | 82 | { args: [undefined] }, |
michael@0 | 83 | { args: [null] }, |
michael@0 | 84 | { args: [""], code: 5 }, |
michael@0 | 85 | { args: ["<div>"], code: 5 }, |
michael@0 | 86 | { args: ["0div"], code: 5 }, |
michael@0 | 87 | { args: ["di v"], code: 5 }, |
michael@0 | 88 | { args: ["di<v"], code: 5 }, |
michael@0 | 89 | { args: ["-div"], code: 5 }, |
michael@0 | 90 | { args: [".div"], code: 5 }, |
michael@0 | 91 | { args: [":"], message: "valid XML name, invalid QName" }, |
michael@0 | 92 | { args: [":div"], message: "valid XML name, invalid QName" }, |
michael@0 | 93 | { args: ["div:"], message: "valid XML name, invalid QName" }, |
michael@0 | 94 | { args: ["d:iv"] }, |
michael@0 | 95 | { args: ["a:b:c"], message: "valid XML name, invalid QName" }, |
michael@0 | 96 | { args: ["a::c"], message: "valid XML name, invalid QName" }, |
michael@0 | 97 | { args: ["a::c:"], message: "valid XML name, invalid QName" }, |
michael@0 | 98 | { args: ["a:0"], message: "valid XML name, not a valid QName" }, |
michael@0 | 99 | { args: ["0:a"], code: 5, message: "0 at start makes it not a valid XML name" }, |
michael@0 | 100 | { args: ["a:_"] }, |
michael@0 | 101 | { args: ["a:\u0BC6"], |
michael@0 | 102 | message: "non-ASCII character after colon is CombiningChar, which is " + |
michael@0 | 103 | "valid in pre-namespace XML" }, |
michael@0 | 104 | { args: ["\u0BC6:a"], code: 5, message: "not a valid start character" }, |
michael@0 | 105 | { args: ["a:a\u0BC6"] }, |
michael@0 | 106 | { args: ["a\u0BC6:a"] }, |
michael@0 | 107 | { args: ["xml:test"] }, |
michael@0 | 108 | { args: ["xmlns:test"] }, |
michael@0 | 109 | { args: ["x:test"] }, |
michael@0 | 110 | { args: ["xmlns:test"] }, |
michael@0 | 111 | ]; |
michael@0 | 112 | |
michael@0 | 113 | function sourceify(v) |
michael@0 | 114 | { |
michael@0 | 115 | switch (typeof v) |
michael@0 | 116 | { |
michael@0 | 117 | case "undefined": |
michael@0 | 118 | return v; |
michael@0 | 119 | |
michael@0 | 120 | case "string": |
michael@0 | 121 | return '"' + v.replace('"', '\\"') + '"'; |
michael@0 | 122 | |
michael@0 | 123 | default: |
michael@0 | 124 | return String(v); |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function sourceifyArgs(args) |
michael@0 | 129 | { |
michael@0 | 130 | var copy = new Array(args.length); |
michael@0 | 131 | for (var i = 0, sz = args.length; i < sz; i++) |
michael@0 | 132 | copy[i] = sourceify(args[i]); |
michael@0 | 133 | |
michael@0 | 134 | return copy.join(", "); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | function runTests(tests, methodName, document) |
michael@0 | 138 | { |
michael@0 | 139 | for (var i = 0, sz = tests.length; i < sz; i++) |
michael@0 | 140 | { |
michael@0 | 141 | var test = tests[i]; |
michael@0 | 142 | |
michael@0 | 143 | var argStr = sourceifyArgs(test.args); |
michael@0 | 144 | try |
michael@0 | 145 | { |
michael@0 | 146 | document[methodName].apply(document, test.args); |
michael@0 | 147 | var msg = "expected no exception for " + |
michael@0 | 148 | "document." + methodName + "(" + argStr + ")"; |
michael@0 | 149 | if ("message" in test) |
michael@0 | 150 | msg += "; " + test.message; |
michael@0 | 151 | ok(!("code" in test), msg); |
michael@0 | 152 | } |
michael@0 | 153 | catch (e) |
michael@0 | 154 | { |
michael@0 | 155 | msg = "exception code for document." + methodName + "(" + argStr + ")"; |
michael@0 | 156 | if ("message" in test) |
michael@0 | 157 | msg += "; " + test.message; |
michael@0 | 158 | is(e.code, test.code || "no exception", msg); |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | |
michael@0 | 164 | function run() |
michael@0 | 165 | { |
michael@0 | 166 | // HTML document |
michael@0 | 167 | runTests(allNSTests, "createElementNS", document); |
michael@0 | 168 | runTests(allNoNSTests, "createElement", document); |
michael@0 | 169 | |
michael@0 | 170 | // XML document |
michael@0 | 171 | var xmlDocument = window.frames.xmlWindow.document; |
michael@0 | 172 | runTests(allNSTests, "createElementNS", xmlDocument); |
michael@0 | 173 | runTests(allNoNSTests, "createElement", xmlDocument); |
michael@0 | 174 | |
michael@0 | 175 | // XHTML document, for good measure |
michael@0 | 176 | var xhtmlDocument = window.frames.xhtmlWindow.document; |
michael@0 | 177 | runTests(allNSTests, "createElementNS", xhtmlDocument); |
michael@0 | 178 | runTests(allNoNSTests, "createElement", xhtmlDocument); |
michael@0 | 179 | |
michael@0 | 180 | SimpleTest.finish(); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | window.addEventListener("load", run, false); |
michael@0 | 184 | |
michael@0 | 185 | </script> |
michael@0 | 186 | </pre> |
michael@0 | 187 | </body> |
michael@0 | 188 | </html> |