1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
5 * Verify that background tasks that create non-ephemeral profiles update
6 * `profiles.ini` with a salted profile location.
10 skip_if: () => !AppConstants.MOZ_BACKGROUNDTASKS,
13 // MOZ_APP_VENDOR is empty on Thunderbird.
14 let vendor = AppConstants.MOZ_APP_NAME == "thunderbird" ? "" : "Mozilla";
16 add_task(condition, async () => {
17 let hash = xreDirProvider.getInstallHash();
19 writeProfilesIni(BACKGROUNDTASKS_PROFILE_DATA);
21 // Pretend that this is a background task. For a task that does *not* use an
22 // ephemeral profile, i.e., that uses a persistent profile, `profiles.ini` is
23 // updated with a new entry in section `BackgroundTaskProfiles`.
24 const bts = Cc["@mozilla.org/backgroundtasks;1"].getService(
27 // "not_ephemeral_profile" is a special name recognized by the
28 // background task system.
29 bts.overrideBackgroundTaskNameForTesting("not_ephemeral_profile");
31 let { didCreate, rootDir } = selectStartupProfile();
32 checkStartupReason("backgroundtask-not-ephemeral");
34 Assert.equal(didCreate, true, "Created new non-ephemeral profile");
36 let profileData = readProfilesIni();
38 // Profile names are lexicographically ordered, and `not_ephemeral_profile`
39 // sorts before `unrelated_task`.
40 Assert.equal(profileData.backgroundTasksProfiles.length, 2);
42 [profileData.backgroundTasksProfiles[1]],
43 BACKGROUNDTASKS_PROFILE_DATA.backgroundTasksProfiles
46 let saltedPath = profileData.backgroundTasksProfiles[0].path;
49 `.${vendor}BackgroundTask-${hash}-not_ephemeral_profile`
51 `${saltedPath} ends with ".${vendor}BackgroundTask-${hash}-not_ephemeral_profile"`
54 !saltedPath.startsWith(
55 `.${vendor}BackgroundTask-${hash}-not_ephemeral_profile`
57 `${saltedPath} is really salted`
59 Assert.deepEqual(profileData.backgroundTasksProfiles[0], {
60 name: `${vendor}BackgroundTask-${hash}-not_ephemeral_profile`,
65 rootDir.path.endsWith(saltedPath),
66 `rootDir "${rootDir.path}" ends with salted path "${saltedPath}"`
69 // Really, "UAppData", but this is xpcshell.
70 let backgroundTasksProfilesPath = gDataHome;
71 if (!AppConstants.XP_UNIX || AppConstants.platform === "macosx") {
72 backgroundTasksProfilesPath.append("Background Tasks Profiles");
75 rootDir.path.startsWith(backgroundTasksProfilesPath.path),
76 `rootDir "${rootDir.path}" is sibling to user profiles directory ${backgroundTasksProfilesPath}`