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 | const Ci = Components.interfaces; |
michael@0 | 2 | const Cc = Components.classes; |
michael@0 | 3 | const CC = Components.Constructor; |
michael@0 | 4 | |
michael@0 | 5 | function CreateScriptableConverter() |
michael@0 | 6 | { |
michael@0 | 7 | var ScriptableUnicodeConverter = |
michael@0 | 8 | CC("@mozilla.org/intl/scriptableunicodeconverter", |
michael@0 | 9 | "nsIScriptableUnicodeConverter"); |
michael@0 | 10 | |
michael@0 | 11 | return new ScriptableUnicodeConverter(); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | function checkDecode(converter, charset, inText, expectedText) |
michael@0 | 15 | { |
michael@0 | 16 | try { |
michael@0 | 17 | converter.charset = charset; |
michael@0 | 18 | } catch(e) { |
michael@0 | 19 | converter.charset = "iso-8859-1"; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | dump("testing decoding from " + charset + " to Unicode.\n"); |
michael@0 | 23 | try { |
michael@0 | 24 | var outText = converter.ConvertToUnicode(inText) + converter.Finish(); |
michael@0 | 25 | } catch(e) { |
michael@0 | 26 | outText = "\ufffd"; |
michael@0 | 27 | } |
michael@0 | 28 | do_check_eq(outText, expectedText); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function checkEncode(converter, charset, inText, expectedText) |
michael@0 | 32 | { |
michael@0 | 33 | try { |
michael@0 | 34 | converter.charset = charset; |
michael@0 | 35 | } catch(e) { |
michael@0 | 36 | converter.charset = "iso-8859-1"; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | dump("testing encoding from Unicode to " + charset + "\n"); |
michael@0 | 40 | var outText = converter.ConvertFromUnicode(inText) + converter.Finish(); |
michael@0 | 41 | do_check_eq(outText, expectedText); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function testDecodeAliases() |
michael@0 | 45 | { |
michael@0 | 46 | var converter = CreateScriptableConverter(); |
michael@0 | 47 | for (var i = 0; i < aliases.length; ++i) { |
michael@0 | 48 | checkDecode(converter, aliases[i], inString, expectedString); |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function testEncodeAliases() |
michael@0 | 53 | { |
michael@0 | 54 | var converter = CreateScriptableConverter(); |
michael@0 | 55 | for (var i = 0; i < aliases.length; ++i) { |
michael@0 | 56 | checkEncode(converter, aliases[i], inString, expectedString); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function testDecodeAliasesInternal() |
michael@0 | 61 | { |
michael@0 | 62 | var converter = CreateScriptableConverter(); |
michael@0 | 63 | converter.isInternal = true; |
michael@0 | 64 | for (var i = 0; i < aliases.length; ++i) { |
michael@0 | 65 | checkDecode(converter, aliases[i], inString, expectedString); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function testEncodeAliasesInternal() |
michael@0 | 70 | { |
michael@0 | 71 | var converter = CreateScriptableConverter(); |
michael@0 | 72 | converter.isInternal = true; |
michael@0 | 73 | for (var i = 0; i < aliases.length; ++i) { |
michael@0 | 74 | checkEncode(converter, aliases[i], inString, expectedString); |
michael@0 | 75 | } |
michael@0 | 76 | } |