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/mail/test/browser/global-search-bar | |
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 'comm/mail/test/browser/global-search-bar')
3 files changed, 197 insertions, 0 deletions
diff --git a/comm/mail/test/browser/global-search-bar/browser.ini b/comm/mail/test/browser/global-search-bar/browser.ini new file mode 100644 index 0000000000..e88cc8c00f --- /dev/null +++ b/comm/mail/test/browser/global-search-bar/browser.ini @@ -0,0 +1,12 @@ +[DEFAULT] +prefs = + mail.provider.suppress_dialog_on_startup=true + mail.spotlight.firstRunDone=true + mail.winsearch.firstRunDone=true + mailnews.start_page.override_url=about:blank + mailnews.start_page.url=about:blank + datareporting.policy.dataSubmissionPolicyBypassNotification=true +subsuite = thunderbird + +[browser_globalSearchBar.js] +[browser_clickResultItem.js] diff --git a/comm/mail/test/browser/global-search-bar/browser_clickResultItem.js b/comm/mail/test/browser/global-search-bar/browser_clickResultItem.js new file mode 100644 index 0000000000..d76d05203b --- /dev/null +++ b/comm/mail/test/browser/global-search-bar/browser_clickResultItem.js @@ -0,0 +1,142 @@ +/* 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/. */ + +"use strict"; + +const { + be_in_folder, + create_folder, + inboxFolder, + make_message_sets_in_folders, +} = ChromeUtils.import( + "resource://testing-common/mozmill/FolderDisplayHelpers.jsm" +); + +const { GlodaMsgIndexer } = ChromeUtils.import( + "resource:///modules/gloda/IndexMsg.jsm" +); + +let folder; +let threads; + +/** + * Tests the 3 global search bars found in the UI: + * 1) The one on the mail tab. + * 2) The one in the search result tab. + */ +let tests = [ + { + selector: "#unifiedToolbarContent .search-bar global-search-bar", + isNewSearchBar: true, + tabCountBefore: 1, + tabCountAfter: 2, + }, + { + selector: ".remote-gloda-search", + tabCountBefore: 2, + async before() { + // Run a search so we can search from the results tab. + let input = document.querySelector("#unifiedToolbarContent .search-bar"); + EventUtils.synthesizeMouseAtCenter(input, {}); + EventUtils.sendString("us", window); + EventUtils.synthesizeKey("KEY_Enter", {}); + + await BrowserTestUtils.waitForCondition( + () => + window.document.getElementById("tabmail").selectedTab.browser && + window.document.getElementById("tabmail").selectedTab.browser.src == + "chrome://messenger/content/glodaFacetView.xhtml", + "search result tab did not open in time" + ); + }, + tabCountAfter: 3, + }, +]; + +/** + * Tests clicking on an item in the various global search bars opens one tab + * only. See bug 1679113. + */ +add_task(async function testClickingGlobalSearchResultItemOpensOneTab() { + window.focus(); + folder = await create_folder("SearchedFolder"); + await be_in_folder(folder); + threads = await make_message_sets_in_folders( + [folder], + [ + { from: ["User", "user@example.com"] }, + { from: ["User", "user@example.com"] }, + { from: ["User", "user@example.com"] }, + ] + ); + + await new Promise(callback => { + GlodaMsgIndexer.indexFolder(folder, { callback, force: true }); + }); + + let tabmail = window.document.getElementById("tabmail"); + for (let test of tests) { + while (tabmail.tabInfo.length > 1) { + tabmail.closeTab(1); + } + + if (test.before) { + await test.before(); + } + + Assert.equal( + tabmail.tabInfo.length, + test.tabCountBefore, + "tab count is as expected before" + ); + + let input = document.querySelector(test.selector); + if (test.isNewSearchBar) { + input.reset(); + } else { + input.value = ""; + } + input.focus(); + + EventUtils.synthesizeKey("u", {}); + EventUtils.synthesizeKey("s", {}); + EventUtils.synthesizeKey("e", {}); + + await BrowserTestUtils.waitForCondition( + () => input.controller.matchCount > 0, + `"${test.selector}" did not find any matches` + ); + + let target = document.querySelector( + "#PopupGlodaAutocomplete > richlistbox > richlistitem" + ); + Assert.ok(target, "target item to click found"); + EventUtils.synthesizeMouseAtCenter(target, {}); + + // Give any potentially extra tabs time to appear. + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(resolve => window.setTimeout(resolve, 1000)); + + Assert.equal( + tabmail.tabInfo.length, + test.tabCountAfter, + "tab count is as expected after" + ); + Assert.equal( + tabmail.selectedTab.browser.src, + "chrome://messenger/content/glodaFacetView.xhtml", + "current tab is the search results tab" + ); + } +}); + +registerCleanupFunction(async function () { + let tabmail = window.document.getElementById("tabmail"); + tabmail.selectTabByMode("mail3PaneTab"); + await be_in_folder(inboxFolder); + folder.deleteSelf(null); + while (tabmail.tabInfo.length > 1) { + tabmail.closeTab(1); + } +}); diff --git a/comm/mail/test/browser/global-search-bar/browser_globalSearchBar.js b/comm/mail/test/browser/global-search-bar/browser_globalSearchBar.js new file mode 100644 index 0000000000..58c573a893 --- /dev/null +++ b/comm/mail/test/browser/global-search-bar/browser_globalSearchBar.js @@ -0,0 +1,43 @@ +/* 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 Gloda search bar is focused after a search. What we are really + * interested in however, is the search input not causing an error when it + * gains focus. + */ +add_task(async function testGlobalSearchInputGainsFocus() { + let searchInput = document.querySelector(".search-bar"); + EventUtils.synthesizeMouseAtCenter(searchInput, {}, window); + EventUtils.sendString("Bugzilla", window); + EventUtils.synthesizeKey("KEY_Enter", {}, window); + + let tabmail = document.querySelector("tabmail"); + Assert.equal(tabmail.tabInfo.length, 2); + Assert.equal(tabmail.currentTabInfo, tabmail.tabInfo[1]); + + await TestUtils.waitForCondition(() => { + let browser = tabmail.currentTabInfo.browser; + return ( + browser && + !browser.webProgress?.isLoadingDocument && + browser.currentURI?.spec != "about:blank" + ); + }); + + let activeElement = document.activeElement; + info(`<${activeElement.localName}>`); + Assert.equal( + activeElement.getAttribute("is"), + "gloda-autocomplete-input", + "gloda search input has focus" + ); +}); + +registerCleanupFunction(function tearDown() { + let tabmail = document.querySelector("tabmail"); + while (tabmail.tabInfo.length > 1) { + tabmail.closeTab(1); + } +}); |