mirror of
https://github.com/bitwarden/browser.git
synced 2025-02-01 23:01:28 +01:00
[PM-8447] Autofill On Load Causes Extension to Hang After Browser Startup (#9400)
This commit is contained in:
parent
7fbd9901f0
commit
e14e2627ad
@ -1,6 +1,8 @@
|
|||||||
import { mock, mockReset, MockProxy } from "jest-mock-extended";
|
import { mock, mockReset, MockProxy } from "jest-mock-extended";
|
||||||
import { BehaviorSubject, of } from "rxjs";
|
import { BehaviorSubject, of } from "rxjs";
|
||||||
|
|
||||||
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/services/user-verification/user-verification.service";
|
import { UserVerificationService } from "@bitwarden/common/auth/services/user-verification/user-verification.service";
|
||||||
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
|
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
|
||||||
import { AutofillSettingsService } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
import { AutofillSettingsService } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||||
@ -78,12 +80,17 @@ describe("AutofillService", () => {
|
|||||||
const userVerificationService = mock<UserVerificationService>();
|
const userVerificationService = mock<UserVerificationService>();
|
||||||
const billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
const billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
||||||
const platformUtilsService = mock<PlatformUtilsService>();
|
const platformUtilsService = mock<PlatformUtilsService>();
|
||||||
|
let activeAccountStatusMock$: BehaviorSubject<AuthenticationStatus>;
|
||||||
|
let authService: MockProxy<AuthService>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
scriptInjectorService = new BrowserScriptInjectorService(platformUtilsService, logService);
|
scriptInjectorService = new BrowserScriptInjectorService(platformUtilsService, logService);
|
||||||
inlineMenuVisibilityMock$ = new BehaviorSubject(AutofillOverlayVisibility.OnFieldFocus);
|
inlineMenuVisibilityMock$ = new BehaviorSubject(AutofillOverlayVisibility.OnFieldFocus);
|
||||||
autofillSettingsService = mock<AutofillSettingsService>();
|
autofillSettingsService = mock<AutofillSettingsService>();
|
||||||
(autofillSettingsService as any).inlineMenuVisibility$ = inlineMenuVisibilityMock$;
|
(autofillSettingsService as any).inlineMenuVisibility$ = inlineMenuVisibilityMock$;
|
||||||
|
activeAccountStatusMock$ = new BehaviorSubject(AuthenticationStatus.Unlocked);
|
||||||
|
authService = mock<AuthService>();
|
||||||
|
authService.activeAccountStatus$ = activeAccountStatusMock$;
|
||||||
autofillService = new AutofillService(
|
autofillService = new AutofillService(
|
||||||
cipherService,
|
cipherService,
|
||||||
autofillSettingsService,
|
autofillSettingsService,
|
||||||
@ -95,6 +102,7 @@ describe("AutofillService", () => {
|
|||||||
billingAccountProfileStateService,
|
billingAccountProfileStateService,
|
||||||
scriptInjectorService,
|
scriptInjectorService,
|
||||||
accountService,
|
accountService,
|
||||||
|
authService,
|
||||||
);
|
);
|
||||||
|
|
||||||
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider);
|
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider);
|
||||||
@ -287,6 +295,18 @@ describe("AutofillService", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("skips injecting the autofiller script when the user's account is not unlocked", async () => {
|
||||||
|
activeAccountStatusMock$.next(AuthenticationStatus.Locked);
|
||||||
|
|
||||||
|
await autofillService.injectAutofillScripts(sender.tab, sender.frameId, true);
|
||||||
|
|
||||||
|
expect(BrowserApi.executeScriptInTab).not.toHaveBeenCalledWith(tabMock.id, {
|
||||||
|
file: "content/autofiller.js",
|
||||||
|
frameId: sender.frameId,
|
||||||
|
...defaultExecuteScriptOptions,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("will inject the bootstrap-autofill-overlay script if the user has the autofill overlay enabled", async () => {
|
it("will inject the bootstrap-autofill-overlay script if the user has the autofill overlay enabled", async () => {
|
||||||
await autofillService.injectAutofillScripts(sender.tab, sender.frameId);
|
await autofillService.injectAutofillScripts(sender.tab, sender.frameId);
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ import { pairwise } from "rxjs/operators";
|
|||||||
|
|
||||||
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
|
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||||
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
|
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
|
||||||
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||||
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
|
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
|
||||||
@ -61,6 +63,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||||
private scriptInjectorService: ScriptInjectorService,
|
private scriptInjectorService: ScriptInjectorService,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
|
private authService: AuthService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,6 +116,8 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
// Autofill user settings loaded from state can await the active account state indefinitely
|
// Autofill user settings loaded from state can await the active account state indefinitely
|
||||||
// if not guarded by an active account check (e.g. the user is logged in)
|
// if not guarded by an active account check (e.g. the user is logged in)
|
||||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
const authStatus = await firstValueFrom(this.authService.activeAccountStatus$);
|
||||||
|
const accountIsUnlocked = authStatus === AuthenticationStatus.Unlocked;
|
||||||
let overlayVisibility: InlineMenuVisibilitySetting = AutofillOverlayVisibility.Off;
|
let overlayVisibility: InlineMenuVisibilitySetting = AutofillOverlayVisibility.Off;
|
||||||
let autoFillOnPageLoadIsEnabled = false;
|
let autoFillOnPageLoadIsEnabled = false;
|
||||||
|
|
||||||
@ -126,7 +131,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
|
|
||||||
const injectedScripts = [mainAutofillScript];
|
const injectedScripts = [mainAutofillScript];
|
||||||
|
|
||||||
if (activeAccount) {
|
if (activeAccount && accountIsUnlocked) {
|
||||||
autoFillOnPageLoadIsEnabled = await this.getAutofillOnPageLoad();
|
autoFillOnPageLoadIsEnabled = await this.getAutofillOnPageLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -872,6 +872,7 @@ export default class MainBackground {
|
|||||||
this.billingAccountProfileStateService,
|
this.billingAccountProfileStateService,
|
||||||
this.scriptInjectorService,
|
this.scriptInjectorService,
|
||||||
this.accountService,
|
this.accountService,
|
||||||
|
this.authService,
|
||||||
);
|
);
|
||||||
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);
|
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);
|
||||||
|
|
||||||
|
@ -341,6 +341,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
BillingAccountProfileStateService,
|
BillingAccountProfileStateService,
|
||||||
ScriptInjectorService,
|
ScriptInjectorService,
|
||||||
AccountServiceAbstraction,
|
AccountServiceAbstraction,
|
||||||
|
AuthService,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
Loading…
Reference in New Issue
Block a user