mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
[PM-5189] Fixing jest tests within AutofillService
This commit is contained in:
@@ -43,7 +43,7 @@ import {
|
|||||||
createChromeTabMock,
|
createChromeTabMock,
|
||||||
createGenerateFillScriptOptionsMock,
|
createGenerateFillScriptOptionsMock,
|
||||||
} from "../spec/autofill-mocks";
|
} from "../spec/autofill-mocks";
|
||||||
import { triggerTestFailure } from "../spec/testing-utils";
|
import { flushPromises, triggerTestFailure } from "../spec/testing-utils";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AutoFillOptions,
|
AutoFillOptions,
|
||||||
@@ -104,6 +104,9 @@ describe("AutofillService", () => {
|
|||||||
tab2 = createChromeTabMock({ id: 2, url: "http://some-url.com" });
|
tab2 = createChromeTabMock({ id: 2, url: "http://some-url.com" });
|
||||||
tab3 = createChromeTabMock({ id: 3, url: "chrome-extension://some-extension-route" });
|
tab3 = createChromeTabMock({ id: 3, url: "chrome-extension://some-extension-route" });
|
||||||
jest.spyOn(BrowserApi, "tabsQuery").mockResolvedValueOnce([tab1, tab2]);
|
jest.spyOn(BrowserApi, "tabsQuery").mockResolvedValueOnce([tab1, tab2]);
|
||||||
|
jest
|
||||||
|
.spyOn(BrowserApi, "getAllFrames")
|
||||||
|
.mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]);
|
||||||
jest
|
jest
|
||||||
.spyOn(autofillService, "getOverlayVisibility")
|
.spyOn(autofillService, "getOverlayVisibility")
|
||||||
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
|
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
|
||||||
@@ -114,6 +117,7 @@ describe("AutofillService", () => {
|
|||||||
jest.spyOn(autofillService, "injectAutofillScripts");
|
jest.spyOn(autofillService, "injectAutofillScripts");
|
||||||
|
|
||||||
await autofillService.loadAutofillScriptsOnInstall();
|
await autofillService.loadAutofillScriptsOnInstall();
|
||||||
|
await flushPromises();
|
||||||
|
|
||||||
expect(BrowserApi.tabsQuery).toHaveBeenCalledWith({});
|
expect(BrowserApi.tabsQuery).toHaveBeenCalledWith({});
|
||||||
expect(autofillService.injectAutofillScripts).toHaveBeenCalledWith(tab1, 0, false);
|
expect(autofillService.injectAutofillScripts).toHaveBeenCalledWith(tab1, 0, false);
|
||||||
|
|||||||
@@ -65,10 +65,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
*/
|
*/
|
||||||
async loadAutofillScriptsOnInstall() {
|
async loadAutofillScriptsOnInstall() {
|
||||||
BrowserApi.addListener(chrome.runtime.onConnect, this.handleInjectedScriptPortConnection);
|
BrowserApi.addListener(chrome.runtime.onConnect, this.handleInjectedScriptPortConnection);
|
||||||
|
void this.injectAutofillScriptsInAllTabs();
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2064,9 +2061,8 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
for (let index = 0; index < tabs.length; index++) {
|
for (let index = 0; index < tabs.length; index++) {
|
||||||
const tab = tabs[index];
|
const tab = tabs[index];
|
||||||
if (tab.url?.startsWith("http")) {
|
if (tab.url?.startsWith("http")) {
|
||||||
chrome.webNavigation.getAllFrames({ tabId: tab.id }, (frames) =>
|
const frames = await BrowserApi.getAllFrames({ tabId: tab.id });
|
||||||
frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false)),
|
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));
|
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
|
// 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
|
// them when the popup gets unloaded, otherwise we cause a memory leak
|
||||||
private static trackedChromeEventListeners: [
|
private static trackedChromeEventListeners: [
|
||||||
|
|||||||
Reference in New Issue
Block a user