test_create_profile.js (2767B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_setup(() => { 7 Services.prefs.setBoolPref("browser.profiles.enabled", true); 8 9 let mockFs = [ 10 { 11 path: `/localization/browser/profiles.ftl`, 12 source: ` 13 default-profile-name = Profile number: { $number } 14 original-profile-name = Original profile name 15 `, 16 }, 17 ]; 18 19 let mockSource = L10nFileSource.createMock( 20 "test", 21 "app", 22 Services.locale.packagedLocales, 23 "/localization/", 24 mockFs 25 ); 26 let registry = L10nRegistry.getInstance(); 27 registry.clearSources(); 28 registry.registerSources([mockSource]); 29 }); 30 31 add_task(async function test_create_profile() { 32 startProfileService(); 33 34 const SelectableProfileService = getSelectableProfileService(); 35 const ProfilesDatastoreService = getProfilesDatastoreService(); 36 37 await ProfilesDatastoreService.init(); 38 await SelectableProfileService.init(); 39 Assert.ok(SelectableProfileService.isEnabled, "Service should be enabled"); 40 41 let profiles = await SelectableProfileService.getAllProfiles(); 42 43 Assert.ok(!profiles.length, "No selectable profiles exist yet"); 44 45 await SelectableProfileService.maybeSetupDataStore(); 46 let currentProfile = SelectableProfileService.currentProfile; 47 48 let leafName = (await currentProfile.rootDir).leafName; 49 50 Assert.equal( 51 leafName, 52 getProfileService().currentProfile.rootDir.leafName, 53 "The name for the original profile should be correct" 54 ); 55 Assert.equal( 56 currentProfile.name, 57 "Original profile name", 58 "The name for the original profile should be correct" 59 ); 60 61 let newProfile = await SelectableProfileService.createNewProfile(false); 62 leafName = (await newProfile.rootDir).leafName; 63 64 Assert.equal( 65 // Strip off the random salt prefix added to the profile path 66 leafName.substring(8), 67 ".Profile number_ 1", 68 "The name for the new profile's directory should be correct" 69 ); 70 Assert.equal( 71 newProfile.name, 72 "Profile number: 1", 73 "The name for the new profile should be correct" 74 ); 75 76 profiles = await SelectableProfileService.getAllProfiles(); 77 78 Assert.equal(profiles.length, 2, "Two selectable profiles exist"); 79 80 let db = await openDatabase(); 81 let rows = await db.execute("SELECT path FROM Profiles WHERE id=:id;", { 82 id: newProfile.id, 83 }); 84 await db.close(); 85 86 Assert.equal(rows.length, 1, "There should be one row for the profile"); 87 let path = rows[0].getResultByName("path"); 88 89 // Non-unix and mac prefix the profile path with "Profiles/" 90 if (!AppConstants.XP_UNIX || AppConstants.platform == "macosx") { 91 path = path.substring("Profiles".length + 1); 92 } 93 94 Assert.equal(path, leafName, "The profile path should be relative"); 95 });