test: emulate the position in the geolocation permission-granted spec (#54698)

* test: emulate the position in the geolocation permission-granted spec

The test only ran on official builds, because other builds replace
the system location provider with FakeLocationProvider, which always
reports an error. On official builds it queried the real network
location service, which fails on CI with "Failed to query location
from network service."

Set the position with the DevTools Emulation.setGeolocationOverride
command instead, so the test runs on every build and doesn't depend
on the network. The permission request still goes through the
session's handler, and the test now checks that it did and that the
emulated coordinates come back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: remove FakeLocationProvider

It was added to mock geolocation responses in tests.
The geolocation spec now sets the position with
Emulation.setGeolocationOverride instead, so the fake provider,
the enable_fake_location_provider GN arg, and the
OVERRIDE_LOCATION_PROVIDER buildflag are no longer needed.

The permission-denied spec no longer depends on the fake provider:
a denied request fails before any provider is queried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Charles KerrandClaude Opus 5.5 authored and GitHub committed 2026-10-09 11:22:53 +09:00
1 parent afa25aee96
commit e27347b73a
10 files changed
+16 -136

No files matched your search

-7
View File
@@ -664,13 +664,6 @@ source_set("electron_lib") {
defines += [ "NODE_SHARED_MODE" ]
}
if (enable_fake_location_provider) {
sources += [
"shell/browser/fake_location_provider.cc",
"shell/browser/fake_location_provider.h",
]
}
if (enable_prompt_api) {
sources += [
"shell/browser/ai/proxying_ai_manager.cc",
-1
View File
@@ -13,7 +13,6 @@ buildflag_header("buildflags") {
"ENABLE_ELECTRON_EXTENSIONS=$enable_electron_extensions",
"ENABLE_BUILTIN_SPELLCHECKER=$enable_builtin_spellchecker",
"ENABLE_PROMPT_API=$enable_prompt_api",
"OVERRIDE_LOCATION_PROVIDER=$enable_fake_location_provider",
]
if (electron_vendor_version != "") {
-6
View File
@@ -5,12 +5,6 @@
declare_args() {
enable_pdf_viewer = true
# Provide a fake location provider for mocking
# the geolocation responses. Disable it if you
# need to test with chromium's location provider.
# Should not be enabled for release build.
enable_fake_location_provider = !is_official_build
# Enable Chrome extensions support.
enable_electron_extensions = true
-14
View File
@@ -72,7 +72,6 @@
#include "printing/buildflags/buildflags.h"
#include "sandbox/policy/switches.h"
#include "services/device/public/cpp/geolocation/geolocation_system_permission_manager.h"
#include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "services/network/public/cpp/network_switches.h"
@@ -165,10 +164,6 @@
#include "components/spellcheck/common/spellcheck.mojom.h" // nogncheck
#endif
#if BUILDFLAG(OVERRIDE_LOCATION_PROVIDER)
#include "shell/browser/fake_location_provider.h"
#endif // BUILDFLAG(OVERRIDE_LOCATION_PROVIDER)
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "base/functional/bind.h"
#include "chrome/common/webui_url_constants.h"
@@ -956,15 +951,6 @@ ElectronBrowserClient::CreateClientCertStore(
#endif
}
std::unique_ptr<device::LocationProvider>
ElectronBrowserClient::OverrideSystemLocationProvider() {
#if BUILDFLAG(OVERRIDE_LOCATION_PROVIDER)
return std::make_unique<FakeLocationProvider>();
#else
return {};
#endif
}
void ElectronBrowserClient::ConfigureNetworkContextParams(
content::BrowserContext* browser_context,
bool in_memory,
-2
View File
@@ -225,8 +225,6 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
std::vector<std::string>* additional_schemes) override;
void GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) override;
std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider()
override;
void ConfigureNetworkContextParams(
content::BrowserContext* browser_context,
bool in_memory,
-52
View File
@@ -1,52 +0,0 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/fake_location_provider.h"
#include "services/device/public/mojom/geoposition.mojom-shared.h"
#include "services/device/public/mojom/geoposition.mojom.h"
namespace electron {
FakeLocationProvider::FakeLocationProvider() {
result_ = device::mojom::GeopositionResult::NewError(
device::mojom::GeopositionError::New(
device::mojom::GeopositionErrorCode::kPositionUnavailable,
"Position unavailable.", ""));
}
FakeLocationProvider::~FakeLocationProvider() = default;
void FakeLocationProvider::FillDiagnostics(
device::mojom::GeolocationDiagnostics& diagnostics) {
diagnostics.provider_state = state_;
}
void FakeLocationProvider::SetUpdateCallback(
const LocationProviderUpdateCallback& callback) {
callback_ = callback;
}
void FakeLocationProvider::StartProvider(bool high_accuracy) {
state_ =
high_accuracy
? device::mojom::GeolocationDiagnostics::ProviderState::kHighAccuracy
: device::mojom::GeolocationDiagnostics::ProviderState::kLowAccuracy;
}
void FakeLocationProvider::StopProvider() {
state_ = device::mojom::GeolocationDiagnostics::ProviderState::kStopped;
}
const device::mojom::GeopositionResult* FakeLocationProvider::GetPosition() {
return result_.get();
}
void FakeLocationProvider::OnPermissionGranted() {
if (!callback_.is_null()) {
callback_.Run(this, result_.Clone());
}
}
} // namespace electron
-41
View File
@@ -1,41 +0,0 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_FAKE_LOCATION_PROVIDER_H_
#define ELECTRON_SHELL_BROWSER_FAKE_LOCATION_PROVIDER_H_
#include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h"
namespace electron {
class FakeLocationProvider : public device::LocationProvider {
public:
FakeLocationProvider();
~FakeLocationProvider() override;
// disable copy
FakeLocationProvider(const FakeLocationProvider&) = delete;
FakeLocationProvider& operator=(const FakeLocationProvider&) = delete;
// LocationProvider Implementation:
void FillDiagnostics(
device::mojom::GeolocationDiagnostics& diagnostics) override;
void SetUpdateCallback(
const LocationProviderUpdateCallback& callback) override;
void StartProvider(bool high_accuracy) override;
void StopProvider() override;
const device::mojom::GeopositionResult* GetPosition() override;
void OnPermissionGranted() override;
private:
device::mojom::GeolocationDiagnostics::ProviderState state_ =
device::mojom::GeolocationDiagnostics::ProviderState::kStopped;
device::mojom::GeopositionResultPtr result_;
LocationProviderUpdateCallback callback_;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_FAKE_LOCATION_PROVIDER_H_
-6
View File
@@ -18,10 +18,6 @@ bool IsPDFViewerEnabled() {
return BUILDFLAG(ENABLE_PDF_VIEWER);
}
bool IsFakeLocationProviderEnabled() {
return BUILDFLAG(OVERRIDE_LOCATION_PROVIDER);
}
bool IsPrintingEnabled() {
return BUILDFLAG(ENABLE_PRINTING);
}
@@ -50,8 +46,6 @@ void Initialize(v8::Local<v8::Object> exports,
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod<&IsBuiltinSpellCheckerEnabled>("isBuiltinSpellCheckerEnabled");
dict.SetMethod<&IsPDFViewerEnabled>("isPDFViewerEnabled");
dict.SetMethod<&IsFakeLocationProviderEnabled>(
"isFakeLocationProviderEnabled");
dict.SetMethod<&IsPrintingEnabled>("isPrintingEnabled");
dict.SetMethod<&IsPromptAPIEnabled>("isPromptAPIEnabled");
dict.SetMethod<&IsComponentBuild>("isComponentBuild");
+16 -6
View File
@@ -1257,7 +1257,7 @@ describe('chromium features', () => {
});
describe('navigator.geolocation', () => {
ifit(features.isFakeLocationProviderEnabled())('returns error when permission is denied', async () => {
it('returns error when permission is denied', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
@@ -1279,23 +1279,33 @@ describe('chromium features', () => {
expect(channel).to.equal('success', 'unexpected response from geolocation api');
});
ifit(!features.isFakeLocationProviderEnabled())('returns position when permission is granted', async () => {
it('returns position when permission is granted', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
partition: 'geolocation-spec'
}
});
w.webContents.session.setPermissionRequestHandler((_wc, _permission, callback) => {
const requested: string[] = [];
w.webContents.session.setPermissionRequestHandler((_wc, permission, callback) => {
requested.push(permission);
callback(true);
});
// Supply the position over CDP so the test doesn't depend on a real provider:
// the network location service fails on CI.
// The permission request still goes through the session's handler.
const override = { latitude: 37.7749, longitude: -122.4194, accuracy: 10 };
w.webContents.debugger.attach();
await w.webContents.debugger.sendCommand('Emulation.setGeolocationOverride', override);
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const position = await w.webContents.executeJavaScript(`new Promise((resolve, reject) =>
navigator.geolocation.getCurrentPosition(
x => resolve({coords: x.coords, timestamp: x.timestamp}),
({ coords: { latitude, longitude, accuracy }, timestamp }) =>
resolve({ coords: { latitude, longitude, accuracy }, timestamp }),
err => reject(new Error(err.message))))`);
expect(position).to.have.property('coords');
expect(position).to.have.property('timestamp');
expect(requested).to.include('geolocation');
expect(position.coords).to.deep.equal(override);
expect(position.timestamp).to.be.a('number');
});
ifdescribe(process.platform === 'darwin')('with --disable-geolocation', () => {
-1
View File
@@ -20,7 +20,6 @@ declare namespace NodeJS {
interface FeaturesBinding {
isBuiltinSpellCheckerEnabled(): boolean;
isPDFViewerEnabled(): boolean;
isFakeLocationProviderEnabled(): boolean;
isPrintingEnabled(): boolean;
isPromptAPIEnabled(): boolean;
isComponentBuild(): boolean;