tor-browser

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

test_parser.js (4709B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/licenses/publicdomain/  */
      3 
      4 // It is necessary to manually disable `xpc::IsInAutomation` since
      5 // `resetPrefs` will flip the preference to re-enable `once`-synced
      6 // preference change assertions, and also change the value of those
      7 // preferences.
      8 Services.prefs.setBoolPref(
      9  "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer",
     10  false
     11 );
     12 
     13 function run_test() {
     14  const ps = Services.prefs;
     15 
     16  ps.resetPrefs();
     17  ps.readDefaultPrefsFromFile(do_get_file("data/testParser.js"));
     18 
     19  Assert.equal(ps.getBoolPref("comment1"), true);
     20  Assert.equal(ps.getBoolPref("comment2"), true);
     21  Assert.equal(ps.getBoolPref("spaced-out"), true);
     22 
     23  Assert.equal(ps.getBoolPref("pref"), true);
     24  Assert.equal(ps.getBoolPref("sticky_pref"), true);
     25  Assert.equal(ps.getBoolPref("user_pref"), true);
     26  Assert.equal(ps.getBoolPref("sticky_pref2"), true);
     27  Assert.equal(ps.getBoolPref("locked_pref"), true);
     28  Assert.equal(ps.getBoolPref("locked_sticky_pref"), true);
     29  Assert.equal(ps.prefIsLocked("locked_pref"), true);
     30  Assert.equal(ps.prefIsLocked("locked_sticky_pref"), true);
     31 
     32  Assert.equal(ps.getBoolPref("bool.true"), true);
     33  Assert.equal(ps.getBoolPref("bool.false"), false);
     34 
     35  Assert.equal(ps.getIntPref("int.0"), 0);
     36  Assert.equal(ps.getIntPref("int.1"), 1);
     37  Assert.equal(ps.getIntPref("int.123"), 123);
     38  Assert.equal(ps.getIntPref("int.+234"), 234);
     39  Assert.equal(ps.getIntPref("int.+  345"), 345);
     40  Assert.equal(ps.getIntPref("int.-0"), -0);
     41  Assert.equal(ps.getIntPref("int.-1"), -1);
     42  Assert.equal(ps.getIntPref("int.- /* hmm */\t456"), -456);
     43  Assert.equal(ps.getIntPref("int.-\n567"), -567);
     44  Assert.equal(ps.getIntPref("int.INT_MAX-1"), 2147483646);
     45  Assert.equal(ps.getIntPref("int.INT_MAX"), 2147483647);
     46  Assert.equal(ps.getIntPref("int.INT_MIN+2"), -2147483646);
     47  Assert.equal(ps.getIntPref("int.INT_MIN+1"), -2147483647);
     48  Assert.equal(ps.getIntPref("int.INT_MIN"), -2147483648);
     49 
     50  Assert.equal(ps.getCharPref("string.empty"), "");
     51  Assert.equal(ps.getCharPref("string.abc"), "abc");
     52  Assert.equal(
     53    ps.getCharPref("string.long"),
     54    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
     55  );
     56  Assert.equal(ps.getCharPref("string.single-quotes"), '"abc"');
     57  Assert.equal(ps.getCharPref("string.double-quotes"), "'abc'");
     58  Assert.equal(
     59    ps.getCharPref("string.weird-chars"),
     60    "\x0d \x09 \x0b \x0c \x06 \x16"
     61  );
     62  Assert.equal(ps.getCharPref("string.escapes"), "\" ' \\ \n \r");
     63 
     64  // This one is ASCII, so we can use getCharPref() and getStringPref
     65  // interchangeably.
     66  Assert.equal(
     67    ps.getCharPref("string.x-escapes1"),
     68    "Mozilla0\x4d\x6F\x7a\x69\x6c\x6C\x610"
     69  );
     70  Assert.equal(ps.getStringPref("string.x-escapes1"), "Mozilla0Mozilla0");
     71 
     72  // This one has chars with value > 127, so it's not valid UTF8, so we can't
     73  // use getStringPref on it.
     74  Assert.equal(
     75    ps.getCharPref("string.x-escapes2"),
     76    "AA A_umlaut\xc4 y_umlaut\xff"
     77  );
     78 
     79  // The following strings use \uNNNN escapes, which are UTF16 code points.
     80  // libpref stores them internally as UTF8 byte sequences. In each case we get
     81  // the string in two ways:
     82  // - getStringPref() interprets it as UTF8, which is then converted to UTF16
     83  //   in JS. I.e. code points that are multiple bytes in UTF8 become a single
     84  //   16-bit char in JS (except for the non-BMP chars, which become a 16-bit
     85  //   surrogate pair).
     86  // - getCharPref() interprets it as Latin1, which is then converted to UTF16
     87  //   in JS. I.e. code points that are multiple bytes in UTF8 become multiple
     88  //   16-bit chars in JS.
     89 
     90  Assert.equal(
     91    ps.getStringPref("string.u-escapes1"),
     92    "A\u0041 A_umlaut\u00c4 y_umlaut\u00ff0"
     93  );
     94  Assert.equal(
     95    ps.getCharPref("string.u-escapes1"),
     96    "A\x41 A_umlaut\xc3\x84 y_umlaut\xc3\xbf0"
     97  );
     98 
     99  Assert.equal(
    100    ps.getStringPref("string.u-escapes2"),
    101    "S_acute\u015a y_grave\u1Ef3"
    102  );
    103  Assert.equal(
    104    ps.getCharPref("string.u-escapes2"),
    105    "S_acute\xc5\x9a y_grave\xe1\xbb\xb3"
    106  );
    107 
    108  Assert.equal(
    109    ps.getStringPref("string.u-surrogates"),
    110    "cyclone\uD83C\uDF00 grinning_face\uD83D\uDE00"
    111  );
    112  Assert.equal(
    113    ps.getCharPref("string.u-surrogates"),
    114    "cyclone\xF0\x9F\x8C\x80 grinning_face\xF0\x9F\x98\x80"
    115  );
    116 }