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 /comm/mailnews/extensions/newsblog/test/browser | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.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 'comm/mailnews/extensions/newsblog/test/browser')
4 files changed, 292 insertions, 0 deletions
diff --git a/comm/mailnews/extensions/newsblog/test/browser/browser.ini b/comm/mailnews/extensions/newsblog/test/browser/browser.ini new file mode 100644 index 0000000000..1abed389c7 --- /dev/null +++ b/comm/mailnews/extensions/newsblog/test/browser/browser.ini @@ -0,0 +1,20 @@ +[DEFAULT] +prefs = + datareporting.policy.dataSubmissionPolicyBypassNotification=true + mail.account.account1.server=server1 + mail.accountmanager.accounts=account1 + mail.provider.suppress_dialog_on_startup=true + mail.server.server1.hostname=Feeds + mail.server.server1.name=Feeds + mail.server.server1.type=rss + mail.server.server1.userName=nobody + mail.spellcheck.inline=false + mail.spotlight.firstRunDone=true + mail.winsearch.firstRunDone=true + mailnews.database.global.indexer.enabled=false + mailnews.start_page.override_url=about:blank + mailnews.start_page.url=about:blank +subsuite = thunderbird +support-files = data/** + +[browser_feedDisplay.js] diff --git a/comm/mailnews/extensions/newsblog/test/browser/browser_feedDisplay.js b/comm/mailnews/extensions/newsblog/test/browser/browser_feedDisplay.js new file mode 100644 index 0000000000..98fa755c46 --- /dev/null +++ b/comm/mailnews/extensions/newsblog/test/browser/browser_feedDisplay.js @@ -0,0 +1,228 @@ +/* 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/. */ + +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); +var { mailTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/MailTestUtils.jsm" +); +var { MockRegistrar } = ChromeUtils.importESModule( + "resource://testing-common/MockRegistrar.sys.mjs" +); + +add_task(async () => { + function folderTreeClick(row, event = {}) { + EventUtils.synthesizeMouseAtCenter( + folderTree.rows[row].querySelector(".name"), + event, + about3Pane + ); + } + function threadTreeClick(row, event = {}) { + EventUtils.synthesizeMouseAtCenter( + threadTree.getRowAtIndex(row), + event, + about3Pane + ); + } + + /** @implements {nsIExternalProtocolService} */ + let mockExternalProtocolService = { + QueryInterface: ChromeUtils.generateQI(["nsIExternalProtocolService"]), + _loadedURLs: [], + loadURI(uri, windowContext) { + this._loadedURLs.push(uri.spec); + }, + isExposedProtocol(scheme) { + return true; + }, + urlLoaded(url) { + return this._loadedURLs.includes(url); + }, + }; + + let mockExternalProtocolServiceCID = MockRegistrar.register( + "@mozilla.org/uriloader/external-protocol-service;1", + mockExternalProtocolService + ); + + registerCleanupFunction(() => { + MockRegistrar.unregister(mockExternalProtocolServiceCID); + + // Some tests that open new windows don't return focus to the main window + // in a way that satisfies mochitest, and the test times out. + Services.focus.focusedWindow = about3Pane; + }); + + let tabmail = document.getElementById("tabmail"); + let about3Pane = tabmail.currentAbout3Pane; + let { folderTree, threadTree, messageBrowser } = about3Pane; + let menu = about3Pane.document.getElementById("folderPaneContext"); + let menuItem = about3Pane.document.getElementById( + "folderPaneContext-subscribe" + ); + // Not `currentAboutMessage` as that's null right now. + let aboutMessage = messageBrowser.contentWindow; + let messagePane = aboutMessage.getMessagePaneBrowser(); + + let account = MailServices.accounts.getAccount("account1"); + let rootFolder = account.incomingServer.rootFolder; + about3Pane.displayFolder(rootFolder.URI); + let index = about3Pane.folderTree.selectedIndex; + Assert.equal(index, 0); + + let shownPromise = BrowserTestUtils.waitForEvent(menu, "popupshown"); + folderTreeClick(index, { type: "contextmenu" }); + await shownPromise; + + let hiddenPromise = BrowserTestUtils.waitForEvent(menu, "popuphidden"); + let dialogPromise = BrowserTestUtils.promiseAlertDialog( + null, + "chrome://messenger-newsblog/content/feed-subscriptions.xhtml", + { + async callback(dialogWindow) { + let dialogDocument = dialogWindow.document; + + let list = dialogDocument.getElementById("rssSubscriptionsList"); + let locationInput = dialogDocument.getElementById("locationValue"); + let addFeedButton = dialogDocument.getElementById("addFeed"); + + await BrowserTestUtils.waitForEvent(list, "select"); + + EventUtils.synthesizeMouseAtCenter(locationInput, {}, dialogWindow); + await TestUtils.waitForCondition(() => !addFeedButton.disabled); + EventUtils.sendString( + "https://example.org/browser/comm/mailnews/extensions/newsblog/test/browser/data/rss.xml", + dialogWindow + ); + EventUtils.synthesizeKey("VK_TAB", {}, dialogWindow); + + // There's no good way to know if we're ready to continue. + await new Promise(r => dialogWindow.setTimeout(r, 250)); + + let hiddenPromise = BrowserTestUtils.waitForAttribute( + "hidden", + addFeedButton, + "true" + ); + EventUtils.synthesizeMouseAtCenter(addFeedButton, {}, dialogWindow); + await hiddenPromise; + + EventUtils.synthesizeMouseAtCenter( + dialogDocument.querySelector("dialog").getButton("accept"), + {}, + dialogWindow + ); + }, + } + ); + menu.activateItem(menuItem); + await Promise.all([hiddenPromise, dialogPromise]); + + let folder = rootFolder.subFolders.find(f => f.name == "Test Feed"); + Assert.ok(folder); + + about3Pane.displayFolder(folder.URI); + index = folderTree.selectedIndex; + Assert.equal(about3Pane.threadTree.view.rowCount, 1); + + // Description mode. + + let loadedPromise = BrowserTestUtils.browserLoaded(messagePane); + threadTreeClick(0); + await loadedPromise; + + Assert.notEqual(messagePane.currentURI.spec, "about:blank"); + await SpecialPowers.spawn(messagePane, [], () => { + let doc = content.document; + + let p = doc.querySelector("p"); + Assert.equal(p.textContent, "This is the description."); + + let style = content.getComputedStyle(doc.body); + Assert.equal(style.backgroundColor, "rgba(0, 0, 0, 0)"); + + let noscript = doc.querySelector("noscript"); + style = content.getComputedStyle(noscript); + Assert.equal(style.display, "inline"); + }); + + Assert.ok( + aboutMessage.document.getElementById("expandedtoRow").hidden, + "The To field is not visible" + ); + Assert.equal( + aboutMessage.document.getElementById("dateLabel").textContent, + aboutMessage.document.getElementById("dateLabelSubject").textContent, + "The regular date label and the subject date have the same value" + ); + Assert.ok( + BrowserTestUtils.is_hidden( + aboutMessage.document.getElementById("dateLabel"), + "The regular date label is not visible" + ) + ); + Assert.ok( + BrowserTestUtils.is_visible( + aboutMessage.document.getElementById("dateLabelSubject") + ), + "The date label on the subject line is visible" + ); + + await BrowserTestUtils.synthesizeMouseAtCenter("a", {}, messagePane); + Assert.deepEqual(mockExternalProtocolService._loadedURLs, [ + "https://example.org/link/from/description", + ]); + mockExternalProtocolService._loadedURLs.length = 0; + + // Web mode. + + loadedPromise = BrowserTestUtils.browserLoaded( + messagePane, + false, + "https://example.org/browser/comm/mailnews/extensions/newsblog/test/browser/data/article.html" + ); + window.FeedMessageHandler.onSelectPref = 0; + await loadedPromise; + + await SpecialPowers.spawn(messagePane, [], () => { + let doc = content.document; + + let p = doc.querySelector("p"); + Assert.equal(p.textContent, "This is the article."); + + let style = content.getComputedStyle(doc.body); + Assert.equal(style.backgroundColor, "rgb(0, 128, 0)"); + + let noscript = doc.querySelector("noscript"); + style = content.getComputedStyle(noscript); + Assert.equal(style.display, "none"); + }); + await BrowserTestUtils.synthesizeMouseAtCenter("a", {}, messagePane); + Assert.deepEqual(mockExternalProtocolService._loadedURLs, [ + "https://example.org/link/from/article", + ]); + mockExternalProtocolService._loadedURLs.length = 0; + + // Clean up. + + shownPromise = BrowserTestUtils.waitForEvent(menu, "popupshown"); + EventUtils.synthesizeMouseAtCenter( + about3Pane.folderTree.selectedRow, + { type: "contextmenu" }, + about3Pane + ); + await shownPromise; + + hiddenPromise = BrowserTestUtils.waitForEvent(menu, "popuphidden"); + let promptPromise = BrowserTestUtils.promiseAlertDialog("accept"); + menuItem = about3Pane.document.getElementById("folderPaneContext-remove"); + menu.activateItem(menuItem); + await Promise.all([hiddenPromise, promptPromise]); + + window.FeedMessageHandler.onSelectPref = 1; + + folderTree.selectedIndex = 0; +}); diff --git a/comm/mailnews/extensions/newsblog/test/browser/data/article.html b/comm/mailnews/extensions/newsblog/test/browser/data/article.html new file mode 100644 index 0000000000..4c6b780c41 --- /dev/null +++ b/comm/mailnews/extensions/newsblog/test/browser/data/article.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"/> + <title></title> + </head> + <body> + <p>This is the article.</p> + <p><a href="https://example.org/link/from/article">Here's a link.</a></p> + <script> + document.body.style.backgroundColor = "green"; + </script> + <noscript> + <p>This noscript should not display.</p> + </noscript> + </body> +</html> diff --git a/comm/mailnews/extensions/newsblog/test/browser/data/rss.xml b/comm/mailnews/extensions/newsblog/test/browser/data/rss.xml new file mode 100644 index 0000000000..ec6aebccc1 --- /dev/null +++ b/comm/mailnews/extensions/newsblog/test/browser/data/rss.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0"> + <channel> + <title>Test Feed</title> + <link>https://example.org/</link> + <description></description> + <lastBuildDate>Thu, 21 Jan 2021 17:57:54 +0000</lastBuildDate> + <language>en-US</language> + + <item> + <title>Test Article</title> + <link>https://example.org/browser/comm/mailnews/extensions/newsblog/test/browser/data/article.html</link> + <pubDate>Wed, 20 Jan 2021 17:00:39 +0000</pubDate> + + <description><![CDATA[ + <p>This is the description.</p> + <p><a href="https://example.org/link/from/description">Here's a link.</a></p> + <script> + document.body.style.backgroundColor = "red"; + </script> + <noscript> + <p>This noscript should display.</p> + </noscript> + ]]></description> + </item> + </channel> +</rss> |