commit 60163ba1664911c7cb810b56fbfa3880c6a99757
parent 2a88ddb2544a72aa7ae773b0441657132f616803
Author: Emily McMinn <emcminn@mozilla.com>
Date: Wed, 26 Nov 2025 17:22:12 +0000
Bug 1999785 - Add check for persistentPath to disableSubmit r=sthompson,hsohaney
Differential Revision: https://phabricator.services.mozilla.com/D273603
Diffstat:
2 files changed, 133 insertions(+), 55 deletions(-)
diff --git a/browser/components/backup/content/turn-on-scheduled-backups.mjs b/browser/components/backup/content/turn-on-scheduled-backups.mjs
@@ -417,13 +417,16 @@ export default class TurnOnScheduledBackups extends MozLitElement {
}
contentTemplate() {
+ const hasEmbeddedPersistentData =
+ this.embeddedFxBackupOptIn &&
+ this.backupServiceState?.embeddedComponentPersistentData?.path;
// All the situations where we want to disable submit:
// - passwords don't match
// - there's no destination folder
// - other unknown errors
if (
(this._showPasswordOptions && !this._passwordsMatch) ||
- (!this._newPath && !this.defaultLabel) ||
+ (!this._newPath && !this.defaultLabel && !hasEmbeddedPersistentData) ||
this.enableBackupErrorCode != ERRORS.NONE
) {
this.disableSubmit = true;
diff --git a/browser/components/backup/tests/chrome/test_turn_on_scheduled_backups.html b/browser/components/backup/tests/chrome/test_turn_on_scheduled_backups.html
@@ -36,13 +36,60 @@
});
/**
+ * Tests that the dialog displays a default save location for backups and updates to a custom one
+ * if there is one selected.
+ */
+ add_task(async function test_locationInputs() {
+ let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
+
+ let inputDefault = turnOnScheduledBackups.filePathInputDefaultEl;
+ ok(inputDefault, "Default input should be found");
+
+ let promise = BrowserTestUtils.waitForCondition(() => inputDefault.value);
+
+ /* Normally we would pass in the default attributes, but for this test, we will
+ * hardcode them since file paths vary across different platforms.
+ */
+ const defaultPathFilename = "testdefaultpath";
+ let defaultPath = PathUtils.join(PathUtils.tempDir, defaultPathFilename);
+ turnOnScheduledBackups.defaultPath = defaultPath;
+ turnOnScheduledBackups.defaultLabel = defaultPathFilename;
+ await turnOnScheduledBackups.updateComplete;
+ await promise;
+
+ is(inputDefault.value, `${defaultPathFilename} (recommended)`, "Default input should not be empty and should contain part of the default path");
+
+ // Now pretend a custom file path was selected
+ const newPathFilename = "testnewpath";
+ let newPath = PathUtils.join(PathUtils.tempDir, newPathFilename);
+ turnOnScheduledBackups._newPath = newPath;
+ turnOnScheduledBackups._newLabel = newPathFilename;
+ await turnOnScheduledBackups.updateComplete;
+
+ let inputCustom = turnOnScheduledBackups.filePathInputCustomEl;
+ ok(inputCustom, "Input should be updated");
+ is(inputCustom.value, newPathFilename, "Input value should be set to the new path");
+ })
+
+ /**
* Tests that pressing the confirm button will dispatch the expected events.
*/
add_task(async function test_confirm() {
let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
let confirmButton = turnOnScheduledBackups.confirmButtonEl;
+ // Reset the component state
+ turnOnScheduledBackups.defaultPath = null;
+ turnOnScheduledBackups.defaultLabel = null;
+ turnOnScheduledBackups._newPath = null;
+ turnOnScheduledBackups._newPathLabel = null;
+
+ await turnOnScheduledBackups.updateComplete;
+
// The confirm button will be disabled if BackupService cannot find a file path
+ ok(confirmButton.disabled, "confirm button should be inactive if there is no default path");
+
+ // Now we can set the default path
const defaultPathFilename = "testdefaultpath";
let defaultPath = PathUtils.join(PathUtils.tempDir, defaultPathFilename);
turnOnScheduledBackups.defaultPath = defaultPath;
@@ -63,6 +110,88 @@
})
/**
+ * Tests that setting a new path will enable the confirm button and dispatch the expected events.
+ */
+ add_task(async function test_confirm_newpath() {
+ let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
+ let confirmButton = turnOnScheduledBackups.confirmButtonEl;
+
+ // The confirm button will be disabled if BackupService cannot find a file path
+ const defaultPathFilename = null;
+ let defaultPath = PathUtils.join(PathUtils.tempDir, defaultPathFilename);
+ turnOnScheduledBackups.defaultPath = defaultPath;
+ turnOnScheduledBackups.defaultLabel = defaultPathFilename;
+
+ await turnOnScheduledBackups.updateComplete;
+
+ ok(confirmButton.disabled, "confirm button should be inactive if there is no default path");
+
+ // Set a new file path to enable the button
+ const newPathFilename = "testnewpath";
+ let newPath = PathUtils.join(PathUtils.tempDir, newPathFilename);
+ turnOnScheduledBackups._newPath = newPath;
+ turnOnScheduledBackups._newPathLabel = newPathFilename;
+
+ await turnOnScheduledBackups.updateComplete;
+
+ ok(confirmButton, "Confirm button should be found");
+ ok(!confirmButton.disabled, "confirm button should be active");
+
+ let content = document.getElementById("content");
+ let promise = BrowserTestUtils.waitForEvent(content, "BackupUI:EnableScheduledBackups");
+
+ confirmButton.click()
+
+ await promise;
+ ok(true, "Detected event after selecting the confirm button");
+ })
+
+ /**
+ * Tests that setting a persisted path will enable the confirm button and dispatch the expected events.
+ */
+ add_task(async function test_confirm_persisted_path() {
+ let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
+ let confirmButton = turnOnScheduledBackups.confirmButtonEl;
+ // For the purposes of this test, we are embedded
+ turnOnScheduledBackups.embeddedFxBackupOptIn = true;
+
+ // Reset the component state
+ turnOnScheduledBackups.defaultPath = "";
+ turnOnScheduledBackups.defaultLabel = "";
+ turnOnScheduledBackups._newPath = "";
+ turnOnScheduledBackups._newPathLabel = "";
+
+ turnOnScheduledBackups.backupServiceState = createBackupServiceState({
+ embeddedComponentPersistentData: {},
+ });
+
+ await turnOnScheduledBackups.updateComplete;
+
+ ok(confirmButton.disabled, "confirm button should be inactive if there is no default path");
+
+ // Set the persisted path to enable the button
+ const persistedPathFilename = "testpersistedpath";
+ let persistedPath = PathUtils.join(PathUtils.tempDir, persistedPathFilename);
+ turnOnScheduledBackups.backupServiceState.embeddedComponentPersistentData = {
+ path: persistedPath
+ }
+
+ turnOnScheduledBackups.reset();
+ await turnOnScheduledBackups.updateComplete;
+
+ ok(confirmButton, "Confirm button should be found");
+ ok(!confirmButton.disabled, "confirm button should be active");
+
+ let content = document.getElementById("content");
+ let promise = BrowserTestUtils.waitForEvent(content, "BackupUI:EnableScheduledBackups");
+
+ confirmButton.click()
+
+ await promise;
+ ok(true, "Detected event after selecting the confirm button");
+ })
+
+ /**
* Tests that pressing the cancel button will dispatch the expected events.
*/
add_task(async function test_cancel() {
@@ -139,60 +268,6 @@
ok(confirmButton.disabled, "Confirm button should be disabled again");
})
-
- /**
- * Tests that the Confirm button cannot be selected if the file path is invalid.
- */
- add_task(async function test_filepathValidityConfirmButton() {
- let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
-
- // The confirm button will be disabled if BackupService cannot find a file path
- const emptyPathFilename = "";
- let emptyPath = PathUtils.join(PathUtils.tempDir, emptyPathFilename);
- turnOnScheduledBackups.defaultPath = emptyPath;
- turnOnScheduledBackups.defaultLabel = emptyPathFilename;
-
- await turnOnScheduledBackups.updateComplete;
-
- let confirmButton = turnOnScheduledBackups.confirmButtonEl;
- ok(confirmButton, "Confirm button should be found");
- ok(confirmButton.disabled, "Confirm button should be disabled since there is no default file path");
- })
-
- /**
- * Tests that the dialog displays a default save location for backups and updates to a custom one
- * if there is one selected.
- */
- add_task(async function test_locationInputs() {
- let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
- let inputDefault = turnOnScheduledBackups.filePathInputDefaultEl;
- ok(inputDefault, "Default input should be found");
-
- let promise = BrowserTestUtils.waitForCondition(() => inputDefault.value);
-
- /* Normally we would pass in the default attributes, but for this test, we will
- * hardcode them since file paths vary across different platforms.
- */
- const defaultPathFilename = "testdefaultpath";
- let defaultPath = PathUtils.join(PathUtils.tempDir, defaultPathFilename);
- turnOnScheduledBackups.defaultPath = defaultPath;
- turnOnScheduledBackups.defaultLabel = defaultPathFilename;
- await turnOnScheduledBackups.updateComplete;
- await promise;
-
- is(inputDefault.value, `${defaultPathFilename} (recommended)`, "Default input should not be empty and should contain part of the default path");
-
- // Now pretend a custom file path was selected
- const newPathFilename = "testnewpath";
- let newPath = PathUtils.join(PathUtils.tempDir, newPathFilename);
- turnOnScheduledBackups._newPath = newPath;
- turnOnScheduledBackups._newLabel = newPathFilename;
- await turnOnScheduledBackups.updateComplete;
-
- let inputCustom = turnOnScheduledBackups.filePathInputCustomEl;
- ok(inputCustom, "Input should be updated");
- is(inputCustom.value, newPathFilename, "Input value should be set to the new path");
- })
</script>
</head>
<body>