forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1817206: Use visibleResults for telemetry instead of results in q…
…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
Showing
3 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_engagement_edge_cases.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |