diff --git a/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.spec.ts b/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.spec.ts index 84421a9fe1c..878ceece2f4 100644 --- a/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.spec.ts +++ b/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.spec.ts @@ -60,6 +60,7 @@ describe("ItemMoreOptionsComponent", () => { const domainSettingsService = { resolvedDefaultUriMatchStrategy$: uriMatchStrategy$.asObservable(), + getUrlEquivalentDomains: jest.fn().mockReturnValue(of(new Set())), }; 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 () => { diff --git a/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.ts b/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.ts index 89ad5cf964c..1cd7a9071fc 100644 --- a/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.ts +++ b/apps/browser/src/vault/popup/components/vault/item-more-options/item-more-options.component.ts @@ -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 { + 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) {