commit b8ce2b52596bb57ec1bd8abb939d74a7a7562a69
parent 48c957b927e49699a1d35e864484e442ea943ebb
Author: Reem H <42309026+reemhamz@users.noreply.github.com>
Date: Wed, 17 Dec 2025 20:29:27 +0000
Bug 2006254 - Send weather request to Merino with complete location parameters. r=home-newtab-reviewers,maxx
Differential Revision: https://phabricator.services.mozilla.com/D276602
Diffstat:
2 files changed, 46 insertions(+), 22 deletions(-)
diff --git a/browser/extensions/newtab/lib/WeatherFeed.sys.mjs b/browser/extensions/newtab/lib/WeatherFeed.sys.mjs
@@ -334,19 +334,21 @@ export class WeatherFeed {
return [];
}
- if (geolocation.country_code) {
- otherParams.country = geolocation.country_code;
- }
- let region = geolocation.region_code || geolocation.region;
- if (region) {
- otherParams.region = region;
- }
- let city = geolocation.city || geolocation.region;
- if (city) {
- otherParams.city = city;
+ const country = geolocation.country_code;
+ // Adding geolocation.city as an option for region to count for city-states (i.e. Singapore)
+ const region =
+ geolocation.region_code || geolocation.region || geolocation.city;
+ const city = geolocation.city || geolocation.region;
+
+ // Merino requires all three parameters (city, region, country) when query is not provided
+ if (!country || !region || !city) {
+ return [];
}
- }
+ otherParams.country = country;
+ otherParams.region = region;
+ otherParams.city = city;
+ }
const attempt = async (retry = 0) => {
try {
// Because this can happen after a timeout,
diff --git a/browser/extensions/newtab/test/xpcshell/test_WeatherFeed.js b/browser/extensions/newtab/test/xpcshell/test_WeatherFeed.js
@@ -333,41 +333,63 @@ add_task(async function test_fetch_weather_with_geolocation() {
},
},
{
+ // Test city-state fallback: Singapore (no region field)
geolocation: {
- country_code: "TestCountry",
+ country_code: "SG",
+ region_code: null,
+ region: null,
+ city: "Singapore",
},
expected: {
- country: "TestCountry",
+ country: "SG",
+ region: "Singapore", // City used as fallback for region
+ city: "Singapore",
},
},
{
+ // Test city-state fallback: Monaco (no region field)
geolocation: {
- region_code: "TestRegionCode",
+ country_code: "MC",
+ city: "Monaco",
},
expected: {
- region: "TestRegionCode",
+ country: "MC",
+ region: "Monaco", // City used as fallback for region
+ city: "Monaco",
},
},
{
geolocation: {
- region: "TestRegion",
+ country_code: "TestCountry",
},
- expected: {
- region: "TestRegion",
- city: "TestRegion",
+ // Missing region and city - request should be blocked
+ expected: false,
+ },
+ {
+ geolocation: {
+ region_code: "TestRegionCode",
},
+ // Missing country and city - request should be blocked
+ expected: false,
},
{
geolocation: {
- city: "TestCity",
+ region: "TestRegion",
},
- expected: {
+ // Missing country - request should be blocked
+ expected: false,
+ },
+ {
+ geolocation: {
city: "TestCity",
},
+ // Missing country and region - request should be blocked
+ expected: false,
},
{
geolocation: {},
- expected: {},
+ // Empty geolocation - request should be blocked
+ expected: false,
},
{
geolocation: null,