blob: 510cb37298db0d92604b2cf23f2f94e315b21154 [file] [log] [blame]
[email protected]217e3f062013-11-29 21:53:131<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2<html>
3<head>
tkentc5e88f02017-02-06 22:47:314<script src="../resources/js-test.js"></script>
Reilly Grantbe310ab2017-07-11 01:51:265<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
6<script src="file:///gen/device/geolocation/public/interfaces/geolocation.mojom.js"></script>
Julie Jeongeun Kim162c2d282019-03-13 07:23:527<script src="file:///gen/third_party/blink/public/mojom/geolocation/geolocation_service.mojom.js"></script>
8<script src="file:///gen/third_party/blink/public/mojom/permissions/permission.mojom.js"></script>
sammce6687802016-05-13 04:06:579<script src="resources/geolocation-mock.js"></script>
[email protected]217e3f062013-11-29 21:53:1310</head>
11<body>
tkent98122ee2017-02-02 07:38:5112<script>
13description('Tests that when a cached position is available the callback for getCurrentPosition is called only once. This is a regression test for http://crbug.com/311876 .');
14
15// Only one success callback should be reported per call to getCurrentPosition.
16var reportCount = 0;
17var isSuccess;
18
19function reportCallback(success, id) {
20 isSuccess = success;
21 shouldBeTrue('isSuccess');
22 getCurrentPositionCallId = id;
23 shouldBe('getCurrentPositionCallId', 'reportCount');
24 if (++reportCount >= 3)
25 finishJSTest();
26}
27
28var getCurrentPositionCall = 0;
29function getPosition(milliseconds) {
30 var id = getCurrentPositionCall++;
31 var fn = function() {
32 navigator.geolocation.getCurrentPosition(
33 function(position) {
34 reportCallback(true, id);
35 },
36 function(error) {
37 reportCallback(false, id);
38 },
39 { maximumAge:600000, timeout:0 });
40 };
41 setTimeout(fn, milliseconds);
42}
43
Reilly Grantbe310ab2017-07-11 01:51:2644let mock = geolocationMock;
45mock.setGeolocationPosition(31.478, -0.166, 100);
46mock.setGeolocationPermission(true);
tkent98122ee2017-02-02 07:38:5147
Reilly Grantbe310ab2017-07-11 01:51:2648// Make a geolocation request to populate the cached value so requests with a
49// timeout of 0 can succeed.
50navigator.geolocation.getCurrentPosition(function(position) {
51 // The test terminates at the 3rd reported callback. If the bug still exists
52 // this happens after the 2nd call to getCurrentPosition, one of them is a
53 // repeat of the first.
54 getPosition(0);
55 getPosition(100);
56 getPosition(200);
57}, function(error) {
58 testFailed('Error callback invoked unexpectedly');
Maxim Kolosovskiy2291dbc2017-12-08 10:48:5459});
tkent98122ee2017-02-02 07:38:5160
61window.jsTestIsAsync = true;
62</script>
[email protected]217e3f062013-11-29 21:53:1363</body>
64</html>