From 8015817bc5a7967f2f93d74a17036e018f9af06d Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Mon, 23 Mar 2015 15:36:42 +0100 Subject: [PATCH] Bug 1042561 - Implement stopAutoCompleteSearch() for FormAutoCompleteChild to prevent e10s tests from running into assertions r=mak --- .../components/satchel/nsFormAutoComplete.js | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/toolkit/components/satchel/nsFormAutoComplete.js b/toolkit/components/satchel/nsFormAutoComplete.js index 42f1c4de96ef..150965a63f2b 100644 --- a/toolkit/components/satchel/nsFormAutoComplete.js +++ b/toolkit/components/satchel/nsFormAutoComplete.js @@ -335,6 +335,7 @@ FormAutoCompleteChild.prototype = { _debug: false, _enabled: true, + _pendingSearch: null, /* * init @@ -367,7 +368,9 @@ FormAutoCompleteChild.prototype = { autoCompleteSearchAsync : function (aInputName, aUntrimmedSearchString, aField, aPreviousResult, aListener) { this.log("autoCompleteSearchAsync"); - this._pendingListener = aListener; + if (this._pendingSearch) { + this.stopAutoCompleteSearch(); + } let rect = BrowserUtils.getElementBoundingScreenRect(aField); @@ -389,26 +392,35 @@ FormAutoCompleteChild.prototype = { height: rect.height }); - mm.addMessageListener("FormAutoComplete:AutoCompleteSearchAsyncResult", - function searchFinished(message) { - mm.removeMessageListener("FormAutoComplete:AutoCompleteSearchAsyncResult", searchFinished); - let result = new FormAutoCompleteResult( - null, - [{text: res} for (res of message.data.results)], - null, - null - ); - if (aListener) { - aListener.onSearchCompletion(result); - } - } - ); + let search = this._pendingSearch = {}; + let searchFinished = message => { + mm.removeMessageListener("FormAutoComplete:AutoCompleteSearchAsyncResult", searchFinished); + // Check whether stopAutoCompleteSearch() was called, i.e. the search + // was cancelled, while waiting for a result. + if (search != this._pendingSearch) { + return; + } + this._pendingSearch = null; + + let result = new FormAutoCompleteResult( + null, + [for (res of message.data.results) {text: res}], + null, + null + ); + if (aListener) { + aListener.onSearchCompletion(result); + } + } + + mm.addMessageListener("FormAutoComplete:AutoCompleteSearchAsyncResult", searchFinished); this.log("autoCompleteSearchAsync message was sent"); }, stopAutoCompleteSearch : function () { - this.log("stopAutoCompleteSearch"); + this.log("stopAutoCompleteSearch"); + this._pendingSearch = null; }, }; // end of FormAutoCompleteChild implementation