Bug 1383720 - Only show http and https sites in Top Sites
MozReview-Commit-ID: 2NNoKO9BJvo
--- a/toolkit/modules/NewTabUtils.jsm
+++ b/toolkit/modules/NewTabUtils.jsm
@@ -956,16 +956,17 @@ var ActivityStreamProvider = {
frecency,
last_visit_date,
moz_places.guid AS guid,
moz_bookmarks.guid AS bookmarkGuid
FROM moz_places
LEFT JOIN moz_bookmarks
on moz_places.id = moz_bookmarks.fk
WHERE hidden = 0 AND last_visit_date NOTNULL
+ AND (SUBSTR(moz_places.url, 1, 6) == "https:" OR SUBSTR(moz_places.url, 1, 5) == "http:")
ORDER BY frecency, last_visit_date, moz_places.url DESC
) GROUP BY rev_host)
GROUP BY rev_nowww
ORDER BY frecency DESC, lastVisitDate DESC, url
LIMIT ${limit}`;
let links = await this.executePlacesQuery(sqlQuery, {
columns: [
--- a/toolkit/modules/tests/xpcshell/test_NewTabUtils.js
+++ b/toolkit/modules/tests/xpcshell/test_NewTabUtils.js
@@ -413,16 +413,43 @@ add_task(async function getTopFrencentSi
await PlacesTestUtils.addVisits(testURI);
}
let links = await provider.getTopSites();
Assert.ok(links.length < MANY_LINKS, "query default limited to less than many");
Assert.ok(links.length > 6, "query default to more than visible count");
});
+add_task(async function getTopFrencentSites_allowedProtocols() {
+ await setUpActivityStreamTest();
+
+ let provider = NewTabUtils.activityStreamLinks;
+
+ // add a visit from a file:// site
+ let testURI = "file:///some/file/path.png";
+ await PlacesTestUtils.addVisits(testURI);
+
+ let links = await provider.getTopSites();
+ Assert.equal(links.length, 0, "don't get sites with the file:// protocol");
+
+ // now add a site with an allowed protocol
+ testURI = "http://www.mozilla.com";
+ await PlacesTestUtils.addVisits(testURI);
+
+ links = await provider.getTopSites();
+ Assert.equal(links.length, 1, "http:// is an allowed protocol");
+
+ // and just to be sure, add a visit to a site with ftp:// protocol
+ testURI = "ftp://bad/example";
+ await PlacesTestUtils.addVisits(testURI);
+
+ links = await provider.getTopSites();
+ Assert.equal(links.length, 1, "we still only accept http:// and https:// for top sites");
+});
+
add_task(async function getTopFrecentSites_order() {
await setUpActivityStreamTest();
let provider = NewTabUtils.activityStreamLinks;
let {TRANSITION_TYPED} = PlacesUtils.history;
let timeEarlier = timeDaysAgo(0);
let timeLater = timeDaysAgo(2);