tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_input_stream.js (1110B)


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