From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser/composition/browser_imageDisplay.js | 172 +++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 comm/mail/test/browser/composition/browser_imageDisplay.js (limited to 'comm/mail/test/browser/composition/browser_imageDisplay.js') diff --git a/comm/mail/test/browser/composition/browser_imageDisplay.js b/comm/mail/test/browser/composition/browser_imageDisplay.js new file mode 100644 index 0000000000..8d759832a9 --- /dev/null +++ b/comm/mail/test/browser/composition/browser_imageDisplay.js @@ -0,0 +1,172 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Tests that we load and display embedded images in messages. + */ + +"use strict"; + +var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.jsm"); +var { + close_compose_window, + open_compose_with_forward, + open_compose_with_reply, +} = ChromeUtils.import("resource://testing-common/mozmill/ComposeHelpers.jsm"); +var { + assert_selected_and_displayed, + be_in_folder, + create_folder, + get_about_message, + mc, + open_message_from_file, + select_click_row, +} = ChromeUtils.import( + "resource://testing-common/mozmill/FolderDisplayHelpers.jsm" +); +var { click_menus_in_sequence, close_window } = ChromeUtils.import( + "resource://testing-common/mozmill/WindowHelpers.jsm" +); + +var gImageFolder; + +add_setup(async function () { + gImageFolder = await create_folder("ImageFolder"); + registerCleanupFunction(() => { + gImageFolder.deleteSelf(null); + }); +}); + +/** + * Check dimensions of the embedded image and whether it could be loaded. + */ +async function check_image_size(aController, aImage, aSrcStart) { + Assert.notEqual(null, aImage, "should have a image"); + await TestUtils.waitForCondition( + () => aImage.complete, + "waiting for image.complete" + ); + // There should not be a cid: URL now. + Assert.ok(!aImage.src.startsWith("cid:")); + if (aSrcStart) { + Assert.ok(aImage.src.startsWith(aSrcStart)); + } + + // Check if there are height and width attributes forcing the image to a size. + let id = aImage.id; + Assert.ok( + aImage.hasAttribute("height"), + "Image " + id + " is missing a required attribute" + ); + Assert.ok( + aImage.hasAttribute("width"), + "Image " + id + " is missing a required attribute" + ); + + Assert.ok( + aImage.height > 0, + "Image " + id + " is missing a required attribute" + ); + Assert.ok( + aImage.width > 0, + "Image " + id + " is missing a required attribute" + ); + + // If the image couldn't be loaded, the naturalWidth and Height are zero. + Assert.ok( + aImage.naturalHeight > 0, + "Loaded image " + id + " is of zero size" + ); + Assert.ok(aImage.naturalWidth > 0, "Loaded image " + id + " is of zero size"); +} + +/** + * Bug 1352701 and bug 1360443 + * Test that showing an image with cid: URL in a HTML message from file will work. + */ +add_task(async function test_cid_image_load() { + let file = new FileUtils.File( + getTestFilePath("data/content-utf8-rel-only.eml") + ); + + // Make sure there is a cid: referenced image in the message. + let msgSource = await IOUtils.readUTF8(file.path); + Assert.ok(msgSource.includes('