tor-browser

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

test_ChromeMigrationUtils_path.js (4017B)


      1 "use strict";
      2 
      3 const { ChromeMigrationUtils } = ChromeUtils.importESModule(
      4  "resource:///modules/ChromeMigrationUtils.sys.mjs"
      5 );
      6 
      7 const SUB_DIRECTORIES = {
      8  win: {
      9    Chrome: ["Google", "Chrome", "User Data"],
     10    Chromium: ["Chromium", "User Data"],
     11    Canary: ["Google", "Chrome SxS", "User Data"],
     12  },
     13  macosx: {
     14    Chrome: ["Application Support", "Google", "Chrome"],
     15    Chromium: ["Application Support", "Chromium"],
     16    Canary: ["Application Support", "Google", "Chrome Canary"],
     17  },
     18  linux: {
     19    Chrome: [".config", "google-chrome"],
     20    Chromium: [".config", "chromium"],
     21    Canary: [],
     22  },
     23 };
     24 
     25 add_task(async function setup_fakePaths() {
     26  let pathId;
     27  if (AppConstants.platform == "macosx") {
     28    pathId = "ULibDir";
     29  } else if (AppConstants.platform == "win") {
     30    pathId = "LocalAppData";
     31  } else {
     32    pathId = "Home";
     33  }
     34 
     35  registerFakePath(pathId, do_get_file("chromefiles/", true));
     36 });
     37 
     38 add_task(async function test_getDataPath_function() {
     39  let projects = ["Chrome", "Chromium", "Canary"];
     40  let rootPath = getRootPath();
     41 
     42  for (let project of projects) {
     43    let subfolders = SUB_DIRECTORIES[AppConstants.platform][project];
     44 
     45    await IOUtils.makeDirectory(PathUtils.join(rootPath, ...subfolders), {
     46      createAncestor: true,
     47      ignoreExisting: true,
     48    });
     49  }
     50 
     51  let chromeUserDataPath = await ChromeMigrationUtils.getDataPath("Chrome");
     52  let chromiumUserDataPath = await ChromeMigrationUtils.getDataPath("Chromium");
     53  let canaryUserDataPath = await ChromeMigrationUtils.getDataPath("Canary");
     54  if (AppConstants.platform == "win") {
     55    Assert.equal(
     56      chromeUserDataPath,
     57      PathUtils.join(getRootPath(), "Google", "Chrome", "User Data"),
     58      "Should get the path of Chrome data directory."
     59    );
     60    Assert.equal(
     61      chromiumUserDataPath,
     62      PathUtils.join(getRootPath(), "Chromium", "User Data"),
     63      "Should get the path of Chromium data directory."
     64    );
     65    Assert.equal(
     66      canaryUserDataPath,
     67      PathUtils.join(getRootPath(), "Google", "Chrome SxS", "User Data"),
     68      "Should get the path of Canary data directory."
     69    );
     70  } else if (AppConstants.platform == "macosx") {
     71    Assert.equal(
     72      chromeUserDataPath,
     73      PathUtils.join(getRootPath(), "Application Support", "Google", "Chrome"),
     74      "Should get the path of Chrome data directory."
     75    );
     76    Assert.equal(
     77      chromiumUserDataPath,
     78      PathUtils.join(getRootPath(), "Application Support", "Chromium"),
     79      "Should get the path of Chromium data directory."
     80    );
     81    Assert.equal(
     82      canaryUserDataPath,
     83      PathUtils.join(
     84        getRootPath(),
     85        "Application Support",
     86        "Google",
     87        "Chrome Canary"
     88      ),
     89      "Should get the path of Canary data directory."
     90    );
     91  } else {
     92    Assert.equal(
     93      chromeUserDataPath,
     94      PathUtils.join(getRootPath(), ".config", "google-chrome"),
     95      "Should get the path of Chrome data directory."
     96    );
     97    Assert.equal(
     98      chromiumUserDataPath,
     99      PathUtils.join(getRootPath(), ".config", "chromium"),
    100      "Should get the path of Chromium data directory."
    101    );
    102    Assert.equal(canaryUserDataPath, null, "Should get null for Canary.");
    103  }
    104 });
    105 
    106 add_task(async function test_getExtensionPath_function() {
    107  let extensionPath = await ChromeMigrationUtils.getExtensionPath("Default");
    108  let expectedPath;
    109  if (AppConstants.platform == "win") {
    110    expectedPath = PathUtils.join(
    111      getRootPath(),
    112      "Google",
    113      "Chrome",
    114      "User Data",
    115      "Default",
    116      "Extensions"
    117    );
    118  } else if (AppConstants.platform == "macosx") {
    119    expectedPath = PathUtils.join(
    120      getRootPath(),
    121      "Application Support",
    122      "Google",
    123      "Chrome",
    124      "Default",
    125      "Extensions"
    126    );
    127  } else {
    128    expectedPath = PathUtils.join(
    129      getRootPath(),
    130      ".config",
    131      "google-chrome",
    132      "Default",
    133      "Extensions"
    134    );
    135  }
    136  Assert.equal(
    137    extensionPath,
    138    expectedPath,
    139    "Should get the path of extensions directory."
    140  );
    141 });