Bug 1383720 - Only show http and https sites in Top Sites draft
authorUrsula Sarracini
Thu, 27 Jul 2017 15:41:56 -0400
changeset 617046 fa1fbfd2dcf18b98c7b7c01e05216d4f01d7287c
parent 616724 658cba6a971257e2ba39715ec938256dfc414776
child 639674 5abb28a1ebeba4def05f7ebd61e27a5232bff208
push id70899
push userusarracini@mozilla.com
push dateThu, 27 Jul 2017 19:42:22 +0000
bugs1383720
milestone56.0a1
Bug 1383720 - Only show http and https sites in Top Sites MozReview-Commit-ID: 2NNoKO9BJvo
toolkit/modules/NewTabUtils.jsm
toolkit/modules/tests/xpcshell/test_NewTabUtils.js
--- 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);