Backed out changeset 3e9e40d668c1 (bug 1714242) for causing bc failures on browser_urlbar_event_telemetry_noEvent.js. CLOSED TREE

This commit is contained in:
Iulian Moraru 2021-07-14 04:10:35 +03:00
Родитель 6b5bc91eec
Коммит 8f714d1514
9 изменённых файлов: 470 добавлений и 542 удалений

Просмотреть файл

@ -70,7 +70,7 @@ class SearchOneOffs {
this.header = this.querySelector(".search-panel-one-offs-header");
this.settingsButton = this.querySelector(".search-setting-button");
this.settingsButtonCompact = this.querySelector(".search-setting-button");
this.spacerCompact = this.querySelector(".search-one-offs-spacer");
@ -271,7 +271,7 @@ class SearchOneOffs {
"searchbar-engine-one-off-item"
) &&
!(
this.selectedButton == this.settingsButton &&
this.selectedButton == this.settingsButtonCompact &&
this.hasAttribute("is_searchbar")
);
// Typing de-selects the settings or opensearch buttons at the bottom
@ -467,7 +467,7 @@ class SearchOneOffs {
// Ensure we can refer to the settings buttons by ID:
let origin = this.telemetryOrigin;
this.settingsButton.id = origin + "-anon-search-settings";
this.settingsButtonCompact.id = origin + "-anon-search-settings";
if (this.popup) {
let buttonsWidth = this.popup.clientWidth;
@ -485,7 +485,7 @@ class SearchOneOffs {
}
// 8 is for the margin-inline of the setting button.
buttonsWidth -= this.settingsButton.clientWidth + 8;
buttonsWidth -= this.settingsButtonCompact.clientWidth + 8;
// If the header string is very long, then the searchbar buttons will
// overflow their container unless max-width is set.
@ -570,7 +570,7 @@ class SearchOneOffs {
];
if (aIncludeNonEngineButtons) {
buttons.push(this.settingsButton);
buttons.push(this.settingsButtonCompact);
}
return buttons;
@ -1024,7 +1024,7 @@ class SearchOneOffs {
_on_command(event) {
let target = event.target;
if (target == this.settingsButton) {
if (target == this.settingsButtonCompact) {
this.window.openPreferences("paneSearch");
// If the preference tab was already selected, the panel doesn't

Просмотреть файл

@ -129,7 +129,10 @@ class UrlbarSearchOneOffs extends SearchOneOffs {
super.selectedButton = button;
let expectedSearchMode;
if (button && button != this.view.oneOffSearchButtons.settingsButton) {
if (
button &&
button != this.view.oneOffSearchButtons.settingsButtonCompact
) {
expectedSearchMode = {
engineName: button.engine?.name,
source: button.source,
@ -188,7 +191,8 @@ class UrlbarSearchOneOffs extends SearchOneOffs {
// The settings button and adding engines are a special case and executed
// immediately.
if (
this.selectedButton == this.view.oneOffSearchButtons.settingsButton ||
this.selectedButton ==
this.view.oneOffSearchButtons.settingsButtonCompact ||
this.selectedButton.classList.contains(
"searchbar-engine-one-off-add-engine"
)

Просмотреть файл

@ -285,16 +285,11 @@ support-files =
[browser_typed_value.js]
[browser_unitConversion.js]
[browser_updateForDomainCompletion.js]
[browser_urlbar_event_telemetry_abandonment.js]
support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
[browser_urlbar_event_telemetry_engagement.js]
[browser_urlbar_event_telemetry.js]
skip-if = apple_catalina # Bug 1625690
support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
[browser_urlbar_event_telemetry_noEvent.js]
[browser_urlbar_selection.js]
skip-if = (os == 'mac') # bug 1570474
[browser_urlbar_telemetry_dynamic.js]

Просмотреть файл

@ -51,29 +51,30 @@ add_task(async function slowHeuristicSelected() {
UrlbarProvidersManager.registerProvider(nonHeuristicProvider);
// Do a search.
const win = await BrowserTestUtils.openNewBrowserWindow();
await UrlbarTestUtils.promiseAutocompleteResultPopup({
value: "test",
window: win,
window,
});
// The first result should be the heuristic and it should be selected.
let actualHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(win, 0);
let actualHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.equal(actualHeuristic.type, UrlbarUtils.RESULT_TYPE.SEARCH);
Assert.equal(
UrlbarTestUtils.getSelectedElement(win),
UrlbarTestUtils.getSelectedElement(window),
actualHeuristic.element.row
);
Assert.equal(UrlbarTestUtils.getSelectedElementIndex(win), 0);
Assert.equal(UrlbarTestUtils.getSelectedElementIndex(window), 0);
// Check the second result for good measure.
let actualNonHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(win, 1);
let actualNonHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(
window,
1
);
Assert.equal(actualNonHeuristic.type, UrlbarUtils.RESULT_TYPE.TIP);
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.promisePopupClose(window);
UrlbarProvidersManager.unregisterProvider(heuristicProvider);
UrlbarProvidersManager.unregisterProvider(nonHeuristicProvider);
await BrowserTestUtils.closeWindow(win);
});
// When the heuristic result is not the first result added but a one-off search
@ -122,42 +123,43 @@ add_task(async function oneOffRemainsSelected() {
UrlbarProvidersManager.registerProvider(nonHeuristicProvider);
// Do a search but don't wait for it to finish.
const win = await BrowserTestUtils.openNewBrowserWindow();
let searchPromise = UrlbarTestUtils.promiseAutocompleteResultPopup({
value: "test",
window: win,
window,
});
// When the view opens, press the up arrow key to select the one-off search
// settings button. There's no point in selecting instead the non-heuristic
// result because once we do that, the search is canceled, and the heuristic
// result will never be added.
await UrlbarTestUtils.promisePopupOpen(win, () => {});
EventUtils.synthesizeKey("KEY_ArrowUp", {}, win);
await UrlbarTestUtils.promisePopupOpen(window, () => {});
EventUtils.synthesizeKey("KEY_ArrowUp");
// Wait for the search to finish.
await searchPromise;
// The first result should be the heuristic.
let actualHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(win, 0);
let actualHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
Assert.equal(actualHeuristic.type, UrlbarUtils.RESULT_TYPE.SEARCH);
// Check the second result for good measure.
let actualNonHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(win, 1);
let actualNonHeuristic = await UrlbarTestUtils.getDetailsOfResultAt(
window,
1
);
Assert.equal(actualNonHeuristic.type, UrlbarUtils.RESULT_TYPE.TIP);
// No result should be selected.
Assert.equal(UrlbarTestUtils.getSelectedElement(win), null);
Assert.equal(UrlbarTestUtils.getSelectedElementIndex(win), -1);
Assert.equal(UrlbarTestUtils.getSelectedElement(window), null);
Assert.equal(UrlbarTestUtils.getSelectedElementIndex(window), -1);
// The one-off settings button should be selected.
Assert.equal(
win.gURLBar.view.oneOffSearchButtons.selectedButton,
win.gURLBar.view.oneOffSearchButtons.settingsButton
gURLBar.view.oneOffSearchButtons.selectedButton,
gURLBar.view.oneOffSearchButtons.settingsButtonCompact
);
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.promisePopupClose(window);
UrlbarProvidersManager.unregisterProvider(heuristicProvider);
UrlbarProvidersManager.unregisterProvider(nonHeuristicProvider);
await BrowserTestUtils.closeWindow(win);
});

Просмотреть файл

@ -33,17 +33,20 @@ add_task(async function init() {
await PlacesTestUtils.addVisits(visits);
});
async function selectSettings(win, activateFn) {
async function selectSettings(activateFn) {
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "about:blank" },
{ gBrowser, url: "about:blank" },
async browser => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "example.com",
});
await UrlbarTestUtils.waitForAutocompleteResultAt(win, gMaxResults - 1);
await UrlbarTestUtils.waitForAutocompleteResultAt(
window,
gMaxResults - 1
);
await UrlbarTestUtils.promisePopupClose(win, async () => {
await UrlbarTestUtils.promisePopupClose(window, async () => {
let prefPaneLoaded = TestUtils.topicObserved(
"sync-pane-loaded",
() => true
@ -55,7 +58,7 @@ async function selectSettings(win, activateFn) {
});
Assert.equal(
win.gBrowser.contentWindow.history.state,
gBrowser.contentWindow.history.state,
"paneSearch",
"Should have opened the search preferences pane"
);
@ -64,26 +67,24 @@ async function selectSettings(win, activateFn) {
}
add_task(async function test_open_settings_with_enter() {
const win = await BrowserTestUtils.openNewBrowserWindow();
await selectSettings(win, () => {
EventUtils.synthesizeKey("KEY_ArrowUp", {}, win);
await selectSettings(() => {
EventUtils.synthesizeKey("KEY_ArrowUp");
Assert.ok(
UrlbarTestUtils.getOneOffSearchButtons(
win
window
).selectedButton.classList.contains("search-setting-button"),
"Should have selected the settings button"
);
EventUtils.synthesizeKey("KEY_Enter", {}, win);
EventUtils.synthesizeKey("KEY_Enter");
});
await BrowserTestUtils.closeWindow(win);
});
add_task(async function test_open_settings_with_click() {
const win = await BrowserTestUtils.openNewBrowserWindow();
await selectSettings(win, () => {
UrlbarTestUtils.getOneOffSearchButtons(win).settingsButton.click();
await selectSettings(() => {
UrlbarTestUtils.getOneOffSearchButtons(
window
).settingsButtonCompact.click();
});
await BrowserTestUtils.closeWindow(win);
});

Просмотреть файл

@ -9,18 +9,13 @@
const TEST_ENGINE_NAME = "Test";
let win;
add_task(async function setup() {
win = await BrowserTestUtils.openNewBrowserWindow();
await SearchTestUtils.installSearchExtension({
name: TEST_ENGINE_NAME,
keyword: "@test",
});
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
await PlacesUtils.history.clear();
});
});
@ -54,15 +49,15 @@ function getExpectedSearchMode(button, isPreview = true) {
// Tests that cycling through token alias engines enters search mode preview.
add_task(async function tokenAlias() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "@",
});
let result;
while (win.gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
let index = UrlbarTestUtils.getSelectedRowIndex(win);
result = await UrlbarTestUtils.getDetailsOfResultAt(win, index);
while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
let index = UrlbarTestUtils.getSelectedRowIndex(window);
result = await UrlbarTestUtils.getDetailsOfResultAt(window, index);
let expectedSearchMode = {
engineName: result.searchParams.engine,
isPreview: true,
@ -72,44 +67,44 @@ add_task(async function tokenAlias() {
if (engine.isGeneralPurposeEngine) {
expectedSearchMode.source = UrlbarUtils.RESULT_SOURCE.SEARCH;
}
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
}
let searchPromise = UrlbarTestUtils.promiseSearchComplete(win);
EventUtils.synthesizeKey("KEY_Enter", {}, win);
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
// Test that we are in confirmed search mode.
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: result.searchParams.engine,
entry: "keywordoffer",
});
await UrlbarTestUtils.exitSearchMode(win);
await UrlbarTestUtils.exitSearchMode(window);
});
// Tests that starting to type a query exits search mode preview in favour of
// full search mode.
add_task(async function startTyping() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "@",
});
while (win.gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
}
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: TEST_ENGINE_NAME,
isPreview: true,
entry: "keywordoffer",
});
let searchPromise = UrlbarTestUtils.promiseSearchComplete(win);
EventUtils.synthesizeKey("M", {}, win);
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("M");
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: TEST_ENGINE_NAME,
entry: "keywordoffer",
});
await UrlbarTestUtils.exitSearchMode(win);
await UrlbarTestUtils.exitSearchMode(window);
});
// Tests that highlighting a search shortcut Top Site enters search mode
@ -122,75 +117,75 @@ add_task(async function topSites() {
true
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
fireInputEvent: true,
});
// We previously verified that the first Top Site is a search shortcut.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
let searchTopSite = await UrlbarTestUtils.getDetailsOfResultAt(win, 0);
await UrlbarTestUtils.assertSearchMode(win, {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
let searchTopSite = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
await UrlbarTestUtils.assertSearchMode(window, {
engineName: searchTopSite.searchParams.engine,
isPreview: true,
entry: "topsites_urlbar",
});
await UrlbarTestUtils.exitSearchMode(win);
await UrlbarTestUtils.exitSearchMode(window);
});
// Tests that search mode preview is exited when the view is closed.
add_task(async function closeView() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "@",
});
while (win.gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
}
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: TEST_ENGINE_NAME,
isPreview: true,
entry: "keywordoffer",
});
// We should close search mode when closing the view.
await UrlbarTestUtils.promisePopupClose(win, () => win.gURLBar.blur());
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.promisePopupClose(window, () => gURLBar.blur());
await UrlbarTestUtils.assertSearchMode(window, null);
// Check search mode isn't re-entered when re-opening the view.
await UrlbarTestUtils.promisePopupOpen(win, () => {
if (win.gURLBar.getAttribute("pageproxystate") == "invalid") {
win.gURLBar.handleRevert();
await UrlbarTestUtils.promisePopupOpen(window, () => {
if (gURLBar.getAttribute("pageproxystate") == "invalid") {
gURLBar.handleRevert();
}
EventUtils.synthesizeMouseAtCenter(win.gURLBar.inputField, {}, win);
EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {});
});
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.promisePopupClose(window);
});
// Tests that search more preview is exited when the user switches tabs.
add_task(async function tabSwitch() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "@",
});
while (win.gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
}
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: TEST_ENGINE_NAME,
isPreview: true,
entry: "keywordoffer",
});
// Open a new tab then switch back to the original tab.
let tab1 = win.gBrowser.selectedTab;
let tab2 = await BrowserTestUtils.openNewForegroundTab(win.gBrowser);
await BrowserTestUtils.switchTab(win.gBrowser, tab1);
let tab1 = gBrowser.selectedTab;
let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser);
await BrowserTestUtils.switchTab(gBrowser, tab1);
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.assertSearchMode(window, null);
BrowserTestUtils.removeTab(tab2);
});
@ -198,44 +193,44 @@ add_task(async function tabSwitch() {
// one-offs.
add_task(async function oneOff_downArrow() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
});
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(win);
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
await TestUtils.waitForCondition(
() => !oneOffs._rebuilding,
"Waiting for one-offs to finish rebuilding"
);
let resultCount = UrlbarTestUtils.getResultCount(win);
let resultCount = UrlbarTestUtils.getResultCount(window);
// Key down through all results.
for (let i = 0; i < resultCount; i++) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
}
// Key down again. The first one-off should be selected.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
// Check for the one-off's search mode previews.
while (oneOffs.selectedButton != oneOffs.settingsButton) {
while (oneOffs.selectedButton != oneOffs.settingsButtonCompact) {
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton)
);
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
}
// Check that selecting the search settings button leaves search mode preview.
Assert.equal(
oneOffs.selectedButton,
oneOffs.settingsButton,
oneOffs.settingsButtonCompact,
"The settings button is selected."
);
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Closing the view should also exit search mode preview.
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.assertSearchMode(window, null);
});
// Tests that search mode is previewed when the user Alt+down arrows through the
@ -257,85 +252,85 @@ add_task(async function oneOff_alt_downArrow() {
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
});
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(win);
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
await TestUtils.waitForCondition(
() => !oneOffs._rebuilding,
"Waiting for one-offs to finish rebuilding"
);
// Key down to the first result and check that it enters search mode preview.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
let searchTopSite = await UrlbarTestUtils.getDetailsOfResultAt(win, 0);
await UrlbarTestUtils.assertSearchMode(win, {
EventUtils.synthesizeKey("KEY_ArrowDown");
let searchTopSite = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
await UrlbarTestUtils.assertSearchMode(window, {
engineName: searchTopSite.searchParams.engine,
isPreview: true,
entry: "topsites_urlbar",
});
// Alt+down. The first one-off should be selected.
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
// Check for the one-offs' search mode previews.
while (oneOffs.selectedButton) {
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton)
);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
}
// Now key down without a modifier. We should move to the second result and
// have no search mode preview.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
Assert.equal(
UrlbarTestUtils.getSelectedRowIndex(win),
UrlbarTestUtils.getSelectedRowIndex(window),
1,
"The second result is selected."
);
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Arrow back up to the keywordoffer result and check for search mode preview.
EventUtils.synthesizeKey("KEY_ArrowUp", {}, win);
await UrlbarTestUtils.assertSearchMode(win, {
EventUtils.synthesizeKey("KEY_ArrowUp");
await UrlbarTestUtils.assertSearchMode(window, {
engineName: searchTopSite.searchParams.engine,
isPreview: true,
entry: "topsites_urlbar",
});
await PlacesUtils.history.clear();
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.assertSearchMode(window, null);
});
// Tests that search mode is previewed when the user is in full search mode
// and down arrows through the one-offs.
add_task(async function fullSearchMode_oneOff_downArrow() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
});
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(win);
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
await TestUtils.waitForCondition(
() => !oneOffs._rebuilding,
"Waiting for one-offs to finish rebuilding"
);
let oneOffButtons = oneOffs.getSelectableButtons(true);
await UrlbarTestUtils.enterSearchMode(win);
await UrlbarTestUtils.enterSearchMode(window);
let expectedSearchMode = getExpectedSearchMode(oneOffButtons[0], false);
// Sanity check: we are in the correct search mode.
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
// Key down through all results.
let resultCount = UrlbarTestUtils.getResultCount(win);
let resultCount = UrlbarTestUtils.getResultCount(window);
for (let i = 0; i < resultCount; i++) {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
// If the result is a shortcut, it will enter preview mode.
let result = await UrlbarTestUtils.getDetailsOfResultAt(win, i);
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
await UrlbarTestUtils.assertSearchMode(
win,
window,
Object.assign(expectedSearchMode, {
isPreview: !!result.searchParams.keyword,
})
@ -343,21 +338,21 @@ add_task(async function fullSearchMode_oneOff_downArrow() {
}
// Key down again. The first one-off should be selected.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
// Check that we show the correct preview as we cycle through the one-offs.
while (oneOffs.selectedButton != oneOffs.settingsButton) {
while (oneOffs.selectedButton != oneOffs.settingsButtonCompact) {
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton, true)
);
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
}
// We should still be in the same search mode after cycling through all the
// one-offs.
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
await UrlbarTestUtils.exitSearchMode(win);
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
await UrlbarTestUtils.exitSearchMode(window);
await UrlbarTestUtils.promisePopupClose(window);
});
// Tests that search mode is previewed when the user is in full search mode
@ -366,25 +361,25 @@ add_task(async function fullSearchMode_oneOff_downArrow() {
// search mode preview for subsequent one-offs.
add_task(async function fullSearchMode_oneOff_alt_downArrow() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
});
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(win);
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
let oneOffButtons = oneOffs.getSelectableButtons(true);
await TestUtils.waitForCondition(
() => !oneOffs._rebuilding,
"Waiting for one-offs to finish rebuilding"
);
await UrlbarTestUtils.enterSearchMode(win);
await UrlbarTestUtils.enterSearchMode(window);
let expectedSearchMode = getExpectedSearchMode(oneOffButtons[0], false);
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
// Key down to the first result.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
// Alt+down. The first one-off should be selected.
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
// Cycle through the first half of the one-offs and verify that search mode
// preview is entered.
Assert.greater(
@ -394,25 +389,25 @@ add_task(async function fullSearchMode_oneOff_alt_downArrow() {
);
for (let i = 1; i < oneOffButtons.length / 2; i++) {
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton, true)
);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
}
// Now click out of search mode.
await UrlbarTestUtils.exitSearchMode(win, { clickClose: true });
await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
// Now check for the remaining one-offs' search mode previews.
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
while (oneOffs.selectedButton) {
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton, true)
);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
}
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.assertSearchMode(win, null);
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.assertSearchMode(window, null);
});
// Tests that the original search mode is preserved when going through some
@ -429,62 +424,62 @@ add_task(async function fullSearchMode_oneOff_restore_on_down() {
await updateTopSites(sites => sites?.length > 2, false);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
});
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(win);
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window);
let oneOffButtons = oneOffs.getSelectableButtons(true);
await TestUtils.waitForCondition(
() => !oneOffs._rebuilding,
"Waiting for one-offs to finish rebuilding"
);
await UrlbarTestUtils.enterSearchMode(win, {
await UrlbarTestUtils.enterSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.HISTORY,
});
let expectedSearchMode = getExpectedSearchMode(
oneOffButtons.find(b => b.source == UrlbarUtils.RESULT_SOURCE.HISTORY),
false
);
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
info("Down to the first result");
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
info("Alt+down to the first one-off.");
Assert.greater(
oneOffButtons.length,
1,
"Sanity check: We should have at least two one-offs."
);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton, true)
);
info("Go again down through the list of results");
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
await UrlbarTestUtils.assertSearchMode(win, expectedSearchMode);
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode);
// Now do a similar test without initial search mode.
info("Exit search mode.");
await UrlbarTestUtils.exitSearchMode(win);
await UrlbarTestUtils.exitSearchMode(window);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
window,
value: "",
});
info("Down to the first result");
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
await UrlbarTestUtils.assertSearchMode(win, null);
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.assertSearchMode(window, null);
info("select a one-off to start preview");
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true });
await UrlbarTestUtils.assertSearchMode(
win,
window,
getExpectedSearchMode(oneOffs.selectedButton, true)
);
info("Go again through the list of results");
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
await UrlbarTestUtils.assertSearchMode(win, null);
EventUtils.synthesizeKey("KEY_ArrowDown");
await UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.promisePopupClose(win);
await UrlbarTestUtils.promisePopupClose(window);
await PlacesUtils.history.clear();
});

