intl/uconv/tests/unit/test_input_stream.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 var Ci = Components.interfaces,
michael@0 2 Cc = Components.classes,
michael@0 3 CC = Components.Constructor;
michael@0 4 var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
michael@0 5 .createInstance(Ci.nsIScriptableUnicodeConverter);
michael@0 6 converter.charset = "UTF-8";
michael@0 7
michael@0 8 var SIS = CC("@mozilla.org/scriptableinputstream;1",
michael@0 9 "nsIScriptableInputStream",
michael@0 10 "init");
michael@0 11
michael@0 12 function test_char(code) {
michael@0 13 dump("test_char(0x" + code.toString(16) + ")\n");
michael@0 14 var original = String.fromCharCode(code);
michael@0 15 var nativeStream = converter.convertToInputStream(original);
michael@0 16 var stream = new SIS(nativeStream);
michael@0 17 var utf8Result = stream.read(stream.available());
michael@0 18 stream.close();
michael@0 19 var result = converter.ConvertToUnicode(utf8Result);
michael@0 20 do_check_eq(escape(original), escape(result));
michael@0 21 }
michael@0 22
michael@0 23 function run_test() {
michael@0 24 // This is not a very comprehensive test.
michael@0 25 for (var i = 0x007f - 2; i <= 0x007f; i++)
michael@0 26 test_char(i);
michael@0 27 for (i = 0x07ff - 2; i <= 0x07ff; i++)
michael@0 28 test_char(i);
michael@0 29 for (i = 0x1000 - 2; i <= 0x1000 + 2; i++)
michael@0 30 test_char(i);
michael@0 31 for (i = 0xe000; i <= 0xe000 + 2; i++)
michael@0 32 test_char(i);
michael@0 33 }

mercurial