1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-06 19:53:59 +00:00

Isolate with cleanup and return empty nodelists.

This commit is contained in:
Miles Blackwood
2025-12-18 12:44:33 -05:00
parent cec52c19e2
commit b9663d4c97
2 changed files with 15 additions and 2 deletions

View File

@@ -2297,6 +2297,9 @@ describe("CollectAutofillContentService", () => {
it("schedules a debounced check for new shadow roots", () => {
jest.useFakeTimers();
const div = document.createElement("div");
document.body.appendChild(div);
const mutationRecord: MutationRecord = {
type: "childList",
addedNodes: document.querySelectorAll("div"),
@@ -2305,7 +2308,7 @@ describe("CollectAutofillContentService", () => {
nextSibling: null,
oldValue: null,
previousSibling: null,
removedNodes: null,
removedNodes: document.querySelectorAll("nonexistent"),
target: document.body,
};
collectAutofillContentService["currentLocationHref"] = window.location.href;
@@ -2330,6 +2333,9 @@ describe("CollectAutofillContentService", () => {
it("does not schedule duplicate shadow root checks when already pending", () => {
jest.useFakeTimers();
const div = document.createElement("div");
document.body.appendChild(div);
const mutationRecord: MutationRecord = {
type: "childList",
addedNodes: document.querySelectorAll("div"),
@@ -2338,7 +2344,7 @@ describe("CollectAutofillContentService", () => {
nextSibling: null,
oldValue: null,
previousSibling: null,
removedNodes: null,
removedNodes: document.querySelectorAll("nonexistent"),
target: document.body,
};
collectAutofillContentService["currentLocationHref"] = window.location.href;

View File

@@ -233,6 +233,13 @@ describe("DomQueryService", () => {
});
describe("checkForNewShadowRoots", () => {
beforeEach(() => {
// Clear any shadow roots from previous tests
document.body.innerHTML = "";
// Reset the observed shadow roots set
domQueryService["observedShadowRoots"] = new WeakSet<ShadowRoot>();
});
it("returns true when a shadow root is not in the observed set", () => {
const customElement = document.createElement("custom-element");
customElement.attachShadow({ mode: "open" });