Просмотреть файл

@ -13,9 +13,27 @@ const TEST_ENGINE_NAME = "Test";
const TEST_ENGINE_ALIAS = "@test";
const TEST_ENGINE_DOMAIN = "example.com";
function copyToClipboard(str) {
return new Promise((resolve, reject) => {
waitForClipboard(
str,
() => {
Cc["@mozilla.org/widget/clipboardhelper;1"]
.getService(Ci.nsIClipboardHelper)
.copyString(str);
},
resolve,
reject
);
});
}
// Each test is a function that executes an urlbar action and returns the
// expected event object.
// expected event object, or null if no event is expected.
const tests = [
/*
* Engagement tests.
*/
async function(win) {
info("Type something, press Enter.");
win.gURLBar.select();
@ -114,7 +132,7 @@ const tests = [
.selectedButton;
selectedOneOff.click();
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: selectedOneOff.engine.name,
entry: "oneoff",
});
@ -286,7 +304,7 @@ const tests = [
win.gURLBar.select();
const promise = BrowserTestUtils.waitForDocLoadAndStopIt(
"https://www.example.com/",
win.gBrowser.selectedBrowser
gBrowser.selectedBrowser
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
@ -525,7 +543,7 @@ const tests = [
value: `${alias} `,
});
await UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: "AliasTest",
entry: "typed",
});
@ -858,7 +876,7 @@ const tests = [
info("Open search mode with a keyboard shortcut.");
let defaultEngine = await Services.search.getDefault();
win.gURLBar.select();
EventUtils.synthesizeKey("k", { accelKey: true }, win);
EventUtils.synthesizeKey("k", { accelKey: true });
await UrlbarTestUtils.assertSearchMode(win, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: defaultEngine.name,
@ -917,9 +935,9 @@ const tests = [
);
// Select the tab-to-search result.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
EventUtils.synthesizeKey("KEY_ArrowDown");
let searchPromise = UrlbarTestUtils.promiseSearchComplete(win);
EventUtils.synthesizeKey("KEY_Enter", {}, win);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
engineName: TEST_ENGINE_NAME,
@ -1104,6 +1122,248 @@ const tests = [
},
};
},
/*
* Abandonment tests.
*/
async function(win) {
info("Type something, blur.");
win.gURLBar.select();
EventUtils.synthesizeKey("x", {}, win);
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "typed",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "1",
numWords: "1",
},
};
},
async function(win) {
info("Open the panel with DOWN, don't type, blur it.");
await addTopSite("http://example.org/");
win.gURLBar.value = "";
win.gURLBar.select();
await UrlbarTestUtils.promisePopupOpen(win, () => {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
});
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "topsites",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info("With pageproxystate=valid, autoopen the panel, don't type, blur it.");
win.gURLBar.value = "";
await UrlbarTestUtils.promisePopupOpen(win, () => {
win.document.getElementById("Browser:OpenLocation").doCommand();
});
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "topsites",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info("Enter search mode from Top Sites.");
await updateTopSites(sites => true, /* enableSearchShorcuts */ true);
win.gURLBar.value = "";
win.gURLBar.select();
await UrlbarTestUtils.promisePopupOpen(win, () => {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
});
while (win.gURLBar.searchMode?.engineName != "Google") {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
}
let element = UrlbarTestUtils.getSelectedRow(win);
Assert.ok(
element.result.source == UrlbarUtils.RESULT_SOURCE.SEARCH,
"The selected result is a search Top Site."
);
let engine = element.result.payload.engine;
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(element, {}, win);
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
engineName: engine,
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
entry: "topsites_urlbar",
});
await UrlbarTestUtils.exitSearchMode(win);
// To avoid needing to add a custom search shortcut Top Site, we just
// abandon this interaction.
await UrlbarTestUtils.promisePopupClose(win, () => {
win.gURLBar.blur();
});
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "topsites",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info("Open search mode from a tab-to-search result.");
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.tabToSearch.onboard.interactionsLeft", 0]],
});
await PlacesUtils.history.clear();
for (let i = 0; i < 3; i++) {
await PlacesTestUtils.addVisits([`https://${TEST_ENGINE_DOMAIN}/`]);
}
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
value: TEST_ENGINE_DOMAIN.slice(0, 4),
});
let tabToSearchResult = (
await UrlbarTestUtils.waitForAutocompleteResultAt(win, 1)
).result;
Assert.equal(
tabToSearchResult.providerName,
"TabToSearch",
"The second result is a tab-to-search result."
);
// Select the tab-to-search result.
EventUtils.synthesizeKey("KEY_ArrowDown");
let searchPromise = UrlbarTestUtils.promiseSearchComplete(win);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
engineName: TEST_ENGINE_NAME,
entry: "tabtosearch",
});
// Abandon the interaction since simply entering search mode is not
// considered the end of an engagement.
await UrlbarTestUtils.promisePopupClose(win, () => {
win.gURLBar.blur();
});
await PlacesUtils.history.clear();
await SpecialPowers.popPrefEnv();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "typed",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info(
"With pageproxystate=invalid, open retained results, don't type, blur it."
);
win.gURLBar.value = "mochi.test";
win.gURLBar.setPageProxyState("invalid");
await UrlbarTestUtils.promisePopupOpen(win, () => {
win.document.getElementById("Browser:OpenLocation").doCommand();
});
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "returned",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "10",
numWords: "1",
},
};
},
];
const noEventTests = [
async function(win) {
info("Type something, click on search settings.");
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "about:blank" },
async browser => {
win.gURLBar.select();
let promise = BrowserTestUtils.browserLoaded(browser);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
value: "x",
fireInputEvent: true,
});
UrlbarTestUtils.getOneOffSearchButtons(
win
).settingsButtonCompact.click();
await promise;
}
);
return null;
},
async function(win) {
info("Type something, Up, Enter on search settings.");
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "about:blank" },
async browser => {
win.gURLBar.select();
let promise = BrowserTestUtils.browserLoaded(browser);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
value: "x",
fireInputEvent: true,
});
EventUtils.synthesizeKey("KEY_ArrowUp", {}, win);
Assert.ok(
UrlbarTestUtils.getOneOffSearchButtons(
win
).selectedButton.classList.contains("search-setting-button"),
"Should have selected the settings button"
);
EventUtils.synthesizeKey("VK_RETURN", {}, win);
await promise;
}
);
return null;
},
];
add_task(async function test() {
@ -1140,15 +1400,35 @@ add_task(async function test() {
keyword: "kw",
url: "http://example.com/?q=%s",
});
await PlacesTestUtils.addVisits([
{
uri: "http://mochi.test:8888/",
transition: PlacesUtils.history.TRANSITIONS.TYPED,
},
]);
const win = await BrowserTestUtils.openNewBrowserWindow();
// This test used to rely on the initial timer of
// TestUtils.waitForCondition. See bug 1667216.
let originalWaitForCondition = TestUtils.waitForCondition;
TestUtils.waitForCondition = async function(
condition,
msg,
interval = 100,
maxTries = 50
) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(resolve => setTimeout(resolve, 100));
return originalWaitForCondition(condition, msg, interval, maxTries);
};
registerCleanupFunction(async function() {
await Services.search.setDefault(oldDefaultEngine);
await PlacesUtils.keywords.remove("kw");
await PlacesUtils.bookmarks.remove(bm);
await PlacesUtils.history.clear();
await UrlbarTestUtils.formHistory.clear(win);
await UrlbarTestUtils.formHistory.clear(window);
TestUtils.waitForCondition = originalWaitForCondition;
});
// This is not necessary after each loop, because assertEvents does it.
@ -1156,18 +1436,24 @@ add_task(async function test() {
for (let i = 0; i < tests.length; i++) {
info(`Running test at index ${i}`);
let events = await tests[i](win);
let events = await tests[i](window);
if (!Array.isArray(events)) {
events = [events];
}
// Always blur to ensure it's not accounted as an additional abandonment.
win.gURLBar.setSearchMode({});
win.gURLBar.blur();
window.gURLBar.setSearchMode({});
gURLBar.blur();
TelemetryTestUtils.assertEvents(events, { category: "urlbar" });
await UrlbarTestUtils.formHistory.clear(win);
await UrlbarTestUtils.formHistory.clear(window);
}
await BrowserTestUtils.closeWindow(win);
for (let i = 0; i < noEventTests.length; i++) {
info(`Running no event test at index ${i}`);
await noEventTests[i](window);
// Always blur to ensure it's not accounted as an additional abandonment.
gURLBar.blur();
TelemetryTestUtils.assertEvents([], { category: "urlbar" });
}
});
/**

Просмотреть файл

@ -1,283 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
const TEST_ENGINE_NAME = "Test";
const TEST_ENGINE_ALIAS = "@test";
const TEST_ENGINE_DOMAIN = "example.com";
// Each test is a function that executes an urlbar action and returns the
// expected event object.
const tests = [
async function(win) {
info("Type something, blur.");
win.gURLBar.select();
EventUtils.synthesizeKey("x", {}, win);
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "typed",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "1",
numWords: "1",
},
};
},
async function(win) {
info("Open the panel with DOWN, don't type, blur it.");
await addTopSite("http://example.org/");
win.gURLBar.value = "";
win.gURLBar.select();
await UrlbarTestUtils.promisePopupOpen(win, () => {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
});
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "topsites",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info("With pageproxystate=valid, autoopen the panel, don't type, blur it.");
win.gURLBar.value = "";
await UrlbarTestUtils.promisePopupOpen(win, () => {
win.document.getElementById("Browser:OpenLocation").doCommand();
});
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "topsites",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info("Enter search mode from Top Sites.");
await updateTopSites(sites => true, /* enableSearchShorcuts */ true);
win.gURLBar.value = "";
win.gURLBar.select();
await UrlbarTestUtils.promisePopupOpen(win, () => {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
});
while (win.gURLBar.searchMode?.engineName != "Google") {
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
}
let element = UrlbarTestUtils.getSelectedRow(win);
Assert.ok(
element.result.source == UrlbarUtils.RESULT_SOURCE.SEARCH,
"The selected result is a search Top Site."
);
let engine = element.result.payload.engine;
let searchPromise = UrlbarTestUtils.promiseSearchComplete(win);
EventUtils.synthesizeMouseAtCenter(element, {}, win);
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
engineName: engine,
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
entry: "topsites_urlbar",
});
await UrlbarTestUtils.exitSearchMode(win);
// To avoid needing to add a custom search shortcut Top Site, we just
// abandon this interaction.
await UrlbarTestUtils.promisePopupClose(win, () => {
win.gURLBar.blur();
});
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "topsites",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info("Open search mode from a tab-to-search result.");
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.tabToSearch.onboard.interactionsLeft", 0]],
});
await PlacesUtils.history.clear();
for (let i = 0; i < 3; i++) {
await PlacesTestUtils.addVisits([`https://${TEST_ENGINE_DOMAIN}/`]);
}
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
value: TEST_ENGINE_DOMAIN.slice(0, 4),
});
let tabToSearchResult = (
await UrlbarTestUtils.waitForAutocompleteResultAt(win, 1)
).result;
Assert.equal(
tabToSearchResult.providerName,
"TabToSearch",
"The second result is a tab-to-search result."
);
// Select the tab-to-search result.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
let searchPromise = UrlbarTestUtils.promiseSearchComplete(win);
EventUtils.synthesizeKey("KEY_Enter", {}, win);
await searchPromise;
await UrlbarTestUtils.assertSearchMode(win, {
engineName: TEST_ENGINE_NAME,
entry: "tabtosearch",
});
// Abandon the interaction since simply entering search mode is not
// considered the end of an engagement.
await UrlbarTestUtils.promisePopupClose(win, () => {
win.gURLBar.blur();
});
await PlacesUtils.history.clear();
await SpecialPowers.popPrefEnv();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "typed",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
},
};
},
async function(win) {
info(
"With pageproxystate=invalid, open retained results, don't type, blur it."
);
win.gURLBar.value = "mochi.test";
win.gURLBar.setPageProxyState("invalid");
await UrlbarTestUtils.promisePopupOpen(win, () => {
win.document.getElementById("Browser:OpenLocation").doCommand();
});
win.gURLBar.blur();
return {
category: "urlbar",
method: "abandonment",
object: "blur",
value: "returned",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "10",
numWords: "1",
},
};
},
];
add_task(async function test() {
await PlacesUtils.history.clear();
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.eventTelemetry.enabled", true]],
});
// Create a new search engine and mark it as default
let engine = await SearchTestUtils.promiseNewSearchEngine(
getRootDirectory(gTestPath) + "searchSuggestionEngine.xml"
);
let oldDefaultEngine = await Services.search.getDefault();
await Services.search.setDefault(engine);
await Services.search.moveEngine(engine, 0);
await SearchTestUtils.installSearchExtension({
name: TEST_ENGINE_NAME,
keyword: TEST_ENGINE_ALIAS,
search_url: `https://${TEST_ENGINE_DOMAIN}/`,
});
// This test used to rely on the initial timer of
// TestUtils.waitForCondition. See bug 1667216.
let originalWaitForCondition = TestUtils.waitForCondition;
TestUtils.waitForCondition = async function(
condition,
msg,
interval = 100,
maxTries = 50
) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(resolve => setTimeout(resolve, 100));
return originalWaitForCondition(condition, msg, interval, maxTries);
};
const win = await BrowserTestUtils.openNewBrowserWindow();
registerCleanupFunction(async function() {
await Services.search.setDefault(oldDefaultEngine);
await PlacesUtils.history.clear();
await UrlbarTestUtils.formHistory.clear(win);
TestUtils.waitForCondition = originalWaitForCondition;
});
// This is not necessary after each loop, because assertEvents does it.
Services.telemetry.clearEvents();
for (let i = 0; i < tests.length; i++) {
info(`Running test at index ${i}`);
let events = await tests[i](win);
if (!Array.isArray(events)) {
events = [events];
}
// Always blur to ensure it's not accounted as an additional abandonment.
win.gURLBar.setSearchMode({});
win.gURLBar.blur();
TelemetryTestUtils.assertEvents(events, { category: "urlbar" });
await UrlbarTestUtils.formHistory.clear(win);
}
await BrowserTestUtils.closeWindow(win);
});
/**
* Replaces the contents of Top Sites with the specified site.
* @param {string} site
* A site to add to Top Sites.
*/
async function addTopSite(site) {
await PlacesUtils.history.clear();
for (let i = 0; i < 5; i++) {
await PlacesTestUtils.addVisits(site);
}
await updateTopSites(sites => sites && sites[0] && sites[0].url == site);
}

