Skip to content

Commit ba4e1ad

Browse files
authored
Bidi: Implement SetGeolocalizationAsync (#3000)
1 parent 4e27d19 commit ba4e1ad

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -930,21 +930,6 @@
930930
"FAIL"
931931
]
932932
},
933-
{
934-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
935-
"testIdPattern": "[page.spec] *Page.setGeolocation*",
936-
"platforms": [
937-
"darwin",
938-
"linux",
939-
"win32"
940-
],
941-
"parameters": [
942-
"webDriverBiDi"
943-
],
944-
"expectations": [
945-
"FAIL"
946-
]
947-
},
948933
{
949934
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
950935
"testIdPattern": "[page.spec] *Page.metrics*",

lib/PuppeteerSharp/Bidi/BidiPage.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,46 @@ public override async Task<IResponse> ReloadAsync(NavigationOptions options)
162162
public override Task<IFrame> WaitForFrameAsync(Func<IFrame, bool> predicate, WaitForOptions options = null) => throw new NotImplementedException();
163163

164164
/// <inheritdoc />
165-
public override Task SetGeolocationAsync(GeolocationOption options) => throw new NotImplementedException();
165+
public override async Task SetGeolocationAsync(GeolocationOption options)
166+
{
167+
if (options == null)
168+
{
169+
throw new ArgumentNullException(nameof(options));
170+
}
171+
172+
var longitude = options.Longitude;
173+
var latitude = options.Latitude;
174+
var accuracy = options.Accuracy;
175+
176+
if (longitude < -180 || longitude > 180)
177+
{
178+
throw new ArgumentException($"Invalid longitude '{longitude}': precondition -180 <= LONGITUDE <= 180 failed.");
179+
}
180+
181+
if (latitude < -90 || latitude > 90)
182+
{
183+
throw new ArgumentException($"Invalid latitude '{latitude}': precondition -90 <= LATITUDE <= 90 failed.");
184+
}
185+
186+
if (accuracy < 0)
187+
{
188+
throw new ArgumentException($"Invalid accuracy '{accuracy}': precondition 0 <= ACCURACY failed.");
189+
}
190+
191+
var coordinates = new WebDriverBiDi.Emulation.GeolocationCoordinates((double)longitude, (double)latitude)
192+
{
193+
Accuracy = (double?)accuracy,
194+
};
195+
196+
var commandParameters = new WebDriverBiDi.Emulation.SetGeolocationOverrideCoordinatesCommandParameters
197+
{
198+
Coordinates = coordinates,
199+
};
200+
201+
commandParameters.Contexts.Add(BidiMainFrame.BrowsingContext.Id);
202+
203+
await BidiMainFrame.BrowsingContext.Session.Driver.Emulation.SetGeolocationOverrideAsync(commandParameters).ConfigureAwait(false);
204+
}
166205

167206
/// <inheritdoc />
168207
public override Task SetJavaScriptEnabledAsync(bool enabled) => throw new NotImplementedException();

0 commit comments

Comments
 (0)