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 --- .../search/test/browser/browser_ime_composition.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 browser/components/search/test/browser/browser_ime_composition.js (limited to 'browser/components/search/test/browser/browser_ime_composition.js') diff --git a/browser/components/search/test/browser/browser_ime_composition.js b/browser/components/search/test/browser/browser_ime_composition.js new file mode 100644 index 0000000000..763885aad6 --- /dev/null +++ b/browser/components/search/test/browser/browser_ime_composition.js @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests ime composition handling on searchbar. + +add_setup(async function () { + await gCUITestUtils.addSearchBar(); + + await SearchTestUtils.installSearchExtension({}, { setAsDefault: true }); + + registerCleanupFunction(async function () { + gCUITestUtils.removeSearchBar(); + }); +}); + +add_task(async function test_composition_with_focus() { + info("Open a page"); + await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com"); + + info("Focus on the search bar"); + const searchBarTextBox = BrowserSearch.searchBar.textbox; + EventUtils.synthesizeMouseAtCenter(searchBarTextBox, {}); + is( + document.activeElement, + BrowserSearch.searchBar.textbox, + "The text box of search bar has focus" + ); + + info("Do search with new tab"); + EventUtils.synthesizeKey("x"); + EventUtils.synthesizeKey("KEY_Enter", { altKey: true, type: "keydown" }); + is(gBrowser.tabs.length, 3, "Alt+Return key added new tab"); + await TestUtils.waitForCondition( + () => document.activeElement === gBrowser.selectedBrowser, + "Wait for focus to be moved to the browser" + ); + info("The focus is moved to the browser"); + + info("Focus on the search bar again"); + EventUtils.synthesizeMouseAtCenter(searchBarTextBox, {}); + is( + document.activeElement, + BrowserSearch.searchBar.textbox, + "The textbox of search bar has focus again" + ); + + info("Type some characters during composition"); + const string = "ex"; + EventUtils.synthesizeCompositionChange({ + composition: { + string, + clauses: [ + { + length: string.length, + attr: Ci.nsITextInputProcessor.ATTR_RAW_CLAUSE, + }, + ], + }, + caret: { start: string.length, length: 0 }, + key: { key: string[string.length - 1] }, + }); + + info("Commit the composition"); + EventUtils.synthesizeComposition({ + type: "compositioncommitasis", + key: { key: "KEY_Enter" }, + }); + is( + document.activeElement, + BrowserSearch.searchBar.textbox, + "The search bar still has focus" + ); + + // Close all open tabs + await BrowserTestUtils.removeTab(gBrowser.tabs[2]); + await BrowserTestUtils.removeTab(gBrowser.tabs[1]); +}); -- cgit v1.2.3