summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_empty_search.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/urlbar/tests/unit/test_empty_search.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/urlbar/tests/unit/test_empty_search.js')
-rw-r--r--browser/components/urlbar/tests/unit/test_empty_search.js181
1 files changed, 181 insertions, 0 deletions
diff --git a/browser/components/urlbar/tests/unit/test_empty_search.js b/browser/components/urlbar/tests/unit/test_empty_search.js
new file mode 100644
index 0000000000..2c6dffe8e6
--- /dev/null
+++ b/browser/components/urlbar/tests/unit/test_empty_search.js
@@ -0,0 +1,181 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test for bug 426864 that makes sure searching a space only shows typed pages
+ * from history.
+ */
+
+testEngine_setup();
+
+add_task(async function test_empty_search() {
+ Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
+ Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
+ registerCleanupFunction(() => {
+ Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
+ Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
+ });
+
+ let uri1 = Services.io.newURI("http://t.foo/1");
+ let uri2 = Services.io.newURI("http://t.foo/2");
+ let uri3 = Services.io.newURI("http://t.foo/3");
+ let uri4 = Services.io.newURI("http://t.foo/4");
+ let uri5 = Services.io.newURI("http://t.foo/5");
+ let uri6 = Services.io.newURI("http://t.foo/6");
+ let uri7 = Services.io.newURI("http://t.foo/7");
+
+ await PlacesTestUtils.addVisits([
+ { uri: uri7, title: "title" },
+ { uri: uri6, title: "title" },
+ { uri: uri4, title: "title" },
+ { uri: uri3, title: "title" },
+ { uri: uri2, title: "title" },
+ { uri: uri1, title: "title" },
+ ]);
+
+ await PlacesTestUtils.addBookmarkWithDetails({ uri: uri6, title: "title" });
+ await PlacesTestUtils.addBookmarkWithDetails({ uri: uri5, title: "title" });
+ await PlacesTestUtils.addBookmarkWithDetails({ uri: uri4, title: "title" });
+ await PlacesTestUtils.addBookmarkWithDetails({ uri: uri2, title: "title" });
+
+ await addOpenPages(uri7, 1);
+
+ // Now remove page 6 from history, so it is an unvisited bookmark.
+ await PlacesUtils.history.remove(uri6);
+
+ await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();
+
+ // With the changes above, the sites in descending order of frecency are:
+ // uri2
+ // uri4
+ // uri5
+ // uri6
+ // uri1
+ // uri3
+ // uri7
+
+ info("Match everything");
+ let context = createContext("foo", { isPrivate: false });
+ await check_results({
+ context,
+ matches: [
+ makeSearchResult(context, {
+ engineName: SUGGESTIONS_ENGINE_NAME,
+ heuristic: true,
+ }),
+ makeBookmarkResult(context, {
+ uri: uri2.spec,
+ title: "title",
+ }),
+ makeBookmarkResult(context, {
+ uri: uri4.spec,
+ title: "title",
+ }),
+ makeBookmarkResult(context, {
+ uri: uri5.spec,
+ title: "title",
+ }),
+ makeBookmarkResult(context, {
+ uri: uri6.spec,
+ title: "title",
+ }),
+ makeVisitResult(context, { uri: uri1.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri3.spec, title: "title" }),
+ makeTabSwitchResult(context, { uri: uri7.spec, title: "title" }),
+ ],
+ });
+
+ info("Match only history");
+ context = createContext(`foo ${UrlbarTokenizer.RESTRICT.HISTORY}`, {
+ isPrivate: false,
+ });
+ await check_results({
+ context,
+ matches: [
+ makeSearchResult(context, {
+ engineName: SUGGESTIONS_ENGINE_NAME,
+ heuristic: true,
+ }),
+ makeVisitResult(context, { uri: uri2.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri4.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri1.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri3.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri7.spec, title: "title" }),
+ ],
+ });
+
+ info("Drop-down empty search matches history sorted by frecency desc");
+ context = createContext(" ", { isPrivate: false });
+ await check_results({
+ context,
+ matches: [
+ makeSearchResult(context, {
+ engineName: SUGGESTIONS_ENGINE_NAME,
+ // query is made explict so makeSearchResult doesn't trim it.
+ query: " ",
+ heuristic: true,
+ }),
+ makeVisitResult(context, { uri: uri2.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri4.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri1.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri3.spec, title: "title" }),
+ makeVisitResult(context, { uri: uri7.spec, title: "title" }),
+ ],
+ });
+
+ info("Empty search matches only bookmarks when history is disabled");
+ Services.prefs.setBoolPref("browser.urlbar.suggest.history", false);
+ Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
+ context = createContext(" ", { isPrivate: false });
+ await check_results({
+ context,
+ matches: [
+ makeSearchResult(context, {
+ engineName: SUGGESTIONS_ENGINE_NAME,
+ // query is made explict so makeSearchResult doesn't trim it.
+ query: " ",
+ heuristic: true,
+ }),
+ makeBookmarkResult(context, {
+ uri: uri2.spec,
+ title: "title",
+ }),
+ makeBookmarkResult(context, {
+ uri: uri4.spec,
+ title: "title",
+ }),
+ makeBookmarkResult(context, {
+ uri: uri5.spec,
+ title: "title",
+ }),
+ makeBookmarkResult(context, {
+ uri: uri6.spec,
+ title: "title",
+ }),
+ ],
+ });
+
+ info(
+ "Empty search matches only open tabs when bookmarks and history are disabled"
+ );
+ Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
+ context = createContext(" ", { isPrivate: false });
+ await check_results({
+ context,
+ matches: [
+ makeSearchResult(context, {
+ engineName: SUGGESTIONS_ENGINE_NAME,
+ // query is made explict so makeSearchResult doesn't trim it.
+ query: " ",
+ heuristic: true,
+ }),
+ makeTabSwitchResult(context, { uri: uri7.spec, title: "title" }),
+ ],
+ });
+
+ Services.prefs.clearUserPref("browser.urlbar.suggest.history");
+ Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark");
+
+ await cleanupPlaces();
+});