diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /browser/components/newtab/test/xpcshell | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/xpcshell')
5 files changed, 333 insertions, 36 deletions
diff --git a/browser/components/newtab/test/xpcshell/test_PlacesFeed.js b/browser/components/newtab/test/xpcshell/test_PlacesFeed.js index 78dda7818e..d6f7079d77 100644 --- a/browser/components/newtab/test/xpcshell/test_PlacesFeed.js +++ b/browser/components/newtab/test/xpcshell/test_PlacesFeed.js @@ -424,7 +424,7 @@ add_task(async function test_onAction_OPEN_LINK() { data: { url: "https://foo.com" }, _target: { browser: { - ownerGlobal: { openTrustedLinkIn, whereToOpenLink: () => "current" }, + ownerGlobal: { openTrustedLinkIn }, }, }, }; @@ -524,7 +524,7 @@ add_task(async function test_onAction_OPEN_LINK_pocket() { }, _target: { browser: { - ownerGlobal: { openTrustedLinkIn, whereToOpenLink: () => "current" }, + ownerGlobal: { openTrustedLinkIn }, }, }, }; @@ -551,7 +551,7 @@ add_task(async function test_onAction_OPEN_LINK_not_http() { data: { url: "file:///foo.com" }, _target: { browser: { - ownerGlobal: { openTrustedLinkIn, whereToOpenLink: () => "current" }, + ownerGlobal: { openTrustedLinkIn }, }, }, }; diff --git a/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js b/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js index 4be520fcca..247e08b333 100644 --- a/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js +++ b/browser/components/newtab/test/xpcshell/test_TopSitesFeed.js @@ -2970,9 +2970,10 @@ add_task(async function test_ContileIntegration() { Assert.ok(fetched); // Both "foo" and "bar" should be filtered - Assert.equal(feed._contile.sites.length, 2); + Assert.equal(feed._contile.sites.length, 3); Assert.equal(feed._contile.sites[0].url, "https://www.test.com"); Assert.equal(feed._contile.sites[1].url, "https://test1.com"); + Assert.equal(feed._contile.sites[2].url, "https://test2.com"); } { 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, diff --git a/browser/components/newtab/test/xpcshell/test_WeatherFeed.js b/browser/components/newtab/test/xpcshell/test_WeatherFeed.js new file mode 100644 index 0000000000..2821f4b7d0 --- /dev/null +++ b/browser/components/newtab/test/xpcshell/test_WeatherFeed.js @@ -0,0 +1,99 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { WeatherFeed } = ChromeUtils.importESModule( + "resource://activity-stream/lib/WeatherFeed.sys.mjs" +); + +const { actionCreators: ac, actionTypes: at } = ChromeUtils.importESModule( + "resource://activity-stream/common/Actions.mjs" +); + +ChromeUtils.defineESModuleGetters(this, { + sinon: "resource://testing-common/Sinon.sys.mjs", + MerinoTestUtils: "resource://testing-common/MerinoTestUtils.sys.mjs", +}); + +const { WEATHER_SUGGESTION } = MerinoTestUtils; + +const WEATHER_ENABLED = "browser.newtabpage.activity-stream.showWeather"; +const SYS_WEATHER_ENABLED = + "browser.newtabpage.activity-stream.system.showWeather"; + +add_task(async function test_construction() { + let sandbox = sinon.createSandbox(); + sandbox.stub(WeatherFeed.prototype, "PersistentCache").returns({ + set: () => {}, + get: () => {}, + }); + + let feed = new WeatherFeed(); + + info("WeatherFeed constructor should create initial values"); + + Assert.ok(feed, "Could construct a WeatherFeed"); + Assert.ok(feed.loaded === false, "WeatherFeed is not loaded"); + Assert.ok(feed.merino === null, "merino is initialized as null"); + Assert.ok( + feed.suggestions.length === 0, + "suggestions is initialized as a array with length of 0" + ); + Assert.ok(feed.fetchTimer === null, "fetchTimer is initialized as null"); + sandbox.restore(); +}); + +add_task(async function test_onAction_INIT() { + let sandbox = sinon.createSandbox(); + sandbox.stub(WeatherFeed.prototype, "MerinoClient").returns({ + get: () => [WEATHER_SUGGESTION], + on: () => {}, + }); + sandbox.stub(WeatherFeed.prototype, "PersistentCache").returns({ + set: () => {}, + get: () => {}, + }); + const dateNowTestValue = 1; + sandbox.stub(WeatherFeed.prototype, "Date").returns({ + now: () => dateNowTestValue, + }); + + let feed = new WeatherFeed(); + + Services.prefs.setBoolPref(WEATHER_ENABLED, true); + Services.prefs.setBoolPref(SYS_WEATHER_ENABLED, true); + + sandbox.stub(feed, "isEnabled").returns(true); + + sandbox.stub(feed, "fetchHelper"); + feed.suggestions = [WEATHER_SUGGESTION]; + + feed.store = { + dispatch: sinon.spy(), + }; + + info("WeatherFeed.onAction INIT should initialize Weather"); + + await feed.onAction({ + type: at.INIT, + }); + + Assert.ok(feed.store.dispatch.calledOnce); + Assert.ok( + feed.store.dispatch.calledWith( + ac.BroadcastToContent({ + type: at.WEATHER_UPDATE, + data: { + suggestions: [WEATHER_SUGGESTION], + lastUpdated: dateNowTestValue, + }, + meta: { + isStartup: true, + }, + }) + ) + ); + Services.prefs.clearUserPref(WEATHER_ENABLED); + sandbox.restore(); +}); diff --git a/browser/components/newtab/test/xpcshell/xpcshell.toml b/browser/components/newtab/test/xpcshell/xpcshell.toml index 13c11b0541..567927c31c 100644 --- a/browser/components/newtab/test/xpcshell/xpcshell.toml +++ b/browser/components/newtab/test/xpcshell/xpcshell.toml @@ -28,3 +28,5 @@ support-files = ["../schemas/*.schema.json"] ["test_TopSitesFeed_glean.js"] ["test_WallpaperFeed.js"] + +["test_WeatherFeed.js"] |