summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/unit/test_ChromeMigrationUtils_path_chromium_snap.js
blob: 50119915367afc3d9ea31df6eaa09fdba44922c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { ChromeMigrationUtils } = ChromeUtils.importESModule(
  "resource:///modules/ChromeMigrationUtils.sys.mjs"
);

const SUB_DIRECTORIES = {
  linux: {
    Chromium: [".config", "chromium"],
    SnapChromium: ["snap", "chromium", "common", "chromium"],
  },
};

add_task(async function setup_fakePaths() {
  let pathId;
  if (AppConstants.platform == "macosx") {
    pathId = "ULibDir";
  } else if (AppConstants.platform == "win") {
    pathId = "LocalAppData";
  } else {
    pathId = "Home";
  }

  registerFakePath(pathId, do_get_file("chromefiles/", true));
});

add_task(async function test_getDataPath_function() {
  let rootPath = getRootPath();
  let chromiumSubFolders = SUB_DIRECTORIES[AppConstants.platform].Chromium;
  // must remove normal chromium path
  await IOUtils.remove(PathUtils.join(rootPath, ...chromiumSubFolders), {
    ignoreAbsent: true,
  });

  let snapChromiumSubFolders =
    SUB_DIRECTORIES[AppConstants.platform].SnapChromium;
  // must create snap chromium path
  await IOUtils.makeDirectory(
    PathUtils.join(rootPath, ...snapChromiumSubFolders),
    {
      createAncestor: true,
      ignoreExisting: true,
    }
  );

  let chromiumUserDataPath = await ChromeMigrationUtils.getDataPath("Chromium");
  Assert.equal(
    chromiumUserDataPath,
    PathUtils.join(getRootPath(), ...snapChromiumSubFolders),
    "Should get the path of Snap Chromium data directory."
  );
});