mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-10 19:38:11 +01:00
[PM-5189] Merging work done for PM-8518 into branch to remove Platform team review requirement
This commit is contained in:
commit
89dbdd73ee
@ -125,7 +125,7 @@ describe("AutofillService", () => {
|
||||
tab3 = createChromeTabMock({ id: 3, url: "chrome-extension://some-extension-route" });
|
||||
jest.spyOn(BrowserApi, "tabsQuery").mockResolvedValueOnce([tab1, tab2]);
|
||||
jest
|
||||
.spyOn(BrowserApi, "getAllFrames")
|
||||
.spyOn(BrowserApi, "getAllFrameDetails")
|
||||
.mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]);
|
||||
jest
|
||||
.spyOn(autofillService, "getInlineMenuVisibility")
|
||||
|
@ -2094,7 +2094,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
for (let index = 0; index < tabs.length; index++) {
|
||||
const tab = tabs[index];
|
||||
if (tab.url?.startsWith("http")) {
|
||||
const frames = await BrowserApi.getAllFrames({ tabId: tab.id });
|
||||
const frames = await BrowserApi.getAllFrameDetails(tab.id);
|
||||
frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false));
|
||||
}
|
||||
}
|
||||
|
@ -235,6 +235,46 @@ describe("BrowserApi", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getFrameDetails", () => {
|
||||
it("returns the frame details of the specified frame", async () => {
|
||||
const tabId = 1;
|
||||
const frameId = 2;
|
||||
const mockFrameDetails = mock<chrome.webNavigation.GetFrameResultDetails>();
|
||||
chrome.webNavigation.getFrame = jest
|
||||
.fn()
|
||||
.mockImplementation((_details, callback) => callback(mockFrameDetails));
|
||||
|
||||
const returnFrame = await BrowserApi.getFrameDetails({ tabId, frameId });
|
||||
|
||||
expect(chrome.webNavigation.getFrame).toHaveBeenCalledWith(
|
||||
{ tabId, frameId },
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(returnFrame).toEqual(mockFrameDetails);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAllFrameDetails", () => {
|
||||
it("returns all sub frame details of the specified tab", async () => {
|
||||
const tabId = 1;
|
||||
const mockFrameDetails1 = mock<chrome.webNavigation.GetAllFrameResultDetails>();
|
||||
const mockFrameDetails2 = mock<chrome.webNavigation.GetAllFrameResultDetails>();
|
||||
chrome.webNavigation.getAllFrames = jest
|
||||
.fn()
|
||||
.mockImplementation((_details, callback) =>
|
||||
callback([mockFrameDetails1, mockFrameDetails2]),
|
||||
);
|
||||
|
||||
const frames = await BrowserApi.getAllFrameDetails(tabId);
|
||||
|
||||
expect(chrome.webNavigation.getAllFrames).toHaveBeenCalledWith(
|
||||
{ tabId },
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(frames).toEqual([mockFrameDetails1, mockFrameDetails2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reloadExtension", () => {
|
||||
it("reloads the window location if the passed globalContext is for the window", () => {
|
||||
const windowMock = mock<Window>({
|
||||
|
@ -263,16 +263,26 @@ export class BrowserApi {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers the details for a specified sub-frame of a tab.
|
||||
*
|
||||
* @param details - The details of the frame to get.
|
||||
*/
|
||||
static async getFrameDetails(
|
||||
details: chrome.webNavigation.GetFrameDetails,
|
||||
): Promise<chrome.webNavigation.GetFrameResultDetails> {
|
||||
return new Promise((resolve) => chrome.webNavigation.getFrame(details, resolve));
|
||||
}
|
||||
|
||||
static async getAllFrames(
|
||||
details: chrome.webNavigation.GetAllFrameDetails,
|
||||
/**
|
||||
* Gets all frames associated with a tab.
|
||||
*
|
||||
* @param tabId - The id of the tab to get the frames for.
|
||||
*/
|
||||
static async getAllFrameDetails(
|
||||
tabId: chrome.tabs.Tab["id"],
|
||||
): Promise<chrome.webNavigation.GetAllFrameResultDetails[]> {
|
||||
return new Promise((resolve) => chrome.webNavigation.getAllFrames(details, resolve));
|
||||
return new Promise((resolve) => chrome.webNavigation.getAllFrames({ tabId }, resolve));
|
||||
}
|
||||
|
||||
// Keep track of all the events registered in a Safari popup so we can remove
|
||||
|
Loading…
Reference in New Issue
Block a user