Bug 1650444 - Explicitly disallow finding in <input type=password>. r=jfkthame

Maybe if / when we have a native way to allow showing the password we
can lift this if the password is visible or what not. Until then this is
just confusing.

Differential Revision: https://phabricator.services.mozilla.com/D82296
This commit is contained in:
Emilio Cobos Álvarez 2020-07-06 15:05:47 +00:00
Родитель 77e8fe49d3
Коммит 69bd04067f
2 изменённых файлов: 24 добавлений и 22 удалений

Просмотреть файл

@ -143,29 +143,27 @@ static bool IsVisibleNode(const nsINode* aNode) {
return frame->StyleVisibility()->IsVisible();
}
static bool IsTextFormControl(nsIContent& aContent) {
if (!aContent.IsNodeOfType(nsINode::eHTML_FORM_CONTROL)) {
return false;
}
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(&aContent);
return formControl->IsTextControl(true);
}
static bool ShouldFindAnonymousContent(const nsIContent& aContent) {
MOZ_ASSERT(aContent.IsInNativeAnonymousSubtree());
nsIContent& parent = AnonymousSubtreeRootParent(aContent);
if (IsTextFormControl(parent)) {
// Only editable NAC in textfields should be findable. That is, we want to
// find "bar" in `<input value="bar">`, but not in `<input
// placeholder="bar">`.
//
// TODO(emilio): Ideally we could lift this restriction, but we hide the
// placeholder text at paint-time instead of with CSS visibility, which
// means that we won't skip it even if invisible. We should probably fix
// that.
return aContent.IsEditable();
if (nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(&parent)) {
if (formControl->IsTextControl(/* aExcludePassword = */ true)) {
// Only editable NAC in textfields should be findable. That is, we want to
// find "bar" in `<input value="bar">`, but not in `<input
// placeholder="bar">`.
//
// TODO(emilio): Ideally we could lift this restriction, but we hide the
// placeholder text at paint-time instead of with CSS visibility, which
// means that we won't skip it even if invisible. We should probably fix
// that.
return aContent.IsEditable();
}
// We want to avoid finding in password inputs anyway, as it is confusing.
if (formControl->ControlType() == NS_FORM_INPUT_PASSWORD) {
return false;
}
}
return true;

Просмотреть файл

@ -78,6 +78,7 @@ add_task(async function test_find_anon_content() {
<div> </div>
<img alt="Some fallback text">
<input type="submit" value="Some button text">
<input type="password" value="password">
`;
await BrowserTestUtils.withNewTab(
{
@ -99,14 +100,16 @@ add_task(async function test_find_anon_content() {
});
}
async function assertFindable(text) {
async function assertFindable(text, findable = true) {
let promiseFind = waitForFind();
finder.fastFind(text, false, false);
let findResult = await promiseFind;
is(
findResult.result,
Ci.nsITypeAheadFind.FIND_FOUND,
`${text} should be findable`
findable
? Ci.nsITypeAheadFind.FIND_FOUND
: Ci.nsITypeAheadFind.FIND_NOTFOUND,
`${text} should ${findable ? "" : "not "}be findable`
);
}
@ -114,6 +117,7 @@ add_task(async function test_find_anon_content() {
await assertFindable("after content");
await assertFindable("fallback text");
await assertFindable("button text");
await assertFindable("password", false);
finder.removeResultListener(listener);
}