Commit 65f2600e authored by Drew Willcoxon's avatar Drew Willcoxon
Browse files

Bug 1747575 - Fix a bug that prevents search mode from being exited in new...

Bug 1747575 - Fix a bug that prevents search mode from being exited in new windows. r=harry, a=RyanVM

This is a regression from bug 1723158, specifically [this change](https://hg.mozilla.org/mozilla-central/rev/904db8e18e53#l4.12).

`this._queryContext` is undefined in the view in new windows. If you press the
key shortcut to enter search mode immediately in a new window, search mode is
entered without running a query. Then if you hit Escape or Backspace, we hit the
`allowEmptySelection` getter and throw an error because `this._queryContext` is
undefined but we're trying to destructure it. This bug does not happen if you
first focus the urlbar and then enter search mode because focusing the urlbar
causes the top-sites query to run.

Differential Revision: https://phabricator.services.mozilla.com/D135583
parent 4e45354b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ class UrlbarView {
  }

  get allowEmptySelection() {
    let { heuristicResult } = this._queryContext;
    let { heuristicResult } = this._queryContext || {};
    return !heuristicResult || !this._shouldShowHeuristic(heuristicResult);
  }

+1 −0
Original line number Diff line number Diff line
@@ -210,6 +210,7 @@ support-files =
support-files =
  searchSuggestionEngine.xml
  searchSuggestionEngine.sjs
[browser_searchMode_newWindow.js]
[browser_searchMode_no_results.js]
[browser_searchMode_oneOffButton.js]
[browser_searchMode_pickResult.js]
+40 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests immediately entering search mode in a new window and then exiting it.
// No errors should be thrown and search mode should be exited successfully.

"use strict";

add_task(async function escape() {
  await doTest(win =>
    EventUtils.synthesizeKey("KEY_Escape", { repeat: 2 }, win)
  );
});

add_task(async function backspace() {
  await doTest(win => EventUtils.synthesizeKey("KEY_Backspace", {}, win));
});

async function doTest(exitSearchMode) {
  let win = await BrowserTestUtils.openNewBrowserWindow();

  // Press accel+K to enter search mode.
  await UrlbarTestUtils.promisePopupOpen(win, () =>
    EventUtils.synthesizeKey("k", { accelKey: true }, win)
  );
  await UrlbarTestUtils.assertSearchMode(win, {
    engineName: Services.search.defaultEngine.name,
    isGeneralPurposeEngine: true,
    source: UrlbarUtils.RESULT_SOURCE.SEARCH,
    isPreview: false,
    entry: "shortcut",
  });

  // Exit search mode.
  await exitSearchMode(win);
  await UrlbarTestUtils.assertSearchMode(win, null);

  await UrlbarTestUtils.promisePopupClose(win);
  await BrowserTestUtils.closeWindow(win);
}