Bug 1582234 - Change the meaning of browser.urlbar.suggest.bookmark = false so that visited bookmarks are autofilled but unvisited bookmarks still are not. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Wed, 23 Oct 2019 16:09:31 +0000
changeset 498727 36e230321fd00eab502391f7a16aff4aef35364d
parent 498726 e9c9a624d055b54cf65a5361f5261a2278ec6d3e
child 498728 0f93829d0ed172b2d80c72876b81b799df6a53ae
push id36724
push useraiakab@mozilla.com
push dateWed, 23 Oct 2019 21:54:06 +0000
treeherdermozilla-central@82274c202574 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1582234
milestone72.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 1582234 - Change the meaning of browser.urlbar.suggest.bookmark = false so that visited bookmarks are autofilled but unvisited bookmarks still are not. r=mak When suggest.history = true and suggest.bookmark = false, change the inclusion logic from `NOT bookmarked` to `visited OR NOT bookmarked`. That will include visited bookmarks above the autofill threshold but still exclude unvisited bookmarks. This also renames the various SQL query consts to better reflect when they are used: `HISTORY_BOOKMARK` for when both suggest.history and suggest.bookmark = true, `HISTORY` for when only suggest.history = true, and `BOOKMARK` for when only suggest.bookmark = true. Finally, it adds a bunch of test tasks consistent with the other existing autofill test tasks. Differential Revision: https://phabricator.services.mozilla.com/D50146
toolkit/components/places/UnifiedComplete.jsm
toolkit/components/places/tests/unifiedcomplete/autofill_tasks.js
--- a/toolkit/components/places/UnifiedComplete.jsm
+++ b/toolkit/components/places/UnifiedComplete.jsm
@@ -173,148 +173,175 @@ const SQL_AUTOFILL_WITH = `
     FROM frecency_stats
   )
 `;
 
 const SQL_AUTOFILL_FRECENCY_THRESHOLD = `(
   SELECT value FROM autofill_frecency_threshold
 )`;
 
