From 777657f883e23afff02e33c506a8c81aad1a1b44 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Thu, 22 Jan 2015 07:21:21 +0900 Subject: [PATCH] Bug 1115616 - Part 2: Commit composition string forcibly when search suggestion list is clicked in about:home. r=adw --- browser/base/content/searchSuggestionUI.js | 15 ++---- .../content/test/general/browser_aboutHome.js | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/browser/base/content/searchSuggestionUI.js b/browser/base/content/searchSuggestionUI.js index f171606c8ec4..ba49b23102b4 100644 --- a/browser/base/content/searchSuggestionUI.js +++ b/browser/base/content/searchSuggestionUI.js @@ -240,16 +240,11 @@ SearchSuggestionUIController.prototype = { // Commit composition string forcibly, because setting input value does not // work if input has composition string (see bug 1115616 and bug 632744). - try { - let imeEditor = this.input.editor.QueryInterface(Components.interfaces.nsIEditorIMESupport); - if (imeEditor.composing) { - // Ignore input event for compisition end to avoid getting suggestion - // again. - this._ignoreInputEvent = true; - imeEditor.forceCompositionEnd(); - this._ignoreInputEvent = false; - } - } catch(e) { } + // Ignore input event for composition end to avoid getting suggestion again. + this._ignoreInputEvent = true; + this.input.blur(); + this.input.focus(); + this._ignoreInputEvent = false; this.input.value = suggestion; this.input.setAttribute("selection-index", idx); diff --git a/browser/base/content/test/general/browser_aboutHome.js b/browser/base/content/test/general/browser_aboutHome.js index ff976fc2a3ac..f1d38908b97f 100644 --- a/browser/base/content/test/general/browser_aboutHome.js +++ b/browser/base/content/test/general/browser_aboutHome.js @@ -380,6 +380,56 @@ let gTests = [ }); } }, +{ + desc: "Clicking suggestion list while composing", + setup: function() {}, + run: function() + { + return Task.spawn(function* () { + // Start composition and type "x" + let input = gBrowser.contentDocument.getElementById("searchText"); + input.focus(); + EventUtils.synthesizeComposition({ type: "compositionstart", data: "" }); + EventUtils.synthesizeComposition({ type: "compositionupdate", data: "x" }); + EventUtils.synthesizeCompositionChange({ + composition: { + string: "x", + clauses: [ + { length: 1, attr: EventUtils.COMPOSITION_ATTR_RAWINPUT } + ] + }, + caret: { start: 1, length: 0 } + }); + + // Wait for the search suggestions to become visible. + let table = + gBrowser.contentDocument.getElementById("searchSuggestionTable"); + let deferred = Promise.defer(); + let observer = new MutationObserver(() => { + if (input.getAttribute("aria-expanded") == "true") { + observer.disconnect(); + ok(!table.hidden, "Search suggestion table unhidden"); + deferred.resolve(); + } + }); + observer.observe(input, { + attributes: true, + attributeFilter: ["aria-expanded"], + }); + yield deferred.promise; + + // Click the second suggestion. + let expectedURL = Services.search.currentEngine. + getSubmission("xbar", null, "homepage"). + uri.spec; + let loadPromise = waitForDocLoadAndStopIt(expectedURL); + let row = table.children[1]; + EventUtils.sendMouseEvent({ type: "mousedown" }, row, gBrowser.contentWindow); + yield loadPromise; + ok(input.value == "xbar", "Suggestion is selected"); + }); + } +}, { desc: "Cmd+k should focus the search box in the page when the search box in the toolbar is absent", setup: function () {