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
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests for the password-validation-inputs 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/password-validation-inputs.mjs"
type="module"
></script>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script>
const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);
/**
* Tests that valid and invalid passwords will dispatch the expected events.
*/
add_task(async function test_valid_password() {
let passwordInputs = document.getElementById("test-password-validation-inputs");
let newPasswordInput = passwordInputs.inputNewPasswordEl;
let repeatPasswordInput = passwordInputs.inputRepeatPasswordEl;
ok(newPasswordInput, "New password input should be found");
ok(repeatPasswordInput, "Repeat password input should be found");
// Pretend we're entering a password in the new password field
let newPassPromise = createMockPassInputEventPromise(newPasswordInput, MOCK_PASSWORD)
await newPassPromise;
let content = document.getElementById("content");
let validPromise = BrowserTestUtils.waitForEvent(content, "ValidPasswordsDetected");
// Pretend we're entering a password in the repeat field
// Passwords match
let promiseMatchPass = createMockPassInputEventPromise(repeatPasswordInput, MOCK_PASSWORD);
await promiseMatchPass;
await validPromise;
ok(true, "Detected event after matching passwords");
let invalidPromise = BrowserTestUtils.waitForEvent(content, "InvalidPasswordsDetected");
// Passwords do not match
const tempPassword = `${MOCK_PASSWORD}-notMatch`;
let promiseNotMatchPass = createMockPassInputEventPromise(repeatPasswordInput, tempPassword);
await promiseNotMatchPass;
await invalidPromise;
ok(true, "Detected event after unmatching passwords");
})
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<password-validation-inputs id="test-password-validation-inputs"></password-validation-inputs>
</div>
<pre id="test"></pre>
</body>
</html>
|