Bug 1964063 - Try to reset a geolocation override only if it was set before. r=saschanaz

Differential Revision: https://phabricator.services.mozilla.com/D247601
This commit is contained in:
Alexandra Borovova
2025-05-05 12:15:50 +00:00
committed by aborovova@mozilla.com
parent c9e995bfa3
commit e4fed060be
2 changed files with 48 additions and 4 deletions

View File

@@ -3254,13 +3254,12 @@ void BrowsingContext::SetGeolocationServiceOverride(
mGeolocationServiceOverride->Init();
}
mGeolocationServiceOverride->Update(aGeolocationOverride.Value());
} else {
} else if (RefPtr<nsGeolocationService> serviceOverride =
mGeolocationServiceOverride.forget()) {
// Create an original service and move the locators.
RefPtr<nsGeolocationService> service =
nsGeolocationService::GetGeolocationService();
mGeolocationServiceOverride->MoveLocators(service);
mGeolocationServiceOverride = nullptr;
serviceOverride->MoveLocators(service);
}
}

View File

@@ -440,3 +440,48 @@ add_task(async function test_amount_of_updates_for_watchPosition() {
BrowserTestUtils.removeTab(tab);
});
add_task(async function test_call_empty_without_override() {
await SpecialPowers.pushPrefEnv({
set: required_preferences,
});
let pageLoaded;
let browser;
const tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
() => {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, PAGE_URL);
browser = gBrowser.selectedBrowser;
pageLoaded = BrowserTestUtils.browserLoaded(browser, true);
},
false
);
await pageLoaded;
await SpecialPowers.spawn(browser, [], async () => {
await SpecialPowers.pushPermissions([
{
type: "geo",
allow: SpecialPowers.Services.perms.ALLOW_ACTION,
context: content.document,
},
]);
const browsingContext = content.browsingContext;
info("Reset the geolocation override");
browsingContext.setGeolocationServiceOverride();
const positionPromise4 = new Promise(resolve =>
content.window.navigator.geolocation.getCurrentPosition(position => {
resolve(position.coords.toJSON());
})
);
const coordinates4 = await positionPromise4;
is(coordinates4.latitude, 37.41857, "Original latitude is returned");
is(coordinates4.longitude, -122.08769, "Original longitude is returned");
is(coordinates4.accuracy, 42, "Original accuracy is returned");
});
BrowserTestUtils.removeTab(tab);
});