зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1480888 - Implement blocking system for special search shortcut top sites r=k88hudson
Differential Revision: https://phabricator.services.mozilla.com/D3035 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c036fd8591
Коммит
130d05505f
|
@ -4,6 +4,9 @@ ChromeUtils.import("resource://gre/modules/PlacesUtils.jsm");
|
|||
ChromeUtils.import("resource://gre/modules/NewTabUtils.jsm");
|
||||
ChromeUtils.import("resource://testing-common/PlacesTestUtils.jsm");
|
||||
|
||||
// Disable top site search shortcuts for this test
|
||||
Services.prefs.setBoolPref("browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts", false);
|
||||
|
||||
// A small 1x1 test png
|
||||
const IMAGE_1x1 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ const image96x96 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAJCAYAAA
|
|||
const baseURL = "http://mozilla${i}.com/";
|
||||
|
||||
function* runTests() {
|
||||
yield SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts", false]]
|
||||
});
|
||||
// Add 3 top sites - 2 visits each so it can pass frecency threshold of the top sites query
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
yield PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
|
|
|
@ -10,6 +10,18 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.importGlobalProperties(["btoa", "URL"]);
|
||||
|
||||
// Android tests don't import these properly, so guard against that
|
||||
let shortURL = {};
|
||||
let searchShortcuts = {};
|
||||
let didSuccessfulImport = false;
|
||||
try {
|
||||
ChromeUtils.import("resource://activity-stream/lib/ShortURL.jsm", shortURL);
|
||||
ChromeUtils.import("resource://activity-stream/lib/SearchShortcuts.jsm", searchShortcuts);
|
||||
didSuccessfulImport = true;
|
||||
} catch (e) {
|
||||
// The test failed to import these files
|
||||
}
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm");
|
||||
|
||||
|
@ -1170,6 +1182,16 @@ var ActivityStreamProvider = {
|
|||
map.set(host, link);
|
||||
}
|
||||
|
||||
// Convert all links that are supposed to be a seach shortcut to its canonical URL
|
||||
if (didSuccessfulImport && Services.prefs.getBoolPref(`browser.newtabpage.activity-stream.${searchShortcuts.SEARCH_SHORTCUTS_EXPERIMENT}`)) {
|
||||
links.forEach(link => {
|
||||
let searchProvider = searchShortcuts.getSearchProvider(shortURL.shortURL(link));
|
||||
if (searchProvider) {
|
||||
link.url = searchProvider.url;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Remove any blocked links.
|
||||
if (!options.ignoreBlocked) {
|
||||
links = links.filter(link => !BlockedLinks.isBlocked(link));
|
||||
|
|
|
@ -10,12 +10,14 @@ ChromeUtils.defineModuleGetter(this, "PlacesUtils",
|
|||
"resource://gre/modules/PlacesUtils.jsm");
|
||||
|
||||
const PREF_NEWTAB_ENHANCED = "browser.newtabpage.enhanced";
|
||||
const SEARCH_SHORTCUTS_EXPERIMENT_PREF = "browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts";
|
||||
|
||||
// use time at the start of the tests, chnaging it inside timeDaysAgo()
|
||||
// may cause tiny time differences, which break expected sql ordering
|
||||
const TIME_NOW = (new Date()).getTime();
|
||||
|
||||
Services.prefs.setBoolPref(PREF_NEWTAB_ENHANCED, true);
|
||||
Services.prefs.setBoolPref(SEARCH_SHORTCUTS_EXPERIMENT_PREF, false);
|
||||
|
||||
do_get_profile();
|
||||
|
||||
|
|
|
@ -679,6 +679,22 @@ add_task(async function getTopFrecentSites() {
|
|||
Assert.equal(links[0].url, testURI, "added visit corresponds to added url");
|
||||
});
|
||||
|
||||
add_task(async function getTopFrecentSites_improveSearch() {
|
||||
await setUpActivityStreamTest();
|
||||
const SEARCH_SHORTCUTS_EXPERIMENT_PREF = "browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts";
|
||||
Services.prefs.setBoolPref(SEARCH_SHORTCUTS_EXPERIMENT_PREF, true);
|
||||
|
||||
let testURI = "https://www.amazon.com?search=tv";
|
||||
await PlacesTestUtils.addVisits(testURI);
|
||||
|
||||
let provider = NewTabUtils.activityStreamLinks;
|
||||
let links = await provider.getTopSites({topsiteFrecency: 100});
|
||||
Assert.equal(links.length, 1, "sanity check that we got the link from top sites");
|
||||
Assert.equal(links[0].url, "https://amazon.com", "the amazon site was converted to generic search shortcut site");
|
||||
|
||||
Services.prefs.setBoolPref(SEARCH_SHORTCUTS_EXPERIMENT_PREF, false);
|
||||
});
|
||||
|
||||
add_task(async function getTopFrecentSites_no_dedup() {
|
||||
await setUpActivityStreamTest();
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
[DEFAULT]
|
||||
head = head.js
|
||||
firefox-appdir = browser
|
||||
support-files =
|
||||
propertyLists/bug710259_propertyListBinary.plist
|
||||
propertyLists/bug710259_propertyListXML.plist
|
||||
|
|
Загрузка…
Ссылка в новой задаче