test_delete_last_profile.js (3228B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { sinon } = ChromeUtils.importESModule( 7 "resource://testing-common/Sinon.sys.mjs" 8 ); 9 10 const { TestUtils } = ChromeUtils.importESModule( 11 "resource://testing-common/TestUtils.sys.mjs" 12 ); 13 14 const execProcess = sinon.fake(); 15 const sendCommandLine = sinon.fake.throws(Cr.NS_ERROR_NOT_AVAILABLE); 16 17 add_setup(async () => { 18 await initSelectableProfileService(); 19 20 sinon.replace( 21 getSelectableProfileService(), 22 "sendCommandLine", 23 (path, args, raise) => sendCommandLine(path, [...args], raise) 24 ); 25 sinon.replace(getSelectableProfileService(), "execProcess", execProcess); 26 }); 27 28 add_task(async function test_delete_last_profile() { 29 const SelectableProfileService = getSelectableProfileService(); 30 31 let profiles = await SelectableProfileService.getAllProfiles(); 32 Assert.equal(profiles.length, 1, "Only 1 profile exists before deleting"); 33 34 let profile = profiles[0]; 35 Assert.equal( 36 SelectableProfileService.groupToolkitProfile.rootDir.path, 37 profile.path, 38 "The group toolkit profile path should be the path of the original profile" 39 ); 40 41 await SelectableProfileService.setShowProfileSelectorWindow(true); 42 Assert.ok( 43 SelectableProfileService.groupToolkitProfile.showProfileSelector, 44 "Show profile selector is enabled" 45 ); 46 47 let updated = updateNotified(); 48 await SelectableProfileService.deleteCurrentProfile(); 49 await updated; 50 51 profiles = await SelectableProfileService.getAllProfiles(); 52 Assert.equal(profiles.length, 1, "Only 1 profile exists after deleting"); 53 54 profile = profiles[0]; 55 56 let expected = ["-new-tab", "about:newprofile"]; 57 58 await TestUtils.waitForCondition( 59 () => sendCommandLine.callCount > 1, 60 "Waiting for notify task to complete" 61 ); 62 63 Assert.equal( 64 sendCommandLine.callCount, 65 2, 66 "Should have attempted to remote twice" 67 ); 68 69 let [openCall, updateCall] = sendCommandLine.getCalls(); 70 // These can come in any order so switch them if needed. 71 if (openCall.args[1].length == 1) { 72 [updateCall, openCall] = [openCall, updateCall]; 73 } 74 75 Assert.deepEqual( 76 openCall.args, 77 [profile.path, expected, true], 78 "Expected sendCommandLine arguments to open new profile" 79 ); 80 81 Assert.deepEqual( 82 updateCall.args, 83 [profile.path, ["--profiles-updated"], false], 84 "Expected sendCommandLine arguments to update other profiles" 85 ); 86 87 expected.unshift("--profile", profile.path); 88 89 if (Services.appinfo.OS === "Darwin") { 90 expected.unshift("-foreground"); 91 } 92 93 // Our mock remote service claims the instance is not running so we will fall back to launching 94 // a new process. 95 96 Assert.equal(execProcess.callCount, 1, "Should have called execProcess once"); 97 Assert.deepEqual( 98 execProcess.firstCall.args, 99 [expected], 100 "Expected execProcess arguments" 101 ); 102 103 Assert.equal( 104 SelectableProfileService.groupToolkitProfile.rootDir.path, 105 profile.path, 106 "The group toolkit profile path should be the path of the newly created profile" 107 ); 108 109 Assert.ok( 110 !SelectableProfileService.groupToolkitProfile.showProfileSelector, 111 "Show profile selector is disabled" 112 ); 113 });