test_selectable_profile_launch.js (2451B)
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 execProcess = sinon.fake(); 11 const sendCommandLine = sinon.fake.throws(Cr.NS_ERROR_NOT_AVAILABLE); 12 13 add_setup(async () => { 14 await initSelectableProfileService(); 15 16 sinon.replace( 17 getSelectableProfileService(), 18 "sendCommandLine", 19 (path, args, raise) => sendCommandLine(path, [...args], raise) 20 ); 21 sinon.replace(getSelectableProfileService(), "execProcess", execProcess); 22 }); 23 24 add_task(async function test_launcher() { 25 let profile = await createTestProfile(); 26 27 const SelectableProfileService = getSelectableProfileService(); 28 SelectableProfileService.launchInstance(profile); 29 30 let expected = ["--profiles-activate"]; 31 32 Assert.equal( 33 sendCommandLine.callCount, 34 1, 35 "Should have attempted to remote to one instance" 36 ); 37 Assert.deepEqual( 38 sendCommandLine.firstCall.args, 39 [profile.path, expected, true], 40 "Expected sendCommandLine arguments" 41 ); 42 43 expected.unshift("--profile", profile.path); 44 45 if (Services.appinfo.OS === "Darwin") { 46 expected.unshift("-foreground"); 47 } 48 49 // Our mock remote service claims the instance is not running so we will fall back to launching 50 // a new process. 51 52 Assert.equal(execProcess.callCount, 1, "Should have called execProcess once"); 53 Assert.deepEqual( 54 execProcess.firstCall.args, 55 [expected], 56 "Expected execProcess arguments" 57 ); 58 59 sendCommandLine.resetHistory(); 60 execProcess.resetHistory(); 61 62 SelectableProfileService.launchInstance(profile, ["about:profilemanager"]); 63 64 expected = ["-new-tab", "about:profilemanager"]; 65 66 Assert.equal( 67 sendCommandLine.callCount, 68 1, 69 "Should have attempted to remote to one instance" 70 ); 71 Assert.deepEqual( 72 sendCommandLine.firstCall.args, 73 [profile.path, expected, true], 74 "Expected sendCommandLine arguments" 75 ); 76 77 expected.unshift("--profile", profile.path); 78 79 if (Services.appinfo.OS === "Darwin") { 80 expected.unshift("-foreground"); 81 } 82 83 // Our mock remote service claims the instance is not running so we will fall back to launching 84 // a new process. 85 86 Assert.equal(execProcess.callCount, 1, "Should have called execProcess once"); 87 Assert.deepEqual( 88 execProcess.firstCall.args, 89 [expected], 90 "Expected execProcess arguments" 91 ); 92 });