test_recover_empty_database.js (2010B)
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 and there 7 // are no other profiles we should reset state. 8 add_task(async function test_recover_empty_database() { 9 startProfileService(); 10 11 const SelectableProfileService = getSelectableProfileService(); 12 const ProfilesDatastoreService = getProfilesDatastoreService(); 13 14 await ProfilesDatastoreService.init(); 15 16 let toolkitProfile = getProfileService().currentProfile; 17 toolkitProfile.storeID = await ProfilesDatastoreService.storeID; 18 19 Services.prefs.setBoolPref("browser.profiles.enabled", true); 20 Services.prefs.setBoolPref("browser.profiles.created", true); 21 await SelectableProfileService.init(); 22 23 Assert.ok(SelectableProfileService.isEnabled, "Service should be enabled"); 24 25 Assert.ok( 26 !Services.prefs.getBoolPref("browser.profiles.created", false), 27 "Should have reset the profile created state." 28 ); 29 30 Assert.ok(!toolkitProfile.storeID, "Should have cleared the store ID"); 31 Assert.ok( 32 !SelectableProfileService.currentProfile, 33 "Should be no current profile" 34 ); 35 36 let profiles = await SelectableProfileService.getAllProfiles(); 37 Assert.ok(!profiles.length, "No selectable profiles exist yet"); 38 39 let newProfile = await SelectableProfileService.createNewProfile(false); 40 Assert.ok(newProfile, "Should have created a new profile"); 41 Assert.ok( 42 Services.prefs.getBoolPref("browser.profiles.created", false), 43 "Should have set the profile created state." 44 ); 45 Assert.equal( 46 toolkitProfile.storeID, 47 await ProfilesDatastoreService.storeID, 48 "Should have set the store ID" 49 ); 50 51 Assert.ok( 52 SelectableProfileService.currentProfile, 53 "Should have created a current profile entry" 54 ); 55 56 profiles = await SelectableProfileService.getAllProfiles(); 57 Assert.equal(profiles.length, 2, "Two profiles should exist in the database"); 58 });