Commit 9f57c4ff authored by mcheang's avatar mcheang
Browse files

Bug 1743709 - Dedupe switchTab by checking if tab is already added to results. r=harry,adw a=RyanVM

parent b067a484
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
      strippedUrlToTopPrefixAndTitle: new Map(),
      urlToTabResultType: new Map(),
      addedRemoteTabUrls: new Set(),
      addedSwitchTabUrls: new Set(),
      canShowPrivateSearch: context.results.length > 1,
      canShowTailSuggestions: true,
      // Form history and remote suggestions added so far.  Used for deduping
@@ -186,6 +187,7 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
      ),
      urlToTabResultType: new Map(state.urlToTabResultType),
      addedRemoteTabUrls: new Set(state.addedRemoteTabUrls),
      addedSwitchTabUrls: new Set(state.addedSwitchTabUrls),
      suggestions: new Set(state.suggestions),
    });

@@ -805,6 +807,14 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
      }
    }

    // Discard switch-to-tab results that dupes another switch-to-tab result.
    if (
      result.type == UrlbarUtils.RESULT_TYPE.TAB_SWITCH &&
      state.addedSwitchTabUrls.has(result.payload.url)
    ) {
      return false;
    }

    // Discard history results that dupe either remote or switch-to-tab results.
    if (
      !result.heuristic &&
@@ -1087,6 +1097,11 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
    if (result.type == UrlbarUtils.RESULT_TYPE.REMOTE_TAB) {
      state.addedRemoteTabUrls.add(result.payload.url);
    }

    // Keep track of which switch tabs we've added to dedupe switch tabs.
    if (result.type == UrlbarUtils.RESULT_TYPE.TAB_SWITCH) {
      state.addedSwitchTabUrls.add(result.payload.url);
    }
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ add_task(async function test_n_autocomplete_results() {
        new UrlbarResult(
          UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
          UrlbarUtils.RESULT_SOURCE.TABS,
          { url: TEST_URL + "/i" }
          { url: TEST_URL + "/" + i }
        ),
      ],
      false
+47 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function setup() {
  let engine = await addTestSuggestionsEngine();
  let oldDefaultEngine = await Services.search.getDefault();

  registerCleanupFunction(async () => {
    Services.search.setDefault(oldDefaultEngine);
    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
    await cleanupPlaces();
  });

  // Install a test engine.
  Services.search.setDefault(engine);
  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
});

add_task(async function test_deduplication_for_switch_tab() {
  // Set up Places to think the tab is open locally.
  let uri = Services.io.newURI("http://example.com/");

  await PlacesTestUtils.addVisits({ uri, title: "An Example" });
  await addOpenPages(uri, 1);
  await UrlbarUtils.addToInputHistory("http://example.com/", "An");

  let query = "An";
  let context = createContext(query, { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeTabSwitchResult(context, {
        uri: "http://example.com/",
        title: "An Example",
      }),
    ],
  });

  await removeOpenPages(uri, 1);
  await cleanupPlaces();
});
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ support-files =
[test_calculator.js]
[test_casing.js]
[test_dedupe_prefix.js]
[test_dedupe_switchTab.js]
[test_download_embed_bookmarks.js]
[test_empty_search.js]
[test_encoded_urls.js]