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.

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

mercurial