зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1617345 - If top sites are disabled, show the user's most frecent sites instead. r=harry
In other words, for users who have disabled top sites, this restores the history popup we used to show when you clicked the dropmarker or pressed the down arrow key in an empty urlbar. Differential Revision: https://phabricator.services.mozilla.com/D64286 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
2f59f29d27
Коммит
aa97780410
|
@ -16,6 +16,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
PlacesSearchAutocompleteProvider:
|
||||
"resource://gre/modules/PlacesSearchAutocompleteProvider.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
|
||||
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
|
||||
UrlbarProviderOpenTabs: "resource:///modules/UrlbarProviderOpenTabs.jsm",
|
||||
|
@ -69,13 +70,18 @@ class ProviderTopSites extends UrlbarProvider {
|
|||
* @returns {boolean} Whether this provider should be invoked for the search.
|
||||
*/
|
||||
isActive(queryContext) {
|
||||
// We don't want to show Top sites in private windows or if they are
|
||||
// disabled in about:newtab, but the provider is not disabled in those cases
|
||||
// because the user may still want to show them by pressing down.
|
||||
// If top sites on new tab are disabled, the pref below will be false, and
|
||||
// activity stream's top sites will be unavailable (an empty array), so we
|
||||
// make this provider inactive. For empty search strings, we instead show
|
||||
// the most frecent URLs in the user's history from the UnifiedComplete
|
||||
// provider.
|
||||
return (
|
||||
UrlbarPrefs.get("update1") &&
|
||||
UrlbarPrefs.get("openViewOnFocus") &&
|
||||
!queryContext.searchString
|
||||
!queryContext.searchString &&
|
||||
Services.prefs.getBoolPref(
|
||||
"browser.newtabpage.activity-stream.feeds.topsites"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -188,3 +188,65 @@ add_task(async function topSitesBookmarksAndTabs() {
|
|||
window.gURLBar.blur();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function topSitesDisabled() {
|
||||
// Disable top sites.
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.newtabpage.activity-stream.feeds.topsites", false]],
|
||||
});
|
||||
|
||||
// Add some visits.
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
let urlCount = 5;
|
||||
for (let i = 0; i < urlCount; i++) {
|
||||
await PlacesTestUtils.addVisits(`http://example.com/${i}`);
|
||||
}
|
||||
|
||||
// Open the view.
|
||||
await UrlbarTestUtils.promisePopupOpen(window, () => {
|
||||
EventUtils.synthesizeMouseAtCenter(window.gURLBar.inputField, {});
|
||||
});
|
||||
Assert.ok(window.gURLBar.view.isOpen, "UrlbarView should be open.");
|
||||
await UrlbarTestUtils.promiseSearchComplete(window);
|
||||
|
||||
// Check the results. We should show the most frecent sites from history via
|
||||
// the UnifiedComplete provider.
|
||||
Assert.equal(
|
||||
UrlbarTestUtils.getResultCount(window),
|
||||
urlCount,
|
||||
"The number of results should be the same as the number of URLs added"
|
||||
);
|
||||
|
||||
for (let i = 0; i < urlCount; i++) {
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
|
||||
Assert.equal(
|
||||
result.url,
|
||||
`http://example.com/${urlCount - i - 1}`,
|
||||
`Expected URL at index ${i}`
|
||||
);
|
||||
Assert.equal(
|
||||
result.source,
|
||||
UrlbarUtils.RESULT_SOURCE.HISTORY,
|
||||
"The result should be from history"
|
||||
);
|
||||
Assert.equal(
|
||||
result.type,
|
||||
UrlbarUtils.RESULT_TYPE.URL,
|
||||
"The result should be a URL"
|
||||
);
|
||||
Assert.strictEqual(
|
||||
result.heuristic,
|
||||
false,
|
||||
"The result should not be heuristic"
|
||||
);
|
||||
}
|
||||
|
||||
await UrlbarTestUtils.promisePopupClose(window, () => {
|
||||
window.gURLBar.blur();
|
||||
});
|
||||
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче