automatically autofill in search results (#19951)

This commit is contained in:
Jordan Aasen 2026-04-08 08:43:50 -07:00 committed by GitHub
parent 92b04c24fe
commit 51a306f5cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View File

@ -60,6 +60,7 @@ describe("ItemMoreOptionsComponent", () => {
const domainSettingsService = {
resolvedDefaultUriMatchStrategy$: uriMatchStrategy$.asObservable(),
getUrlEquivalentDomains: jest.fn().mockReturnValue(of(new Set<string>())),
};
const baseCipher = {
@ -137,6 +138,10 @@ describe("ItemMoreOptionsComponent", () => {
}
describe("doAutofill", () => {
beforeEach(() => {
jest.spyOn(component as any, "_domainMatched").mockResolvedValue(false);
});
it("calls the passwordService to passwordRepromptCheck", async () => {
autofillSvc.currentAutofillTab$.next({ url: "https://page.example.com" });
mockConfirmDialogResult(AutofillConfirmationDialogResult.AutofilledOnly);
@ -162,6 +167,22 @@ describe("ItemMoreOptionsComponent", () => {
beforeEach(() => {
uriMatchStrategy$.next(UriMatchStrategy.Domain);
passwordRepromptService.passwordRepromptCheck.mockResolvedValue(true);
jest.spyOn(component as any, "_domainMatched").mockResolvedValue(false);
});
it("autofills directly without showing confirmation dialog when domain matches", async () => {
autofillSvc.currentAutofillTab$.next({ url: "https://one.example.com" });
jest.spyOn(component as any, "_domainMatched").mockResolvedValue(true);
const openSpy = jest.spyOn(AutofillConfirmationDialogComponent, "open");
await component.doAutofill();
expect(openSpy).not.toHaveBeenCalled();
expect(autofillSvc.doAutofill).toHaveBeenCalledWith(
expect.objectContaining({ id: "cipher-1" }),
true,
true,
);
});
it("calls the passwordService to passwordRepromptCheck", async () => {

View File

@ -235,6 +235,11 @@ export class ItemMoreOptionsComponent {
return;
}
if (await this._domainMatched(currentTab.url)) {
await this.vaultPopupAutofillService.doAutofill(cipher, true, true);
return;
}
const ref = AutofillConfirmationDialogComponent.open(this.dialogService, {
data: {
currentUrl: currentTab?.url || "",
@ -257,6 +262,17 @@ export class ItemMoreOptionsComponent {
}
}
private async _domainMatched(url: string): Promise<boolean> {
const equivalentDomains = await firstValueFrom(
this.domainSettingsService.getUrlEquivalentDomains(url),
);
const defaultMatch = await firstValueFrom(
this.domainSettingsService.resolvedDefaultUriMatchStrategy$,
);
return CipherViewLikeUtils.matchesUri(this.cipher, url, equivalentDomains, defaultMatch);
}
async onView() {
const repromptPassed = await this.passwordRepromptService.passwordRepromptCheck(this.cipher);
if (!repromptPassed) {