Skip to content

Commit 39193a8

Browse files
authored
Decimal support on GeoLocation options (#1156)
* Decimal support on GeoLocation options * Add tests
1 parent 5cdb3cd commit 39193a8

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/PuppeteerSharp.Tests/PageTests/GeoLocationTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,26 @@ public async Task ShouldThrowWhenInvalidLongitude()
4545
}));
4646
Assert.Contains("Invalid longitude '200'", exception.Message);
4747
}
48+
49+
[Fact]
50+
public async Task ShouldWorkWithDecimalValues()
51+
{
52+
await Context.OverridePermissionsAsync(TestConstants.ServerUrl, new[] { OverridePermission.Geolocation });
53+
await Page.GoToAsync(TestConstants.EmptyPage);
54+
await Page.SetGeolocationAsync(new GeolocationOption
55+
{
56+
Longitude = 10.25m,
57+
Latitude = 10.54m
58+
});
59+
var geolocation = await Page.EvaluateFunctionAsync<GeolocationOption>(
60+
@"() => new Promise(resolve => navigator.geolocation.getCurrentPosition(position => {
61+
resolve({latitude: position.coords.latitude, longitude: position.coords.longitude});
62+
}))");
63+
Assert.Equal(new GeolocationOption
64+
{
65+
Longitude = 10.25m,
66+
Latitude = 10.54m
67+
}, geolocation);
68+
}
4869
}
4970
}

lib/PuppeteerSharp/GeolocationOption.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ public class GeolocationOption : IEquatable<GeolocationOption>
1313
/// Latitude between -90 and 90.
1414
/// </summary>
1515
/// <value>The latitude.</value>
16-
public int Latitude { get; set; }
16+
public decimal Latitude { get; set; }
1717
/// <summary>
1818
/// Longitude between -180 and 180.
1919
/// </summary>
2020
/// <value>The longitude.</value>
21-
public int Longitude { get; set; }
21+
public decimal Longitude { get; set; }
2222
/// <summary>
2323
/// Optional non-negative accuracy value.
2424
/// </summary>
2525
/// <value>The accuracy.</value>
26-
public int Accuracy { get; set; }
26+
public decimal Accuracy { get; set; }
2727

2828
/// <summary>
2929
/// Determines whether the specified <see cref="PuppeteerSharp.GeolocationOption"/> is equal to the current <see cref="T:PuppeteerSharp.GeolocationOption"/>.

0 commit comments

Comments
 (0)