Bug 1339250 - Fix error caused by ending an input session immediately after the session is started r?robwu draft
authorMatthew Wein <mwein@mozilla.com>
Tue, 14 Feb 2017 12:02:40 +0000
changeset 566474 113efa1dd11eec22097c6e7302db38e38cbd2eca
parent 566473 0b1d1dfe7055a8568e1cc7ea5f74c6fd63ada14c
child 625329 6363ad74f3e2f21d4de013556cbe04119c811ea6
push id55231
push usermwein@mozilla.com
push dateFri, 21 Apr 2017 16:54:22 +0000
reviewersrobwu
bugs1339250
milestone55.0a1
Bug 1339250 - Fix error caused by ending an input session immediately after the session is started r?robwu MozReview-Commit-ID: Gz9B468NTI1
browser/components/extensions/test/browser/browser_ext_omnibox.js
toolkit/components/places/ExtensionSearchHandler.jsm
--- 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",