-function originQuery(conditions = "") {
+function originQuery({ select = "", where = "", having = "" }) {
   return `${SQL_AUTOFILL_WITH}
           SELECT :query_type,
                  fixed_up_host || '/',
                  IFNULL(:prefix, prefix) || moz_origins.host || '/',
                  frecency,
                  bookmarked,
                  id
           FROM (
             SELECT host,
                    host AS fixed_up_host,
                    TOTAL(frecency) AS host_frecency,
                    (
                      SELECT TOTAL(foreign_count) > 0
                      FROM moz_places
                      WHERE moz_places.origin_id = moz_origins.id
                    ) AS bookmarked
+                   ${select}
             FROM moz_origins
             WHERE host BETWEEN :searchString AND :searchString || X'FFFF'
-                  ${conditions}
+                  ${where}
             GROUP BY host
             HAVING host_frecency >= ${SQL_AUTOFILL_FRECENCY_THRESHOLD}
-                   OR bookmarked
+                   ${having}
             UNION ALL
             SELECT host,
                    fixup_url(host) AS fixed_up_host,
                    TOTAL(frecency) AS host_frecency,
                    (
                      SELECT TOTAL(foreign_count) > 0
                      FROM moz_places
                      WHERE moz_places.origin_id = moz_origins.id
                    ) AS bookmarked
+                   ${select}
             FROM moz_origins
             WHERE host BETWEEN 'www.' || :searchString AND 'www.' || :searchString || X'FFFF'
-                  ${conditions}
+                  ${where}
             GROUP BY host
             HAVING host_frecency >= ${SQL_AUTOFILL_FRECENCY_THRESHOLD}
-                   OR bookmarked
+                   ${having}
           ) AS grouped_hosts
           JOIN moz_origins ON moz_origins.host = grouped_hosts.host
           ORDER BY frecency DESC, id DESC
           LIMIT 1 `;
 }
 
-const SQL_ORIGIN_QUERY = originQuery();
+const QUERY_ORIGIN_HISTORY_BOOKMARK = originQuery({
+  having: `OR bookmarked`,
+});
+
+const QUERY_ORIGIN_PREFIX_HISTORY_BOOKMARK = originQuery({
+  where: `AND prefix BETWEEN :prefix AND :prefix || X'FFFF'`,
+  having: `OR bookmarked`,
+});
 
-const SQL_ORIGIN_PREFIX_QUERY = originQuery(
-  `AND prefix BETWEEN :prefix AND :prefix || X'FFFF'`
-);
-
-const SQL_ORIGIN_NOT_BOOKMARKED_QUERY = originQuery(`AND NOT bookmarked`);
+const QUERY_ORIGIN_HISTORY = originQuery({
+  select: `, (
+    SELECT TOTAL(visit_count) > 0
+    FROM moz_places
+    WHERE moz_places.origin_id = moz_origins.id
+   ) AS visited`,
+  having: `AND (visited OR NOT bookmarked)`,
+});
 
-const SQL_ORIGIN_PREFIX_NOT_BOOKMARKED_QUERY = originQuery(
-  `AND NOT bookmarked
-   AND prefix BETWEEN :prefix AND :prefix || X'FFFF'`
-);
+const QUERY_ORIGIN_PREFIX_HISTORY = originQuery({
+  select: `, (
+    SELECT TOTAL(visit_count) > 0
+    FROM moz_places
+    WHERE moz_places.origin_id = moz_origins.id
+   ) AS visited`,
+  where: `AND prefix BETWEEN :prefix AND :prefix || X'FFFF'`,
+  having: `AND (visited OR NOT bookmarked)`,
+});
 
-const SQL_ORIGIN_BOOKMARKED_QUERY = originQuery(`AND bookmarked`);
+const QUERY_ORIGIN_BOOKMARK = originQuery({
+  having: `AND bookmarked`,
+});
 
-const SQL_ORIGIN_PREFIX_BOOKMARKED_QUERY = originQuery(
-  `AND bookmarked
-   AND prefix BETWEEN :prefix AND :prefix || X'FFFF'`
-);
+const QUERY_ORIGIN_PREFIX_BOOKMARK = originQuery({
+  where: `AND prefix BETWEEN :prefix AND :prefix || X'FFFF'`,
+  having: `AND bookmarked`,
+});
 
 // Result row indexes for urlQuery()
 const QUERYINDEX_URL_URL = 1;
 const QUERYINDEX_URL_STRIPPED_URL = 2;
 const QUERYINDEX_URL_FRECENCY = 3;
 
-function urlQuery(conditions1, conditions2) {
+function urlQuery(where1, where2) {
   // We limit the search to places that are either bookmarked or have a frecency
   // over some small, arbitrary threshold (20) in order to avoid scanning as few
   // rows as possible.  Keep in mind that we run this query every time the user
   // types a key when the urlbar value looks like a URL with a path.
   return `/* do not warn (bug no): cannot use an index to sort */
           SELECT :query_type,
                  url,
                  :strippedURL,
                  frecency,
                  foreign_count > 0 AS bookmarked,
+                 visit_count > 0 AS visited,
                  id
           FROM moz_places
           WHERE rev_host = :revHost
-                AND (bookmarked OR frecency > 20)
-                ${conditions1}
+                ${where1}
           UNION ALL
           SELECT :query_type,
                  url,
                  :strippedURL,
                  frecency,
                  foreign_count > 0 AS bookmarked,
+                 visit_count > 0 AS visited,
                  id
           FROM moz_places
           WHERE rev_host = :revHost || 'www.'
-                AND (bookmarked OR frecency > 20)
-                ${conditions2}
+                ${where2}
           ORDER BY frecency DESC, id DESC
           LIMIT 1 `;
 }
 
-const SQL_URL_QUERY = urlQuery(
-  `AND strip_prefix_and_userinfo(url) BETWEEN :strippedURL AND :strippedURL || X'FFFF'`,
-  `AND strip_prefix_and_userinfo(url) BETWEEN 'www.' || :strippedURL AND 'www.' || :strippedURL || X'FFFF'`
-);
-
-const SQL_URL_PREFIX_QUERY = urlQuery(
-  `AND url BETWEEN :prefix || :strippedURL AND :prefix || :strippedURL || X'FFFF'`,
-  `AND url BETWEEN :prefix || 'www.' || :strippedURL AND :prefix || 'www.' || :strippedURL || X'FFFF'`
-);
-
-const SQL_URL_NOT_BOOKMARKED_QUERY = urlQuery(
-  `AND NOT bookmarked
+const QUERY_URL_HISTORY_BOOKMARK = urlQuery(
+  `AND (bookmarked OR frecency > 20)
    AND strip_prefix_and_userinfo(url) BETWEEN :strippedURL AND :strippedURL || X'FFFF'`,
-  `AND NOT bookmarked
+  `AND (bookmarked OR frecency > 20)
    AND strip_prefix_and_userinfo(url) BETWEEN 'www.' || :strippedURL AND 'www.' || :strippedURL || X'FFFF'`
 );
 
-const SQL_URL_PREFIX_NOT_BOOKMARKED_QUERY = urlQuery(
-  `AND NOT bookmarked
+const QUERY_URL_PREFIX_HISTORY_BOOKMARK = urlQuery(
+  `AND (bookmarked OR frecency > 20)
    AND url BETWEEN :prefix || :strippedURL AND :prefix || :strippedURL || X'FFFF'`,
-  `AND NOT bookmarked
+  `AND (bookmarked OR frecency > 20)
    AND url BETWEEN :prefix || 'www.' || :strippedURL AND :prefix || 'www.' || :strippedURL || X'FFFF'`
 );
 
-const SQL_URL_BOOKMARKED_QUERY = urlQuery(
+const QUERY_URL_HISTORY = urlQuery(
+  `AND (visited OR NOT bookmarked)
+   AND frecency > 20
+   AND strip_prefix_and_userinfo(url) BETWEEN :strippedURL AND :strippedURL || X'FFFF'`,
+  `AND (visited OR NOT bookmarked)
+   AND frecency > 20
+   AND strip_prefix_and_userinfo(url) BETWEEN 'www.' || :strippedURL AND 'www.' || :strippedURL || X'FFFF'`
+);
+
+const QUERY_URL_PREFIX_HISTORY = urlQuery(
+  `AND (visited OR NOT bookmarked)
+   AND frecency > 20
+   AND url BETWEEN :prefix || :strippedURL AND :prefix || :strippedURL || X'FFFF'`,
+  `AND (visited OR NOT bookmarked)
+   AND frecency > 20
+   AND url BETWEEN :prefix || 'www.' || :strippedURL AND :prefix || 'www.' || :strippedURL || X'FFFF'`
+);
+
+const QUERY_URL_BOOKMARK = urlQuery(
   `AND bookmarked
    AND strip_prefix_and_userinfo(url) BETWEEN :strippedURL AND :strippedURL || X'FFFF'`,
   `AND bookmarked
    AND strip_prefix_and_userinfo(url) BETWEEN 'www.' || :strippedURL AND 'www.' || :strippedURL || X'FFFF'`
 );
 
-const SQL_URL_PREFIX_BOOKMARKED_QUERY = urlQuery(
+const QUERY_URL_PREFIX_BOOKMARK = urlQuery(
   `AND bookmarked
    AND url BETWEEN :prefix || :strippedURL AND :prefix || :strippedURL || X'FFFF'`,
   `AND bookmarked
    AND url BETWEEN :prefix || 'www.' || :strippedURL AND :prefix || 'www.' || :strippedURL || X'FFFF'`
 );
 
 // Getters
 
@@ -2618,33 +2645,35 @@ Search.prototype = {
       stddevMultiplier: UrlbarPrefs.get("autoFill.stddevMultiplier"),
     };
     if (this._strippedPrefix) {
       opts.prefix = this._strippedPrefix;
     }
 
     if (this.hasBehavior("history") && this.hasBehavior("bookmark")) {
       return [
-        this._strippedPrefix ? SQL_ORIGIN_PREFIX_QUERY : SQL_ORIGIN_QUERY,
+        this._strippedPrefix
+          ? QUERY_ORIGIN_PREFIX_HISTORY_BOOKMARK
+          : QUERY_ORIGIN_HISTORY_BOOKMARK,
         opts,
       ];
     }
     if (this.hasBehavior("history")) {
       return [
         this._strippedPrefix
-          ? SQL_ORIGIN_PREFIX_NOT_BOOKMARKED_QUERY
-          : SQL_ORIGIN_NOT_BOOKMARKED_QUERY,
+          ? QUERY_ORIGIN_PREFIX_HISTORY
+          : QUERY_ORIGIN_HISTORY,
         opts,
       ];
     }
     if (this.hasBehavior("bookmark")) {
       return [
         this._strippedPrefix
-          ? SQL_ORIGIN_PREFIX_BOOKMARKED_QUERY
-          : SQL_ORIGIN_BOOKMARKED_QUERY,
+          ? QUERY_ORIGIN_PREFIX_BOOKMARK
+          : QUERY_ORIGIN_BOOKMARK,
         opts,
       ];
     }
     throw new Error("Either history or bookmark behavior expected");
   },
 
   /**
    * Obtains the query to search for autoFill url results.
@@ -2688,33 +2717,31 @@ Search.prototype = {
       strippedURL,
     };
     if (this._strippedPrefix) {
       opts.prefix = this._strippedPrefix;
     }
 
     if (this.hasBehavior("history") && this.hasBehavior("bookmark")) {
       return [
-        this._strippedPrefix ? SQL_URL_PREFIX_QUERY : SQL_URL_QUERY,
+        this._strippedPrefix
+          ? QUERY_URL_PREFIX_HISTORY_BOOKMARK
+          : QUERY_URL_HISTORY_BOOKMARK,
         opts,
       ];
     }
     if (this.hasBehavior("history")) {
       return [
-        this._strippedPrefix
-          ? SQL_URL_PREFIX_NOT_BOOKMARKED_QUERY
-          : SQL_URL_NOT_BOOKMARKED_QUERY,
+        this._strippedPrefix ? QUERY_URL_PREFIX_HISTORY : QUERY_URL_HISTORY,
         opts,
       ];
     }
     if (this.hasBehavior("bookmark")) {
       return [
-        this._strippedPrefix
-          ? SQL_URL_PREFIX_BOOKMARKED_QUERY
-          : SQL_URL_BOOKMARKED_QUERY,
+        this._strippedPrefix ? QUERY_URL_PREFIX_BOOKMARK : QUERY_URL_BOOKMARK,
         opts,
       ];
     }
     throw new Error("Either history or bookmark behavior expected");
   },
 
   // The result is notified to the search listener on a timer, to chunk multiple
   // match updates together and avoid rebuilding the popup at every new match.
--- a/toolkit/components/places/tests/unifiedcomplete/autofill_tasks.js
+++ b/toolkit/components/places/tests/unifiedcomplete/autofill_tasks.js
@@ -1240,24 +1240,24 @@ function addAutofillTasks(origins) {
     await cleanup();
   });
 
   // Tests interaction between the suggest.history and suggest.bookmark prefs.
   //
   // Config:
   //   suggest.history = true
   //   suggest.bookmark = false
-  //   search for: bookmark
+  //   search for: unvisited bookmark
   //   prefix search: no
   //   prefix matches search: n/a
   //   origin matches search: yes
   //
   // Expected result:
   //   should autofill: no
-  add_task(async function suggestBookmarkFalse_bookmark() {
+  add_task(async function suggestBookmarkFalse_unvisitedBookmark() {
     await addBookmark({
       uri: "http://" + url,
     });
     await check_autocomplete({
       search,
       autofilled: url,
       completed: "http://" + url,
       matches: [
@@ -1276,24 +1276,24 @@ function addAutofillTasks(origins) {
     await cleanup();
   });
 
   // Tests interaction between the suggest.history and suggest.bookmark prefs.
   //
   // Config:
   //   suggest.history = true
   //   suggest.bookmark = false
-  //   search for: bookmark
+  //   search for: unvisited bookmark
   //   prefix search: yes
   //   prefix matches search: yes
   //   origin matches search: yes
   //
   // Expected result:
   //   should autofill: no
-  add_task(async function suggestBookmarkFalse_bookmark_prefix() {
+  add_task(async function suggestBookmarkFalse_unvisitedBookmark_prefix_0() {
     await addBookmark({
       uri: "http://" + url,
     });
     await check_autocomplete({
       search: "http://" + search,
       autofilled: "http://" + url,
       completed: "http://" + url,
       matches: [
@@ -1306,16 +1306,554 @@ function addAutofillTasks(origins) {
     });
     Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
     await check_autocomplete({
       search: "http://" + search,
       matches: [],
     });
     await cleanup();
   });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: unvisited bookmark
+  //   prefix search: yes
+  //   prefix matches search: no
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_unvisitedBookmark_prefix_1() {
+    await addBookmark({
+      uri: "ftp://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: unvisited bookmark
+  //   prefix search: yes
+  //   prefix matches search: yes
+  //   origin matches search: no
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_unvisitedBookmark_prefix_2() {
+    await addBookmark({
+      uri: "http://non-matching-" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: unvisited bookmark
+  //   prefix search: yes
+  //   prefix matches search: no
+  //   origin matches search: no
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_unvisitedBookmark_prefix_3() {
+    await addBookmark({
+      uri: "ftp://non-matching-" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark above autofill threshold
+  //   prefix search: no
+  //   prefix matches search: n/a
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: yes
+  add_task(async function suggestBookmarkFalse_visitedBookmark_above() {
+    await PlacesTestUtils.addVisits("http://" + url);
+    await addBookmark({
+      uri: "http://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search,
+      autofilled: url,
+      completed: "http://" + url,
+      matches: [
+        {
+          value: url,
+          comment,
+          style: ["autofill", "heuristic"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark above autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: yes
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: yes
+  add_task(async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_0() {
+    await PlacesTestUtils.addVisits("http://" + url);
+    await addBookmark({
+      uri: "http://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      autofilled: "http://" + url,
+      completed: "http://" + url,
+      matches: [
+        {
+          value: "http://" + url,
+          comment,
+          style: ["autofill", "heuristic"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark above autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: no
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_1() {
+    await PlacesTestUtils.addVisits("ftp://" + url);
+    await addBookmark({
+      uri: "ftp://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "ftp://" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark above autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: yes
+  //   origin matches search: no
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_2() {
+    await PlacesTestUtils.addVisits("http://non-matching-" + url);
+    await addBookmark({
+      uri: "http://non-matching-" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "http://non-matching-" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark above autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: no
+  //   origin matches search: no
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_3() {
+    await PlacesTestUtils.addVisits("ftp://non-matching-" + url);
+    await addBookmark({
+      uri: "ftp://non-matching-" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "ftp://non-matching-" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // The following suggestBookmarkFalse_visitedBookmarkBelow* tests are similar
+  // to the suggestBookmarkFalse_visitedBookmarkAbove* tests, but instead of
+  // checking visited bookmarks above the autofill threshold, they check visited
+  // bookmarks below the threshold.  These tests don't make sense for URL
+  // queries (as opposed to origin queries) because URL queries don't use the
+  // same autofill threshold, so we skip them when !origins.
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark below autofill threshold
+  //   prefix search: no
+  //   prefix matches search: n/a
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkBelow() {
+    if (!origins) {
+      // See comment above suggestBookmarkFalse_visitedBookmarkBelow.
+      return;
+    }
+    // First, make sure that `url` is below the autofill threshold.
+    await PlacesTestUtils.addVisits("http://" + url);
+    for (let i = 0; i < 3; i++) {
+      await PlacesTestUtils.addVisits("http://some-other-" + url);
+    }
+    await check_autocomplete({
+      search,
+      matches: [
+        {
+          value: "http://some-other-" + url,
+          comment: "test visit for http://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "http://" + url,
+          comment: "test visit for http://" + url,
+          style: ["favicon"],
+        },
+      ],
+    });
+    // Now bookmark it and set suggest.bookmark to false.
+    await addBookmark({
+      uri: "http://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search,
+      matches: [
+        {
+          value: "http://some-other-" + url,
+          comment: "test visit for http://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "http://" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark below autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: yes
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_0() {
+    if (!origins) {
+      // See comment above suggestBookmarkFalse_visitedBookmarkBelow.
+      return;
+    }
+    // First, make sure that `url` is below the autofill threshold.
+    await PlacesTestUtils.addVisits("http://" + url);
+    for (let i = 0; i < 3; i++) {
+      await PlacesTestUtils.addVisits("http://some-other-" + url);
+    }
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "http://some-other-" + url,
+          comment: "test visit for http://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "http://" + url,
+          comment: "test visit for http://" + url,
+          style: ["favicon"],
+        },
+      ],
+    });
+    // Now bookmark it and set suggest.bookmark to false.
+    await addBookmark({
+      uri: "http://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "http://some-other-" + url,
+          comment: "test visit for http://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "http://" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark below autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: no
+  //   origin matches search: yes
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_1() {
+    if (!origins) {
+      // See comment above suggestBookmarkFalse_visitedBookmarkBelow.
+      return;
+    }
+    // First, make sure that `url` is below the autofill threshold.
+    await PlacesTestUtils.addVisits("ftp://" + url);
+    for (let i = 0; i < 3; i++) {
+      await PlacesTestUtils.addVisits("ftp://some-other-" + url);
+    }
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "ftp://some-other-" + url,
+          comment: "test visit for ftp://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "ftp://" + url,
+          comment: "test visit for ftp://" + url,
+          style: ["favicon"],
+        },
+      ],
+    });
+    // Now bookmark it and set suggest.bookmark to false.
+    await addBookmark({
+      uri: "ftp://" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "ftp://some-other-" + url,
+          comment: "test visit for ftp://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "ftp://" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark below autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: yes
+  //   origin matches search: no
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_2() {
+    if (!origins) {
+      // See comment above suggestBookmarkFalse_visitedBookmarkBelow.
+      return;
+    }
+    // First, make sure that `url` is below the autofill threshold.
+    await PlacesTestUtils.addVisits("http://non-matching-" + url);
+    for (let i = 0; i < 3; i++) {
+      await PlacesTestUtils.addVisits("http://some-other-" + url);
+    }
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "http://some-other-" + url,
+          comment: "test visit for http://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "http://non-matching-" + url,
+          comment: "test visit for http://non-matching-" + url,
+          style: ["favicon"],
+        },
+      ],
+    });
+    // Now bookmark it and set suggest.bookmark to false.
+    await addBookmark({
+      uri: "http://non-matching-" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "http://some-other-" + url,
+          comment: "test visit for http://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "http://non-matching-" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
+
+  // Tests interaction between the suggest.history and suggest.bookmark prefs.
+  //
+  // Config:
+  //   suggest.history = true
+  //   suggest.bookmark = false
+  //   search for: visited bookmark below autofill threshold
+  //   prefix search: yes
+  //   prefix matches search: no
+  //   origin matches search: no
+  //
+  // Expected result:
+  //   should autofill: no
+  add_task(async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_3() {
+    if (!origins) {
+      // See comment above suggestBookmarkFalse_visitedBookmarkBelow.
+      return;
+    }
+    // First, make sure that `url` is below the autofill threshold.
+    await PlacesTestUtils.addVisits("ftp://non-matching-" + url);
+    for (let i = 0; i < 3; i++) {
+      await PlacesTestUtils.addVisits("ftp://some-other-" + url);
+    }
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "ftp://some-other-" + url,
+          comment: "test visit for ftp://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "ftp://non-matching-" + url,
+          comment: "test visit for ftp://non-matching-" + url,
+          style: ["favicon"],
+        },
+      ],
+    });
+    // Now bookmark it and set suggest.bookmark to false.
+    await addBookmark({
+      uri: "ftp://non-matching-" + url,
+    });
+    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+    await check_autocomplete({
+      search: "http://" + search,
+      matches: [
+        {
+          value: "ftp://some-other-" + url,
+          comment: "test visit for ftp://some-other-" + url,
+          style: ["favicon"],
+        },
+        {
+          value: "ftp://non-matching-" + url,
+          comment: "A bookmark",
+          style: ["favicon"],
+        },
+      ],
+    });
+    await cleanup();
+  });
 }
 
 /**
  * Returns the frecency of an origin.
  *
  * @param   {string} prefix
  *          The origin's prefix, e.g., "http://".
  * @param   {string} host