From c171a6357bd8d3f65e0f5e70ffe1954309dd9e43 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Tue, 5 Nov 2024 12:59:04 +0000 Subject: [PATCH] Bug 1894239: Enable MOZ_SELECTABLE_PROFILES by default. r=jhirsch,omc-reviewers,niklas,emcminn,mconley This also removes some tests of `MOZ_SELECTABLE_PROFILES` from `browser/components/profiles` files where the test is pointless because that test is excluded from the build if `MOZ_SELECTABLE_PROFILES` is unset. Differential Revision: https://phabricator.services.mozilla.com/D227372 --- browser/base/content/browser-profiles.js | 3 +- .../test/performance/browser_appmenu.js | 4 +- .../static/browser_all_files_referenced.js | 3 + .../static/browser_sentence_case_strings.js | 4 +- browser/components/BrowserGlue.sys.mjs | 5 +- .../modules/ASRouterTargeting.sys.mjs | 4 +- .../browser/browser_asrouter_targeting.js | 12 ++ .../profiles/SelectableProfileService.sys.mjs | 11 + .../profiles/content/profiles-pages.css | 1 - .../profiles/content/profiles-theme-card.css | 5 +- .../browser_create_profile_page_test.js | 7 - .../browser/browser_edit_profile_test.js | 7 - .../browser/browser_test_db_lazily_created.js | 7 - .../browser/browser_test_profile_selector.js | 7 - ...browser_update_profile_on_window_switch.js | 7 - .../tests/unit/test_fail_recover_storeID.js | 47 ++-- .../tests/unit/test_recover_storeID.js | 92 ++++---- .../unit/test_selectable_profile_launch.js | 49 ++--- .../test_selectable_profile_service_exists.js | 25 +-- .../test_selectable_profiles_lifecycle.js | 200 +++++++++--------- .../test_shared_prefs_lifecycles_methods.js | 111 +++++----- .../profiles/tests/unit/xpcshell.toml | 4 + .../components/remote/nsDBusRemoteClient.cpp | 4 + toolkit/moz.configure | 12 +- toolkit/profile/test/xpcshell/head.js | 8 +- 25 files changed, 306 insertions(+), 333 deletions(-) diff --git a/browser/base/content/browser-profiles.js b/browser/base/content/browser-profiles.js index e90b47419b2d..c38baae7f2c2 100644 --- a/browser/base/content/browser-profiles.js +++ b/browser/base/content/browser-profiles.js @@ -21,7 +21,8 @@ var gProfiles = { "PROFILES_ENABLED", "browser.profiles.enabled", false, - this.toggleProfileButtonVisibility.bind(this) + this.toggleProfileButtonVisibility.bind(this), + () => SelectableProfileService?.isEnabled ); if (!this.PROFILES_ENABLED) { diff --git a/browser/base/content/test/performance/browser_appmenu.js b/browser/base/content/test/performance/browser_appmenu.js index 984d2b9fd898..ebbd20dc9885 100644 --- a/browser/base/content/test/performance/browser_appmenu.js +++ b/browser/base/content/test/performance/browser_appmenu.js @@ -73,7 +73,9 @@ add_task(async function () { async function openSubViewsRecursively(currentView) { let navButtons = Array.from( // Ensure that only enabled buttons are tested - currentView.querySelectorAll(".subviewbutton-nav:not([disabled])") + currentView.querySelectorAll( + ".subviewbutton-nav:not([disabled]):not([hidden])" + ) ); if (!navButtons) { return; diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js index 4a3bf385911f..ff015f28492f 100644 --- a/browser/base/content/test/static/browser_all_files_referenced.js +++ b/browser/base/content/test/static/browser_all_files_referenced.js @@ -100,6 +100,9 @@ var gExceptionPaths = [ // The ONNX runtime picks files to run programmaticaly "chrome://global/content/ml/", + + // The profile avatars are directly referenced. + "chrome://browser/content/profiles/assets/", ]; // These are not part of the omni.ja file, so we find them only when running diff --git a/browser/base/content/test/static/browser_sentence_case_strings.js b/browser/base/content/test/static/browser_sentence_case_strings.js index 12952c96000c..8fe24fdd29e3 100644 --- a/browser/base/content/test/static/browser_sentence_case_strings.js +++ b/browser/base/content/test/static/browser_sentence_case_strings.js @@ -43,7 +43,9 @@ let gLocalization = new Localization(["browser/newtab/asrouter.ftl"], true); async function* iterateSubviews(parentView) { let navButtons = Array.from( // Ensure that only enabled buttons are tested - parentView.querySelectorAll(".subviewbutton-nav:not([disabled])") + parentView.querySelectorAll( + ".subviewbutton-nav:not([disabled]):not([hidden])" + ) ); if (!navButtons) { return; diff --git a/browser/components/BrowserGlue.sys.mjs b/browser/components/BrowserGlue.sys.mjs index 52d40c5f8a9e..dc07e50b33fe 100644 --- a/browser/components/BrowserGlue.sys.mjs +++ b/browser/components/BrowserGlue.sys.mjs @@ -1957,10 +1957,7 @@ BrowserGlue.prototype = { lazy.DoHController.init(); - if ( - AppConstants.MOZ_SELECTABLE_PROFILES && - Services.prefs.getBoolPref("browser.profiles.enabled", false) - ) { + if (AppConstants.MOZ_SELECTABLE_PROFILES) { lazy.SelectableProfileService.init().catch(console.error); } diff --git a/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs b/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs index 66b89eee118b..39e98059916c 100644 --- a/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs +++ b/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs @@ -588,9 +588,9 @@ const TargetingGetters = { }, get canCreateSelectableProfiles() { if (!AppConstants.MOZ_SELECTABLE_PROFILES) { - return null; + return false; } - return !!lazy.SelectableProfileService?.groupToolkitProfile; + return lazy.SelectableProfileService?.isEnabled ?? false; }, get hasSelectableProfiles() { return !!lazy.profileStoreID; diff --git a/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js b/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js index 54f093a53273..b31d3cf5e99e 100644 --- a/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js +++ b/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js @@ -219,6 +219,16 @@ add_task(async function check_canCreateSelectableProfiles() { return; } + is( + await ASRouterTargeting.Environment.canCreateSelectableProfiles, + false, + "The new profiles feature doesn't support standalone profiles which are used in automation." + ); + + // We have to fake there being a real profile available and enable the profiles feature + await pushPrefs(["browser.profiles.enabled", "someValue"]); + await SelectableProfileService.resetProfileService({ currentProfile: {} }); + is( await ASRouterTargeting.Environment.canCreateSelectableProfiles, true, @@ -231,6 +241,8 @@ add_task(async function check_canCreateSelectableProfiles() { message, "should select correct item by canCreateSelectableProfiles" ); + + await SelectableProfileService.resetProfileService(null); }); add_task(async function check_hasSelectableProfiles() { diff --git a/browser/components/profiles/SelectableProfileService.sys.mjs b/browser/components/profiles/SelectableProfileService.sys.mjs index 081a2751a028..3f4127122a2f 100644 --- a/browser/components/profiles/SelectableProfileService.sys.mjs +++ b/browser/components/profiles/SelectableProfileService.sys.mjs @@ -118,6 +118,13 @@ class SelectableProfileServiceClass { this.#asyncShutdownBlocker = () => this.uninit(); } + get isEnabled() { + return ( + Services.prefs.getBoolPref("browser.profiles.enabled", false) && + !!(this.#storeID || this.#groupToolkitProfile) + ); + } + /** * For use in testing only, override the profile service with a mock version * and reset state accordingly. @@ -258,6 +265,10 @@ class SelectableProfileServiceClass { ); } + if (!this.isEnabled) { + return; + } + // If the storeID doesn't exist, we don't want to create the db until we // need to so we early return. if (!this.storeID) { diff --git a/browser/components/profiles/content/profiles-pages.css b/browser/components/profiles/content/profiles-pages.css index e35cf45bb7c7..ac5dd83c1f65 100644 --- a/browser/components/profiles/content/profiles-pages.css +++ b/browser/components/profiles/content/profiles-pages.css @@ -4,7 +4,6 @@ :host { --header-avatar-size: 80px; - --header-avatar-img-size: 40px; } html, diff --git a/browser/components/profiles/content/profiles-theme-card.css b/browser/components/profiles/content/profiles-theme-card.css index 3575df438984..37692bab2384 100644 --- a/browser/components/profiles/content/profiles-theme-card.css +++ b/browser/components/profiles/content/profiles-theme-card.css @@ -52,8 +52,9 @@ moz-card { padding-inline-start: var(--space-medium); padding-block: var(--space-small); - border-width: var(--theme-card-border-width); - border-top: var(--card-border); + border-inline-width: var(--theme-card-border-width); + border-block-end-width: var(--theme-card-border-width); + border-block-start: var(--card-border); } :host([selected]) .theme-card { diff --git a/browser/components/profiles/tests/browser/browser_create_profile_page_test.js b/browser/components/profiles/tests/browser/browser_create_profile_page_test.js index e3764a6df2ea..21db525346b8 100644 --- a/browser/components/profiles/tests/browser/browser_create_profile_page_test.js +++ b/browser/components/profiles/tests/browser/browser_create_profile_page_test.js @@ -6,13 +6,6 @@ const NEW_PROFILE_NAME = "This is a new profile name"; add_task(async function test_create_profile_name() { - if (!AppConstants.MOZ_SELECTABLE_PROFILES) { - // `mochitest-browser` suite `add_task` does not yet support - // `properties.skip_if`. - ok(true, "Skipping because !AppConstants.MOZ_SELECTABLE_PROFILES"); - return; - } - await SpecialPowers.pushPrefEnv({ set: [["browser.profiles.profile-name.updated", false]], }); diff --git a/browser/components/profiles/tests/browser/browser_edit_profile_test.js b/browser/components/profiles/tests/browser/browser_edit_profile_test.js index f7a3ed78e40e..d268c0a4403a 100644 --- a/browser/components/profiles/tests/browser/browser_edit_profile_test.js +++ b/browser/components/profiles/tests/browser/browser_edit_profile_test.js @@ -6,13 +6,6 @@ const NEW_PROFILE_NAME = "This is a new profile name"; add_task(async function test_edit_profile_name() { - if (!AppConstants.MOZ_SELECTABLE_PROFILES) { - // `mochitest-browser` suite `add_task` does not yet support - // `properties.skip_if`. - ok(true, "Skipping because !AppConstants.MOZ_SELECTABLE_PROFILES"); - return; - } - await initGroupDatabase(); let profile = SelectableProfileService.currentProfile; Assert.ok(profile, "Should have a profile now"); diff --git a/browser/components/profiles/tests/browser/browser_test_db_lazily_created.js b/browser/components/profiles/tests/browser/browser_test_db_lazily_created.js index d60729532012..909c256df9b9 100644 --- a/browser/components/profiles/tests/browser/browser_test_db_lazily_created.js +++ b/browser/components/profiles/tests/browser/browser_test_db_lazily_created.js @@ -4,13 +4,6 @@ "use strict"; add_task(async function test_dbLazilyCreated() { - if (!AppConstants.MOZ_SELECTABLE_PROFILES) { - // `mochitest-browser` suite `add_task` does not yet support - // `properties.skip_if`. - ok(true, "Skipping because !AppConstants.MOZ_SELECTABLE_PROFILES"); - return; - } - Assert.ok( !SelectableProfileService.initialized, `Selectable Profile Service should not be initialized because the default profile has no storeID` diff --git a/browser/components/profiles/tests/browser/browser_test_profile_selector.js b/browser/components/profiles/tests/browser/browser_test_profile_selector.js index 113892c98aa1..24f1e25cb328 100644 --- a/browser/components/profiles/tests/browser/browser_test_profile_selector.js +++ b/browser/components/profiles/tests/browser/browser_test_profile_selector.js @@ -4,13 +4,6 @@ "use strict"; add_task(async function test_selector_window() { - if (!AppConstants.MOZ_SELECTABLE_PROFILES) { - // `mochitest-browser` suite `add_task` does not yet support - // `properties.skip_if`. - ok(true, "Skipping because !AppConstants.MOZ_SELECTABLE_PROFILES"); - return; - } - await initGroupDatabase(); let profile = SelectableProfileService.currentProfile; diff --git a/browser/components/profiles/tests/browser/browser_update_profile_on_window_switch.js b/browser/components/profiles/tests/browser/browser_update_profile_on_window_switch.js index 5c13d506a85a..5a99a5769d75 100644 --- a/browser/components/profiles/tests/browser/browser_update_profile_on_window_switch.js +++ b/browser/components/profiles/tests/browser/browser_update_profile_on_window_switch.js @@ -8,13 +8,6 @@ const { SelectableProfile } = ChromeUtils.importESModule( ); add_task(async function test_updateDefaultProfileOnWindowSwitch() { - if (!AppConstants.MOZ_SELECTABLE_PROFILES) { - // `mochitest-browser` suite `add_task` does not yet support - // `properties.skip_if`. - ok(true, "Skipping because !AppConstants.MOZ_SELECTABLE_PROFILES"); - return; - } - await initGroupDatabase(); let currentProfile = SelectableProfileService.currentProfile; let profileRootDir = await currentProfile.rootDir; diff --git a/browser/components/profiles/tests/unit/test_fail_recover_storeID.js b/browser/components/profiles/tests/unit/test_fail_recover_storeID.js index c3bc07fc0835..dd467c190eb1 100644 --- a/browser/components/profiles/tests/unit/test_fail_recover_storeID.js +++ b/browser/components/profiles/tests/unit/test_fail_recover_storeID.js @@ -3,32 +3,27 @@ https://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; -add_task( - { - skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES, - }, - async function test_recover_storeID() { - startProfileService(); - Services.prefs.setCharPref("toolkit.profiles.storeID", "foobar"); +add_task(async function test_recover_storeID() { + startProfileService(); + Services.prefs.setCharPref("toolkit.profiles.storeID", "foobar"); - const SelectableProfileService = getSelectableProfileService(); - await SelectableProfileService.init(); - Assert.ok( - !SelectableProfileService.initialized, - "Didn't initialize the service" - ); + const SelectableProfileService = getSelectableProfileService(); + await SelectableProfileService.init(); + Assert.ok( + !SelectableProfileService.initialized, + "Didn't initialize the service" + ); - let profile = SelectableProfileService.currentProfile; - Assert.ok(!profile, "Should not have a current profile"); - Assert.equal( - getProfileService().currentProfile.storeID, - null, - "Should not have updated the store ID on the profile" - ); + let profile = SelectableProfileService.currentProfile; + Assert.ok(!profile, "Should not have a current profile"); + Assert.equal( + getProfileService().currentProfile.storeID, + null, + "Should not have updated the store ID on the profile" + ); - Assert.ok( - !Services.prefs.prefHasUserValue("toolkit.profiles.storeID"), - "Should have cleared the storeID pref" - ); - } -); + Assert.ok( + !Services.prefs.prefHasUserValue("toolkit.profiles.storeID"), + "Should have cleared the storeID pref" + ); +}); diff --git a/browser/components/profiles/tests/unit/test_recover_storeID.js b/browser/components/profiles/tests/unit/test_recover_storeID.js index 04e24839d5db..4d14fb5154f3 100644 --- a/browser/components/profiles/tests/unit/test_recover_storeID.js +++ b/browser/components/profiles/tests/unit/test_recover_storeID.js @@ -7,33 +7,27 @@ const { Sqlite } = ChromeUtils.importESModule( "resource://gre/modules/Sqlite.sys.mjs" ); -add_task( - { - skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES, - }, - async function test_recover_storeID() { - startProfileService(); - Services.prefs.setCharPref("toolkit.profiles.storeID", "foobar"); +add_task(async function test_recover_storeID() { + startProfileService(); + Services.prefs.setCharPref("toolkit.profiles.storeID", "foobar"); - // The database needs to exist already - let groupsPath = PathUtils.join( - Services.dirsvc.get("UAppData", Ci.nsIFile).path, - "Profile Groups" - ); + // The database needs to exist already + let groupsPath = PathUtils.join( + Services.dirsvc.get("UAppData", Ci.nsIFile).path, + "Profile Groups" + ); - await IOUtils.makeDirectory(groupsPath); - let dbFile = PathUtils.join(groupsPath, "foobar.sqlite"); - let db = await Sqlite.openConnection({ - path: dbFile, - openNotExclusive: true, - }); + await IOUtils.makeDirectory(groupsPath); + let dbFile = PathUtils.join(groupsPath, "foobar.sqlite"); + let db = await Sqlite.openConnection({ + path: dbFile, + openNotExclusive: true, + }); - let path = getRelativeProfilePath( - getProfileService().currentProfile.rootDir - ); + let path = getRelativeProfilePath(getProfileService().currentProfile.rootDir); - // Slightly annoying we have to replicate this... - await db.execute(`CREATE TABLE IF NOT EXISTS "Profiles" ( + // Slightly annoying we have to replicate this... + await db.execute(`CREATE TABLE IF NOT EXISTS "Profiles" ( id INTEGER NOT NULL, path TEXT NOT NULL UNIQUE, name TEXT NOT NULL, @@ -43,34 +37,30 @@ add_task( themeBg TEXT NOT NULL, PRIMARY KEY(id) );`); - await db.execute( - `INSERT INTO Profiles VALUES (NULL, :path, :name, :avatar, :themeL10nId, :themeFg, :themeBg);`, - { - path, - name: "Fake Profile", - avatar: "book", - themeL10nId: "default", - themeFg: "", - themeBg: "", - } - ); + await db.execute( + `INSERT INTO Profiles VALUES (NULL, :path, :name, :avatar, :themeL10nId, :themeFg, :themeBg);`, + { + path, + name: "Fake Profile", + avatar: "book", + themeL10nId: "default", + themeFg: "", + themeBg: "", + } + ); - await db.close(); + await db.close(); - const SelectableProfileService = getSelectableProfileService(); - await SelectableProfileService.init(); - Assert.ok( - SelectableProfileService.initialized, - "Did initialize the service" - ); + const SelectableProfileService = getSelectableProfileService(); + await SelectableProfileService.init(); + Assert.ok(SelectableProfileService.initialized, "Did initialize the service"); - let profile = SelectableProfileService.currentProfile; - Assert.ok(profile, "Should have a current profile"); - Assert.equal(profile.name, "Fake Profile"); - Assert.equal( - getProfileService().currentProfile.storeID, - "foobar", - "Should have updated the store ID on the profile" - ); - } -); + let profile = SelectableProfileService.currentProfile; + Assert.ok(profile, "Should have a current profile"); + Assert.equal(profile.name, "Fake Profile"); + Assert.equal( + getProfileService().currentProfile.storeID, + "foobar", + "Should have updated the store ID on the profile" + ); +}); diff --git a/browser/components/profiles/tests/unit/test_selectable_profile_launch.js b/browser/components/profiles/tests/unit/test_selectable_profile_launch.js index 007e7a5f0f71..c0aee7284352 100644 --- a/browser/components/profiles/tests/unit/test_selectable_profile_launch.js +++ b/browser/components/profiles/tests/unit/test_selectable_profile_launch.js @@ -5,35 +5,30 @@ https://creativecommons.org/publicdomain/zero/1.0/ */ add_setup(initSelectableProfileService); -add_task( - { - skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES, - }, - async function test_launcher() { - // mock() returns an object with a fake `runw` method that, when - // called, records its arguments. - let input = []; - let mock = () => { - return { - runw: (...args) => { - input = args; - }, - }; +add_task(async function test_launcher() { + // mock() returns an object with a fake `runw` method that, when + // called, records its arguments. + let input = []; + let mock = () => { + return { + runw: (...args) => { + input = args; + }, }; + }; - let profile = await createTestProfile(); + let profile = await createTestProfile(); - const SelectableProfileService = getSelectableProfileService(); - SelectableProfileService.getExecutableProcess = mock; - SelectableProfileService.launchInstance(profile); + const SelectableProfileService = getSelectableProfileService(); + SelectableProfileService.getExecutableProcess = mock; + SelectableProfileService.launchInstance(profile); - let expected; - if (Services.appinfo.OS == "Darwin") { - expected = ["-foreground", "--profile", profile.path]; - } else { - expected = ["--profile", profile.path]; - } - - Assert.deepEqual(expected, input[1], "Expected runw arguments"); + let expected; + if (Services.appinfo.OS == "Darwin") { + expected = ["-foreground", "--profile", profile.path]; + } else { + expected = ["--profile", profile.path]; } -); + + Assert.deepEqual(expected, input[1], "Expected runw arguments"); +}); diff --git a/browser/components/profiles/tests/unit/test_selectable_profile_service_exists.js b/browser/components/profiles/tests/unit/test_selectable_profile_service_exists.js index d5a712f3dfc9..d9adce3c0ad2 100644 --- a/browser/components/profiles/tests/unit/test_selectable_profile_service_exists.js +++ b/browser/components/profiles/tests/unit/test_selectable_profile_service_exists.js @@ -3,19 +3,14 @@ https://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; -add_task( - { - skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES, - }, - async function test_SelectableProfileAndServiceExist() { - const { SelectableProfile } = ChromeUtils.importESModule( - "resource:///modules/profiles/SelectableProfile.sys.mjs" - ); - const { SelectableProfileService } = ChromeUtils.importESModule( - "resource:///modules/profiles/SelectableProfileService.sys.mjs" - ); +add_task(async function test_SelectableProfileAndServiceExist() { + const { SelectableProfile } = ChromeUtils.importESModule( + "resource:///modules/profiles/SelectableProfile.sys.mjs" + ); + const { SelectableProfileService } = ChromeUtils.importESModule( + "resource:///modules/profiles/SelectableProfileService.sys.mjs" + ); - ok(SelectableProfile, "SelectableProfile exists"); - ok(SelectableProfileService, "SelectableProfileService exists"); - } -); + ok(SelectableProfile, "SelectableProfile exists"); + ok(SelectableProfileService, "SelectableProfileService exists"); +}); diff --git a/browser/components/profiles/tests/unit/test_selectable_profiles_lifecycle.js b/browser/components/profiles/tests/unit/test_selectable_profiles_lifecycle.js index 8ac27c38a01b..6974cb9ef632 100644 --- a/browser/components/profiles/tests/unit/test_selectable_profiles_lifecycle.js +++ b/browser/components/profiles/tests/unit/test_selectable_profiles_lifecycle.js @@ -3,110 +3,116 @@ https://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; -add_task( - { - skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES, - }, - async function test_SelectableProfileLifecycle() { - startProfileService(); - const SelectableProfileService = getSelectableProfileService(); - await SelectableProfileService.init(); +add_task(async function test_SelectableProfileLifecycle() { + startProfileService(); + const SelectableProfileService = getSelectableProfileService(); - let profiles = await SelectableProfileService.getAllProfiles(); + Services.prefs.setBoolPref("browser.profiles.enabled", false); + await SelectableProfileService.init(); + Assert.ok( + !SelectableProfileService.isEnabled, + "Service should not be enabled" + ); - Assert.ok(!profiles.length, "No selectable profiles exist yet"); + Services.prefs.setBoolPref("browser.profiles.enabled", true); + await SelectableProfileService.init(); + Assert.ok( + SelectableProfileService.isEnabled, + "Service should now be enabled" + ); - await SelectableProfileService.maybeSetupDataStore(); - let currentProfile = SelectableProfileService.currentProfile; + let profiles = await SelectableProfileService.getAllProfiles(); - const leafName = (await currentProfile.rootDir).leafName; + Assert.ok(!profiles.length, "No selectable profiles exist yet"); - const profilePath = PathUtils.join( - Services.dirsvc.get("DefProfRt", Ci.nsIFile).path, - leafName + await SelectableProfileService.maybeSetupDataStore(); + let currentProfile = SelectableProfileService.currentProfile; + + const leafName = (await currentProfile.rootDir).leafName; + + const profilePath = PathUtils.join( + Services.dirsvc.get("DefProfRt", Ci.nsIFile).path, + leafName + ); + + let profileDirExists = await IOUtils.exists(profilePath); + const profileLocalPath = PathUtils.join( + Services.dirsvc.get("DefProfLRt", Ci.nsIFile).path, + leafName + ); + let profileLocalDirExists = await IOUtils.exists(profileLocalPath); + + Assert.ok( + profileDirExists, + `Profile dir was successfully created at ${profilePath}` + ); + Assert.ok( + profileLocalDirExists, + `Profile local dir was successfully created at ${profileLocalPath}` + ); + + profiles = await SelectableProfileService.getAllProfiles(); + + Assert.equal(profiles.length, 1, "One selectable profile exists"); + + let selectableProfile = profiles[0]; + + let profile = await SelectableProfileService.getProfile(selectableProfile.id); + + for (let attr of ["id", "name", "path"]) { + Assert.equal( + profile[attr], + currentProfile[attr], + `We got the correct profile ${attr}` ); - let profileDirExists = await IOUtils.exists(profilePath); - const profileLocalPath = PathUtils.join( - Services.dirsvc.get("DefProfLRt", Ci.nsIFile).path, - leafName - ); - let profileLocalDirExists = await IOUtils.exists(profileLocalPath); - - Assert.ok( - profileDirExists, - `Profile dir was successfully created at ${profilePath}` - ); - Assert.ok( - profileLocalDirExists, - `Profile local dir was successfully created at ${profileLocalPath}` - ); - - profiles = await SelectableProfileService.getAllProfiles(); - - Assert.equal(profiles.length, 1, "One selectable profile exists"); - - let selectableProfile = profiles[0]; - - let profile = await SelectableProfileService.getProfile( - selectableProfile.id - ); - - for (let attr of ["id", "name", "path"]) { - Assert.equal( - profile[attr], - currentProfile[attr], - `We got the correct profile ${attr}` - ); - - Assert.equal( - selectableProfile[attr], - currentProfile[attr], - `We got the correct profile ${attr}` - ); - } - - selectableProfile.name = "updatedTestProfile"; - - await SelectableProfileService.updateProfile(selectableProfile); - - profile = await SelectableProfileService.getProfile(selectableProfile.id); - Assert.equal( - profile.name, - "updatedTestProfile", - "We got the correct profile name: updatedTestProfile" - ); - - let newProfile = await createTestProfile({ name: "New profile" }); - let rootDir = await newProfile.rootDir; - let localDir = PathUtils.join( - Services.dirsvc.get("DefProfLRt", Ci.nsIFile).path, - rootDir.leafName - ); - - profileDirExists = await IOUtils.exists(rootDir.path); - profileLocalDirExists = await IOUtils.exists(localDir); - Assert.ok(profileDirExists, "Profile dir was successfully created"); - Assert.ok( - profileLocalDirExists, - "Profile local dir was successfully created" - ); - - profiles = await SelectableProfileService.getAllProfiles(); - Assert.equal(profiles.length, 2, "Should now be two profiles."); - - await SelectableProfileService.deleteProfile(newProfile); - - profiles = await SelectableProfileService.getAllProfiles(); - Assert.equal(profiles.length, 1, "Should now be one profiles."); - - profileDirExists = await IOUtils.exists(rootDir.path); - profileLocalDirExists = await IOUtils.exists(localDir); - Assert.ok(!profileDirExists, "Profile dir was successfully removed"); - Assert.ok( - !profileLocalDirExists, - "Profile local dir was successfully removed" + selectableProfile[attr], + currentProfile[attr], + `We got the correct profile ${attr}` ); } -); + + selectableProfile.name = "updatedTestProfile"; + + await SelectableProfileService.updateProfile(selectableProfile); + + profile = await SelectableProfileService.getProfile(selectableProfile.id); + + Assert.equal( + profile.name, + "updatedTestProfile", + "We got the correct profile name: updatedTestProfile" + ); + + let newProfile = await createTestProfile({ name: "New profile" }); + let rootDir = await newProfile.rootDir; + let localDir = PathUtils.join( + Services.dirsvc.get("DefProfLRt", Ci.nsIFile).path, + rootDir.leafName + ); + + profileDirExists = await IOUtils.exists(rootDir.path); + profileLocalDirExists = await IOUtils.exists(localDir); + Assert.ok(profileDirExists, "Profile dir was successfully created"); + Assert.ok( + profileLocalDirExists, + "Profile local dir was successfully created" + ); + + profiles = await SelectableProfileService.getAllProfiles(); + Assert.equal(profiles.length, 2, "Should now be two profiles."); + + await SelectableProfileService.deleteProfile(newProfile); + + profiles = await SelectableProfileService.getAllProfiles(); + Assert.equal(profiles.length, 1, "Should now be one profiles."); + + profileDirExists = await IOUtils.exists(rootDir.path); + profileLocalDirExists = await IOUtils.exists(localDir); + Assert.ok(!profileDirExists, "Profile dir was successfully removed"); + Assert.ok( + !profileLocalDirExists, + "Profile local dir was successfully removed" + ); +}); diff --git a/browser/components/profiles/tests/unit/test_shared_prefs_lifecycles_methods.js b/browser/components/profiles/tests/unit/test_shared_prefs_lifecycles_methods.js index f765ab0a6bb4..5173175be473 100644 --- a/browser/components/profiles/tests/unit/test_shared_prefs_lifecycles_methods.js +++ b/browser/components/profiles/tests/unit/test_shared_prefs_lifecycles_methods.js @@ -5,69 +5,64 @@ https://creativecommons.org/publicdomain/zero/1.0/ */ add_setup(initSelectableProfileService); -add_task( - { - skip_if: () => !AppConstants.MOZ_SELECTABLE_PROFILES, - }, - async function test_SharedPrefsLifecycle() { - const SelectableProfileService = getSelectableProfileService(); - let prefs = await SelectableProfileService.getAllPrefs(); +add_task(async function test_SharedPrefsLifecycle() { + const SelectableProfileService = getSelectableProfileService(); + let prefs = await SelectableProfileService.getAllPrefs(); - Assert.equal(prefs.length, 3, "The default shared prefs exist"); + Assert.equal(prefs.length, 3, "The default shared prefs exist"); - await SelectableProfileService.setIntPref("testPrefInt0", 0); - await SelectableProfileService.setIntPref("testPrefInt1", 1); - await SelectableProfileService.setPref("testPrefInt2", 2); + await SelectableProfileService.setIntPref("testPrefInt0", 0); + await SelectableProfileService.setIntPref("testPrefInt1", 1); + await SelectableProfileService.setPref("testPrefInt2", 2); - await SelectableProfileService.setStringPref( - "testPrefString0", - "Hello world!" - ); - await SelectableProfileService.setPref("testPrefString1", "Hello world 2!"); + await SelectableProfileService.setStringPref( + "testPrefString0", + "Hello world!" + ); + await SelectableProfileService.setPref("testPrefString1", "Hello world 2!"); - await SelectableProfileService.setBoolPref("testPrefBoolTrue", true); - await SelectableProfileService.setPref("testPrefBoolFalse", false); + await SelectableProfileService.setBoolPref("testPrefBoolTrue", true); + await SelectableProfileService.setPref("testPrefBoolFalse", false); - prefs = await SelectableProfileService.getAllPrefs(); + prefs = await SelectableProfileService.getAllPrefs(); - Assert.equal(prefs.length, 10, "10 shared prefs exist"); + Assert.equal(prefs.length, 10, "10 shared prefs exist"); - Assert.equal( - await SelectableProfileService.getIntPref("testPrefInt0"), - 0, - "testPrefInt0 value is 0" - ); - Assert.equal( - await SelectableProfileService.getIntPref("testPrefInt1"), - 1, - "testPrefInt1 value is 1" - ); - Assert.equal( - await SelectableProfileService.getPref("testPrefInt2"), - 2, - "testPrefInt2 value is 2" - ); - Assert.equal( - await SelectableProfileService.getStringPref("testPrefString0"), - "Hello world!", - 'testPrefString0 value is "Hello world!"' - ); - Assert.equal( - await SelectableProfileService.getPref("testPrefString1"), - "Hello world 2!", - 'testPrefString1 value is "Hello world 2!"' - ); - Assert.equal( - await SelectableProfileService.getBoolPref("testPrefBoolTrue"), - true, - "testPrefBoolTrue value is true" - ); - Assert.equal( - await SelectableProfileService.getPref("testPrefBoolFalse"), - false, - "testPrefBoolFalse value is false" - ); + Assert.equal( + await SelectableProfileService.getIntPref("testPrefInt0"), + 0, + "testPrefInt0 value is 0" + ); + Assert.equal( + await SelectableProfileService.getIntPref("testPrefInt1"), + 1, + "testPrefInt1 value is 1" + ); + Assert.equal( + await SelectableProfileService.getPref("testPrefInt2"), + 2, + "testPrefInt2 value is 2" + ); + Assert.equal( + await SelectableProfileService.getStringPref("testPrefString0"), + "Hello world!", + 'testPrefString0 value is "Hello world!"' + ); + Assert.equal( + await SelectableProfileService.getPref("testPrefString1"), + "Hello world 2!", + 'testPrefString1 value is "Hello world 2!"' + ); + Assert.equal( + await SelectableProfileService.getBoolPref("testPrefBoolTrue"), + true, + "testPrefBoolTrue value is true" + ); + Assert.equal( + await SelectableProfileService.getPref("testPrefBoolFalse"), + false, + "testPrefBoolFalse value is false" + ); - await SelectableProfileService.deleteProfileGroup(); - } -); + await SelectableProfileService.deleteProfileGroup(); +}); diff --git a/browser/components/profiles/tests/unit/xpcshell.toml b/browser/components/profiles/tests/unit/xpcshell.toml index 8b775be4cfbb..bad7a0542aa0 100644 --- a/browser/components/profiles/tests/unit/xpcshell.toml +++ b/browser/components/profiles/tests/unit/xpcshell.toml @@ -2,6 +2,10 @@ head = "../../../../../toolkit/profile/test/xpcshell/head.js head.js" firefox-appdir = "browser" +prefs = [ + "browser.profiles.enabled=true", +] + ["test_fail_recover_storeID.js"] ["test_recover_storeID.js"] diff --git a/toolkit/components/remote/nsDBusRemoteClient.cpp b/toolkit/components/remote/nsDBusRemoteClient.cpp index aad9d7054af8..204b3b9c37dd 100644 --- a/toolkit/components/remote/nsDBusRemoteClient.cpp +++ b/toolkit/components/remote/nsDBusRemoteClient.cpp @@ -107,6 +107,10 @@ nsresult nsDBusRemoteClient::DoSendDBusCommandLine(const char* aProfile, int aLength) { LOG("nsDBusRemoteClient::DoSendDBusCommandLine()"); + if (!gAppData) { + return NS_ERROR_FAILURE; + } + nsAutoCString appName; gAppData->GetDBusAppName(appName); diff --git a/toolkit/moz.configure b/toolkit/moz.configure index b72d08acd463..6679576f5a1f 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -1092,16 +1092,10 @@ with only_when(target_is_osx): # Profile Management # ============================================================== -# Selectable profiles are temporarily gated behind a build flag -# while we build and stabilize the backend (bug 1893315). +# Selectable profiles are enabled by default. -option( - env="MOZ_SELECTABLE_PROFILES", - help="Enable experimental and unstable profile groups", -) - -set_define("MOZ_SELECTABLE_PROFILES", True, when="MOZ_SELECTABLE_PROFILES") -set_config("MOZ_SELECTABLE_PROFILES", True, when="MOZ_SELECTABLE_PROFILES") +set_define("MOZ_SELECTABLE_PROFILES", True) +set_config("MOZ_SELECTABLE_PROFILES", True) project_flag( "MOZ_DEDICATED_PROFILES", diff --git a/toolkit/profile/test/xpcshell/head.js b/toolkit/profile/test/xpcshell/head.js index f16d53529f5b..093a44631fe5 100644 --- a/toolkit/profile/test/xpcshell/head.js +++ b/toolkit/profile/test/xpcshell/head.js @@ -33,10 +33,12 @@ xreDirProvider.setUserDataDirectory(gDataHome, false); xreDirProvider.setUserDataDirectory(gDataHomeLocal, true); Services.dirsvc.set("UAppData", gDataHome); let gProfilesRoot = gDataHome.clone(); -gProfilesRoot.append("profiles"); -Services.dirsvc.set("DefProfRt", gProfilesRoot); let gProfilesTemp = gDataHomeLocal.clone(); -gProfilesTemp.append("profiles"); +if (!AppConstants.XP_UNIX || AppConstants.platform == "macosx") { + gProfilesRoot.append("Profiles"); + gProfilesTemp.append("Profiles"); +} +Services.dirsvc.set("DefProfRt", gProfilesRoot); Services.dirsvc.set("DefProfLRt", gProfilesTemp); let gIsDefaultApp = false;