diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/browser/browser_webext_icon.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/mozapps/extensions/test/browser/browser_webext_icon.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/browser/browser_webext_icon.js b/toolkit/mozapps/extensions/test/browser/browser_webext_icon.js new file mode 100644 index 0000000000..123fe0c665 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_webext_icon.js @@ -0,0 +1,82 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +function pngArrayBuffer(size) { + const canvas = document.createElementNS( + "http://www.w3.org/1999/xhtml", + "canvas" + ); + canvas.height = canvas.width = size; + const ctx = canvas.getContext("2d"); + ctx.fillStyle = "blue"; + ctx.fillRect(0, 0, size, size); + return new Promise(resolve => { + canvas.toBlob(blob => { + const fileReader = new FileReader(); + fileReader.onload = () => { + resolve(fileReader.result); + }; + fileReader.readAsArrayBuffer(blob); + }); + }); +} + +async function checkIconInView(view, name, findIcon) { + const manager = await open_manager(view); + const icon = findIcon(manager.document); + const size = Number(icon.src.match(/icon(\d+)\.png/)[1]); + is( + icon.clientWidth, + icon.clientHeight, + `The icon should be square in ${name}` + ); + is( + size, + icon.clientWidth * window.devicePixelRatio, + `The correct icon size should have been chosen in ${name}` + ); + await close_manager(manager); +} + +add_task(async function test_addon_icon() { + // This test loads an extension with a variety of icon sizes, and checks that the + // fitting one is chosen. If this fails it's because you changed the icon size in + // about:addons but didn't update some AddonManager.getPreferredIconURL call. + const id = "@test-addon-icon"; + const icons = {}; + const files = {}; + const file = await pngArrayBuffer(256); + for (let size = 1; size <= 256; ++size) { + let fileName = `icon${size}.png`; + icons[size] = fileName; + files[fileName] = file; + } + const extensionDefinition = { + useAddonManager: "temporary", + manifest: { + browser_specific_settings: { + gecko: { id }, + }, + icons, + }, + files, + }; + + const extension = ExtensionTestUtils.loadExtension(extensionDefinition); + await extension.startup(); + + await checkIconInView("addons://list/extension", "list", doc => { + return getAddonCard(doc.defaultView, id).querySelector(".addon-icon"); + }); + + await checkIconInView( + "addons://detail/" + encodeURIComponent(id), + "details", + doc => { + return getAddonCard(doc.defaultView, id).querySelector(".addon-icon"); + } + ); + + await extension.unload(); +}); |