Skip to content

Commit

Permalink
Backed out 5 changesets (bug 1647881, bug 1645521, bug 1645324) for B…
Browse files Browse the repository at this point in the history
…C failures in urlbar/tests/browser/browser_autocomplete_a11y_label.js. CLOSED TREE

Backed out changeset 65f908569875 (bug 1645324)
Backed out changeset 3080a3cacd0a (bug 1645521)
Backed out changeset d32236f070bf (bug 1645521)
Backed out changeset 579362aab769 (bug 1645521)
Backed out changeset 2b306b83c0d1 (bug 1647881)
  • Loading branch information
dgluca committed Jul 9, 2020
1 parent 86ae59f commit 04d611d
Show file tree
Hide file tree
Showing 28 changed files with 882 additions and 1,123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ add_task(async function test_registerProvider() {
});

// Adds a single active provider that returns many kinds of results. This also
// checks that the heuristic result from the built-in HeuristicFallback provider
// checks that the heuristic result from the built-in UnifiedComplete provider
// is included.
add_task(async function test_onProviderResultsRequested() {
let ext = ExtensionTestUtils.loadExtension({
Expand Down Expand Up @@ -276,7 +276,7 @@ add_task(async function test_onProviderResultsRequested() {

// Check the results.
let expectedResults = [
// The first result should be a search result returned by HeuristicFallback.
// The first result should be a search result returned by UnifiedComplete.
{
type: UrlbarUtils.RESULT_TYPE.SEARCH,
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
Expand Down
85 changes: 15 additions & 70 deletions browser/components/urlbar/UrlbarMuxerUnifiedComplete.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ function groupFromResult(result) {
}
}

// Breaks ties among heuristic results. Providers higher up the list are higher
// priority.
const heuristicOrder = [
// Test providers are handled in sort(),
// Extension providers are handled in sort(),
"UrlbarProviderSearchTips",
"Omnibox",
"UnifiedComplete",
"HeuristicFallback",
];
/**
* Class used to create a muxer.
* The muxer receives and sorts results in a UrlbarQueryContext.
Expand All @@ -64,19 +54,11 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
return "UnifiedComplete";
}

/* eslint-disable complexity */
/**
* Sorts results in the given UrlbarQueryContext.
*
* sort() is not suitable to be broken up into smaller functions or to rely
* on more convenience functions. It exists to efficiently group many
* conditions into just three loops. As a result, we must disable complexity
* linting.
*
* @param {UrlbarQueryContext} context
* The query context.
* @returns {boolean} If results were successfully sorted. This return value
* is a stopgap and can be removed when bug 1648468 lands.
*/
sort(context) {
// This method is called multiple times per keystroke, so it should be as
Expand All @@ -88,42 +70,19 @@ class MuxerUnifiedComplete extends UrlbarMuxer {

// Capture information about the heuristic result to dedupe results from the
// heuristic more quickly.
let topHeuristicRank = Infinity;
for (let result of context.allHeuristicResults) {
// Determine the highest-ranking heuristic result.
if (!result.heuristic) {
continue;
}

// + 2 to reserve the highest-priority slots for test and extension
// providers.
let heuristicRank = heuristicOrder.indexOf(result.providerName) + 2;
// Extension and test provider names vary widely and aren't suitable
// for a static safelist like heuristicOrder.
if (result.providerType == UrlbarUtils.PROVIDER_TYPE.EXTENSION) {
heuristicRank = 1;
} else if (result.providerName.startsWith("TestProvider")) {
heuristicRank = 0;
} else if (heuristicRank - 2 == -1) {
throw new Error(
`Heuristic result returned by unexpected provider: ${result.providerName}`
);
}
// Replace in case of ties, which would occur if a provider sent two
// heuristic results.
if (heuristicRank <= topHeuristicRank) {
topHeuristicRank = heuristicRank;
context.heuristicResult = result;
}
}

let heuristicResultQuery;
let heuristicResultOmniboxContent;
if (context.heuristicResult) {
if (
context.heuristicResult.type == UrlbarUtils.RESULT_TYPE.SEARCH &&
context.heuristicResult.payload.query
) {
heuristicResultQuery = context.heuristicResult.payload.query.toLocaleLowerCase();
} else if (
context.heuristicResult.type == UrlbarUtils.RESULT_TYPE.OMNIBOX &&
context.heuristicResult.payload.content
) {
heuristicResultOmniboxContent = context.heuristicResult.payload.content.toLocaleLowerCase();
}
}

Expand All @@ -136,17 +95,10 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
UrlbarPrefs.get("maxHistoricalSearchSuggestions"),
context.maxResults
);
let hasUnifiedComplete = false;

// Do the first pass through the results. We only collect info for the
// second pass here.
for (let result of context.results) {
// Keep track of whether UnifiedComplete has returned results. We will
// quit early if it hasn't.
if (result.providerName == "UnifiedComplete") {
hasUnifiedComplete = true;
}

// The "Search in a Private Window" result should only be shown when there
// are other results and all of them are searches. It should not be shown
// if the user typed an alias because that's an explicit engine choice.
Expand Down Expand Up @@ -187,24 +139,9 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
}
}

// Quit early if we're still waiting on UnifiedComplete. If it turns out
// UnifiedComplete doesn't need to return any results, it will call sort()
// regardless to unblock showing results.
if (
!hasUnifiedComplete &&
context.pendingHeuristicProviders.has("UnifiedComplete")
) {
return false;
}

// Do the second pass through results to build the list of unsorted results.
let unsortedResults = [];
for (let result of context.results) {
// Exclude low-ranked heuristic results.
if (result.heuristic && result != context.heuristicResult) {
continue;
}

// Exclude "Search in a Private Window" as determined in the first pass.
if (
result.type == UrlbarUtils.RESULT_TYPE.SEARCH &&
Expand Down Expand Up @@ -277,6 +214,15 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
}
}

// Exclude omnibox results that dupe the heuristic.
if (
!result.heuristic &&
result.type == UrlbarUtils.RESULT_TYPE.OMNIBOX &&
result.payload.content == heuristicResultOmniboxContent
) {
continue;
}

// Include this result.
unsortedResults.push(result);
}
Expand Down Expand Up @@ -326,7 +272,6 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
}

context.results = sortedResults;
return true;
}

/**
Expand Down
Loading

0 comments on commit 04d611d

Please sign in to comment.