intl/strres/tests/unit/test_bug397093.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/strres/tests/unit/test_bug397093.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +/* Tests getting properties from string bundles with incorrect encoding.
     1.5 + * The string bundle contains one ascii property, one UTF-8 and one Latin-1.
     1.6 + * Expected behaviour is that the whole string bundle should be rejected and
     1.7 + * all GetStringFromName calls should fail.
     1.8 + */
     1.9 +
    1.10 +const name_ascii = "asciiProperty";
    1.11 +const value_ascii = "";
    1.12 +
    1.13 +const name_utf8 = "utf8Property";
    1.14 +const value_utf8 = "";
    1.15 +
    1.16 +const name_latin1 = "latin1";
    1.17 +const value_latin1 = "";
    1.18 +
    1.19 +
    1.20 +function run_test() {
    1.21 +    var StringBundle = 
    1.22 +	Components.classes["@mozilla.org/intl/stringbundle;1"]
    1.23 +	 .getService(Components.interfaces.nsIStringBundleService);
    1.24 +    var ios = Components.classes["@mozilla.org/network/io-service;1"]
    1.25 +	 .getService(Components.interfaces.nsIIOService);
    1.26 +    var bundleURI = ios.newFileURI(do_get_file("397093.properties"));
    1.27 +
    1.28 +    var bundle = StringBundle.createBundle(bundleURI.spec);
    1.29 +    
    1.30 +    var bundle_ascii="", bundle_utf8="", bundle_latin1="";
    1.31 +    try {
    1.32 +	bundle_ascii = bundle.GetStringFromName(name_ascii);
    1.33 +    } catch(e) {}
    1.34 +    do_check_eq(bundle_ascii, value_ascii);
    1.35 +
    1.36 +    try {
    1.37 +	bundle_utf8 = bundle.GetStringFromName(name_utf8);
    1.38 +    } catch(e) {}
    1.39 +    do_check_eq(bundle_utf8, value_utf8);
    1.40 +
    1.41 +    try {
    1.42 +	bundle_latin1 = bundle.GetStringFromName(name_latin1);
    1.43 +    } catch(e) {}
    1.44 +    do_check_eq(bundle_latin1, value_latin1);
    1.45 +}
    1.46 +    

mercurial