tor-browser

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

test_relative_profile_path.js (1839B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const PATH_SEPARATOR = AppConstants.platform == "win" ? "\\" : "/";
      7 
      8 add_setup(() => {
      9  Services.prefs.setBoolPref("browser.profiles.enabled", true);
     10 });
     11 
     12 add_task(async function test_create_profile() {
     13  let hash = xreDirProvider.getInstallHash();
     14 
     15  // In the test harness gProfD is outside of the mocked app data directory so
     16  // this will will use a relative profile path starting with `..`.
     17  let absolutePath = gProfD.clone();
     18  absolutePath.append("absoluteProfile");
     19  absolutePath.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
     20 
     21  let profileData = {
     22    profiles: [
     23      {
     24        name: "default",
     25        path: absolutePath.path,
     26        isRelative: false,
     27      },
     28    ],
     29    installs: {
     30      [hash]: {
     31        default: absolutePath.path,
     32      },
     33    },
     34  };
     35 
     36  writeProfilesIni(profileData);
     37 
     38  startProfileService();
     39  let service = getProfileService();
     40  Assert.equal(service.currentProfile.rootDir.path, absolutePath.path);
     41 
     42  await initSelectableProfileService();
     43 
     44  let currentProfile = getSelectableProfileService().currentProfile;
     45 
     46  Assert.equal(
     47    (await currentProfile.rootDir).path,
     48    absolutePath.path,
     49    "The profile root path should be correct"
     50  );
     51 
     52  Assert.equal(
     53    (await currentProfile.localDir).path,
     54    absolutePath.path,
     55    "The profile local path should be correct"
     56  );
     57 
     58  let db = await openDatabase();
     59  let rows = await db.execute("SELECT path FROM Profiles WHERE id=:id;", {
     60    id: currentProfile.id,
     61  });
     62  await db.close();
     63 
     64  Assert.equal(rows.length, 1, "There should be one row for the profile");
     65  Assert.equal(
     66    rows[0].getResultByName("path"),
     67    `..${PATH_SEPARATOR}absoluteProfile`,
     68    "The profile path in the database should be relative"
     69  );
     70 });