Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<head>
<title>Test for inputting new text while there is unmasked range</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<input type="password" value="012345">
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
let input = document.getElementsByTagName("input")[0];
let editor = SpecialPowers.wrap(input).editor;
async function doTest(aDelay) {
await SpecialPowers.pushPrefEnv({
set: [["editor.password.mask_delay", aDelay]],
});
input.focus();
input.value = "012345";
// Setting value
editor.unmask(3, 4);
input.value = "abcdef";
is(editor.unmaskedStart, 0,
"delay=" + aDelay + ": Setting value should mask all characters (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Setting value should mask all characters (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after setting value");
editor.unmask(3, 4);
input.value = "abcdef";
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Setting same value shouldn't change unmasked range (start)");
is(editor.unmaskedEnd, 4,
"delay=" + aDelay + ": Setting same value shouldn't change unmasked range (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after setting same value");
input.value = "";
is(editor.unmaskedStart, 0,
"delay=" + aDelay + ": Setting empty value should collapse unmasked range (start)");
is(editor.unmaskedEnd, 0,
"delay=" + aDelay + ": Setting empty value should collapse unmasked range (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after setting empty value");
input.value = "abcdef";
is(editor.unmaskedStart, 0,
"delay=" + aDelay + ": Setting empty field to new value should unmask all (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Setting empty field to new value should unmask all (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after setting empty field to new value");
// Simply typing a character
editor.unmask(3, 4);
input.setSelectionRange(3, 3);
synthesizeKey("1");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Inserting character at start of unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Inserting character at start of unmasked range should expand the range (end)");
is(input.value, "abc1def",
"delay=" + aDelay + ": Inserting character at start of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after inserting character at start of unmasked range");
editor.unmask(3, 5);
synthesizeKey("2");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Inserting character in the unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Inserting character in the unmasked range should expand the range (end)");
is(input.value, "abc12def",
"delay=" + aDelay + ": Inserting character in the unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after inserting character in the unmasked range");
editor.unmask(3, 6);
input.setSelectionRange(6, 6);
synthesizeKey("3");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Inserting character at end of unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 7,
"delay=" + aDelay + ": Inserting character at end of unmasked range should expand the range (end)");
is(input.value, "abc12d3ef",
"delay=" + aDelay + ": Inserting character at end of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after inserting character at end of unmasked range");
editor.unmask(3, 4);
input.setSelectionRange(2, 2);
synthesizeKey("4");
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Inserting character before the unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Inserting character before the unmasked range should expand the range (end)");
is(input.value, "ab4c12d3ef",
"delay=" + aDelay + ": Inserting character before the unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after inserting character before the unmasked range");
editor.unmask(2, 5);
input.setSelectionRange(6, 6);
synthesizeKey("5");
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Inserting character after the unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 7,
"delay=" + aDelay + ": Inserting character after the unmasked range should expand the range (end)");
is(input.value, "ab4c125d3ef",
"delay=" + aDelay + ": Inserting character after the unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after inserting character after the unmasked range");
// Simply removing characters
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(3, 3);
editor.deleteSelection(editor.eNext, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing first character of unmasked range should shrink the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing first character of unmasked range should shrink the range (end)");
is(input.value, "abcefgh",
"delay=" + aDelay + ": Removing first character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing first character of unmasked range");
editor.unmask(3, 5);
editor.deleteSelection(editor.ePrevious, editor.eStrip);
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Removing previous character of unmasked range should move the range (start)");
is(editor.unmaskedEnd, 4,
"delay=" + aDelay + ": Removing previous character of unmasked range should move the range (end)");
is(input.value, "abefgh",
"delay=" + aDelay + ": Removing previous character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing previous character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(6, 6);
editor.deleteSelection(editor.ePrevious, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing last character of unmasked range should shrink the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing last character of unmasked range should shrink the range (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing last character of unmasked range should shrink the range");
editor.unmask(3, 5);
editor.deleteSelection(editor.eNext, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing next character of unmasked range shouldn't change the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing next character of unmasked range shouldn't change the range (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing next character of unmasked range shouldn't change the range");
input.value = "abcdef";
editor.unmask(3, 6);
input.setSelectionRange(4, 4);
editor.deleteSelection(editor.eNext, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing middle character of unmasked range should shrink the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing middle character of unmasked range should shrink the range (end)");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing middle character of unmasked range should shrink the range");
// Removing selection
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(3, 4);
editor.deleteSelection(editor.eNone, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing selected first character of unmasked range should shrink the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing selected first character of unmasked range should shrink the range (end)");
is(input.value, "abcefgh",
"delay=" + aDelay + ": Removing selected first character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing selected first character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(2, 3);
editor.deleteSelection(editor.eNone, editor.eStrip);
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Removing selected previous character of unmasked range should move the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing selected previous character of unmasked range should move the range (end)");
is(input.value, "abdefgh",
"delay=" + aDelay + ": Removing selected previous character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing selected previous character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(5, 6);
editor.deleteSelection(editor.eNone, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing selected last character of unmasked range should shrink the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing selected last character of unmasked range should shrink the range (end)");
is(input.value, "abcdegh",
"delay=" + aDelay + ": Removing selected last character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing selected last character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(6, 7);
editor.deleteSelection(editor.eNone, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing selected next character of unmasked range should keep the range (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Removing selected next character of unmasked range should keep the range (end)");
is(input.value, "abcdefh",
"delay=" + aDelay + ": Removing selected next character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing selected next character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(4, 5);
editor.deleteSelection(editor.eNone, editor.eStrip);
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Removing selected middle character of unmasked range should shrink the range (start)");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Removing selected middle character of unmasked range should shrink the range (end)");
is(input.value, "abcdfgh",
"delay=" + aDelay + ": Removing selected middle character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing selected middle character of unmasked range");
// Replacing a character
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(3, 4);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing first character of unmasked range should keep the range (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Replacing first character of unmasked range should keep the range (end)");
is(input.value, "abc0efgh",
"delay=" + aDelay + ": Replacing first character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing first character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(2, 3);
synthesizeKey("0");
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Replacing previous character of unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Replacing previous character of unmasked range should expand the range (end)");
is(input.value, "ab0defgh",
"delay=" + aDelay + ": Replacing previous character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing previous character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(5, 6);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing last character of unmasked range should keep the range (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Replacing last character of unmasked range should keep the range (end)");
is(input.value, "abcde0gh",
"delay=" + aDelay + ": Replacing last character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing last character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(6, 7);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing next character of unmasked range should expand the range (start)");
is(editor.unmaskedEnd, 7,
"delay=" + aDelay + ": Replacing next character of unmasked range should expand the range (end)");
is(input.value, "abcdef0h",
"delay=" + aDelay + ": Replacing next character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing next character of unmasked range");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(4, 5);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing middle character of unmasked range should keep the range (start)");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Replacing middle character of unmasked range should keep the range (end)");
is(input.value, "abcd0fgh",
"delay=" + aDelay + ": Replacing middle character of unmasked range");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing middle character of unmasked range");
// Replace part of the range
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(1, 4);
synthesizeKey("0");
is(editor.unmaskedStart, 1,
"delay=" + aDelay + ": Replacing start edge of unmasked range should move and shrink the range (start) #1");
is(editor.unmaskedEnd, 4,
"delay=" + aDelay + ": Replacing start edge of unmasked range should move and shrink the range (end) #1");
is(input.value, "a0efgh",
"delay=" + aDelay + ": Replacing start edge of unmasked range #1");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing start edge of unmasked range #1");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(2, 5);
synthesizeKey("0");
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Replacing start edge of unmasked range should move and shrink the range (start) #2");
is(editor.unmaskedEnd, 4,
"delay=" + aDelay + ": Replacing start edge of unmasked range should move and shrink the range (end) #2");
is(input.value, "ab0fgh",
"delay=" + aDelay + ": Replacing start edge of unmasked range #2");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing start edge of unmasked range #2");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(4, 7);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing end edge of unmasked range should shrink the range (start) #1");
is(editor.unmaskedEnd, 5,
"delay=" + aDelay + ": Replacing end edge of unmasked range should shrink the range (end) #1");
is(input.value, "abcd0h",
"delay=" + aDelay + ": Replacing end edge of unmasked range #1");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing end edge of unmasked range #1");
input.value = "abcdefghi";
editor.unmask(3, 6);
input.setSelectionRange(5, 8);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing end edge of unmasked range should shrink the range (start) #2");
is(editor.unmaskedEnd, 6,
"delay=" + aDelay + ": Replacing end edge of unmasked range should shrink the range (end) #2");
is(input.value, "abcde0i",
"delay=" + aDelay + ": Replacing end edge of unmasked range #2");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing end edge of unmasked range #2");
// Replaceing all of the range
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(3, 6);
synthesizeKey("0");
is(editor.unmaskedStart, 3,
"delay=" + aDelay + ": Replacing all of unmasked range should shrink the range (start) #1");
is(editor.unmaskedEnd, 4,
"delay=" + aDelay + ": Replacing all of unmasked range should shrink the range (end) #1");
is(input.value, "abc0gh",
"delay=" + aDelay + ": Replacing all of unmasked range #1");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing all of unmasked range #1");
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(2, 7);
synthesizeKey("0");
is(editor.unmaskedStart, 2,
"delay=" + aDelay + ": Replacing all of unmasked range should shrink the range (start) #2");
is(editor.unmaskedEnd, 3,
"delay=" + aDelay + ": Replacing all of unmasked range should shrink the range (end) #2");
is(input.value, "ab0h",
"delay=" + aDelay + ": Replacing all of unmasked range #2");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after replacing all of unmasked range #2");
// Removing all characters and type new character
input.value = "abcdefgh";
editor.unmask(3, 6);
input.setSelectionRange(0, 8);
editor.deleteSelection(editor.eNone, editor.eStrip);
is(editor.unmaskedStart, 0,
"delay=" + aDelay + ": Removing all characters should shrink the range (start)");
is(editor.unmaskedEnd, 0,
"delay=" + aDelay + ": Removing all characters should shrink the range (end)");
is(input.value, "",
"delay=" + aDelay + ": Removing all characters");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after removing all characters");
synthesizeKey("0");
is(editor.unmaskedStart, 0,
"delay=" + aDelay + ": Typing first character should expand unmasked range (start)");
is(editor.unmaskedEnd, 1,
"delay=" + aDelay + ": Typing first character should expand unmasked range (end)");
is(input.value, "0",
"delay=" + aDelay + ": Typing first character");
ok(!editor.autoMaskingEnabled,
"delay=" + aDelay + ": auto masking shouldn't be enabled after typing first character");
}
await doTest(0);
await doTest(600);
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>