commit b631e977b54e216735bb3dd23b800632b8b532c0
parent 4aac7524ee66634bd76c7f5c5b3416e7e6e65a3b
Author: Harsheet <hsohaney@mozilla.com>
Date: Mon, 10 Nov 2025 19:02:01 +0000
Bug 1997067 - Move Document's folder getter into it's own static method for backups. r=cdupuis
Differential Revision: https://phabricator.services.mozilla.com/D271419
Diffstat:
3 files changed, 39 insertions(+), 44 deletions(-)
diff --git a/browser/components/backup/BackupService.sys.mjs b/browser/components/backup/BackupService.sys.mjs
@@ -888,20 +888,11 @@ export class BackupService extends EventTarget {
* @returns {string} The path of the default parent directory
*/
static get DEFAULT_PARENT_DIR_PATH() {
- let path = "";
- try {
- path =
- BackupService.oneDriveFolderPath?.path ||
- Services.dirsvc.get("Docs", Ci.nsIFile).path;
- } catch (e) {
- // If this errors, we can safely return an empty string
- lazy.logConsole.error(
- "There was an error when getting the Default Parent Directory: ",
- e
- );
- }
-
- return path;
+ return (
+ BackupService.oneDriveFolderPath?.path ||
+ BackupService.docsDirFolderPath?.path ||
+ ""
+ );
}
/**
@@ -1139,6 +1130,24 @@ export class BackupService extends EventTarget {
}
/**
+ * Gets the user's Documents folder.
+ * If it doesn't exist, return null.
+ *
+ * @returns {nsIFile|null} The Documents folder or null
+ */
+ static get docsDirFolderPath() {
+ try {
+ return Services.dirsvc.get("Docs", Ci.nsIFile);
+ } catch (e) {
+ lazy.logConsole.warn(
+ "There was an error while trying to get the Document's directory",
+ e
+ );
+ }
+ return null;
+ }
+
+ /**
* Returns a reference to a BackupService singleton. If this is the first time
* that this getter is accessed, this causes the BackupService singleton to be
* be instantiated.
@@ -1226,15 +1235,16 @@ export class BackupService extends EventTarget {
* @type {object}
*/
get state() {
- if (!Object.keys(this.#_state.defaultParent).length) {
+ if (
+ !Object.keys(this.#_state.defaultParent).length ||
+ !this.#_state.defaultParent.path
+ ) {
let defaultPath = BackupService.DEFAULT_PARENT_DIR_PATH;
- if (defaultPath) {
- this.#_state.defaultParent = {
- path: defaultPath,
- fileName: PathUtils.filename(defaultPath),
- iconURL: this.getIconFromFilePath(defaultPath),
- };
- }
+ this.#_state.defaultParent = {
+ path: defaultPath,
+ fileName: defaultPath ? PathUtils.filename(defaultPath) : "",
+ iconURL: defaultPath ? this.getIconFromFilePath(defaultPath) : "",
+ };
}
return Object.freeze(structuredClone(this.#_state));
diff --git a/browser/components/backup/content/turn-on-scheduled-backups.mjs b/browser/components/backup/content/turn-on-scheduled-backups.mjs
@@ -261,7 +261,7 @@ export default class TurnOnScheduledBackups extends MozLitElement {
? "turn-on-scheduled-backups-location-default-folder"
: nothing}
data-l10n-args=${hasFilename ? l10nArgs : nothing}
- data-l10n-attrs=${hasFilename ? "value" : "placeholder"}
+ data-l10n-attrs=${hasFilename ? "value" : nothing}
style=${`background-image: url(${iconURL})`}
/>
`;
diff --git a/browser/components/backup/tests/browser/browser_settings_create_backup.js b/browser/components/backup/tests/browser/browser_settings_create_backup.js
@@ -38,13 +38,10 @@ add_task(async function test_no_default_folder() {
let bs = getAndMaybeInitBackupService();
bs.resetDefaultParentInternalState();
- let callCount = 0;
- let getterStub = sandbox
- .stub(BackupService, "DEFAULT_PARENT_DIR_PATH")
- .get(() => {
- callCount++;
- return "";
- });
+ let docStub = sandbox
+ .stub(BackupService, "docsDirFolderPath")
+ .get()
+ .returns(null);
await BrowserTestUtils.withNewTab("about:preferences#sync", async browser => {
let settings = browser.contentDocument.querySelector("backup-settings");
@@ -52,11 +49,6 @@ add_task(async function test_no_default_folder() {
await settings.updateComplete;
- console.log(
- "DO WE HAVE A DEFAULT PARENT ALREADY???",
- settings.backupServiceState.defaultParent
- );
-
Assert.ok(bs.archiveEnabledStatus, "Archive is enabled for backups");
Assert.ok(
@@ -75,13 +67,6 @@ add_task(async function test_no_default_folder() {
"turn-on-scheduled-backups should be found"
);
- // woops looks like getting the default dir threw an error, lets make sure we handled that
- Assert.greaterOrEqual(
- callCount,
- 1,
- "The default dir getter was called atleast once"
- );
-
let filePathInputDefault = turnOnScheduledBackups.filePathInputDefaultEl;
Assert.equal(
@@ -95,10 +80,10 @@ add_task(async function test_no_default_folder() {
dialog.close();
await dialogClosePromise;
-
- getterStub.restore();
});
+ docStub.restore();
+
await BrowserTestUtils.withNewTab("about:preferences#sync", async browser => {
let settings = browser.contentDocument.querySelector("backup-settings");