mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
[PM-5189] Fixing jest tests within AutofillService
This commit is contained in:
@@ -43,7 +43,7 @@ import {
|
||||
createChromeTabMock,
|
||||
createGenerateFillScriptOptionsMock,
|
||||
} from "../spec/autofill-mocks";
|
||||
import { triggerTestFailure } from "../spec/testing-utils";
|
||||
import { flushPromises, triggerTestFailure } from "../spec/testing-utils";
|
||||
|
||||
import {
|
||||
AutoFillOptions,
|
||||
@@ -104,6 +104,9 @@ describe("AutofillService", () => {
|
||||
tab2 = createChromeTabMock({ id: 2, url: "http://some-url.com" });
|
||||
tab3 = createChromeTabMock({ id: 3, url: "chrome-extension://some-extension-route" });
|
||||
jest.spyOn(BrowserApi, "tabsQuery").mockResolvedValueOnce([tab1, tab2]);
|
||||
jest
|
||||
.spyOn(BrowserApi, "getAllFrames")
|
||||
.mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]);
|
||||
jest
|
||||
.spyOn(autofillService, "getOverlayVisibility")
|
||||
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
|
||||
@@ -114,6 +117,7 @@ describe("AutofillService", () => {
|
||||
jest.spyOn(autofillService, "injectAutofillScripts");
|
||||
|
||||
await autofillService.loadAutofillScriptsOnInstall();
|
||||
await flushPromises();
|
||||
|
||||
expect(BrowserApi.tabsQuery).toHaveBeenCalledWith({});
|
||||
expect(autofillService.injectAutofillScripts).toHaveBeenCalledWith(tab1, 0, false);
|
||||
|
||||
@@ -65,10 +65,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
*/
|
||||
async loadAutofillScriptsOnInstall() {
|
||||
BrowserApi.addListener(chrome.runtime.onConnect, this.handleInjectedScriptPortConnection);
|
||||
|
||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.injectAutofillScriptsInAllTabs();
|
||||
void this.injectAutofillScriptsInAllTabs();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2064,9 +2061,8 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
for (let index = 0; index < tabs.length; index++) {
|
||||
const tab = tabs[index];
|
||||
if (tab.url?.startsWith("http")) {
|
||||
chrome.webNavigation.getAllFrames({ tabId: tab.id }, (frames) =>
|
||||
frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false)),
|
||||
);
|
||||
const frames = await BrowserApi.getAllFrames({ tabId: tab.id });
|
||||
frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,12 @@ export class BrowserApi {
|
||||
return new Promise((resolve) => chrome.webNavigation.getFrame(details, resolve));
|
||||
}
|
||||
|
||||
static async getAllFrames(
|
||||
details: chrome.webNavigation.GetAllFrameDetails,
|
||||
): Promise<chrome.webNavigation.GetAllFrameResultDetails[]> {
|
||||
return new Promise((resolve) => chrome.webNavigation.getAllFrames(details, resolve));
|
||||
}
|
||||
|
||||
// Keep track of all the events registered in a Safari popup so we can remove
|
||||
// them when the popup gets unloaded, otherwise we cause a memory leak
|
||||
private static trackedChromeEventListeners: [
|
||||
|
||||
Reference in New Issue
Block a user