Bug 1494690 - Set the right maxResults in UrlbarInput. r=standard8
authorDão Gottwald <dao@mozilla.com>
Fri, 28 Sep 2018 15:15:58 +0200
changeset 494476 89a23642630a660d5d816143f735019a4fc488e7
parent 494475 8c9b27320d6e37b77631980d19607d5c58717896
child 494477 f0c13ab5db4bc2493139521c317770c981f2116a
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs1494690
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494690 - Set the right maxResults in UrlbarInput. r=standard8
browser/components/urlbar/UrlbarController.jsm
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js
browser/components/urlbar/tests/unit/head.js
browser/components/urlbar/tests/unit/test_UrlbarController_integration.js
--- a/browser/components/urlbar/UrlbarController.jsm
+++ b/browser/components/urlbar/UrlbarController.jsm
@@ -9,17 +9,17 @@ var EXPORTED_SYMBOLS = ["QueryContext", 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // XXX This is a fake manager to provide a basic integration test whilst we
 // are still constructing the manager.
 // eslint-disable-next-line require-jsdoc
 const ProvidersManager = {
   queryStart(queryContext, controller) {
     queryContext.results = [];
-    for (let i = 0; i < 12; i++) {
+    for (let i = 0; i < queryContext.maxResults; i++) {
       const SWITCH_TO_TAB = Math.random() < .3;
       let url = "http://www." + queryContext.searchString;
       while (Math.random() < .9) {
         url += queryContext.searchString;
       }
       let title = queryContext.searchString;
       while (Math.random() < .5) {
         title += queryContext.isPrivate ? " private" : " foo bar";
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -299,21 +299,21 @@ class UrlbarInput {
     return action;
   }
 
   // Event handlers below.
 
   _oninput(event) {
     this.valueIsTyped = true;
 
-    // XXX Fill in lastKey & maxResults, and add anything else we need.
+    // XXX Fill in lastKey, and add anything else we need.
     this.controller.handleQuery(new QueryContext({
       searchString: event.target.value,
       lastKey: "",
-      maxResults: 12,
+      maxResults: UrlbarPrefs.get("maxRichResults"),
       isPrivate: this.isPrivate,
     }));
   }
 
   _onselect(event) {
     if (!Services.clipboard.supportsSelectionClipboard()) {
       return;
     }
--- a/browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js
+++ b/browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js
@@ -110,16 +110,17 @@ add_task(function test_input_starts_quer
       value: "search",
     },
     type: "input",
   });
 
   checkHandleQueryCall(fakeController.handleQuery, {
     searchString: "search",
     isPrivate: false,
+    maxResults: UrlbarPrefs.get("maxRichResults"),
   });
 
   sandbox.resetHistory();
 });
 
 add_task(function test_input_with_private_browsing() {
   PrivateBrowsingUtils.isWindowPrivate.returns(true);
 
--- a/browser/components/urlbar/tests/unit/head.js
+++ b/browser/components/urlbar/tests/unit/head.js
@@ -33,17 +33,17 @@ Services.scriptloader.loadSubScript("res
 /**
  * @param {string} searchString The search string to insert into the context.
  * @returns {QueryContext} Creates a dummy query context with pre-filled required options.
  */
 function createContext(searchString = "foo") {
   return new QueryContext({
     searchString,
     lastKey: searchString ? searchString[searchString.length - 1] : "",
-    maxResults: 1,
+    maxResults: Services.prefs.getIntPref("browser.urlbar.maxRichResults"),
     isPrivate: true,
   });
 }
 
 /**
  * Waits for the given notification from the supplied controller.
  *
  * @param {UrlbarController} controller The controller to wait for a response from.
--- a/browser/components/urlbar/tests/unit/test_UrlbarController_integration.js
+++ b/browser/components/urlbar/tests/unit/test_UrlbarController_integration.js
@@ -41,15 +41,15 @@ add_task(async function test_basic_searc
   controller.handleQuery(context);
 
   let params = await startedPromise;
 
   Assert.equal(params[0], context);
 
   params = await resultsPromise;
 
-  Assert.equal(params[0].results.length, 12,
+  Assert.equal(params[0].results.length, Services.prefs.getIntPref("browser.urlbar.maxRichResults"),
     "Should have given the expected amount of results");
 
   for (let result of params[0].results) {
     Assert.ok(result.url.includes(TEST_URL));
   }
 });