Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
fix(mc): Load default sites from a pref that is empty for testing (#2743
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Mardak committed Jun 20, 2017
1 parent f99344e commit 5e8e570
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
18 changes: 18 additions & 0 deletions mozilla-central-patches/disable-as-default-sites.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/testing/profiles/prefs_general.js b/testing/profiles/prefs_general.js
index c9a402c7f197..fe42e9fedad3 100644
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -291,2 +291,5 @@ user_pref("browser.aboutHomeSnippets.updateUrl", "nonexistent://test");

+// Use an empty list of sites to avoid fetching
+user_pref("browser.newtabpage.activity-stream.default.sites", "");
+
// Don't fetch directory tiles data from real servers
diff --git a/testing/talos/talos/config.py b/testing/talos/talos/config.py
index 04d1a27298d6..c84df65032be 100644
--- a/testing/talos/talos/config.py
+++ b/testing/talos/talos/config.py
@@ -94,2 +94,3 @@ DEFAULTS = dict(
'take_over_this_computer': True,
+ 'browser.newtabpage.activity-stream.default.sites': '',
'browser.newtabpage.directory.source':
12 changes: 0 additions & 12 deletions mozilla-central-patches/disable-as-top-sites-feed-tests.diff

This file was deleted.

5 changes: 5 additions & 0 deletions system-addon/lib/ActivityStream.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ XPCOMUtils.defineLazyModuleGetter(this, "TopSitesFeed",
"resource://activity-stream/lib/TopSitesFeed.jsm");

const PREFS_CONFIG = [
{
name: "default.sites",
title: "Comma-separated list of default top sites to fill in behind visited sites",
value: "https://www.facebook.com/,https://www.youtube.com/,https://www.amazon.com/,https://www.yahoo.com/,https://www.ebay.com/,https://twitter.com/"
},
// When you add a feed pref here:
// 1. The pref should be prefixed with "feeds."
// 2. The init property should be a function that instantiates your Feed
Expand Down
23 changes: 15 additions & 8 deletions system-addon/lib/TopSitesFeed.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@

const {utils: Cu} = Components;
const {actionTypes: at, actionCreators: ac} = Cu.import("resource://activity-stream/common/Actions.jsm", {});
const {Prefs} = Cu.import("resource://activity-stream/lib/ActivityStreamPrefs.jsm", {});

Cu.import("resource://gre/modules/NewTabUtils.jsm");
Cu.import("resource:///modules/PreviewProvider.jsm");

const TOP_SITES_SHOWMORE_LENGTH = 12;
const UPDATE_TIME = 15 * 60 * 1000; // 15 minutes
const DEFAULT_TOP_SITES = [
{"url": "https://www.facebook.com/"},
{"url": "https://www.youtube.com/"},
{"url": "http://www.amazon.com/"},
{"url": "https://www.yahoo.com/"},
{"url": "http://www.ebay.com"},
{"url": "https://twitter.com/"}
].map(row => Object.assign(row, {isDefault: true}));
const DEFAULT_TOP_SITES = [];

// Add default sites if any based on the pref
try {
let sites = new Prefs().get("default.sites").split(",");
sites.filter(url => url).forEach(url => {
DEFAULT_TOP_SITES.push({
isDefault: true,
url
});
});
} catch (e) {
// Use no defaults if something went wrong
}

this.TopSitesFeed = class TopSitesFeed {
constructor() {
Expand Down
10 changes: 8 additions & 2 deletions system-addon/test/unit/lib/TopSitesFeed.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use strict";
const {TopSitesFeed, UPDATE_TIME, TOP_SITES_SHOWMORE_LENGTH, DEFAULT_TOP_SITES} = require("lib/TopSitesFeed.jsm");
const {GlobalOverrider} = require("test/unit/utils");
const injector = require("inject!lib/TopSitesFeed.jsm");
const {UPDATE_TIME, TOP_SITES_SHOWMORE_LENGTH} = require("lib/TopSitesFeed.jsm");
const {FakePrefs, GlobalOverrider} = require("test/unit/utils");
const action = {meta: {fromTarget: {}}};
const {actionTypes: at} = require("common/Actions.jsm");
const FAKE_LINKS = new Array(TOP_SITES_SHOWMORE_LENGTH).fill(null).map((v, i) => ({url: `site${i}.com`}));
const FAKE_SCREENSHOT = "data123";

describe("Top Sites Feed", () => {
let TopSitesFeed;
let DEFAULT_TOP_SITES;
let feed;
let globals;
let sandbox;
Expand All @@ -18,6 +21,8 @@ describe("Top Sites Feed", () => {
sandbox = globals.sandbox;
globals.set("NewTabUtils", {activityStreamLinks: {getTopSites: sandbox.spy(() => Promise.resolve(links))}});
globals.set("PreviewProvider", {getThumbnail: sandbox.spy(() => Promise.resolve(FAKE_SCREENSHOT))});
FakePrefs.prototype.prefs["default.sites"] = "https://foo.com/";
({TopSitesFeed, DEFAULT_TOP_SITES} = injector({"lib/ActivityStreamPrefs.jsm": {Prefs: FakePrefs}}));
feed = new TopSitesFeed();
feed.store = {dispatch: sinon.spy(), getState() { return {TopSites: {rows: Array(12).fill("site")}}; }};
links = FAKE_LINKS;
Expand All @@ -29,6 +34,7 @@ describe("Top Sites Feed", () => {
});

it("should have default sites with .isDefault = true", () => {
assert.ok(DEFAULT_TOP_SITES.length);
DEFAULT_TOP_SITES.forEach(link => assert.propertyVal(link, "isDefault", true));
});

Expand Down

0 comments on commit 5e8e570

Please sign in to comment.