Skip to content

Commit

Permalink
Bug 1647897 - [Quantumbar update 2] Show one-offs when input is empty…
Browse files Browse the repository at this point in the history
…. r=harry

Differential Revision: https://phabricator.services.mozilla.com/D83892
  • Loading branch information
0c0w3 committed Jul 17, 2020
1 parent 10a46d9 commit 5978ac0
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 13 deletions.
4 changes: 3 additions & 1 deletion browser/components/urlbar/UrlbarView.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ class UrlbarView {
// character.
let trimmedValue = queryContext.searchString.trim();
this._enableOrDisableOneOffSearches(
trimmedValue &&
((UrlbarPrefs.get("update2") &&
UrlbarPrefs.get("update2.oneOffsRefresh")) ||
trimmedValue) &&
trimmedValue[0] != "@" &&
(trimmedValue[0] != UrlbarTokenizer.RESTRICT.SEARCH ||
trimmedValue.length != 1)
Expand Down
121 changes: 109 additions & 12 deletions browser/components/urlbar/tests/browser/browser_oneOffs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,121 @@ add_task(async function init() {
await UrlbarTestUtils.formHistory.clear();
});

// Initialize history with enough visits to fill up the view.
await PlacesUtils.history.clear();
await UrlbarTestUtils.formHistory.clear();

let visits = [];
for (let i = 0; i < gMaxResults; i++) {
visits.push({
uri: makeURI("http://example.com/browser_urlbarOneOffs.js/?" + i),
// TYPED so that the visit shows up when the urlbar's drop-down arrow is
// pressed.
transition: Ci.nsINavHistoryService.TRANSITION_TYPED,
});
await PlacesTestUtils.addVisits(
"http://example.com/browser_urlbarOneOffs.js/?" + i
);
}

// Add some more visits to the last URL added above so that the top-sites view
// will be non-empty.
for (let i = 0; i < 5; i++) {
await PlacesTestUtils.addVisits(
"http://example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - 1)
);
}
await PlacesTestUtils.addVisits(visits);
await updateTopSites(sites => {
return sites && sites[0] && sites[0].url.startsWith("http://example.com/");
});
});

// Opens the top-sites view, i.e., the view that's shown when the input hasn't
// been edited. The one-offs should be hidden.
add_task(async function topSitesView() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "",
fireInputEvent: true,
});
Assert.equal(
UrlbarTestUtils.getOneOffSearchButtonsVisible(window),
false,
"One-offs should be hidden"
);
await hidePopup();
});

// Opens the top-sites view with update2 enabled. The one-offs should be shown.
add_task(async function topSitesViewUpdate2() {
// Set the update2 prefs.
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.update2", true],
["browser.urlbar.update2.oneOffsRefresh", true],
],
});

// Do a search.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "",
fireInputEvent: true,
});
await TestUtils.waitForCondition(
() => !oneOffSearchButtons._rebuilding,
"Waiting for one-offs to finish rebuilding"
);

// There's one top sites result, the page with a lot of visits from init.
let resultURL = "example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - 1);
Assert.equal(UrlbarTestUtils.getResultCount(window), 1, "Result count");

Assert.equal(
UrlbarTestUtils.getOneOffSearchButtonsVisible(window),
true,
"One-offs are visible"
);

assertState(-1, -1, "");

// Key down into the result.
EventUtils.synthesizeKey("KEY_ArrowDown");
assertState(0, -1, resultURL);

// Key down through each one-off.
let numButtons = oneOffSearchButtons.getSelectableButtons(true).length;
for (let i = 0; i < numButtons; i++) {
EventUtils.synthesizeKey("KEY_ArrowDown");
assertState(-1, i, "");
}

// Key down again. The selection should go away.
EventUtils.synthesizeKey("KEY_ArrowDown");
assertState(-1, -1, "");

// Key down again. The result should be selected.
EventUtils.synthesizeKey("KEY_ArrowDown");
assertState(0, -1, resultURL);

// Key back up. The selection should go away.
EventUtils.synthesizeKey("KEY_ArrowUp");
assertState(-1, -1, "");

// Key up again. The selection should wrap back around to the one-offs. Key
// up through all the one-offs.
for (let i = numButtons - 1; i >= 0; i--) {
EventUtils.synthesizeKey("KEY_ArrowUp");
assertState(-1, i, "");
}

// Key up. The result should be selected.
EventUtils.synthesizeKey("KEY_ArrowUp");
assertState(0, -1, resultURL);

// Key up again. The selection should go away.
EventUtils.synthesizeKey("KEY_ArrowUp");
assertState(-1, -1, "");

await hidePopup();
await SpecialPowers.popPrefEnv();
});

// Keys up and down through the non-history panel, i.e., the panel that's shown
// when you type something in the textbox.
add_task(async function() {
// Keys up and down through the non-top-sites view, i.e., the view that's shown
// when the input has been edited.
add_task(async function editedView() {
// Use a typed value that returns the visits added above but that doesn't
// trigger autofill since that would complicate the test.
let typedValue = "browser_urlbarOneOffs";
Expand Down

0 comments on commit 5978ac0

Please sign in to comment.