Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
/* Any copyright is dedicated to the Public Domain.
/**
* Tests the the re-integration metric.
*/
"use strict";
const SEARCH_STRING = "exa";
const ADAPTIVE_INPUT = "exa";
add_setup(async function () {
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.autoFill", true],
["browser.urlbar.autoFill.adaptiveHistory.enabled", true],
["browser.urlbar.autoFill.adaptiveHistory.minCharsThreshold", 0],
["browser.urlbar.autoFill.adaptiveHistory.useCountThreshold", 0],
["browser.urlbar.suggest.quicksuggest.sponsored", false],
["browser.urlbar.suggest.quicksuggest.nonsponsored", false],
],
});
registerCleanupFunction(async () => {
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();
});
});
async function addAdaptiveHistoryEntry(url, input, useCount = 3) {
await PlacesTestUtils.addVisits({
uri: url,
transition: PlacesUtils.history.TRANSITIONS.TYPED,
});
for (let i = 0; i < useCount; i++) {
await UrlbarUtils.addToInputHistory(url, input);
}
}
async function pickHistoryResult(url) {
let resultCount = UrlbarTestUtils.getResultCount(window);
let historyIndex = -1;
for (let i = 0; i < resultCount; i++) {
let d = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
if (
!d.autofill &&
d.result.payload.url === url &&
d.result.type === UrlbarUtils.RESULT_TYPE.URL
) {
historyIndex = i;
break;
}
}
Assert.notEqual(historyIndex, -1, "Should find the history result in panel");
let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
while (UrlbarTestUtils.getSelectedRowIndex(window) !== historyIndex) {
EventUtils.synthesizeKey("KEY_ArrowDown");
}
EventUtils.synthesizeKey("KEY_Enter");
await loadPromise;
await TestUtils.waitForTick();
}
// Picking a non-blocked URL as a history result should not record telemetry.
add_task(async function no_telemetry_when_not_blocked() {
Services.fog.testResetFOG();
await addAdaptiveHistoryEntry(ADAPTIVE_URL, ADAPTIVE_INPUT);
await BrowserTestUtils.withNewTab("", async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "e",
fireInputEvent: true,
});
// Pick the URL result (non-autofill) without dismissing first.
await pickHistoryResult(ADAPTIVE_URL);
});
Assert.equal(
Glean.urlbarAutofill.reintegration.origin.testGetValue(),
null,
"Origin reintegration should not be recorded"
);
Assert.equal(
Glean.urlbarAutofill.reintegration.url.testGetValue(),
null,
"URL reintegration should not be recorded"
);
await UrlbarTestUtils.promisePopupClose(window);
await PlacesUtils.history.clear();
});
// Reintegrating a blocked page URL should record the "url" label.
add_task(async function reintegration_page_url_telemetry() {
Services.fog.testResetFOG();
await addAdaptiveHistoryEntry(ADAPTIVE_URL, ADAPTIVE_INPUT);
// Verify adaptive autofill works.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: SEARCH_STRING,
fireInputEvent: true,
});
let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.equal(
details.result.autofill?.type,
"adaptive_url",
"Should have adaptive url autofill before dismissal"
);
// Dismiss via result menu to block the page.
await UrlbarTestUtils.openResultMenuAndClickItem(window, "dismiss_autofill", {
resultIndex: 0,
openByMouse: true,
});
// Wait for the async onEngagement handler to finish writing to the DB.
let originId = await PlacesTestUtils.getDatabaseValue(
"moz_places",
"origin_id",
{ url: ADAPTIVE_URL }
);
await TestUtils.waitForCondition(async () => {
let val = await PlacesTestUtils.getDatabaseValue(
"moz_origins",
"block_pages_until_ms",
{ id: originId }
);
return val > Date.now();
}, "block_pages_until_ms should be set");
Assert.equal(
Glean.urlbarAutofill.reintegration.url.testGetValue(),
null,
"URL reintegration should not be recorded before picking"
);
// Search again and pick the URL as a history result to reintegrate.
await BrowserTestUtils.withNewTab("", async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: SEARCH_STRING,
fireInputEvent: true,
});
await pickHistoryResult(ADAPTIVE_URL);
});
Assert.equal(
Glean.urlbarAutofill.reintegration.url.testGetValue(),
1,
"URL reintegration should be recorded once"
);
Assert.equal(
Glean.urlbarAutofill.reintegration.origin.testGetValue(),
null,
"Origin reintegration should not be recorded for a page URL"
);
await UrlbarTestUtils.promisePopupClose(window);
await PlacesUtils.history.clear();
});
// Reintegrating a blocked origin should record the "origin" label.
add_task(async function reintegration_origin_telemetry() {
Services.fog.testResetFOG();
await addAdaptiveHistoryEntry(ORIGIN_URL, ADAPTIVE_INPUT);
// Verify adaptive autofill works.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: SEARCH_STRING,
fireInputEvent: true,
});
let details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.equal(
details.result.autofill?.type,
"adaptive_origin",
"Should have adaptive origin autofill before dismissal"
);
// Dismiss via result menu to block the origin.
await UrlbarTestUtils.openResultMenuAndClickItem(window, "dismiss_autofill", {
resultIndex: 0,
openByMouse: true,
});
// Wait for the async onEngagement handler to finish writing to the DB.
let originId = await PlacesTestUtils.getDatabaseValue(
"moz_places",
"origin_id",
{ url: ORIGIN_URL }
);
await TestUtils.waitForCondition(async () => {
let val = await PlacesTestUtils.getDatabaseValue(
"moz_origins",
"block_until_ms",
{ id: originId }
);
return val > Date.now();
}, "block_until_ms should be set");
Assert.equal(
Glean.urlbarAutofill.reintegration.origin.testGetValue(),
null,
"Origin reintegration should not be recorded before picking"
);
await BrowserTestUtils.withNewTab("", async () => {
// Search again and pick the origin as a history result to reintegrate.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: SEARCH_STRING,
fireInputEvent: true,
});
await pickHistoryResult(ORIGIN_URL);
});
Assert.equal(
Glean.urlbarAutofill.reintegration.origin.testGetValue(),
1,
"Origin reintegration should be recorded once"
);
Assert.equal(
Glean.urlbarAutofill.reintegration.url.testGetValue(),
null,
"URL reintegration should not be recorded for an origin"
);
await BrowserTestUtils.loadURIString({
browser: gBrowser.selectedBrowser,
uriString: "about:blank",
});
await UrlbarTestUtils.promisePopupClose(window);
await PlacesUtils.history.clear();
});