summaryrefslogtreecommitdiffstats
path: root/toolkit/components/autocomplete
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /toolkit/components/autocomplete
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/autocomplete')
-rw-r--r--toolkit/components/autocomplete/nsAutoCompleteController.cpp104
-rw-r--r--toolkit/components/autocomplete/nsAutoCompleteController.h10
-rw-r--r--toolkit/components/autocomplete/nsIAutoCompleteResult.idl2
-rw-r--r--toolkit/components/autocomplete/nsIAutoCompleteSearch.idl23
-rw-r--r--toolkit/components/autocomplete/tests/unit/head_autocomplete.js8
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_378079.js8
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_393191.js8
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_440866.js8
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_autocomplete_multiple.js8
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_autocomplete_userContextId.js7
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_immediate_search.js174
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_previousResult.js8
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js58
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_stopSearch.js2
-rw-r--r--toolkit/components/autocomplete/tests/unit/xpcshell.toml4
15 files changed, 112 insertions, 320 deletions
diff --git a/toolkit/components/autocomplete/nsAutoCompleteController.cpp b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
index 7c3035271b..126199e3cf 100644
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -49,13 +49,11 @@ nsAutoCompleteController::nsAutoCompleteController()
mPopupClosedByCompositionStart(false),
mProhibitAutoFill(false),
mUserClearedAutoFill(false),
- mClearingAutoFillSearchesAgain(false),
mCompositionState(eCompositionState_None),
mSearchStatus(nsAutoCompleteController::STATUS_NONE),
mMatchCount(0),
mSearchesOngoing(0),
mSearchesFailed(0),
- mImmediateSearchesCount(0),
mCompletedSelectionIndex(-1) {}
nsAutoCompleteController::~nsAutoCompleteController() { SetInput(nullptr); }
@@ -131,9 +129,6 @@ nsAutoCompleteController::SetInput(nsIAutoCompleteInput* aInput) {
input->GetTextValue(value);
SetSearchStringInternal(value);
- // Since the controller can be used as a service it's important to reset this.
- mClearingAutoFillSearchesAgain = false;
-
return NS_OK;
}
@@ -243,20 +238,16 @@ nsAutoCompleteController::HandleText(bool* _retval) {
newValue.Length() < mPlaceholderCompletionString.Length() &&
Substring(mPlaceholderCompletionString, 0, newValue.Length())
.Equals(newValue);
- bool searchAgainOnAutoFillClear =
- mUserClearedAutoFill && mClearingAutoFillSearchesAgain;
- if (!handlingCompositionCommit && !searchAgainOnAutoFillClear &&
- newValue.Length() > 0 && repeatingPreviousSearch) {
+ if (!handlingCompositionCommit && newValue.Length() > 0 &&
+ repeatingPreviousSearch) {
return NS_OK;
}
- if (userRemovedText || searchAgainOnAutoFillClear) {
- if (userRemovedText) {
- // We need to throw away previous results so we don't try to search
- // through them again.
- ClearResults();
- }
+ if (userRemovedText) {
+ // We need to throw away previous results so we don't try to search
+ // through them again.
+ ClearResults();
mProhibitAutoFill = true;
mPlaceholderCompletionString.Truncate();
} else {
@@ -848,16 +839,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY
NS_IMETHODIMP
nsAutoCompleteController::Notify(nsITimer* timer) {
mTimer = nullptr;
-
- if (mImmediateSearchesCount == 0) {
- // If there were no immediate searches, BeforeSearches has not yet been
- // called, so do it now.
- nsresult rv = BeforeSearches();
- if (NS_FAILED(rv)) return rv;
- }
- StartSearch(nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED);
- AfterSearches();
- return NS_OK;
+ return DoSearches();
}
////////////////////////////////////////////////////////////////////////
@@ -928,7 +910,7 @@ nsresult nsAutoCompleteController::BeforeSearches() {
return NS_OK;
}
-nsresult nsAutoCompleteController::StartSearch(uint16_t aSearchType) {
+nsresult nsAutoCompleteController::StartSearch() {
NS_ENSURE_STATE(mInput);
nsCOMPtr<nsIAutoCompleteInput> input = mInput;
@@ -940,14 +922,6 @@ nsresult nsAutoCompleteController::StartSearch(uint16_t aSearchType) {
for (uint32_t i = 0; i < searchesCopy.Length(); ++i) {
nsCOMPtr<nsIAutoCompleteSearch> search = searchesCopy[i];
- // Filter on search type. Not all the searches implement this interface,
- // in such a case just consider them delayed.
- uint16_t searchType = nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED;
- nsCOMPtr<nsIAutoCompleteSearchDescriptor> searchDesc =
- do_QueryInterface(search);
- if (searchDesc) searchDesc->GetSearchType(&searchType);
- if (searchType != aSearchType) continue;
-
nsIAutoCompleteResult* result = mResultCache.SafeObjectAt(i);
if (result) {
@@ -963,13 +937,6 @@ nsresult nsAutoCompleteController::StartSearch(uint16_t aSearchType) {
nsresult rv = input->GetSearchParam(searchParam);
if (NS_FAILED(rv)) return rv;
- // FormFill expects the searchParam to only contain the input element id,
- // other consumers may have other expectations, so this modifies it only
- // for new consumers handling autoFill by themselves.
- if (mProhibitAutoFill && mClearingAutoFillSearchesAgain) {
- searchParam.AppendLiteral(" prohibit-autofill");
- }
-
uint32_t userContextId;
rv = input->GetUserContextId(&userContextId);
if (NS_SUCCEEDED(rv) &&
@@ -1078,7 +1045,6 @@ nsresult nsAutoCompleteController::StartSearches() {
input->GetSearchCount(&searchCount);
mResults.SetCapacity(searchCount);
mSearches.SetCapacity(searchCount);
- mImmediateSearchesCount = 0;
const char* searchCID = kAutoCompleteSearchCID;
@@ -1095,24 +1061,6 @@ nsresult nsAutoCompleteController::StartSearches() {
nsCOMPtr<nsIAutoCompleteSearch> search = do_GetService(cid.get());
if (search) {
mSearches.AppendObject(search);
-
- // Count immediate searches.
- nsCOMPtr<nsIAutoCompleteSearchDescriptor> searchDesc =
- do_QueryInterface(search);
- if (searchDesc) {
- uint16_t searchType =
- nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED;
- if (NS_SUCCEEDED(searchDesc->GetSearchType(&searchType)) &&
- searchType ==
- nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_IMMEDIATE) {
- mImmediateSearchesCount++;
- }
-
- if (!mClearingAutoFillSearchesAgain) {
- searchDesc->GetClearingAutoFillSearchesAgain(
- &mClearingAutoFillSearchesAgain);
- }
- }
}
}
}
@@ -1125,36 +1073,28 @@ nsresult nsAutoCompleteController::StartSearches() {
uint32_t timeout;
input->GetTimeout(&timeout);
- uint32_t immediateSearchesCount = mImmediateSearchesCount;
if (timeout == 0) {
- // All the searches should be executed immediately.
- immediateSearchesCount = mSearches.Length();
+ // If the timeout is 0, we still have to execute the delayed searches,
+ // otherwise this will be a no-op.
+ return DoSearches();
}
- if (immediateSearchesCount > 0) {
- nsresult rv = BeforeSearches();
- if (NS_FAILED(rv)) return rv;
- StartSearch(nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_IMMEDIATE);
-
- if (mSearches.Length() == immediateSearchesCount) {
- // Either all searches are immediate, or the timeout is 0. In the
- // latter case we still have to execute the delayed searches, otherwise
- // this will be a no-op.
- StartSearch(nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED);
-
- // All the searches have been started, just finish.
- AfterSearches();
- return NS_OK;
- }
- }
-
- MOZ_ASSERT(timeout > 0, "Trying to delay searches with a 0 timeout!");
-
// Now start the delayed searches.
return NS_NewTimerWithCallback(getter_AddRefs(mTimer), this, timeout,
nsITimer::TYPE_ONE_SHOT);
}
+nsresult nsAutoCompleteController::DoSearches() {
+ nsresult rv = BeforeSearches();
+ if (NS_FAILED(rv)) return rv;
+
+ StartSearch();
+
+ // All the searches have been started, just finish.
+ AfterSearches();
+ return NS_OK;
+}
+
nsresult nsAutoCompleteController::ClearSearchTimer() {
if (mTimer) {
mTimer->Cancel();
diff --git a/toolkit/components/autocomplete/nsAutoCompleteController.h b/toolkit/components/autocomplete/nsAutoCompleteController.h
index 7e6d8a3b06..fdaf245f56 100644
--- a/toolkit/components/autocomplete/nsAutoCompleteController.h
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.h
@@ -54,8 +54,9 @@ class nsAutoCompleteController final : public nsIAutoCompleteController,
MOZ_CAN_RUN_SCRIPT nsresult OpenPopup();
MOZ_CAN_RUN_SCRIPT nsresult ClosePopup();
- nsresult StartSearch(uint16_t aSearchType);
+ nsresult StartSearch();
+ MOZ_CAN_RUN_SCRIPT nsresult DoSearches();
nsresult BeforeSearches();
MOZ_CAN_RUN_SCRIPT nsresult StartSearches();
MOZ_CAN_RUN_SCRIPT void AfterSearches();
@@ -182,17 +183,13 @@ class nsAutoCompleteController final : public nsIAutoCompleteController,
bool mDefaultIndexCompleted;
bool mPopupClosedByCompositionStart;
- // Whether autofill is allowed for the next search. May be retrieved by the
- // search through the "prohibit-autofill" searchParam.
+ // Whether autofill is allowed for the next search.
bool mProhibitAutoFill;
// Indicates whether the user cleared the autofilled part, returning to the
// originally entered search string.
bool mUserClearedAutoFill;
- // Indicates whether clearing the autofilled string should issue a new search.
- bool mClearingAutoFillSearchesAgain;
-
enum CompositionState {
eCompositionState_None,
eCompositionState_Composing,
@@ -203,7 +200,6 @@ class nsAutoCompleteController final : public nsIAutoCompleteController,
uint32_t mMatchCount;
uint32_t mSearchesOngoing;
uint32_t mSearchesFailed;
- uint32_t mImmediateSearchesCount;
// The index of the match on the popup that was selected using the keyboard,
// if the completeselectedindex attribute is set.
// This is used to distinguish that selection (which would have been put in
diff --git a/toolkit/components/autocomplete/nsIAutoCompleteResult.idl b/toolkit/components/autocomplete/nsIAutoCompleteResult.idl
index 8e8b05ea46..7f85b49b82 100644
--- a/toolkit/components/autocomplete/nsIAutoCompleteResult.idl
+++ b/toolkit/components/autocomplete/nsIAutoCompleteResult.idl
@@ -83,7 +83,7 @@ interface nsIAutoCompleteResult : nsISupports
/**
* True if the value at the given index is removable.
*/
- bool isRemovableAt(in long rowIndex);
+ boolean isRemovableAt(in long rowIndex);
/**
* Remove the value at the given index from the autocomplete results.
diff --git a/toolkit/components/autocomplete/nsIAutoCompleteSearch.idl b/toolkit/components/autocomplete/nsIAutoCompleteSearch.idl
index 2545340bf4..ca41be4a36 100644
--- a/toolkit/components/autocomplete/nsIAutoCompleteSearch.idl
+++ b/toolkit/components/autocomplete/nsIAutoCompleteSearch.idl
@@ -43,26 +43,3 @@ interface nsIAutoCompleteObserver : nsISupports
[can_run_script] void onSearchResult(in nsIAutoCompleteSearch search,
in nsIAutoCompleteResult result);
};
-
-[scriptable, uuid(4c3e7462-fbfb-4310-8f4b-239238392b75)]
-interface nsIAutoCompleteSearchDescriptor : nsISupports
-{
- // The search is started after the timeout specified by the corresponding
- // nsIAutoCompleteInput implementation.
- const unsigned short SEARCH_TYPE_DELAYED = 0;
- // The search is started synchronously, before any delayed searches.
- const unsigned short SEARCH_TYPE_IMMEDIATE = 1;
-
- /**
- * Identifies the search behavior.
- * Should be one of the SEARCH_TYPE_* constants above.
- * Defaults to SEARCH_TYPE_DELAYED.
- */
- readonly attribute unsigned short searchType;
-
- /*
- * Whether a new search should be triggered when the user deletes the
- * autofilled part.
- */
- readonly attribute boolean clearingAutoFillSearchesAgain;
-};
diff --git a/toolkit/components/autocomplete/tests/unit/head_autocomplete.js b/toolkit/components/autocomplete/tests/unit/head_autocomplete.js
index 6aa0382d82..b11d02a855 100644
--- a/toolkit/components/autocomplete/tests/unit/head_autocomplete.js
+++ b/toolkit/components/autocomplete/tests/unit/head_autocomplete.js
@@ -101,7 +101,7 @@ AutoCompleteResultBase.prototype = {
return this._styles[aIndex];
},
- getImageAt(aIndex) {
+ getImageAt() {
return "";
},
@@ -109,11 +109,11 @@ AutoCompleteResultBase.prototype = {
return this._finalCompleteValues[aIndex] || this._values[aIndex];
},
- isRemovableAt(aRowIndex) {
+ isRemovableAt() {
return true;
},
- removeValueAt(aRowIndex) {},
+ removeValueAt() {},
// nsISupports implementation
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteResult"]),
@@ -161,7 +161,7 @@ function AutocompletePopupBase(input) {
AutocompletePopupBase.prototype = {
selectedIndex: 0,
invalidate() {},
- selectBy(reverse, page) {
+ selectBy(reverse) {
let numRows = this.input.controller.matchCount;
if (numRows > 0) {
let delta = reverse ? -1 : 1;
diff --git a/toolkit/components/autocomplete/tests/unit/test_378079.js b/toolkit/components/autocomplete/tests/unit/test_378079.js
index 06819df40b..756783d17f 100644
--- a/toolkit/components/autocomplete/tests/unit/test_378079.js
+++ b/toolkit/components/autocomplete/tests/unit/test_378079.js
@@ -45,7 +45,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
- setSelectedIndex(aIndex) {},
+ setSelectedIndex() {},
invalidate() {},
// nsISupports implementation
@@ -100,7 +100,7 @@ AutoCompleteResult.prototype = {
return this._styles[aIndex];
},
- getImageAt(aIndex) {
+ getImageAt() {
return "";
},
@@ -108,11 +108,11 @@ AutoCompleteResult.prototype = {
return this.getValueAt(aIndex);
},
- isRemovableAt(aRowIndex) {
+ isRemovableAt() {
return true;
},
- removeValueAt(aRowIndex) {},
+ removeValueAt() {},
// nsISupports implementation
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteResult"]),
diff --git a/toolkit/components/autocomplete/tests/unit/test_393191.js b/toolkit/components/autocomplete/tests/unit/test_393191.js
index 9a0481718d..c39a7586e9 100644
--- a/toolkit/components/autocomplete/tests/unit/test_393191.js
+++ b/toolkit/components/autocomplete/tests/unit/test_393191.js
@@ -44,7 +44,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
- setSelectedIndex(aIndex) {},
+ setSelectedIndex() {},
invalidate() {},
// nsISupports implementation
@@ -99,7 +99,7 @@ AutoCompleteResult.prototype = {
return this._styles[aIndex];
},
- getImageAt(aIndex) {
+ getImageAt() {
return "";
},
@@ -107,11 +107,11 @@ AutoCompleteResult.prototype = {
return this.getValueAt(aIndex);
},
- isRemovableAt(aRowIndex) {
+ isRemovableAt() {
return true;
},
- removeValueAt(aRowIndex) {},
+ removeValueAt() {},
// nsISupports implementation
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteResult"]),
diff --git a/toolkit/components/autocomplete/tests/unit/test_440866.js b/toolkit/components/autocomplete/tests/unit/test_440866.js
index ef538cd931..fdc7850b28 100644
--- a/toolkit/components/autocomplete/tests/unit/test_440866.js
+++ b/toolkit/components/autocomplete/tests/unit/test_440866.js
@@ -43,7 +43,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
- setSelectedIndex(aIndex) {},
+ setSelectedIndex() {},
invalidate() {},
// nsISupports implementation
@@ -98,7 +98,7 @@ AutoCompleteResult.prototype = {
return this._styles[aIndex];
},
- getImageAt(aIndex) {
+ getImageAt() {
return "";
},
@@ -106,11 +106,11 @@ AutoCompleteResult.prototype = {
return this.getValueAt(aIndex);
},
- isRemovableAt(aRowIndex) {
+ isRemovableAt() {
return true;
},
- removeValueAt(aRowIndex) {},
+ removeValueAt() {},
// nsISupports implementation
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteResult"]),
diff --git a/toolkit/components/autocomplete/tests/unit/test_autocomplete_multiple.js b/toolkit/components/autocomplete/tests/unit/test_autocomplete_multiple.js
index 68885dc4ab..d94da5ae59 100644
--- a/toolkit/components/autocomplete/tests/unit/test_autocomplete_multiple.js
+++ b/toolkit/components/autocomplete/tests/unit/test_autocomplete_multiple.js
@@ -40,7 +40,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
- setSelectedIndex(aIndex) {},
+ setSelectedIndex() {},
invalidate() {},
// nsISupports implementation
@@ -92,7 +92,7 @@ AutoCompleteResult.prototype = {
return this._styles[aIndex];
},
- getImageAt(aIndex) {
+ getImageAt() {
return "";
},
@@ -100,11 +100,11 @@ AutoCompleteResult.prototype = {
return this.getValueAt(aIndex);
},
- isRemovableAt(aRowIndex) {
+ isRemovableAt() {
return true;
},
- removeValueAt(aRowIndex) {},
+ removeValueAt() {},
// nsISupports implementation
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteResult"]),
diff --git a/toolkit/components/autocomplete/tests/unit/test_autocomplete_userContextId.js b/toolkit/components/autocomplete/tests/unit/test_autocomplete_userContextId.js
index 4fbec408dc..6862e63ede 100644
--- a/toolkit/components/autocomplete/tests/unit/test_autocomplete_userContextId.js
+++ b/toolkit/components/autocomplete/tests/unit/test_autocomplete_userContextId.js
@@ -21,12 +21,7 @@ function doSearch(aString, aUserContextId) {
return new Promise(resolve => {
let search = new AutoCompleteSearch("test");
- search.startSearch = function (
- aSearchString,
- aSearchParam,
- aPreviousResult,
- aListener
- ) {
+ search.startSearch = function (aSearchString, aSearchParam) {
unregisterAutoCompleteSearch(search);
resolve(aSearchParam);
};
diff --git a/toolkit/components/autocomplete/tests/unit/test_immediate_search.js b/toolkit/components/autocomplete/tests/unit/test_immediate_search.js
deleted file mode 100644
index a4524ca5c9..0000000000
--- a/toolkit/components/autocomplete/tests/unit/test_immediate_search.js
+++ /dev/null
@@ -1,174 +0,0 @@
-/* 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/. */
-
-function AutoCompleteImmediateSearch(aName, aResult) {
- this.name = aName;
- this._result = aResult;
-}
-AutoCompleteImmediateSearch.prototype = Object.create(
- AutoCompleteSearchBase.prototype
-);
-AutoCompleteImmediateSearch.prototype.searchType =
- Ci.nsIAutoCompleteSearchDescriptor.SEARCH_TYPE_IMMEDIATE;
-AutoCompleteImmediateSearch.prototype.QueryInterface = ChromeUtils.generateQI([
- "nsIFactory",
- "nsIAutoCompleteSearch",
- "nsIAutoCompleteSearchDescriptor",
-]);
-
-function AutoCompleteDelayedSearch(aName, aResult) {
- this.name = aName;
- this._result = aResult;
-}
-AutoCompleteDelayedSearch.prototype = Object.create(
- AutoCompleteSearchBase.prototype
-);
-
-function AutoCompleteResult(aValues, aDefaultIndex) {
- this._values = aValues;
- this.defaultIndex = aDefaultIndex;
-}
-AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
-
-/**
- * An immediate search should be executed synchronously.
- */
-add_test(function test_immediate_search() {
- let inputStr = "moz";
-
- let immediateSearch = new AutoCompleteImmediateSearch(
- "immediate",
- new AutoCompleteResult(["moz-immediate"], 0)
- );
- registerAutoCompleteSearch(immediateSearch);
- let delayedSearch = new AutoCompleteDelayedSearch(
- "delayed",
- new AutoCompleteResult(["moz-delayed"], 0)
- );
- registerAutoCompleteSearch(delayedSearch);
-
- let controller = Cc["@mozilla.org/autocomplete/controller;1"].getService(
- Ci.nsIAutoCompleteController
- );
-
- let input = new AutoCompleteInputBase([
- delayedSearch.name,
- immediateSearch.name,
- ]);
- input.completeDefaultIndex = true;
- input.textValue = inputStr;
-
- // Caret must be at the end. Autofill doesn't happen unless you're typing
- // characters at the end.
- let strLen = inputStr.length;
- input.selectTextRange(strLen, strLen);
-
- controller.input = input;
- controller.startSearch(inputStr);
-
- // Immediately check the result, the immediate search should have finished.
- Assert.equal(input.textValue, "moz-immediate");
-
- // Wait for both queries to finish.
- input.onSearchComplete = function () {
- // Sanity check.
- Assert.equal(input.textValue, "moz-immediate");
-
- unregisterAutoCompleteSearch(immediateSearch);
- unregisterAutoCompleteSearch(delayedSearch);
- run_next_test();
- };
-});
-
-/**
- * An immediate search should be executed before any delayed search.
- */
-add_test(function test_immediate_search_notimeout() {
- let inputStr = "moz";
-
- let immediateSearch = new AutoCompleteImmediateSearch(
- "immediate",
- new AutoCompleteResult(["moz-immediate"], 0)
- );
- registerAutoCompleteSearch(immediateSearch);
-
- let delayedSearch = new AutoCompleteDelayedSearch(
- "delayed",
- new AutoCompleteResult(["moz-delayed"], 0)
- );
- registerAutoCompleteSearch(delayedSearch);
-
- let controller = Cc["@mozilla.org/autocomplete/controller;1"].getService(
- Ci.nsIAutoCompleteController
- );
-
- let input = new AutoCompleteInputBase([
- delayedSearch.name,
- immediateSearch.name,
- ]);
- input.completeDefaultIndex = true;
- input.textValue = inputStr;
- input.timeout = 0;
-
- // Caret must be at the end. Autofill doesn't happen unless you're typing
- // characters at the end.
- let strLen = inputStr.length;
- input.selectTextRange(strLen, strLen);
-
- controller.input = input;
- let complete = false;
- input.onSearchComplete = function () {
- complete = true;
- };
- controller.startSearch(inputStr);
- Assert.ok(complete);
-
- // Immediately check the result, the immediate search should have finished.
- Assert.equal(input.textValue, "moz-immediate");
-
- unregisterAutoCompleteSearch(immediateSearch);
- unregisterAutoCompleteSearch(delayedSearch);
- run_next_test();
-});
-
-/**
- * A delayed search should be executed synchronously with a zero timeout.
- */
-add_test(function test_delayed_search_notimeout() {
- let inputStr = "moz";
-
- let delayedSearch = new AutoCompleteDelayedSearch(
- "delayed",
- new AutoCompleteResult(["moz-delayed"], 0)
- );
- registerAutoCompleteSearch(delayedSearch);
-
- let controller = Cc["@mozilla.org/autocomplete/controller;1"].getService(
- Ci.nsIAutoCompleteController
- );
-
- let input = new AutoCompleteInputBase([delayedSearch.name]);
- input.completeDefaultIndex = true;
- input.textValue = inputStr;
- input.timeout = 0;
-
- // Caret must be at the end. Autofill doesn't happen unless you're typing
- // characters at the end.
- let strLen = inputStr.length;
- input.selectTextRange(strLen, strLen);
-
- controller.input = input;
- let complete = false;
- input.onSearchComplete = function () {
- complete = true;
- };
- controller.startSearch(inputStr);
- Assert.ok(complete);
-
- // Immediately check the result, the delayed search should have finished.
- Assert.equal(input.textValue, "moz-delayed");
-
- unregisterAutoCompleteSearch(delayedSearch);
- run_next_test();
-});
diff --git a/toolkit/components/autocomplete/tests/unit/test_previousResult.js b/toolkit/components/autocomplete/tests/unit/test_previousResult.js
index 85db3f08c5..e015ff481e 100644
--- a/toolkit/components/autocomplete/tests/unit/test_previousResult.js
+++ b/toolkit/components/autocomplete/tests/unit/test_previousResult.js
@@ -45,7 +45,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
- setSelectedIndex(aIndex) {},
+ setSelectedIndex() {},
invalidate() {},
// nsISupports implementation
@@ -100,7 +100,7 @@ AutoCompleteResult.prototype = {
return this._styles[aIndex];
},
- getImageAt(aIndex) {
+ getImageAt() {
return "";
},
@@ -108,11 +108,11 @@ AutoCompleteResult.prototype = {
return this.getValueAt(aIndex);
},
- isRemovableAt(aRowIndex) {
+ isRemovableAt() {
return true;
},
- removeValueAt(aRowIndex) {},
+ removeValueAt() {},
// nsISupports implementation
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteResult"]),
diff --git a/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js b/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js
new file mode 100644
index 0000000000..a5a0f9aa0f
--- /dev/null
+++ b/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js
@@ -0,0 +1,58 @@
+/* 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/. */
+
+function AutoCompleteDelayedSearch(aName, aResult) {
+ this.name = aName;
+ this._result = aResult;
+}
+AutoCompleteDelayedSearch.prototype = Object.create(
+ AutoCompleteSearchBase.prototype
+);
+
+function AutoCompleteResult(aValues, aDefaultIndex) {
+ this._values = aValues;
+ this.defaultIndex = aDefaultIndex;
+}
+AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
+
+/**
+ * A delayed search should be executed synchronously with a zero timeout.
+ */
+add_test(function test_delayed_search_notimeout() {
+ let inputStr = "moz";
+
+ let delayedSearch = new AutoCompleteDelayedSearch(
+ "delayed",
+ new AutoCompleteResult(["moz-delayed"], 0)
+ );
+ registerAutoCompleteSearch(delayedSearch);
+
+ let controller = Cc["@mozilla.org/autocomplete/controller;1"].getService(
+ Ci.nsIAutoCompleteController
+ );
+
+ let input = new AutoCompleteInputBase([delayedSearch.name]);
+ input.completeDefaultIndex = true;
+ input.textValue = inputStr;
+ input.timeout = 0;
+
+ // Caret must be at the end. Autofill doesn't happen unless you're typing
+ // characters at the end.
+ let strLen = inputStr.length;
+ input.selectTextRange(strLen, strLen);
+
+ controller.input = input;
+ let complete = false;
+ input.onSearchComplete = function () {
+ complete = true;
+ };
+ controller.startSearch(inputStr);
+ Assert.ok(complete);
+
+ // Immediately check the result, the delayed search should have finished.
+ Assert.equal(input.textValue, "moz-delayed");
+
+ unregisterAutoCompleteSearch(delayedSearch);
+ run_next_test();
+});
diff --git a/toolkit/components/autocomplete/tests/unit/test_stopSearch.js b/toolkit/components/autocomplete/tests/unit/test_stopSearch.js
index aecf572df0..01bd67d63b 100644
--- a/toolkit/components/autocomplete/tests/unit/test_stopSearch.js
+++ b/toolkit/components/autocomplete/tests/unit/test_stopSearch.js
@@ -60,7 +60,7 @@ function AutoCompleteSearch(aName) {
AutoCompleteSearch.prototype = {
constructor: AutoCompleteSearch,
stopSearchInvoked: true,
- startSearch(aSearchString, aSearchParam, aPreviousResult, aListener) {
+ startSearch() {
info("Check stop search has been called");
Assert.ok(this.stopSearchInvoked);
this.stopSearchInvoked = false;
diff --git a/toolkit/components/autocomplete/tests/unit/xpcshell.toml b/toolkit/components/autocomplete/tests/unit/xpcshell.toml
index 00d238cdf7..0c2e12495e 100644
--- a/toolkit/components/autocomplete/tests/unit/xpcshell.toml
+++ b/toolkit/components/autocomplete/tests/unit/xpcshell.toml
@@ -33,12 +33,12 @@ head = "head_autocomplete.js"
["test_finalDefaultCompleteValue.js"]
-["test_immediate_search.js"]
-
["test_insertMatchAt.js"]
["test_previousResult.js"]
["test_removeMatchAt.js"]
+["test_search_zerotimeout.js"]
+
["test_stopSearch.js"]