Просмотреть файл

@ -1,72 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const tests = [
async function(win) {
info("Type something, click on search settings.");
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "about:blank" },
async browser => {
win.gURLBar.select();
let promise = BrowserTestUtils.browserLoaded(browser);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
value: "x",
fireInputEvent: true,
});
UrlbarTestUtils.getOneOffSearchButtons(win).settingsButton.click();
await promise;
}
);
return null;
},
async function(win) {
info("Type something, Up, Enter on search settings.");
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "about:blank" },
async browser => {
win.gURLBar.select();
let promise = BrowserTestUtils.browserLoaded(browser);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,
value: "x",
fireInputEvent: true,
});
EventUtils.synthesizeKey("KEY_ArrowUp", {}, win);
Assert.ok(
UrlbarTestUtils.getOneOffSearchButtons(
win
).selectedButton.classList.contains("search-setting-button"),
"Should have selected the settings button"
);
EventUtils.synthesizeKey("VK_RETURN", {}, win);
await promise;
}
);
return null;
},
];
add_task(async function test() {
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.eventTelemetry.enabled", true]],
});
const win = await BrowserTestUtils.openNewBrowserWindow();
// This is not necessary after each loop, because assertEvents does it.
Services.telemetry.clearEvents();
for (let i = 0; i < tests.length; i++) {
info(`Running no event test at index ${i}`);
await tests[i](win);
// Always blur to ensure it's not accounted as an additional abandonment.
win.gURLBar.blur();
TelemetryTestUtils.assertEvents([], { category: "urlbar" });
}
await BrowserTestUtils.closeWindow(win);
});