1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests for the turn-on-scheduled-backups component</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="head.js"></script>
<script
src="chrome://browser/content/backup/turn-on-scheduled-backups.mjs"
type="module"
></script>
<link rel="localization" href="preview/backupSettings.ftl"/>
<link rel="localization" href="branding/brand.ftl"/>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script>
const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);
/**
* Tests that adding a turn-on-scheduled-backups element to the DOM causes it to
* fire a BackupUI:InitWidget event.
*/
add_task(async function test_initWidget() {
let turnOnScheduledBackups = document.createElement("turn-on-scheduled-backups");
let content = document.getElementById("content");
let sawInitWidget = BrowserTestUtils.waitForEvent(content, "BackupUI:InitWidget");
content.appendChild(turnOnScheduledBackups);
await sawInitWidget;
ok(true, "Saw BackupUI:InitWidget");
turnOnScheduledBackups.remove();
});
/**
* 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;
ok(confirmButton, "Confirm button should be found");
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() {
let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
let cancelButton = turnOnScheduledBackups.cancelButtonEl;
ok(cancelButton, "Cancel button should be found");
let content = document.getElementById("content");
let promise = BrowserTestUtils.waitForEvent(content, "dialogCancel");
cancelButton.click()
await promise;
ok(true, "Detected event after selecting the cancel button");
})
/**
* Tests that selecting the checkbox for enabling backup encryption will show more
* options to configure the password needed for encryption.
*/
add_task(async function test_expandedPasswords() {
let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
let passwordsCheckbox = turnOnScheduledBackups.passwordOptionsCheckboxEl;
ok(passwordsCheckbox, "Passwords checkbox should be found");
ok(!turnOnScheduledBackups.passwordOptionsExpandedEl, "Passwords expanded options should not be found");
passwordsCheckbox.click();
await turnOnScheduledBackups.updateComplete;
ok(turnOnScheduledBackups.passwordOptionsExpandedEl, "Passwords expanded options should be found");
// Click again to verify collapse and reset checkbox state for suceeding tests
passwordsCheckbox.click();
await turnOnScheduledBackups.updateComplete;
ok(!turnOnScheduledBackups.passwordOptionsExpandedEl, "Passwords expanded options should be hidden again");
})
/**
* Tests that the Confirm button cannot be selected if password settings are shown and
* inputted passwords are invalid. Once passwords are valid, verifies that the Confirm
* button can be selected.
*/
add_task(async function test_passwordValidityConfirmButton() {
let turnOnScheduledBackups = document.getElementById("test-turn-on-scheduled-backups");
let passwordsCheckbox = turnOnScheduledBackups.passwordOptionsCheckboxEl;
// First check that the confirm button is not disabled with password options collapsed
ok(passwordsCheckbox, "Passwords checkbox should be found");
ok(!turnOnScheduledBackups.passwordOptionsExpandedEl, "Passwords expanded options should not be found");
let confirmButton = turnOnScheduledBackups.confirmButtonEl;
ok(confirmButton, "Confirm button should be found");
ok(!confirmButton.disabled, "Confirm button should not be disabled since there are no passwords expanded options");
passwordsCheckbox.click();
await turnOnScheduledBackups.updateComplete;
// Now check that the confirm button is disabled
ok(turnOnScheduledBackups.passwordOptionsExpandedEl, "Passwords expanded options should be found");
ok(confirmButton.disabled, "Confirm button should now be disabled since there are passwords expanded options");
// Pretend that the password inputs dispatch an event indicating that we have valid passwords
let passwordOptionsExpanded = turnOnScheduledBackups.passwordOptionsExpandedEl;
let validPromise = createMockValidityPassEventPromise(turnOnScheduledBackups, passwordOptionsExpanded, "ValidPasswordsDetected");
await validPromise;
ok(!confirmButton.disabled, "Confirm button should no longer be disabled");
// Now pretend that passwords are no longer valid
let invalidPromise = createMockValidityPassEventPromise(turnOnScheduledBackups, passwordOptionsExpanded, "InvalidPasswordsDetected");
await invalidPromise;
ok(confirmButton.disabled, "Confirm button should be disabled again");
})
/**
* 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>
<p id="display"></p>
<div id="content" style="display: none">
<turn-on-scheduled-backups id="test-turn-on-scheduled-backups"></turn-on-scheduled-backups>
</div>
<pre id="test"></pre>
</body>
</html>
|