Skip to content

Instantly share code, notes, and snippets.

{
"spocs": {
"url": "https://getpocket.cdn.mozilla.net/v3/firefox/global-recs?version=3&consumer_key=40249-e88c401e1b1f2242d9e441c4&locale_lang=en-US&feed_variant=default_spocs_on"
},
"layout": [
{
"width": 12,
"components": [
{
"type": "TopSites",
setTimeout(callback, delay) {
try {
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(callback, delay, Ci.nsITimer.TYPE_ONE_SHOT);
return timer;
} catch (e) {
console.log("error", e);
}
return null;
}
const {setTimeout} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
async fetchFromEndpoint(endpoint) {
if (!endpoint) {
Cu.reportError("Tried to fetch endpoint but none was configured.");
return null;
}
try {
// Make sure the requested endpoint is allowed
const allowed = this.store.getState().Prefs.values[PREF_ENDPOINTS].split(",");
async addBookmark(action) {
const {url} = action.data;
let data;
try {
// Check if url is an existing bookmark
data = await PlacesUtils.bookmarks.fetch({url});
} catch (err) {
Cu.reportError(err);
}
{
"spocs": {
"url": "https://getpocket.cdn.mozilla.net/v3/firefox/unique-spocs?consumer_key=40249-e88c401e1b1f2242d9e441c4",
"spocs_per_domain": 1
},
"layout": [
{
"width": 12,
"components": [
{
{
"spocs": {
"url": "https://getpocket.cdn.mozilla.net/v3/firefox/unique-spocs?consumer_key=40249-e88c401e1b1f2242d9e441c4",
"spocs_per_domain": 1
},
"layout": [
{
"width": 12,
"components": [
{
{
"spocs": {
"url": "https://getpocket.cdn.mozilla.net/v3/firefox/unique-spocs?consumer_key=40249-e88c401e1b1f2242d9e441c4",
"spocs_per_domain": 1
},
"layout": [
{
"width": 12,
"components": [
{
it.only(""SpocsFill - Spocs displayed with multiple out_of_position", () => {
const fakeSpocConfig = {positions: [{index: 0}, {index: 1}, {index: 2}], probability: 0.5};
const fakeLayout = [{width: 3, components: [{type: "foo", feed: {url: "foo.com"}, spocs: fakeSpocConfig}]}];
const fakeSpocsData = {lastUpdated: 0, spocs: {spocs: ["fooSpoc", "barSpoc", "lastSpoc"]}};
store.dispatch({type: at.DISCOVERY_STREAM_LAYOUT_UPDATE, data: {layout: fakeLayout}});
store.dispatch({type: at.DISCOVERY_STREAM_FEEDS_UPDATE, data: FAKE_FEEDS});
store.dispatch({type: at.DISCOVERY_STREAM_SPOCS_UPDATE, data: fakeSpocsData});
const randomStub = globals.sandbox.stub(global.Math, "random");
it.only(“SpocsFill - Not displayed spocs with reason as probability_selection and out_of_position”, () => {
const fakeSpocConfig = {positions: [{index: 0}, {index: 1}, {index: 2}], probability: 0.5};
const fakeLayout = [{width: 3, components: [{type: "foo", feed: {url: "foo.com"}, spocs: fakeSpocConfig}]}];
const fakeSpocsData = {lastUpdated: 0, spocs: {spocs: ["fooSpoc", "barSpoc", "lastSpoc"]}};
store.dispatch({type: at.DISCOVERY_STREAM_LAYOUT_UPDATE, data: {layout: fakeLayout}});
store.dispatch({type: at.DISCOVERY_STREAM_FEEDS_UPDATE, data: FAKE_FEEDS});
store.dispatch({type: at.DISCOVERY_STREAM_SPOCS_UPDATE, data: fakeSpocsData});
const randomStub = globals.sandbox.stub(global.Math, "random");
{
"status": 1,
"settings": {
"spocsPerNewTabs": 1,
"domainAffinityParameterSets": {
"default": {
"recencyFactor": 0.5,
"frequencyFactor": 0.5,
"combinedDomainFactor": 0.5,
"perfectFrequencyVisits": 10,