Bug 1339250 - Fix error caused by ending an input session immediately after the session is started r?robwu
MozReview-Commit-ID: Gz9B468NTI1
--- a/browser/components/extensions/test/browser/browser_ext_omnibox.js
+++ b/browser/components/extensions/test/browser/browser_ext_omnibox.js
@@ -108,16 +108,36 @@ add_task(function* () {
// Start an input session by typing in <keyword><space>.
for (let letter of keyword) {
EventUtils.synthesizeKey(letter, {});
}
EventUtils.synthesizeKey(" ", {});
yield expectEvent("on-input-started-fired");
+ // Test canceling the input before any changed events fire.
+ EventUtils.synthesizeKey("VK_BACK_SPACE", {});
+ yield expectEvent("on-input-cancelled-fired");
+
+ EventUtils.synthesizeKey(" ", {});
+ yield expectEvent("on-input-started-fired");
+
+ // Test submitting the input before any changed events fire.
+ EventUtils.synthesizeKey("VK_RETURN", {});
+ yield expectEvent("on-input-entered-fired");
+
+ gURLBar.focus();
+
+ // Start an input session by typing in <keyword><space>.
+ for (let letter of keyword) {
+ EventUtils.synthesizeKey(letter, {});
+ }
+ EventUtils.synthesizeKey(" ", {});
+ yield expectEvent("on-input-started-fired");
+
// We should expect input changed events now that the keyword is active.
EventUtils.synthesizeKey("b", {});
yield expectEvent("on-input-changed-fired", {text: "b"});
EventUtils.synthesizeKey("c", {});
yield expectEvent("on-input-changed-fired", {text: "bc"});
EventUtils.synthesizeKey("VK_BACK_SPACE", {});
--- a/toolkit/components/places/ExtensionSearchHandler.jsm
+++ b/toolkit/components/places/ExtensionSearchHandler.jsm
@@ -47,39 +47,50 @@ class InputSession {
this._searchFinishedCallback = null;
}
get keyword() {
return this._keyword;
}
addSuggestions(suggestions) {
- this._suggestionsCallback(suggestions);
+ if (this._suggestionsCallback) {
+ this._suggestionsCallback(suggestions);
+ }
}
start(eventName) {
this._extension.emit(eventName);
}
update(eventName, text, suggestionsCallback, searchFinishedCallback) {
+ // Check to see if an existing input session needs to be ended first.
if (this._searchFinishedCallback) {
this._searchFinishedCallback();
}
this._searchFinishedCallback = searchFinishedCallback;
this._suggestionsCallback = suggestionsCallback;
this._extension.emit(eventName, text, ++gCurrentCallbackID);
}
cancel(eventName) {
- this._searchFinishedCallback();
+ if (this._searchFinishedCallback) {
+ this._searchFinishedCallback();
+ this._searchFinishedCallback = null;
+ this._suggestionsCallback = null;
+ }
this._extension.emit(eventName);
}
end(eventName, text, disposition) {
- this._searchFinishedCallback();
+ if (this._searchFinishedCallback) {
+ this._searchFinishedCallback();
+ this._searchFinishedCallback = null;
+ this._suggestionsCallback = null;
+ }
this._extension.emit(eventName, text, disposition);
}
}
var ExtensionSearchHandler = Object.freeze({
MSG_INPUT_STARTED: "webext-omnibox-input-started",
MSG_INPUT_CHANGED: "webext-omnibox-input-changed",
MSG_INPUT_ENTERED: "webext-omnibox-input-entered",