summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/xpcshell
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /browser/components/newtab/test/xpcshell
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--browser/components/newtab/test/xpcshell/test_HighlightsFeed.js2
-rw-r--r--browser/components/newtab/test/xpcshell/test_PlacesFeed.js2
-rw-r--r--browser/components/newtab/test/xpcshell/test_TelemetryFeed.js56
-rw-r--r--browser/components/newtab/test/xpcshell/test_TopSitesFeed.js2
-rw-r--r--browser/components/newtab/test/xpcshell/test_WallpaperFeed.js115
-rw-r--r--browser/components/newtab/test/xpcshell/xpcshell.toml2
6 files changed, 166 insertions, 13 deletions
diff --git a/browser/components/newtab/test/xpcshell/test_HighlightsFeed.js b/browser/components/newtab/test/xpcshell/test_HighlightsFeed.js
index 31a03947cd..1cb8a44631 100644
--- a/browser/components/newtab/test/xpcshell/test_HighlightsFeed.js
+++ b/browser/components/newtab/test/xpcshell/test_HighlightsFeed.js
@@ -4,7 +4,7 @@
"use strict";
const { actionTypes: at } = ChromeUtils.importESModule(
- "resource://activity-stream/common/Actions.sys.mjs"
+ "resource://activity-stream/common/Actions.mjs"
);
ChromeUtils.defineESModuleGetters(this, {
diff --git a/browser/components/newtab/test/xpcshell/test_PlacesFeed.js b/browser/components/newtab/test/xpcshell/test_PlacesFeed.js
index 19f9e343f5..78dda7818e 100644
--- a/browser/components/newtab/test/xpcshell/test_PlacesFeed.js
+++ b/browser/components/newtab/test/xpcshell/test_PlacesFeed.js
@@ -4,7 +4,7 @@
"use strict";
const { actionTypes: at, actionCreators: ac } = ChromeUtils.importESModule(
- "resource://activity-stream/common/Actions.sys.mjs"
+ "resource://activity-stream/common/Actions.mjs"
);
ChromeUtils.defineESModuleGetters(this, {
diff --git a/browser/components/newtab/test/xpcshell/test_TelemetryFeed.js b/browser/components/newtab/test/xpcshell/test_TelemetryFeed.js
index 59d82f5583..354eac8c2a 100644
--- a/browser/components/newtab/test/xpcshell/test_TelemetryFeed.js
+++ b/browser/components/newtab/test/xpcshell/test_TelemetryFeed.js
@@ -4,11 +4,11 @@
"use strict";
const { actionCreators: ac, actionTypes: at } = ChromeUtils.importESModule(
- "resource://activity-stream/common/Actions.sys.mjs"
+ "resource://activity-stream/common/Actions.mjs"
);
const { MESSAGE_TYPE_HASH: msg } = ChromeUtils.importESModule(
- "resource:///modules/asrouter/ActorConstants.sys.mjs"
+ "resource:///modules/asrouter/ActorConstants.mjs"
);
const { updateAppInfo } = ChromeUtils.importESModule(
@@ -947,18 +947,18 @@ add_task(
}
);
-add_task(async function test_applyWhatsNewPolicy() {
+add_task(async function test_applyToolbarBadgePolicy() {
info(
- "TelemetryFeed.applyWhatsNewPolicy should set client_id and set pingType"
+ "TelemetryFeed.applyToolbarBadgePolicy should set client_id and set pingType"
);
let instance = new TelemetryFeed();
- let { ping, pingType } = await instance.applyWhatsNewPolicy({});
+ let { ping, pingType } = await instance.applyToolbarBadgePolicy({});
Assert.equal(
ping.client_id,
Services.prefs.getCharPref("toolkit.telemetry.cachedClientID")
);
- Assert.equal(pingType, "whats-new-panel");
+ Assert.equal(pingType, "toolbar-badge");
});
add_task(async function test_applyInfoBarPolicy() {
@@ -1288,10 +1288,10 @@ add_task(async function test_createASRouterEvent_call_correctPolicy() {
message_id: "onboarding_message_01",
});
- testCallCorrectPolicy("applyWhatsNewPolicy", {
- action: "whats-new-panel_user_event",
- event: "CLICK_BUTTON",
- message_id: "whats-new-panel_message_01",
+ testCallCorrectPolicy("applyToolbarBadgePolicy", {
+ action: "badge_user_event",
+ event: "IMPRESSION",
+ message_id: "badge_message_01",
});
testCallCorrectPolicy("applyMomentsPolicy", {
@@ -2230,6 +2230,8 @@ add_task(
const POS_1 = 1;
const POS_2 = 4;
const SHIM = "Y29uc2lkZXIgeW91ciBjdXJpb3NpdHkgcmV3YXJkZWQ=";
+ const FETCH_TIMESTAMP = new Date("March 22, 2024 10:15:20");
+ const NEWTAB_CREATION_TIMESTAMP = new Date("March 23, 2024 11:10:30");
sandbox.stub(instance.sessions, "get").returns({ session_id: SESSION_ID });
let pingSubmitted = new Promise(resolve => {
@@ -2252,6 +2254,14 @@ add_task(
tile_id: String(2),
});
Assert.equal(Glean.pocket.shim.testGetValue(), SHIM);
+ Assert.deepEqual(
+ Glean.pocket.fetchTimestamp.testGetValue(),
+ FETCH_TIMESTAMP
+ );
+ Assert.deepEqual(
+ Glean.pocket.newtabCreationTimestamp.testGetValue(),
+ NEWTAB_CREATION_TIMESTAMP
+ );
resolve();
});
@@ -2272,10 +2282,12 @@ add_task(
type: "spoc",
recommendation_id: undefined,
shim: SHIM,
+ fetchTimestamp: FETCH_TIMESTAMP.valueOf(),
},
],
window_inner_width: 1000,
window_inner_height: 900,
+ firstVisibleTimestamp: NEWTAB_CREATION_TIMESTAMP.valueOf(),
});
await pingSubmitted;
@@ -2949,6 +2961,8 @@ add_task(
Services.fog.testResetFOG();
const ACTION_POSITION = 42;
const SHIM = "Y29uc2lkZXIgeW91ciBjdXJpb3NpdHkgcmV3YXJkZWQ=";
+ const FETCH_TIMESTAMP = new Date("March 22, 2024 10:15:20");
+ const NEWTAB_CREATION_TIMESTAMP = new Date("March 23, 2024 11:10:30");
let action = ac.DiscoveryStreamUserEvent({
event: "CLICK",
action_position: ACTION_POSITION,
@@ -2957,6 +2971,8 @@ add_task(
recommendation_id: undefined,
tile_id: 448685088,
shim: SHIM,
+ fetchTimestamp: FETCH_TIMESTAMP.valueOf(),
+ firstVisibleTimestamp: NEWTAB_CREATION_TIMESTAMP.valueOf(),
},
});
@@ -2966,6 +2982,14 @@ add_task(
let pingSubmitted = new Promise(resolve => {
GleanPings.spoc.testBeforeNextSubmit(reason => {
Assert.equal(reason, "click");
+ Assert.deepEqual(
+ Glean.pocket.fetchTimestamp.testGetValue(),
+ FETCH_TIMESTAMP
+ );
+ Assert.deepEqual(
+ Glean.pocket.newtabCreationTimestamp.testGetValue(),
+ NEWTAB_CREATION_TIMESTAMP
+ );
resolve();
});
});
@@ -3043,6 +3067,8 @@ add_task(
Services.fog.testResetFOG();
const ACTION_POSITION = 42;
const SHIM = "Y29uc2lkZXIgeW91ciBjdXJpb3NpdHkgcmV3YXJkZWQ=";
+ const FETCH_TIMESTAMP = new Date("March 22, 2024 10:15:20");
+ const NEWTAB_CREATION_TIMESTAMP = new Date("March 23, 2024 11:10:30");
let action = ac.DiscoveryStreamUserEvent({
event: "SAVE_TO_POCKET",
action_position: ACTION_POSITION,
@@ -3051,6 +3077,8 @@ add_task(
recommendation_id: undefined,
tile_id: 448685088,
shim: SHIM,
+ fetchTimestamp: FETCH_TIMESTAMP.valueOf(),
+ newtabCreationTimestamp: NEWTAB_CREATION_TIMESTAMP.valueOf(),
},
});
@@ -3064,6 +3092,14 @@ add_task(
SHIM,
"Pocket shim was recorded"
);
+ Assert.deepEqual(
+ Glean.pocket.fetchTimestamp.testGetValue(),
+ FETCH_TIMESTAMP
+ );
+ Assert.deepEqual(
+ Glean.pocket.newtabCreationTimestamp.testGetValue(),
+ NEWTAB_CREATION_TIMESTAMP
+ );
resolve();
});
diff --git a/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js b/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js
index 860e8758a5..4be520fcca 100644
--- a/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js
+++ b/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js
@@ -8,7 +8,7 @@ const { TopSitesFeed, DEFAULT_TOP_SITES } = ChromeUtils.importESModule(
);
const { actionCreators: ac, actionTypes: at } = ChromeUtils.importESModule(
- "resource://activity-stream/common/Actions.sys.mjs"
+ "resource://activity-stream/common/Actions.mjs"
);
ChromeUtils.defineESModuleGetters(this, {
diff --git a/browser/components/newtab/test/xpcshell/test_WallpaperFeed.js b/browser/components/newtab/test/xpcshell/test_WallpaperFeed.js
new file mode 100644
index 0000000000..c6c12c17bf
--- /dev/null
+++ b/browser/components/newtab/test/xpcshell/test_WallpaperFeed.js
@@ -0,0 +1,115 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { WallpaperFeed } = ChromeUtils.importESModule(
+ "resource://activity-stream/lib/WallpaperFeed.sys.mjs"
+);
+
+const { actionCreators: ac, actionTypes: at } = ChromeUtils.importESModule(
+ "resource://activity-stream/common/Actions.mjs"
+);
+
+ChromeUtils.defineESModuleGetters(this, {
+ Utils: "resource://services-settings/Utils.sys.mjs",
+ sinon: "resource://testing-common/Sinon.sys.mjs",
+});
+
+const PREF_WALLPAPERS_ENABLED =
+ "browser.newtabpage.activity-stream.newtabWallpapers.enabled";
+
+add_task(async function test_construction() {
+ let feed = new WallpaperFeed();
+
+ info("WallpaperFeed constructor should create initial values");
+
+ Assert.ok(feed, "Could construct a WallpaperFeed");
+ Assert.ok(feed.loaded === false, "WallpaperFeed is not loaded");
+ Assert.ok(
+ feed.wallpaperClient === "",
+ "wallpaperClient is initialized as an empty string"
+ );
+ Assert.ok(
+ feed.wallpaperDB === "",
+ "wallpaperDB is initialized as an empty string"
+ );
+ Assert.ok(
+ feed.baseAttachmentURL === "",
+ "baseAttachmentURL is initialized as an empty string"
+ );
+});
+
+add_task(async function test_onAction_INIT() {
+ let sandbox = sinon.createSandbox();
+ let feed = new WallpaperFeed();
+ Services.prefs.setBoolPref(PREF_WALLPAPERS_ENABLED, true);
+ const attachment = {
+ attachment: {
+ location: "attachment",
+ },
+ };
+ sandbox.stub(feed, "RemoteSettings").returns({
+ get: () => [attachment],
+ on: () => {},
+ });
+ sandbox.stub(Utils, "SERVER_URL").returns("http://localhost:8888/v1");
+ feed.store = {
+ dispatch: sinon.spy(),
+ };
+ sandbox.stub(feed, "fetch").resolves({
+ json: () => ({
+ capabilities: {
+ attachments: {
+ base_url: "http://localhost:8888/base_url/",
+ },
+ },
+ }),
+ });
+
+ info("WallpaperFeed.onAction INIT should initialize wallpapers");
+
+ await feed.onAction({
+ type: at.INIT,
+ });
+
+ Assert.ok(feed.store.dispatch.calledOnce);
+ Assert.ok(
+ feed.store.dispatch.calledWith(
+ ac.BroadcastToContent({
+ type: at.WALLPAPERS_SET,
+ data: [
+ {
+ ...attachment,
+ wallpaperUrl: "http://localhost:8888/base_url/attachment",
+ },
+ ],
+ meta: {
+ isStartup: true,
+ },
+ })
+ )
+ );
+ Services.prefs.clearUserPref(PREF_WALLPAPERS_ENABLED);
+ sandbox.restore();
+});
+
+add_task(async function test_onAction_PREF_CHANGED() {
+ let sandbox = sinon.createSandbox();
+ let feed = new WallpaperFeed();
+ Services.prefs.setBoolPref(PREF_WALLPAPERS_ENABLED, true);
+ sandbox.stub(feed, "wallpaperSetup").returns();
+
+ info("WallpaperFeed.onAction PREF_CHANGED should call wallpaperSetup");
+
+ feed.onAction({
+ type: at.PREF_CHANGED,
+ data: { name: "newtabWallpapers.enabled" },
+ });
+
+ Assert.ok(feed.wallpaperSetup.calledOnce);
+ Assert.ok(feed.wallpaperSetup.calledWith(false));
+
+ Services.prefs.clearUserPref(PREF_WALLPAPERS_ENABLED);
+ sandbox.restore();
+});
diff --git a/browser/components/newtab/test/xpcshell/xpcshell.toml b/browser/components/newtab/test/xpcshell/xpcshell.toml
index 87d73669d3..13c11b0541 100644
--- a/browser/components/newtab/test/xpcshell/xpcshell.toml
+++ b/browser/components/newtab/test/xpcshell/xpcshell.toml
@@ -26,3 +26,5 @@ support-files = ["../schemas/*.schema.json"]
["test_TopSitesFeed.js"]
["test_TopSitesFeed_glean.js"]
+
+["test_WallpaperFeed.js"]