From e9e8d1c1c5132689273c63cd6b0be9517c49799f Mon Sep 17 00:00:00 2001 From: LTDigor Date: Mon, 20 Jul 2026 00:51:30 +0300 Subject: [PATCH] Fix blocked list scrolling and incognito image --- src/blocked/blocked.js | 5 ++--- src/popup/popup.css | 7 ++++++- tests/unit/blocked-page.test.js | 32 ++++++++++++++++++++++++++++++-- tests/unit/popup-css.test.js | 12 +++++++++++- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/blocked/blocked.js b/src/blocked/blocked.js index d54464f..ad260b2 100644 --- a/src/blocked/blocked.js +++ b/src/blocked/blocked.js @@ -1,6 +1,5 @@ import { - extensionStorage, - getExtensionUrl + extensionStorage } from "../shared/extension-api.js"; import { matchesUrl, @@ -8,7 +7,7 @@ import { } from "../background/rules.js"; const blockedImage = document.getElementById("blockedImage"); -const defaultImageUrl = getExtensionUrl("assets/images/image.jpg"); +const defaultImageUrl = blockedImage.src; const imageStorageKey = "blockedImageDataUrl"; const temporaryUnblocksStorageKey = "temporaryUnblocks"; diff --git a/src/popup/popup.css b/src/popup/popup.css index 98ccbf2..1d58a1b 100644 --- a/src/popup/popup.css +++ b/src/popup/popup.css @@ -282,8 +282,13 @@ h2 { min-height: 0; } +.rules-section:not(.is-collapsed) { + display: grid; + grid-template-rows: auto minmax(0, 1fr); +} + .rules-content { - max-height: 100%; + min-height: 0; overflow-y: auto; } diff --git a/tests/unit/blocked-page.test.js b/tests/unit/blocked-page.test.js index 7b7f9a7..250f1d5 100644 --- a/tests/unit/blocked-page.test.js +++ b/tests/unit/blocked-page.test.js @@ -28,6 +28,23 @@ test("blocked page shows the default image before storage resolves", async (t) = await importPromise; }); +test("blocked page preserves the default image URL resolved in its incognito context", async (t) => { + const incognitoImageUrl = "chrome-extension://incognito-dynamic/assets/images/image.jpg"; + const blockedImage = { src: incognitoImageUrl }; + const { cleanup } = setupBlockedPageTest({ + blockedImage, + runtimeImageUrl: "chrome-extension://regular-dynamic/assets/images/image.jpg", + storageGet() { + return Promise.resolve({}); + } + }); + t.after(cleanup); + + await importBlockedPageScript(); + + assert.equal(blockedImage.src, incognitoImageUrl); +}); + test("blocked page uses a saved custom image when storage provides one", async (t) => { const blockedImage = {}; const customImage = "data:image/png;base64,custom"; @@ -189,16 +206,27 @@ test("blocked page reload refuses mismatched original URL context", async (t) => assert.deepEqual(redirects, []); }); -function setupBlockedPageTest({ blockedImage, storageGet, url, redirects = [] }) { +function setupBlockedPageTest({ + blockedImage, + storageGet, + url, + redirects = [], + runtimeImageUrl = "chrome-extension://test/assets/images/image.jpg" +}) { const previousBrowser = globalThis.browser; const previousChrome = globalThis.chrome; const previousDocument = globalThis.document; const previousLocation = globalThis.location; + if (!blockedImage.src) { + blockedImage.src = runtimeImageUrl; + } + globalThis.browser = { runtime: { getURL(path) { - return `chrome-extension://test/${path}`; + assert.equal(path, "assets/images/image.jpg"); + return runtimeImageUrl; } }, storage: { diff --git a/tests/unit/popup-css.test.js b/tests/unit/popup-css.test.js index 953b168..25e95a6 100644 --- a/tests/unit/popup-css.test.js +++ b/tests/unit/popup-css.test.js @@ -15,7 +15,17 @@ test("popup keeps a fixed height without stretching the image section", async () "the hidden current-site section must not shift the image section into the flexible grid row", ); assert.match(css, /\.rules-section\s*{[^}]*\bmin-height:\s*0;/s); - assert.match(css, /\.rules-content\s*{[^}]*\boverflow-y:\s*auto;/s); + assert.match( + css, + /\.rules-section:not\(\.is-collapsed\)\s*{[^}]*display:\s*grid;[^}]*grid-template-rows:\s*auto minmax\(0,\s*1fr\);/s, + "the expanded rules card must reserve its header before sizing the scroll area", + ); + assert.match(css, /\.rules-content\s*{[^}]*\bmin-height:\s*0;[^}]*\boverflow-y:\s*auto;/s); + assert.doesNotMatch( + css, + /\.rules-content\s*{[^}]*\bmax-height:\s*100%;/s, + "the scroll area must not claim the full card height in addition to the header", + ); }); test("collapsed rules use content-sized grid rows", async () => {