tor-browser

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

test_recover_storeID.js (2043B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function test_recover_storeID() {
      7  startProfileService();
      8  Services.prefs.setCharPref("toolkit.profiles.storeID", "foobar");
      9  Services.prefs.setBoolPref("browser.profiles.created", true);
     10 
     11  // The database needs to exist already
     12  let groupsPath = PathUtils.join(
     13    Services.dirsvc.get("UAppData", Ci.nsIFile).path,
     14    "Profile Groups"
     15  );
     16 
     17  await IOUtils.makeDirectory(groupsPath);
     18  let dbFile = PathUtils.join(groupsPath, "foobar.sqlite");
     19  // eslint-disable-next-line mozilla/valid-lazy
     20  let db = await lazy.Sqlite.openConnection({
     21    path: dbFile,
     22    openNotExclusive: true,
     23  });
     24 
     25  let path = getRelativeProfilePath(getProfileService().currentProfile.rootDir);
     26 
     27  // Slightly annoying we have to replicate this...
     28  await db.execute(`CREATE TABLE IF NOT EXISTS "Profiles" (
     29      id  INTEGER NOT NULL,
     30      path	TEXT NOT NULL UNIQUE,
     31      name	TEXT NOT NULL,
     32      avatar	TEXT NOT NULL,
     33      themeId	TEXT NOT NULL,
     34      themeFg	TEXT NOT NULL,
     35      themeBg	TEXT NOT NULL,
     36      PRIMARY KEY(id)
     37    );`);
     38 
     39  await db.execute(
     40    `INSERT INTO Profiles VALUES (NULL, :path, :name, :avatar, :themeId, :themeFg, :themeBg);`,
     41    {
     42      path,
     43      name: "Fake Profile",
     44      avatar: "book",
     45      themeId: "default",
     46      themeFg: "",
     47      themeBg: "",
     48    }
     49  );
     50 
     51  await db.close();
     52 
     53  const SelectableProfileService = getSelectableProfileService();
     54  const ProfilesDatastoreService = getProfilesDatastoreService();
     55 
     56  await ProfilesDatastoreService.init();
     57  await SelectableProfileService.init();
     58  Assert.ok(SelectableProfileService.initialized, "Did initialize the service");
     59 
     60  let profile = SelectableProfileService.currentProfile;
     61  Assert.ok(profile, "Should have a current profile");
     62  Assert.equal(profile.name, "Fake Profile");
     63  Assert.equal(
     64    getProfileService().currentProfile.storeID,
     65    "foobar",
     66    "Should have updated the store ID on the profile"
     67  );
     68 });