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=743049 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="UTF-8"> |
michael@0 | 8 | <title>Test for Bug 743049</title> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=743049">Mozilla Bug 743049</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | <iframe id="frame"></iframe> |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | "use strict"; |
michael@0 | 21 | |
michael@0 | 22 | /** Test for Bug 743049 **/ |
michael@0 | 23 | |
michael@0 | 24 | var expected = [ |
michael@0 | 25 | { name: "Error", message: "foo", filename: location, lineNumber: 45 }, |
michael@0 | 26 | { name: "Error", message: "foo", filename: "bar", lineNumber: 123 }, |
michael@0 | 27 | { name: "", message: "uncaught exception: [object Object]" }, |
michael@0 | 28 | { name: "DuckError", message: "foo", filename: "bar", lineNumber: 123 }, |
michael@0 | 29 | { name: "", message: "uncaught exception: [object Object]" }, |
michael@0 | 30 | { name: "", message: "foo", filename: "baz", lineNumber: 123 }, |
michael@0 | 31 | { name: "", message: "uncaught exception: [object Object]" }, |
michael@0 | 32 | { name: "InvalidStateError", message: "An attempt was made to use an object that is not, or is no longer, usable", filename: location, lineNumber: 60 }, |
michael@0 | 33 | { name: "ReferenceError", message: "xxx is not defined", filename: location, lineNumber: 64 }, |
michael@0 | 34 | { name: "ReferenceError", message: "xxx is not defined", filename: location, lineNumber: 66 } |
michael@0 | 35 | ]; |
michael@0 | 36 | |
michael@0 | 37 | var counter = 0; |
michael@0 | 38 | var origin = location.protocol + "//" + location.host; |
michael@0 | 39 | postMessage(counter, origin); |
michael@0 | 40 | window.onmessage = function(e) { |
michael@0 | 41 | if (e.origin !== origin) |
michael@0 | 42 | return; |
michael@0 | 43 | try { |
michael@0 | 44 | if (e.data == 0) { |
michael@0 | 45 | throw new Error("foo"); |
michael@0 | 46 | } else if (e.data == 1) { |
michael@0 | 47 | throw new Error("foo","bar",123); |
michael@0 | 48 | } else if (e.data == 2) { |
michael@0 | 49 | throw {}; |
michael@0 | 50 | } else if (e.data == 3) { |
michael@0 | 51 | throw {name:"DuckError",message:"foo",filename:"bar",lineNumber:123}; |
michael@0 | 52 | } else if (e.data == 4) { |
michael@0 | 53 | throw {name:"DuckError",filename:"bar",lineNumber:123}; |
michael@0 | 54 | } else if (e.data == 5) { |
michael@0 | 55 | throw {message:"foo",fileName:"baz",lineNumber:123}; |
michael@0 | 56 | } else if (e.data == 6) { |
michael@0 | 57 | throw {name:3,message:4,lineNumber:123}; |
michael@0 | 58 | } else if (e.data == 7) { |
michael@0 | 59 | var x = new XMLHttpRequest(); |
michael@0 | 60 | x.responseType = "arraybuffer"; |
michael@0 | 61 | x.open("GET", location, false); |
michael@0 | 62 | var a = x.send(); |
michael@0 | 63 | } else if (e.data == 8) { |
michael@0 | 64 | throw new ReferenceError("xxx is not defined"); |
michael@0 | 65 | } else if (e.data == 9) { |
michael@0 | 66 | new xxx; |
michael@0 | 67 | } else { |
michael@0 | 68 | SimpleTest.finish(); |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | } catch (e) { |
michael@0 | 72 | if (e instanceof Error || typeof e.message=="string" && |
michael@0 | 73 | ("filename" in e || "fileName" in e) && "lineNumber" in e) { |
michael@0 | 74 | is(e.message, expected[counter].message, counter + " catch message"); |
michael@0 | 75 | is(e.filename || e.fileName, expected[counter].filename, counter + " catch filename"); |
michael@0 | 76 | is(e.lineNumber, expected[counter].lineNumber, counter + " catch lineno"); |
michael@0 | 77 | } else { |
michael@0 | 78 | is("uncaught exception: " + e, expected[counter].message, counter + " catch message"); |
michael@0 | 79 | is(undefined, expected[counter].filename, counter + " catch filename"); |
michael@0 | 80 | is(undefined, expected[counter].lineNumber, counter + " catch lineno"); |
michael@0 | 81 | } |
michael@0 | 82 | throw e; |
michael@0 | 83 | } |
michael@0 | 84 | ok(false, counter + " Error should be thrown or test should finish"); |
michael@0 | 85 | }; |
michael@0 | 86 | window.onerror = function(message, filename, lineno) { |
michael@0 | 87 | is(message, Error.prototype.toString.call(expected[counter]), counter + " onerror message"); |
michael@0 | 88 | is(filename, expected[counter].filename || "", counter + " onerror filename"); |
michael@0 | 89 | is(lineno, expected[counter].lineNumber || 0, counter + " onerror lineno"); |
michael@0 | 90 | postMessage(++counter, origin); |
michael@0 | 91 | return true; |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 95 | |
michael@0 | 96 | </script> |
michael@0 | 97 | </pre> |
michael@0 | 98 | </body> |
michael@0 | 99 | </html> |