tor-browser

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

test_distribution.js (5809B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Tests that preferences are properly set by distribution.ini
      6 */
      7 
      8 registerCleanupFunction(async function () {
      9  // Remove the distribution dir, even if the test failed, otherwise all
     10  // next tests will use it.
     11  let folderPath = PathUtils.join(PathUtils.profileDir, "distribution");
     12  await IOUtils.remove(folderPath, { ignoreAbsent: true, recursive: true });
     13  Assert.ok(!(await IOUtils.exists(folderPath)));
     14  Services.prefs.clearUserPref("distribution.testing.loadFromProfile");
     15 });
     16 
     17 add_task(async function () {
     18  // Set special pref to load distribution.ini from the profile folder.
     19  Services.prefs.setBoolPref("distribution.testing.loadFromProfile", true);
     20 
     21  // Copy distribution.ini file to the profile dir.
     22  let distroDir = gProfD.clone();
     23  distroDir.leafName = "distribution";
     24  let iniFile = distroDir.clone();
     25  iniFile.append("distribution.ini");
     26  if (iniFile.exists()) {
     27    iniFile.remove(false);
     28    print("distribution.ini already exists, did some test forget to cleanup?");
     29  }
     30 
     31  let testDistributionFile = do_get_cwd().clone();
     32  testDistributionFile.append("distribution.ini");
     33  testDistributionFile.copyTo(distroDir, "distribution.ini");
     34  Assert.ok(testDistributionFile.exists());
     35 });
     36 
     37 add_task(async function () {
     38  let { DistributionManagement } = ChromeUtils.importESModule(
     39    "resource:///modules/distribution.sys.mjs"
     40  );
     41 
     42  DistributionManagement.applyCustomizations();
     43 
     44  var defaultBranch = Services.prefs.getDefaultBranch(null);
     45 
     46  Assert.equal(defaultBranch.getCharPref("distribution.id"), "disttest");
     47  Assert.equal(defaultBranch.getCharPref("distribution.version"), "1.0");
     48  Assert.equal(
     49    defaultBranch.getStringPref("distribution.about"),
     50    "Tèƨƭ δïƨƭřïβúƭïôñ ƒïℓè"
     51  );
     52 
     53  Assert.equal(
     54    defaultBranch.getCharPref("distribution.test.string"),
     55    "Test String"
     56  );
     57  Assert.equal(
     58    defaultBranch.getCharPref("distribution.test.string.noquotes"),
     59    "Test String"
     60  );
     61  Assert.equal(defaultBranch.getIntPref("distribution.test.int"), 777);
     62  Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.true"), true);
     63  Assert.equal(
     64    defaultBranch.getBoolPref("distribution.test.bool.false"),
     65    false
     66  );
     67 
     68  Assert.throws(
     69    () => defaultBranch.getCharPref("distribution.test.empty"),
     70    /NS_ERROR_UNEXPECTED/
     71  );
     72  Assert.throws(
     73    () => defaultBranch.getIntPref("distribution.test.empty"),
     74    /NS_ERROR_UNEXPECTED/
     75  );
     76  Assert.throws(
     77    () => defaultBranch.getBoolPref("distribution.test.empty"),
     78    /NS_ERROR_UNEXPECTED/
     79  );
     80 
     81  Assert.equal(
     82    defaultBranch.getCharPref("distribution.test.pref.locale"),
     83    "en-US"
     84  );
     85  Assert.equal(
     86    defaultBranch.getCharPref("distribution.test.pref.language.en"),
     87    "en"
     88  );
     89  Assert.equal(
     90    defaultBranch.getCharPref("distribution.test.pref.locale.en-US"),
     91    "en-US"
     92  );
     93  Assert.throws(
     94    () => defaultBranch.getCharPref("distribution.test.pref.language.de"),
     95    /NS_ERROR_UNEXPECTED/
     96  );
     97  // This value was never set because of the empty language specific pref
     98  Assert.throws(
     99    () => defaultBranch.getCharPref("distribution.test.pref.language.reset"),
    100    /NS_ERROR_UNEXPECTED/
    101  );
    102  // This value was never set because of the empty locale specific pref
    103  Assert.throws(
    104    () => defaultBranch.getCharPref("distribution.test.pref.locale.reset"),
    105    /NS_ERROR_UNEXPECTED/
    106  );
    107  // This value was overridden by a locale specific setting
    108  Assert.equal(
    109    defaultBranch.getCharPref("distribution.test.pref.locale.set"),
    110    "Locale Set"
    111  );
    112  // This value was overridden by a language specific setting
    113  Assert.equal(
    114    defaultBranch.getCharPref("distribution.test.pref.language.set"),
    115    "Language Set"
    116  );
    117  // Language should not override locale
    118  Assert.notEqual(
    119    defaultBranch.getCharPref("distribution.test.pref.locale.set"),
    120    "Language Set"
    121  );
    122 
    123  Assert.equal(
    124    defaultBranch.getComplexValue(
    125      "distribution.test.locale",
    126      Ci.nsIPrefLocalizedString
    127    ).data,
    128    "en-US"
    129  );
    130  Assert.equal(
    131    defaultBranch.getComplexValue(
    132      "distribution.test.language.en",
    133      Ci.nsIPrefLocalizedString
    134    ).data,
    135    "en"
    136  );
    137  Assert.equal(
    138    defaultBranch.getComplexValue(
    139      "distribution.test.locale.en-US",
    140      Ci.nsIPrefLocalizedString
    141    ).data,
    142    "en-US"
    143  );
    144  Assert.throws(
    145    () =>
    146      defaultBranch.getComplexValue(
    147        "distribution.test.language.de",
    148        Ci.nsIPrefLocalizedString
    149      ),
    150    /NS_ERROR_UNEXPECTED/
    151  );
    152  // This value was never set because of the empty language specific pref
    153  Assert.throws(
    154    () =>
    155      defaultBranch.getComplexValue(
    156        "distribution.test.language.reset",
    157        Ci.nsIPrefLocalizedString
    158      ),
    159    /NS_ERROR_UNEXPECTED/
    160  );
    161  // This value was never set because of the empty locale specific pref
    162  Assert.throws(
    163    () =>
    164      defaultBranch.getComplexValue(
    165        "distribution.test.locale.reset",
    166        Ci.nsIPrefLocalizedString
    167      ),
    168    /NS_ERROR_UNEXPECTED/
    169  );
    170  // This value was overridden by a locale specific setting
    171  Assert.equal(
    172    defaultBranch.getComplexValue(
    173      "distribution.test.locale.set",
    174      Ci.nsIPrefLocalizedString
    175    ).data,
    176    "Locale Set"
    177  );
    178  // This value was overridden by a language specific setting
    179  Assert.equal(
    180    defaultBranch.getComplexValue(
    181      "distribution.test.language.set",
    182      Ci.nsIPrefLocalizedString
    183    ).data,
    184    "Language Set"
    185  );
    186  // Language should not override locale
    187  Assert.notEqual(
    188    defaultBranch.getComplexValue(
    189      "distribution.test.locale.set",
    190      Ci.nsIPrefLocalizedString
    191    ).data,
    192    "Language Set"
    193  );
    194  Assert.equal(defaultBranch.getCharPref("intl.locale.requested"), "en-US");
    195 });