1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
6 const { WallpaperFeed } = ChromeUtils.importESModule(
7 "resource://activity-stream/lib/WallpaperFeed.sys.mjs"
10 const { actionCreators: ac, actionTypes: at } = ChromeUtils.importESModule(
11 "resource://activity-stream/common/Actions.mjs"
14 ChromeUtils.defineESModuleGetters(this, {
15 Utils: "resource://services-settings/Utils.sys.mjs",
16 sinon: "resource://testing-common/Sinon.sys.mjs",
19 const PREF_WALLPAPERS_ENABLED =
20 "browser.newtabpage.activity-stream.newtabWallpapers.enabled";
22 add_task(async function test_construction() {
23 let feed = new WallpaperFeed();
25 info("WallpaperFeed constructor should create initial values");
27 Assert.ok(feed, "Could construct a WallpaperFeed");
28 Assert.ok(feed.loaded === false, "WallpaperFeed is not loaded");
30 feed.wallpaperClient === "",
31 "wallpaperClient is initialized as an empty string"
34 feed.wallpaperDB === "",
35 "wallpaperDB is initialized as an empty string"
38 feed.baseAttachmentURL === "",
39 "baseAttachmentURL is initialized as an empty string"
43 add_task(async function test_onAction_INIT() {
44 let sandbox = sinon.createSandbox();
45 let feed = new WallpaperFeed();
46 Services.prefs.setBoolPref(PREF_WALLPAPERS_ENABLED, true);
49 location: "attachment",
52 sandbox.stub(feed, "RemoteSettings").returns({
53 get: () => [attachment],
56 sandbox.stub(Utils, "SERVER_URL").returns("http://localhost:8888/v1");
58 dispatch: sinon.spy(),
60 sandbox.stub(feed, "fetch").resolves({
64 base_url: "http://localhost:8888/base_url/",
70 info("WallpaperFeed.onAction INIT should initialize wallpapers");
76 Assert.ok(feed.store.dispatch.calledOnce);
78 feed.store.dispatch.calledWith(
79 ac.BroadcastToContent({
80 type: at.WALLPAPERS_SET,
84 wallpaperUrl: "http://localhost:8888/base_url/attachment",
90 Services.prefs.clearUserPref(PREF_WALLPAPERS_ENABLED);
94 add_task(async function test_onAction_PREF_CHANGED() {
95 let sandbox = sinon.createSandbox();
96 let feed = new WallpaperFeed();
97 Services.prefs.setBoolPref(PREF_WALLPAPERS_ENABLED, true);
98 sandbox.stub(feed, "wallpaperSetup").returns();
100 info("WallpaperFeed.onAction PREF_CHANGED should call wallpaperSetup");
103 type: at.PREF_CHANGED,
104 data: { name: "newtabWallpapers.enabled" },
107 Assert.ok(feed.wallpaperSetup.calledOnce);
109 Services.prefs.clearUserPref(PREF_WALLPAPERS_ENABLED);