зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1608520 - Pocket devtools new actions r=gvn
Differential Revision: https://phabricator.services.mozilla.com/D59567 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
be651315aa
Коммит
85af912c6e
|
@ -46,6 +46,10 @@ for (const type of [
|
|||
"DISCOVERY_STREAM_CONFIG_RESET_DEFAULTS",
|
||||
"DISCOVERY_STREAM_CONFIG_SETUP",
|
||||
"DISCOVERY_STREAM_CONFIG_SET_VALUE",
|
||||
"DISCOVERY_STREAM_DEV_EXPIRE_CACHE",
|
||||
"DISCOVERY_STREAM_DEV_IDLE_DAILY",
|
||||
"DISCOVERY_STREAM_DEV_SYNC_RS",
|
||||
"DISCOVERY_STREAM_DEV_SYSTEM_TICK",
|
||||
"DISCOVERY_STREAM_FEEDS_UPDATE",
|
||||
"DISCOVERY_STREAM_FEED_UPDATE",
|
||||
"DISCOVERY_STREAM_IMPRESSION_STATS",
|
||||
|
|
|
@ -86,6 +86,10 @@ export class DiscoveryStreamAdmin extends React.PureComponent {
|
|||
this.restorePrefDefaults = this.restorePrefDefaults.bind(this);
|
||||
this.setConfigValue = this.setConfigValue.bind(this);
|
||||
this.expireCache = this.expireCache.bind(this);
|
||||
this.refreshCache = this.refreshCache.bind(this);
|
||||
this.idleDaily = this.idleDaily.bind(this);
|
||||
this.systemTick = this.systemTick.bind(this);
|
||||
this.syncRemoteSettings = this.syncRemoteSettings.bind(this);
|
||||
this.changeEndpointVariant = this.changeEndpointVariant.bind(this);
|
||||
this.onStoryToggle = this.onStoryToggle.bind(this);
|
||||
this.state = {
|
||||
|
@ -110,7 +114,7 @@ export class DiscoveryStreamAdmin extends React.PureComponent {
|
|||
);
|
||||
}
|
||||
|
||||
expireCache() {
|
||||
refreshCache() {
|
||||
const { config } = this.props.state;
|
||||
this.props.dispatch(
|
||||
ac.OnlyToMain({
|
||||
|
@ -120,6 +124,30 @@ export class DiscoveryStreamAdmin extends React.PureComponent {
|
|||
);
|
||||
}
|
||||
|
||||
dispatchSimpleAction(type) {
|
||||
this.props.dispatch(
|
||||
ac.OnlyToMain({
|
||||
type,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
systemTick() {
|
||||
this.dispatchSimpleAction(at.DISCOVERY_STREAM_DEV_SYSTEM_TICK);
|
||||
}
|
||||
|
||||
expireCache() {
|
||||
this.dispatchSimpleAction(at.DISCOVERY_STREAM_DEV_EXPIRE_CACHE);
|
||||
}
|
||||
|
||||
idleDaily() {
|
||||
this.dispatchSimpleAction(at.DISCOVERY_STREAM_DEV_IDLE_DAILY);
|
||||
}
|
||||
|
||||
syncRemoteSettings() {
|
||||
this.dispatchSimpleAction(at.DISCOVERY_STREAM_DEV_SYNC_RS);
|
||||
}
|
||||
|
||||
changeEndpointVariant(event) {
|
||||
const endpoint = this.props.state.config.layout_endpoint;
|
||||
if (endpoint) {
|
||||
|
@ -279,8 +307,22 @@ export class DiscoveryStreamAdmin extends React.PureComponent {
|
|||
<button className="button" onClick={this.restorePrefDefaults}>
|
||||
Restore Pref Defaults
|
||||
</button>{" "}
|
||||
<button className="button" onClick={this.refreshCache}>
|
||||
Refresh Cache
|
||||
</button>
|
||||
<br />
|
||||
<button className="button" onClick={this.expireCache}>
|
||||
Expire Cache
|
||||
</button>{" "}
|
||||
<button className="button" onClick={this.systemTick}>
|
||||
Trigger System Tick
|
||||
</button>{" "}
|
||||
<button className="button" onClick={this.idleDaily}>
|
||||
Trigger Idle Daily
|
||||
</button>
|
||||
<br />
|
||||
<button className="button" onClick={this.syncRemoteSettings}>
|
||||
Sync Remote Settings
|
||||
</button>
|
||||
<table>
|
||||
<tbody>
|
||||
|
|
|
@ -194,7 +194,7 @@ const globalImportContext = typeof Window === "undefined" ? BACKGROUND_PROCESS :
|
|||
// }
|
||||
const actionTypes = {};
|
||||
|
||||
for (const type of ["ADDONS_INFO_REQUEST", "ADDONS_INFO_RESPONSE", "ARCHIVE_FROM_POCKET", "AS_ROUTER_INITIALIZED", "AS_ROUTER_PREF_CHANGED", "AS_ROUTER_TARGETING_UPDATE", "AS_ROUTER_TELEMETRY_USER_EVENT", "BLOCK_URL", "BOOKMARK_URL", "CLEAR_PREF", "COPY_DOWNLOAD_LINK", "DELETE_BOOKMARK_BY_ID", "DELETE_FROM_POCKET", "DELETE_HISTORY_URL", "DIALOG_CANCEL", "DIALOG_OPEN", "DISCOVERY_STREAM_CONFIG_CHANGE", "DISCOVERY_STREAM_CONFIG_RESET_DEFAULTS", "DISCOVERY_STREAM_CONFIG_SETUP", "DISCOVERY_STREAM_CONFIG_SET_VALUE", "DISCOVERY_STREAM_FEEDS_UPDATE", "DISCOVERY_STREAM_FEED_UPDATE", "DISCOVERY_STREAM_IMPRESSION_STATS", "DISCOVERY_STREAM_LAYOUT_RESET", "DISCOVERY_STREAM_LAYOUT_UPDATE", "DISCOVERY_STREAM_LINK_BLOCKED", "DISCOVERY_STREAM_LOADED_CONTENT", "DISCOVERY_STREAM_RETRY_FEED", "DISCOVERY_STREAM_SPOCS_CAPS", "DISCOVERY_STREAM_SPOCS_ENDPOINT", "DISCOVERY_STREAM_SPOCS_FILL", "DISCOVERY_STREAM_SPOCS_PLACEMENTS", "DISCOVERY_STREAM_SPOCS_UPDATE", "DISCOVERY_STREAM_SPOC_BLOCKED", "DISCOVERY_STREAM_SPOC_IMPRESSION", "DOWNLOAD_CHANGED", "FAKE_FOCUS_SEARCH", "FILL_SEARCH_TERM", "HANDOFF_SEARCH_TO_AWESOMEBAR", "HIDE_PRIVACY_INFO", "HIDE_SEARCH", "INIT", "NEW_TAB_INIT", "NEW_TAB_INITIAL_STATE", "NEW_TAB_LOAD", "NEW_TAB_REHYDRATED", "NEW_TAB_STATE_REQUEST", "NEW_TAB_UNLOAD", "OPEN_DOWNLOAD_FILE", "OPEN_LINK", "OPEN_NEW_WINDOW", "OPEN_PRIVATE_WINDOW", "OPEN_WEBEXT_SETTINGS", "PLACES_BOOKMARK_ADDED", "PLACES_BOOKMARK_REMOVED", "PLACES_HISTORY_CLEARED", "PLACES_LINKS_CHANGED", "PLACES_LINK_BLOCKED", "PLACES_LINK_DELETED", "PLACES_SAVED_TO_POCKET", "POCKET_CTA", "POCKET_LINK_DELETED_OR_ARCHIVED", "POCKET_LOGGED_IN", "POCKET_WAITING_FOR_SPOC", "PREFS_INITIAL_VALUES", "PREF_CHANGED", "PREVIEW_REQUEST", "PREVIEW_REQUEST_CANCEL", "PREVIEW_RESPONSE", "REMOVE_DOWNLOAD_FILE", "RICH_ICON_MISSING", "SAVE_SESSION_PERF_DATA", "SAVE_TO_POCKET", "SCREENSHOT_UPDATED", "SECTION_DEREGISTER", "SECTION_DISABLE", "SECTION_ENABLE", "SECTION_MOVE", "SECTION_OPTIONS_CHANGED", "SECTION_REGISTER", "SECTION_UPDATE", "SECTION_UPDATE_CARD", "SETTINGS_CLOSE", "SETTINGS_OPEN", "SET_PREF", "SHOW_DOWNLOAD_FILE", "SHOW_FIREFOX_ACCOUNTS", "SHOW_PRIVACY_INFO", "SHOW_SEARCH", "SKIPPED_SIGNIN", "SNIPPETS_BLOCKLIST_CLEARED", "SNIPPETS_BLOCKLIST_UPDATED", "SNIPPETS_DATA", "SNIPPETS_PREVIEW_MODE", "SNIPPETS_RESET", "SNIPPET_BLOCKED", "SUBMIT_EMAIL", "SUBMIT_SIGNIN", "SYSTEM_TICK", "TELEMETRY_IMPRESSION_STATS", "TELEMETRY_PERFORMANCE_EVENT", "TELEMETRY_UNDESIRED_EVENT", "TELEMETRY_USER_EVENT", "TOP_SITES_CANCEL_EDIT", "TOP_SITES_CLOSE_SEARCH_SHORTCUTS_MODAL", "TOP_SITES_EDIT", "TOP_SITES_INSERT", "TOP_SITES_OPEN_SEARCH_SHORTCUTS_MODAL", "TOP_SITES_PIN", "TOP_SITES_PREFS_UPDATED", "TOP_SITES_UNPIN", "TOP_SITES_UPDATED", "TOTAL_BOOKMARKS_REQUEST", "TOTAL_BOOKMARKS_RESPONSE", "TRAILHEAD_ENROLL_EVENT", "UNINIT", "UPDATE_PINNED_SEARCH_SHORTCUTS", "UPDATE_SEARCH_SHORTCUTS", "UPDATE_SECTION_PREFS", "WEBEXT_CLICK", "WEBEXT_DISMISS"]) {
|
||||
for (const type of ["ADDONS_INFO_REQUEST", "ADDONS_INFO_RESPONSE", "ARCHIVE_FROM_POCKET", "AS_ROUTER_INITIALIZED", "AS_ROUTER_PREF_CHANGED", "AS_ROUTER_TARGETING_UPDATE", "AS_ROUTER_TELEMETRY_USER_EVENT", "BLOCK_URL", "BOOKMARK_URL", "CLEAR_PREF", "COPY_DOWNLOAD_LINK", "DELETE_BOOKMARK_BY_ID", "DELETE_FROM_POCKET", "DELETE_HISTORY_URL", "DIALOG_CANCEL", "DIALOG_OPEN", "DISCOVERY_STREAM_CONFIG_CHANGE", "DISCOVERY_STREAM_CONFIG_RESET_DEFAULTS", "DISCOVERY_STREAM_CONFIG_SETUP", "DISCOVERY_STREAM_CONFIG_SET_VALUE", "DISCOVERY_STREAM_DEV_EXPIRE_CACHE", "DISCOVERY_STREAM_DEV_IDLE_DAILY", "DISCOVERY_STREAM_DEV_SYNC_RS", "DISCOVERY_STREAM_DEV_SYSTEM_TICK", "DISCOVERY_STREAM_FEEDS_UPDATE", "DISCOVERY_STREAM_FEED_UPDATE", "DISCOVERY_STREAM_IMPRESSION_STATS", "DISCOVERY_STREAM_LAYOUT_RESET", "DISCOVERY_STREAM_LAYOUT_UPDATE", "DISCOVERY_STREAM_LINK_BLOCKED", "DISCOVERY_STREAM_LOADED_CONTENT", "DISCOVERY_STREAM_RETRY_FEED", "DISCOVERY_STREAM_SPOCS_CAPS", "DISCOVERY_STREAM_SPOCS_ENDPOINT", "DISCOVERY_STREAM_SPOCS_FILL", "DISCOVERY_STREAM_SPOCS_PLACEMENTS", "DISCOVERY_STREAM_SPOCS_UPDATE", "DISCOVERY_STREAM_SPOC_BLOCKED", "DISCOVERY_STREAM_SPOC_IMPRESSION", "DOWNLOAD_CHANGED", "FAKE_FOCUS_SEARCH", "FILL_SEARCH_TERM", "HANDOFF_SEARCH_TO_AWESOMEBAR", "HIDE_PRIVACY_INFO", "HIDE_SEARCH", "INIT", "NEW_TAB_INIT", "NEW_TAB_INITIAL_STATE", "NEW_TAB_LOAD", "NEW_TAB_REHYDRATED", "NEW_TAB_STATE_REQUEST", "NEW_TAB_UNLOAD", "OPEN_DOWNLOAD_FILE", "OPEN_LINK", "OPEN_NEW_WINDOW", "OPEN_PRIVATE_WINDOW", "OPEN_WEBEXT_SETTINGS", "PLACES_BOOKMARK_ADDED", "PLACES_BOOKMARK_REMOVED", "PLACES_HISTORY_CLEARED", "PLACES_LINKS_CHANGED", "PLACES_LINK_BLOCKED", "PLACES_LINK_DELETED", "PLACES_SAVED_TO_POCKET", "POCKET_CTA", "POCKET_LINK_DELETED_OR_ARCHIVED", "POCKET_LOGGED_IN", "POCKET_WAITING_FOR_SPOC", "PREFS_INITIAL_VALUES", "PREF_CHANGED", "PREVIEW_REQUEST", "PREVIEW_REQUEST_CANCEL", "PREVIEW_RESPONSE", "REMOVE_DOWNLOAD_FILE", "RICH_ICON_MISSING", "SAVE_SESSION_PERF_DATA", "SAVE_TO_POCKET", "SCREENSHOT_UPDATED", "SECTION_DEREGISTER", "SECTION_DISABLE", "SECTION_ENABLE", "SECTION_MOVE", "SECTION_OPTIONS_CHANGED", "SECTION_REGISTER", "SECTION_UPDATE", "SECTION_UPDATE_CARD", "SETTINGS_CLOSE", "SETTINGS_OPEN", "SET_PREF", "SHOW_DOWNLOAD_FILE", "SHOW_FIREFOX_ACCOUNTS", "SHOW_PRIVACY_INFO", "SHOW_SEARCH", "SKIPPED_SIGNIN", "SNIPPETS_BLOCKLIST_CLEARED", "SNIPPETS_BLOCKLIST_UPDATED", "SNIPPETS_DATA", "SNIPPETS_PREVIEW_MODE", "SNIPPETS_RESET", "SNIPPET_BLOCKED", "SUBMIT_EMAIL", "SUBMIT_SIGNIN", "SYSTEM_TICK", "TELEMETRY_IMPRESSION_STATS", "TELEMETRY_PERFORMANCE_EVENT", "TELEMETRY_UNDESIRED_EVENT", "TELEMETRY_USER_EVENT", "TOP_SITES_CANCEL_EDIT", "TOP_SITES_CLOSE_SEARCH_SHORTCUTS_MODAL", "TOP_SITES_EDIT", "TOP_SITES_INSERT", "TOP_SITES_OPEN_SEARCH_SHORTCUTS_MODAL", "TOP_SITES_PIN", "TOP_SITES_PREFS_UPDATED", "TOP_SITES_UNPIN", "TOP_SITES_UPDATED", "TOTAL_BOOKMARKS_REQUEST", "TOTAL_BOOKMARKS_RESPONSE", "TRAILHEAD_ENROLL_EVENT", "UNINIT", "UPDATE_PINNED_SEARCH_SHORTCUTS", "UPDATE_SEARCH_SHORTCUTS", "UPDATE_SECTION_PREFS", "WEBEXT_CLICK", "WEBEXT_DISMISS"]) {
|
||||
actionTypes[type] = type;
|
||||
} // These are acceptable actions for AS Router messages to have. They can show up
|
||||
// as call-to-action buttons in snippets, onboarding tour, etc.
|
||||
|
@ -852,6 +852,10 @@ class DiscoveryStreamAdmin extends react__WEBPACK_IMPORTED_MODULE_4___default.a.
|
|||
this.restorePrefDefaults = this.restorePrefDefaults.bind(this);
|
||||
this.setConfigValue = this.setConfigValue.bind(this);
|
||||
this.expireCache = this.expireCache.bind(this);
|
||||
this.refreshCache = this.refreshCache.bind(this);
|
||||
this.idleDaily = this.idleDaily.bind(this);
|
||||
this.systemTick = this.systemTick.bind(this);
|
||||
this.syncRemoteSettings = this.syncRemoteSettings.bind(this);
|
||||
this.changeEndpointVariant = this.changeEndpointVariant.bind(this);
|
||||
this.onStoryToggle = this.onStoryToggle.bind(this);
|
||||
this.state = {
|
||||
|
@ -875,7 +879,7 @@ class DiscoveryStreamAdmin extends react__WEBPACK_IMPORTED_MODULE_4___default.a.
|
|||
}));
|
||||
}
|
||||
|
||||
expireCache() {
|
||||
refreshCache() {
|
||||
const {
|
||||
config
|
||||
} = this.props.state;
|
||||
|
@ -885,6 +889,28 @@ class DiscoveryStreamAdmin extends react__WEBPACK_IMPORTED_MODULE_4___default.a.
|
|||
}));
|
||||
}
|
||||
|
||||
dispatchSimpleAction(type) {
|
||||
this.props.dispatch(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionCreators"].OnlyToMain({
|
||||
type
|
||||
}));
|
||||
}
|
||||
|
||||
systemTick() {
|
||||
this.dispatchSimpleAction(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionTypes"].DISCOVERY_STREAM_DEV_SYSTEM_TICK);
|
||||
}
|
||||
|
||||
expireCache() {
|
||||
this.dispatchSimpleAction(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionTypes"].DISCOVERY_STREAM_DEV_EXPIRE_CACHE);
|
||||
}
|
||||
|
||||
idleDaily() {
|
||||
this.dispatchSimpleAction(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionTypes"].DISCOVERY_STREAM_DEV_IDLE_DAILY);
|
||||
}
|
||||
|
||||
syncRemoteSettings() {
|
||||
this.dispatchSimpleAction(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionTypes"].DISCOVERY_STREAM_DEV_SYNC_RS);
|
||||
}
|
||||
|
||||
changeEndpointVariant(event) {
|
||||
const endpoint = this.props.state.config.layout_endpoint;
|
||||
|
||||
|
@ -997,9 +1023,21 @@ class DiscoveryStreamAdmin extends react__WEBPACK_IMPORTED_MODULE_4___default.a.
|
|||
className: "button",
|
||||
onClick: this.restorePrefDefaults
|
||||
}, "Restore Pref Defaults"), " ", react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("button", {
|
||||
className: "button",
|
||||
onClick: this.refreshCache
|
||||
}, "Refresh Cache"), react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("br", null), react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("button", {
|
||||
className: "button",
|
||||
onClick: this.expireCache
|
||||
}, "Expire Cache"), react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("table", null, react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("tbody", null, prefToggles.map(pref => react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement(Row, {
|
||||
}, "Expire Cache"), " ", react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("button", {
|
||||
className: "button",
|
||||
onClick: this.systemTick
|
||||
}, "Trigger System Tick"), " ", react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("button", {
|
||||
className: "button",
|
||||
onClick: this.idleDaily
|
||||
}, "Trigger Idle Daily"), react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("br", null), react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("button", {
|
||||
className: "button",
|
||||
onClick: this.syncRemoteSettings
|
||||
}, "Sync Remote Settings"), react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("table", null, react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("tbody", null, prefToggles.map(pref => react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement(Row, {
|
||||
key: pref
|
||||
}, react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("td", null, react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement(TogglePrefCheckbox, {
|
||||
checked: config[pref],
|
||||
|
|
|
@ -11,6 +11,11 @@ ChromeUtils.defineModuleGetter(
|
|||
"NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"RemoteSettings",
|
||||
"resource://services-settings/remote-settings.js"
|
||||
);
|
||||
const { setTimeout, clearTimeout } = ChromeUtils.import(
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
|
@ -1302,6 +1307,43 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
}
|
||||
}
|
||||
|
||||
async onPrefChangedAction(action) {
|
||||
switch (action.data.name) {
|
||||
case PREF_CONFIG:
|
||||
case PREF_ENABLED:
|
||||
case PREF_HARDCODED_BASIC_LAYOUT:
|
||||
case PREF_SPOCS_ENDPOINT:
|
||||
case PREF_LANG_LAYOUT_CONFIG:
|
||||
// Clear the cached config and broadcast the newly computed value
|
||||
this._prefCache.config = null;
|
||||
this.store.dispatch(
|
||||
ac.BroadcastToContent({
|
||||
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
|
||||
data: this.config,
|
||||
})
|
||||
);
|
||||
break;
|
||||
case PREF_TOPSTORIES:
|
||||
if (!action.data.value) {
|
||||
// Ensure we delete any remote data potentially related to spocs.
|
||||
this.clearSpocs();
|
||||
} else {
|
||||
this.enableStories();
|
||||
}
|
||||
break;
|
||||
// Check if spocs was disabled. Remove them if they were.
|
||||
case PREF_SHOW_SPONSORED:
|
||||
if (!action.data.value) {
|
||||
// Ensure we delete any remote data potentially related to spocs.
|
||||
this.clearSpocs();
|
||||
}
|
||||
await this.loadSpocs(update =>
|
||||
this.store.dispatch(ac.BroadcastToContent(update))
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async onAction(action) {
|
||||
switch (action.type) {
|
||||
case at.INIT:
|
||||
|
@ -1313,6 +1355,7 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
await this.enable();
|
||||
}
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_DEV_SYSTEM_TICK:
|
||||
case at.SYSTEM_TICK:
|
||||
// Only refresh if we loaded once in .enable()
|
||||
if (
|
||||
|
@ -1323,6 +1366,15 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
await this.refreshAll({ updateOpenTabs: false });
|
||||
}
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_DEV_IDLE_DAILY:
|
||||
Services.obs.notifyObservers(null, "idle-daily");
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_DEV_SYNC_RS:
|
||||
RemoteSettings.pollChanges();
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_DEV_EXPIRE_CACHE:
|
||||
await this.resetCache();
|
||||
break;
|
||||
case at.DISCOVERY_STREAM_CONFIG_SET_VALUE:
|
||||
// Use the original string pref to then set a value instead of
|
||||
// this.config which has some modifications
|
||||
|
@ -1451,40 +1503,7 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
break;
|
||||
}
|
||||
case at.PREF_CHANGED:
|
||||
switch (action.data.name) {
|
||||
case PREF_CONFIG:
|
||||
case PREF_ENABLED:
|
||||
case PREF_HARDCODED_BASIC_LAYOUT:
|
||||
case PREF_SPOCS_ENDPOINT:
|
||||
case PREF_LANG_LAYOUT_CONFIG:
|
||||
// Clear the cached config and broadcast the newly computed value
|
||||
this._prefCache.config = null;
|
||||
this.store.dispatch(
|
||||
ac.BroadcastToContent({
|
||||
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
|
||||
data: this.config,
|
||||
})
|
||||
);
|
||||
break;
|
||||
case PREF_TOPSTORIES:
|
||||
if (!action.data.value) {
|
||||
// Ensure we delete any remote data potentially related to spocs.
|
||||
this.clearSpocs();
|
||||
} else {
|
||||
this.enableStories();
|
||||
}
|
||||
break;
|
||||
// Check if spocs was disabled. Remove them if they were.
|
||||
case PREF_SHOW_SPONSORED:
|
||||
if (!action.data.value) {
|
||||
// Ensure we delete any remote data potentially related to spocs.
|
||||
this.clearSpocs();
|
||||
}
|
||||
await this.loadSpocs(update =>
|
||||
this.store.dispatch(ac.BroadcastToContent(update))
|
||||
);
|
||||
break;
|
||||
}
|
||||
await this.onPrefChangedAction(action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { actionCreators as ac, actionTypes as at } from "common/Actions.jsm";
|
||||
import {
|
||||
ASRouterAdminInner,
|
||||
CollapseToggle,
|
||||
|
@ -310,25 +311,32 @@ describe("ASRouterAdmin", () => {
|
|||
});
|
||||
});
|
||||
describe("#DiscoveryStream", () => {
|
||||
it("should render a DiscoveryStreamAdmin component", () => {
|
||||
let state = {};
|
||||
let dispatch;
|
||||
beforeEach(() => {
|
||||
dispatch = sandbox.stub();
|
||||
state = {
|
||||
config: {
|
||||
enabled: true,
|
||||
layout_endpoint: "",
|
||||
},
|
||||
layout: [],
|
||||
spocs: {
|
||||
frequency_caps: [],
|
||||
},
|
||||
feeds: {
|
||||
data: {},
|
||||
},
|
||||
};
|
||||
wrapper = shallow(
|
||||
<DiscoveryStreamAdmin
|
||||
dispatch={dispatch}
|
||||
otherPrefs={{}}
|
||||
state={{
|
||||
config: {
|
||||
enabled: true,
|
||||
layout_endpint: "",
|
||||
},
|
||||
layout: [],
|
||||
spocs: {
|
||||
frequency_caps: [],
|
||||
},
|
||||
feeds: {
|
||||
data: {},
|
||||
},
|
||||
}}
|
||||
state={state}
|
||||
/>
|
||||
);
|
||||
});
|
||||
it("should render a DiscoveryStreamAdmin component", () => {
|
||||
assert.equal(
|
||||
wrapper
|
||||
.find("h3")
|
||||
|
@ -338,37 +346,108 @@ describe("ASRouterAdmin", () => {
|
|||
);
|
||||
});
|
||||
it("should render a spoc in DiscoveryStreamAdmin component", () => {
|
||||
wrapper = shallow(
|
||||
<DiscoveryStreamAdmin
|
||||
otherPrefs={{}}
|
||||
state={{
|
||||
config: {
|
||||
enabled: true,
|
||||
layout_endpint: "",
|
||||
state.spocs = {
|
||||
frequency_caps: [],
|
||||
data: {
|
||||
spocs: [
|
||||
{
|
||||
id: 12345,
|
||||
},
|
||||
layout: [],
|
||||
spocs: {
|
||||
frequency_caps: [],
|
||||
data: {
|
||||
spocs: [
|
||||
{
|
||||
id: 12345,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
feeds: {
|
||||
data: {},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
],
|
||||
},
|
||||
};
|
||||
wrapper = shallow(<DiscoveryStreamAdmin otherPrefs={{}} state={state} />);
|
||||
wrapper.instance().onStoryToggle({ id: 12345 });
|
||||
const messageSummary = wrapper.find(".message-summary").at(0);
|
||||
const pre = messageSummary.find("pre").at(0);
|
||||
const spocText = pre.text();
|
||||
assert.equal(spocText, '{\n "id": 12345\n}');
|
||||
});
|
||||
it("should fire restorePrefDefaults with DISCOVERY_STREAM_CONFIG_RESET_DEFAULTS", () => {
|
||||
wrapper
|
||||
.find("button")
|
||||
.at(0)
|
||||
.simulate("click");
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_CONFIG_RESET_DEFAULTS,
|
||||
})
|
||||
);
|
||||
});
|
||||
it("should fire config change with DISCOVERY_STREAM_CONFIG_CHANGE", () => {
|
||||
wrapper
|
||||
.find("button")
|
||||
.at(1)
|
||||
.simulate("click");
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
|
||||
data: { enabled: true, layout_endpoint: "" },
|
||||
})
|
||||
);
|
||||
});
|
||||
it("should fire expireCache with DISCOVERY_STREAM_DEV_EXPIRE_CACHE", () => {
|
||||
wrapper
|
||||
.find("button")
|
||||
.at(2)
|
||||
.simulate("click");
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_DEV_EXPIRE_CACHE,
|
||||
})
|
||||
);
|
||||
});
|
||||
it("should fire systemTick with DISCOVERY_STREAM_DEV_SYSTEM_TICK", () => {
|
||||
wrapper
|
||||
.find("button")
|
||||
.at(3)
|
||||
.simulate("click");
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_DEV_SYSTEM_TICK,
|
||||
})
|
||||
);
|
||||
});
|
||||
it("should fire idleDaily with DISCOVERY_STREAM_DEV_IDLE_DAILY", () => {
|
||||
wrapper
|
||||
.find("button")
|
||||
.at(4)
|
||||
.simulate("click");
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_DEV_IDLE_DAILY,
|
||||
})
|
||||
);
|
||||
});
|
||||
it("should fire syncRemoteSettings with DISCOVERY_STREAM_DEV_SYNC_RS", () => {
|
||||
wrapper
|
||||
.find("button")
|
||||
.at(5)
|
||||
.simulate("click");
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_DEV_SYNC_RS,
|
||||
})
|
||||
);
|
||||
});
|
||||
it("should fire setConfigValue with DISCOVERY_STREAM_CONFIG_SET_VALUE", () => {
|
||||
const name = "name";
|
||||
const value = "value";
|
||||
wrapper.instance().setConfigValue(name, value);
|
||||
assert.calledWith(
|
||||
dispatch,
|
||||
ac.OnlyToMain({
|
||||
type: at.DISCOVERY_STREAM_CONFIG_SET_VALUE,
|
||||
data: { name, value },
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("#ToggleStoryButton", () => {
|
||||
it("should fire onClick in toggle button", async () => {
|
||||
|
|
|
@ -972,7 +972,7 @@ describe("DiscoveryStreamFeed", () => {
|
|||
});
|
||||
|
||||
describe("#resetCache", () => {
|
||||
it("should set .layout, .feeds .spocs and .affinities to {", async () => {
|
||||
it("should set .layout, .feeds .spocs and .affinities to {}", async () => {
|
||||
sandbox.stub(feed.cache, "set").returns(Promise.resolve());
|
||||
|
||||
await feed.resetCache();
|
||||
|
@ -2032,6 +2032,55 @@ describe("DiscoveryStreamFeed", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#onAction: DISCOVERY_STREAM_DEV_IDLE_DAILY", () => {
|
||||
it("should trigger idle-daily observer", async () => {
|
||||
sandbox.stub(global.Services.obs, "notifyObservers").returns();
|
||||
await feed.onAction({
|
||||
type: at.DISCOVERY_STREAM_DEV_IDLE_DAILY,
|
||||
});
|
||||
assert.calledWith(
|
||||
global.Services.obs.notifyObservers,
|
||||
null,
|
||||
"idle-daily"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#onAction: DISCOVERY_STREAM_DEV_SYNC_RS", () => {
|
||||
it("should fire remote settings pollChanges", async () => {
|
||||
sandbox.stub(global.RemoteSettings, "pollChanges").returns();
|
||||
await feed.onAction({
|
||||
type: at.DISCOVERY_STREAM_DEV_SYNC_RS,
|
||||
});
|
||||
assert.calledOnce(global.RemoteSettings.pollChanges);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#onAction: DISCOVERY_STREAM_DEV_SYSTEM_TICK", () => {
|
||||
it("should refresh if DiscoveryStream has been loaded at least once and a cache has expired", async () => {
|
||||
sandbox.stub(feed.cache, "set").resolves();
|
||||
setPref(CONFIG_PREF_NAME, { enabled: true });
|
||||
|
||||
await feed.onAction({ type: at.INIT });
|
||||
|
||||
sandbox.stub(feed, "checkIfAnyCacheExpired").resolves(true);
|
||||
sandbox.stub(feed, "refreshAll").resolves();
|
||||
|
||||
await feed.onAction({ type: at.DISCOVERY_STREAM_DEV_SYSTEM_TICK });
|
||||
assert.calledOnce(feed.refreshAll);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#onAction: DISCOVERY_STREAM_DEV_EXPIRE_CACHE", () => {
|
||||
it("should fire resetCache", async () => {
|
||||
sandbox.stub(feed, "resetCache").returns();
|
||||
await feed.onAction({
|
||||
type: at.DISCOVERY_STREAM_DEV_EXPIRE_CACHE,
|
||||
});
|
||||
assert.calledOnce(feed.resetCache);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#isExpired", () => {
|
||||
it("should throw if the key is not valid", () => {
|
||||
assert.throws(() => {
|
||||
|
|
|
@ -36,6 +36,17 @@ chai.use(chaiAssertions);
|
|||
chai.use(chaiJsonSchema);
|
||||
|
||||
const overrider = new GlobalOverrider();
|
||||
const RemoteSettings = name => ({
|
||||
get: () => {
|
||||
if (name === "attachment") {
|
||||
return Promise.resolve([{ attachment: {} }]);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
on: () => {},
|
||||
off: () => {},
|
||||
});
|
||||
RemoteSettings.pollChanges = () => {};
|
||||
const TEST_GLOBAL = {
|
||||
AddonManager: {
|
||||
getActiveAddons() {
|
||||
|
@ -230,6 +241,7 @@ const TEST_GLOBAL = {
|
|||
obs: {
|
||||
addObserver() {},
|
||||
removeObserver() {},
|
||||
notifyObservers() {},
|
||||
},
|
||||
telemetry: {
|
||||
setEventRecordingEnabled: () => {},
|
||||
|
@ -354,17 +366,7 @@ const TEST_GLOBAL = {
|
|||
return Promise.resolve(false);
|
||||
},
|
||||
},
|
||||
RemoteSettings(name) {
|
||||
return {
|
||||
get() {
|
||||
if (name === "attachment") {
|
||||
return Promise.resolve([{ attachment: {} }]);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
on() {},
|
||||
};
|
||||
},
|
||||
RemoteSettings,
|
||||
Localization: class {
|
||||
async formatMessages(stringsIds) {
|
||||
return Promise.resolve(
|
||||
|
|
Загрузка…
Ссылка в новой задаче