Skip to content

Commit

Permalink
[PM-6416] Inline autofill menu does not show if the notification bar …
Browse files Browse the repository at this point in the history
…has been turned off (#8050)

* [PM-6416] Inline autofill menu does not show if notification bar turned off

* [PM-6416] Inline autofill menu does not show if the notification bar has been turned off
  • Loading branch information
cagonzalezcs authored Feb 23, 2024
1 parent 907645e commit ae1b6e8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/browser/src/autofill/content/autofill-init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import AutofillInit from "./autofill-init";
describe("AutofillInit", () => {
let autofillInit: AutofillInit;
const autofillOverlayContentService = mock<AutofillOverlayContentService>();
const originalDocumentReadyState = document.readyState;

beforeEach(() => {
chrome.runtime.connect = jest.fn().mockReturnValue({
Expand All @@ -27,6 +28,10 @@ describe("AutofillInit", () => {
afterEach(() => {
jest.resetModules();
jest.clearAllMocks();
Object.defineProperty(document, "readyState", {
value: originalDocumentReadyState,
writable: true,
});
});

describe("init", () => {
Expand All @@ -37,6 +42,31 @@ describe("AutofillInit", () => {

expect(autofillInit["setupExtensionMessageListeners"]).toHaveBeenCalled();
});

it("triggers a collection of page details if the document is in a `complete` ready state", () => {
jest.useFakeTimers();
Object.defineProperty(document, "readyState", { value: "complete", writable: true });

autofillInit.init();
jest.advanceTimersByTime(250);

expect(chrome.runtime.sendMessage).toHaveBeenCalledWith(
{
command: "bgCollectPageDetails",
sender: "autofillInit",
},
expect.any(Function),
);
});

it("registers a window load listener to collect the page details if the document is not in a `complete` ready state", () => {
jest.spyOn(window, "addEventListener");
Object.defineProperty(document, "readyState", { value: "loading", writable: true });

autofillInit.init();

expect(window.addEventListener).toHaveBeenCalledWith("load", expect.any(Function));
});
});

describe("setupExtensionMessageListeners", () => {
Expand Down
21 changes: 21 additions & 0 deletions apps/browser/src/autofill/content/autofill-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AutofillOverlayContentService } from "../services/abstractions/autofill
import CollectAutofillContentService from "../services/collect-autofill-content.service";
import DomElementVisibilityService from "../services/dom-element-visibility.service";
import InsertAutofillContentService from "../services/insert-autofill-content.service";
import { sendExtensionMessage } from "../utils";

import {
AutofillExtensionMessage,
Expand Down Expand Up @@ -56,6 +57,26 @@ class AutofillInit implements AutofillInitInterface {
init() {
this.setupExtensionMessageListeners();
this.autofillOverlayContentService?.init();
this.collectPageDetailsOnLoad();
}

/**
* Triggers a collection of the page details from the
* background script, ensuring that autofill is ready
* to act on the page.
*/
private collectPageDetailsOnLoad() {
const sendCollectDetailsMessage = () =>
setTimeout(
() => sendExtensionMessage("bgCollectPageDetails", { sender: "autofillInit" }),
250,
);

if (document.readyState === "complete") {
sendCollectDetailsMessage();
}

window.addEventListener("load", sendCollectDetailsMessage);
}

/**
Expand Down

0 comments on commit ae1b6e8

Please sign in to comment.