Bug 1383720 - Only show http and https sites in Top Sites r=Mardak
authorUrsula Sarracini
Thu, 27 Jul 2017 15:41:56 -0400
changeset 420197 4e92ebe6256dbc4776c569004aa416a5ed1f200e
parent 420196 d55e2461a61cf812448504ff23e89f9313d6c442
child 420198 59e214139531f8aaf544d93f9fba0a77d6efa554
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1383720
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1383720 - Only show http and https sites in Top Sites r=Mardak 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);