test_recover_database.js (2256B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // If we think profiles have been created but there is no current profile in the database but there 7 // are other profiles we should create the current profile entry. 8 add_task(async function test_recover_database() { 9 startProfileService(); 10 11 const SelectableProfileService = getSelectableProfileService(); 12 const ProfilesDatastoreService = getProfilesDatastoreService(); 13 14 await ProfilesDatastoreService.init(); 15 16 let db = await ProfilesDatastoreService.getConnection(); 17 18 let rootDir = getProfileService().currentProfile.rootDir.clone(); 19 rootDir.leafName = "other"; 20 let otherPath = getRelativeProfilePath(rootDir); 21 22 // Inject some other profile into the database 23 await db.execute( 24 `INSERT INTO Profiles VALUES (NULL, :path, :name, :avatar, :themeId, :themeFg, :themeBg);`, 25 { 26 path: otherPath, 27 name: "Fake Profile", 28 avatar: "book", 29 themeId: "default", 30 themeFg: "", 31 themeBg: "", 32 } 33 ); 34 35 let toolkitProfile = getProfileService().currentProfile; 36 toolkitProfile.storeID = await ProfilesDatastoreService.storeID; 37 38 Services.prefs.setBoolPref("browser.profiles.enabled", true); 39 Services.prefs.setBoolPref("browser.profiles.created", true); 40 await SelectableProfileService.init(); 41 42 Assert.ok(SelectableProfileService.isEnabled, "Service should be enabled"); 43 44 Assert.ok( 45 Services.prefs.getBoolPref("browser.profiles.created", false), 46 "Should have kept the profile created state." 47 ); 48 49 Assert.equal( 50 toolkitProfile.storeID, 51 await ProfilesDatastoreService.storeID, 52 "Should not have cleared the store ID" 53 ); 54 Assert.ok( 55 SelectableProfileService.currentProfile, 56 "Should have created the current profile" 57 ); 58 59 let profiles = await SelectableProfileService.getAllProfiles(); 60 Assert.equal(profiles.length, 2, "Should be two profiles in the database"); 61 62 let newProfile = await SelectableProfileService.createNewProfile(false); 63 Assert.ok(newProfile, "Should have created a new profile"); 64 65 profiles = await SelectableProfileService.getAllProfiles(); 66 Assert.equal(profiles.length, 3, "Should be three profiles in the database"); 67 });