/* Any copyright is dedicated to the Public Domain. * https://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; const { MockRegistrar } = ChromeUtils.importESModule( "resource://testing-common/MockRegistrar.sys.mjs" ); let gLaunches = []; add_setup(() => { let mockCID = MockRegistrar.register("@mozilla.org/widget/macdocksupport;1", { QueryInterface: ChromeUtils.generateQI(["nsIMacDockSupport"]), launchAppBundle(appBundle, args) { gLaunches.push({ path: appBundle.path, args }); }, }); registerCleanupFunction(() => MockRegistrar.unregister(mockCID)); }); function expectedBundlePath() { return Services.dirsvc.get("XREExeF", Ci.nsIFile).parent.parent.parent.path; } add_task(async function test_createInstanceWithProfile() { gLaunches = []; let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].getService( Ci.nsIToolkitProfileService ); let profileDir = await IOUtils.createUniqueDirectory( PathUtils.tempDir, "createInstanceWithProfile" ); let profile = profileService.createProfile( await IOUtils.getDirectory(profileDir), "Other Profile", "test" ); registerCleanupFunction(async () => { profile.remove(false); await IOUtils.remove(profileDir, { recursive: true }); }); Services.startup.createInstanceWithProfile(profile, ["-new-tab", "about:"]); Assert.deepEqual( gLaunches, [ { path: expectedBundlePath(), args: ["-P", "Other Profile", "-new-tab", "about:"], }, ], "The new instance is launched once through the app bundle" ); }); add_task(function test_launchNewInstance() { gLaunches = []; Services.startup.launchNewInstance(["--profile", "/tmp/some-profile"]); Assert.deepEqual( gLaunches, [ { path: expectedBundlePath(), args: ["--profile", "/tmp/some-profile"], }, ], "The new instance is launched once through the app bundle" ); });