summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js')
-rw-r--r--browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js259
1 files changed, 227 insertions, 32 deletions
diff --git a/browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js b/browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js
index 5d13df0eb0..04501dbe53 100644
--- a/browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js
+++ b/browser/components/newtab/test/xpcshell/test_TopSitesFeed_glean.js
@@ -47,6 +47,15 @@ let contileTile3 = {
image_size: 200,
impression_url: "https://impression_url.com",
};
+let contileTile4 = {
+ id: 75899,
+ name: "Brand4",
+ url: "https://www.brand4.com",
+ click_url: "https://click_url.com",
+ image_url: "https://contile-images.jpg",
+ image_size: 200,
+ impression_url: "https://impression_url.com",
+};
let mozSalesTile = [
{
label: "MozSales Title",
@@ -155,7 +164,12 @@ add_task(async function test_set_contile_tile_to_oversold() {
let feed = getTopSitesFeedForTest(sandbox);
feed._telemetryUtility.setSponsoredTilesConfigured();
- feed._telemetryUtility.setTiles([contileTile1, contileTile2, contileTile3]);
+ feed._telemetryUtility.setTiles([
+ contileTile1,
+ contileTile2,
+ contileTile3,
+ contileTile4,
+ ]);
let mergedTiles = [
{
@@ -170,12 +184,18 @@ add_task(async function test_set_contile_tile_to_oversold() {
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.determineFilteredTilesAndSetToOversold(mergedTiles);
feed._telemetryUtility.finalizeNewtabPingFields(mergedTiles);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -194,6 +214,12 @@ add_task(async function test_set_contile_tile_to_oversold() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -477,7 +503,12 @@ add_task(async function test_set_tiles_to_dismissed_then_updated() {
feed._telemetryUtility.setSponsoredTilesConfigured();
// Step 1: Set initial tiles
- feed._telemetryUtility.setTiles([contileTile1, contileTile2, contileTile3]);
+ feed._telemetryUtility.setTiles([
+ contileTile1,
+ contileTile2,
+ contileTile3,
+ contileTile4,
+ ]);
// Step 2: Set all tiles to dismissed
feed._telemetryUtility.determineFilteredTilesAndSetToDismissed([]);
@@ -495,12 +526,18 @@ add_task(async function test_set_tiles_to_dismissed_then_updated() {
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
// Step 3: Finalize with the updated list of tiles.
feed._telemetryUtility.finalizeNewtabPingFields(updatedTiles);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -522,6 +559,12 @@ add_task(async function test_set_tiles_to_dismissed_then_updated() {
display_position: null,
display_fail_reason: "dismissed",
},
+ {
+ advertiser: "brand4",
+ provider: "amp",
+ display_position: null,
+ display_fail_reason: "dismissed",
+ },
],
};
Assert.equal(
@@ -537,7 +580,12 @@ add_task(async function test_set_tile_positions_after_updated_list() {
feed._telemetryUtility.setSponsoredTilesConfigured();
// Step 1: Set initial tiles
- feed._telemetryUtility.setTiles([contileTile1, contileTile2, contileTile3]);
+ feed._telemetryUtility.setTiles([
+ contileTile1,
+ contileTile2,
+ contileTile3,
+ contileTile4,
+ ]);
// Step 2: Set 1 tile to oversold (brand3)
let mergedTiles = [
@@ -553,6 +601,12 @@ add_task(async function test_set_tile_positions_after_updated_list() {
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.determineFilteredTilesAndSetToOversold(mergedTiles);
@@ -570,10 +624,16 @@ add_task(async function test_set_tile_positions_after_updated_list() {
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.finalizeNewtabPingFields(updatedTiles);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -592,6 +652,12 @@ add_task(async function test_set_tile_positions_after_updated_list() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -610,7 +676,12 @@ add_task(async function test_set_tile_positions_after_updated_list_all_tiles() {
feed._telemetryUtility.setSponsoredTilesConfigured();
// Step 1: Set initial tiles
- feed._telemetryUtility.setTiles([contileTile1, contileTile2, contileTile3]);
+ feed._telemetryUtility.setTiles([
+ contileTile1,
+ contileTile2,
+ contileTile3,
+ contileTile4,
+ ]);
// Step 2: Set 1 tile to oversold (brand3)
let mergedTiles = [
@@ -626,6 +697,12 @@ add_task(async function test_set_tile_positions_after_updated_list_all_tiles() {
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.determineFilteredTilesAndSetToOversold(mergedTiles);
@@ -643,10 +720,16 @@ add_task(async function test_set_tile_positions_after_updated_list_all_tiles() {
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.replacement3.com",
+ label: "replacement3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.finalizeNewtabPingFields(updatedTiles);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -665,6 +748,12 @@ add_task(async function test_set_tile_positions_after_updated_list_all_tiles() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -684,7 +773,12 @@ add_task(
feed._telemetryUtility.setSponsoredTilesConfigured();
// Step 1: Set initial tiles
- feed._telemetryUtility.setTiles([contileTile1, contileTile2, contileTile3]);
+ feed._telemetryUtility.setTiles([
+ contileTile1,
+ contileTile2,
+ contileTile3,
+ contileTile4,
+ ]);
// Step 2: Set 1 tile to oversold (brand3)
let mergedTiles = [
@@ -700,6 +794,12 @@ add_task(
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.determineFilteredTilesAndSetToOversold(mergedTiles);
@@ -717,10 +817,16 @@ add_task(
sponsored_position: 2,
partner: "amp",
},
+ {
+ url: "https://www.brand3.com",
+ label: "brand3",
+ sponsored_position: 3,
+ partner: "amp",
+ },
];
feed._telemetryUtility.finalizeNewtabPingFields(updatedTiles);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -739,6 +845,12 @@ add_task(
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -901,7 +1013,7 @@ add_task(async function test_all_tiles_displayed() {
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -961,18 +1073,25 @@ add_task(async function test_set_one_tile_display_fail_reason_to_oversold() {
impression_url: "https://www.brand3-impression.com",
name: "brand3",
},
+ {
+ url: "https://www.brand4.com",
+ image_url: "images/brnad4-com.png",
+ click_url: "https://www.brand4-click.com",
+ impression_url: "https://www.brand4-impression.com",
+ name: "brand4",
+ },
],
}),
});
const fetched = await feed._contile._fetchSites();
Assert.ok(fetched);
- Assert.equal(feed._contile.sites.length, 2);
+ Assert.equal(feed._contile.sites.length, 3);
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
{
@@ -990,6 +1109,12 @@ add_task(async function test_set_one_tile_display_fail_reason_to_oversold() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -1052,7 +1177,7 @@ add_task(async function test_set_one_tile_display_fail_reason_to_dismissed() {
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1129,6 +1254,13 @@ add_task(
impression_url: "https://www.brand4-impression.com",
name: "brand4",
},
+ {
+ url: "https://www.brand5.com",
+ image_url: "images/brand5-com.png",
+ click_url: "https://www.brand5-click.com",
+ impression_url: "https://www.brand5-impression.com",
+ name: "brand5",
+ },
],
}),
});
@@ -1140,12 +1272,12 @@ add_task(
const fetched = await feed._contile._fetchSites();
Assert.ok(fetched);
- Assert.equal(feed._contile.sites.length, 2);
+ Assert.equal(feed._contile.sites.length, 3);
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1170,6 +1302,12 @@ add_task(
{
advertiser: "brand4",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand5",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -1233,7 +1371,7 @@ add_task(
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1297,6 +1435,13 @@ add_task(async function test_update_tile_count() {
impression_url: "https://www.brand3-impression.com",
name: "brand3",
},
+ {
+ url: "https://www.brand4.com",
+ image_url: "images/brand4-com.png",
+ click_url: "https://www.brand4-click.com",
+ impression_url: "https://www.brand4-impression.com",
+ name: "brand4",
+ },
],
}),
});
@@ -1304,11 +1449,11 @@ add_task(async function test_update_tile_count() {
// 1. Initially the Nimbus pref is set to 2 tiles
let fetched = await feed._contile._fetchSites();
Assert.ok(fetched);
- Assert.equal(feed._contile.sites.length, 2);
+ Assert.equal(feed._contile.sites.length, 3);
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1327,6 +1472,12 @@ add_task(async function test_update_tile_count() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -1344,7 +1495,7 @@ add_task(async function test_update_tile_count() {
);
setNimbusVariablesForNumTiles(nimbusPocketStub, 3);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
expectedResult = {
sponsoredTilesReceived: [
@@ -1363,6 +1514,12 @@ add_task(async function test_update_tile_count() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -1402,6 +1559,12 @@ add_task(async function test_update_tile_count() {
display_position: 3,
display_fail_reason: null,
},
+ {
+ advertiser: "brand4",
+ provider: "amp",
+ display_position: null,
+ display_fail_reason: "oversold",
+ },
],
};
Assert.equal(
@@ -1442,6 +1605,13 @@ add_task(async function test_update_tile_count_sourced_from_cache() {
impression_url: "https://www.brand3-impression.com",
name: "brand3",
},
+ {
+ url: "https://www.brand4.com",
+ image_url: "images/brand4-com.png",
+ click_url: "https://www.brand4-click.com",
+ impression_url: "https://www.brand4-impression.com",
+ name: "brand4",
+ },
];
Services.prefs.setStringPref(CONTILE_CACHE_PREF, JSON.stringify(tiles));
@@ -1459,11 +1629,11 @@ add_task(async function test_update_tile_count_sourced_from_cache() {
// Ensure ContileIntegration._fetchSites is working populate _sites and initilize TelemetryUtility
let fetched = await feed._contile._fetchSites();
Assert.ok(fetched);
- Assert.equal(feed._contile.sites.length, 3);
+ Assert.equal(feed._contile.sites.length, 4);
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1482,6 +1652,12 @@ add_task(async function test_update_tile_count_sourced_from_cache() {
{
advertiser: "brand3",
provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
+ advertiser: "brand4",
+ provider: "amp",
display_position: null,
display_fail_reason: "oversold",
},
@@ -1499,12 +1675,12 @@ add_task(async function test_update_tile_count_sourced_from_cache() {
);
setNimbusVariablesForNumTiles(nimbusPocketStub, 3);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
// 3. Confirm the new count is applied when data pulled from Contile, 3 tiles displayed
fetched = await feed._contile._fetchSites();
Assert.ok(fetched);
- Assert.equal(feed._contile.sites.length, 3);
+ Assert.equal(feed._contile.sites.length, 4);
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
@@ -1530,6 +1706,12 @@ add_task(async function test_update_tile_count_sourced_from_cache() {
display_position: 3,
display_fail_reason: null,
},
+ {
+ advertiser: "brand4",
+ provider: "amp",
+ display_position: null,
+ display_fail_reason: "oversold",
+ },
],
};
Assert.equal(
@@ -1595,7 +1777,7 @@ add_task(
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1636,7 +1818,7 @@ add_task(
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
expectedResult = {
sponsoredTilesReceived: [
@@ -1684,7 +1866,7 @@ add_task(async function test_sponsoredTilesReceived_not_set() {
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = { sponsoredTilesReceived: [] };
Assert.equal(
@@ -1744,7 +1926,7 @@ add_task(async function test_telemetry_data_updates() {
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1896,7 +2078,7 @@ add_task(async function test_reset_telemetry_data() {
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
@@ -1934,7 +2116,7 @@ add_task(async function test_reset_telemetry_data() {
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
expectedResult = { sponsoredTilesReceived: [] };
Assert.equal(
@@ -1982,17 +2164,24 @@ add_task(async function test_set_telemetry_for_moz_sales_tiles() {
impression_url: "https://www.brand2-impression.com",
name: "brand2",
},
+ {
+ url: "https://www.brand3.com",
+ image_url: "images/brand3-com.png",
+ click_url: "https://www.brand3-click.com",
+ impression_url: "https://www.brand3-impression.com",
+ name: "brand2",
+ },
],
}),
});
const fetched = await feed._contile._fetchSites();
Assert.ok(fetched);
- Assert.equal(feed._contile.sites.length, 2);
+ Assert.equal(feed._contile.sites.length, 3);
await feed._readDefaults();
await feed.getLinksWithDefaults(false);
- Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 2);
+ Assert.equal(Glean.topsites.sponsoredTilesConfigured.testGetValue(), 3);
let expectedResult = {
sponsoredTilesReceived: [
{
@@ -2008,6 +2197,12 @@ add_task(async function test_set_telemetry_for_moz_sales_tiles() {
display_fail_reason: null,
},
{
+ advertiser: "brand3",
+ provider: "amp",
+ display_position: 3,
+ display_fail_reason: null,
+ },
+ {
advertiser: "mozsales title",
provider: "moz-sales",
display_position: null,