From a627b97e3540f09032a8f6e478151c2925b3d6e2 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 f171606c8ec..ba49b23102b 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 ff976fc2a3a..f1d38908b97 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 () {