Skip to content

Commit

Permalink
Bug 1817206: Use visibleResults for telemetry instead of results in q…
Browse files Browse the repository at this point in the history
…uery r=adw,mak

Differential Revision: https://phabricator.services.mozilla.com/D171444
  • Loading branch information
Daisuke Akatsuka committed Mar 7, 2023
1 parent 037e327 commit 3da7fb7
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion browser/components/urlbar/UrlbarController.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ class TelemetryEvent {
searchMode
);
const search_mode = this.#getSearchMode(searchMode);
const currentResults = queryContext?.results ?? [];
const currentResults = queryContext?.view?.visibleResults ?? [];
const numResults = currentResults.length;
const groups = currentResults
.map(r => lazy.UrlbarUtils.searchEngagementTelemetryGroup(r))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ skip-if =
[browser_glean_telemetry_abandonment_sap.js]
[browser_glean_telemetry_abandonment_search_mode.js]
[browser_glean_telemetry_abandonment_tips.js]
[browser_glean_telemetry_engagement_edge_cases.js]
[browser_glean_telemetry_engagement_groups.js]
[browser_glean_telemetry_engagement_interaction.js]
[browser_glean_telemetry_engagement_interaction_persisted_search_terms_disabled.js]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test edge cases for engagement.

Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/browser/components/urlbar/tests/ext/browser/head.js",
this
);

add_setup(async function() {
await setup();
});

/**
* UrlbarProvider that does not add any result.
*/
class NoResponseTestProvider extends UrlbarTestUtils.TestProvider {
constructor() {
super({ name: "TestProviderNoResponse ", results: [] });
this.#deferred = PromiseUtils.defer();
}

get type() {
return UrlbarUtils.PROVIDER_TYPE.HEURISTIC;
}

async startQuery(context, addCallback) {
await this.#deferred.promise;
}

done() {
this.#deferred.resolve();
}

#deferred = null;
}
const noResponseProvider = new NoResponseTestProvider();

/**
* UrlbarProvider that adds a heuristic result immediately as usual.
*/
class AnotherHeuristicProvider extends UrlbarTestUtils.TestProvider {
constructor({ results }) {
super({ name: "TestProviderAnotherHeuristic ", results });
this.#deferred = PromiseUtils.defer();
}

get type() {
return UrlbarUtils.PROVIDER_TYPE.HEURISTIC;
}

async startQuery(context, addCallback) {
for (const result of this._results) {
addCallback(this, result);
}

this.#deferred.resolve(context);
}

onQueryStarted() {
return this.#deferred.promise;
}

#deferred = null;
}
const anotherHeuristicProvider = new AnotherHeuristicProvider({
results: [
Object.assign(
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.URL,
UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
{ url: "https://example.com/immediate" }
),
{ heuristic: true }
),
],
});

add_task(async function engagement_before_showing_results() {
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.searchTips.test.ignoreShowLimits", true]],
});

// Update chunkResultsDelayMs to delay the call to notifyResults.
const originalChuldResultDelayMs =
UrlbarProvidersManager._chunkResultsDelayMs;
UrlbarProvidersManager._chunkResultsDelayMs = 1000000;

// Add a provider that waits forever in startQuery() to avoid fireing
// heuristicProviderTimer.
UrlbarProvidersManager.registerProvider(noResponseProvider);

// Add a provider that add a result immediately as usual.
UrlbarProvidersManager.registerProvider(anotherHeuristicProvider);

registerCleanupFunction(function() {
UrlbarProvidersManager.unregisterProvider(noResponseProvider);
UrlbarProvidersManager.unregisterProvider(anotherHeuristicProvider);
UrlbarProvidersManager._chunkResultsDelayMs = originalChuldResultDelayMs;
});

await doTest(async browser => {
// Try to show the results.
const onPopupOpened = openPopup("exam");

// Wait until starting the query and filling expected results.
const context = await anotherHeuristicProvider.onQueryStarted();
await BrowserTestUtils.waitForCondition(
() =>
context.results.some(r => r.providerName === "HeuristicFallback") &&
context.results.some(
r => r.providerName === anotherHeuristicProvider.name
)
);

// Type Enter key before showing any results.
await doEnter();

assertEngagementTelemetry([
{
selected_result: "input_field",
selected_result_subtype: "",
provider: undefined,
results: "",
groups: "",
},
]);

// Clear the pending query to resolve the popup promise.
noResponseProvider.done();
// Search tips will be shown since no results were added.
await onPopupOpened;
});

await SpecialPowers.popPrefEnv();
});

0 comments on commit 3da7fb7

Please sign in to comment.