test_ChromeMigrationUtils_path_chromium_snap.js (1536B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { ChromeMigrationUtils } = ChromeUtils.importESModule( 7 "resource:///modules/ChromeMigrationUtils.sys.mjs" 8 ); 9 10 const SUB_DIRECTORIES = { 11 linux: { 12 Chromium: [".config", "chromium"], 13 SnapChromium: ["snap", "chromium", "common", "chromium"], 14 }, 15 }; 16 17 add_task(async function setup_fakePaths() { 18 let pathId; 19 if (AppConstants.platform == "macosx") { 20 pathId = "ULibDir"; 21 } else if (AppConstants.platform == "win") { 22 pathId = "LocalAppData"; 23 } else { 24 pathId = "Home"; 25 } 26 27 registerFakePath(pathId, do_get_file("chromefiles/", true)); 28 }); 29 30 add_task(async function test_getDataPath_function() { 31 let rootPath = getRootPath(); 32 let chromiumSubFolders = SUB_DIRECTORIES[AppConstants.platform].Chromium; 33 // must remove normal chromium path 34 await IOUtils.remove(PathUtils.join(rootPath, ...chromiumSubFolders), { 35 ignoreAbsent: true, 36 }); 37 38 let snapChromiumSubFolders = 39 SUB_DIRECTORIES[AppConstants.platform].SnapChromium; 40 // must create snap chromium path 41 await IOUtils.makeDirectory( 42 PathUtils.join(rootPath, ...snapChromiumSubFolders), 43 { 44 createAncestor: true, 45 ignoreExisting: true, 46 } 47 ); 48 49 let chromiumUserDataPath = await ChromeMigrationUtils.getDataPath("Chromium"); 50 Assert.equal( 51 chromiumUserDataPath, 52 PathUtils.join(getRootPath(), ...snapChromiumSubFolders), 53 "Should get the path of Snap Chromium data directory." 54 ); 55 });