forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathreentrant-success.https.html
62 lines (54 loc) · 1.86 KB
/
reentrant-success.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/testharness-adapter.js"></script>
</head>
<body>
<script type="module">
import {GeolocationMock} from './resources/geolocation-mock.js';
description("Tests that reentrant calls to Geolocation methods from the success callback are OK.");
let mockLatitude = 51.478;
let mockLongitude = -0.166;
let mockAccuracy = 100.0;
let position;
const mock = new GeolocationMock();
mock.setGeolocationPermission(true);
mock.setGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
let successCallbackInvoked = false;
navigator.geolocation.getCurrentPosition(function(p) {
if (successCallbackInvoked) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}
successCallbackInvoked = true;
position = p;
assert_equals(position.coords.latitude, mockLatitude);
assert_equals(position.coords.longitude, mockLongitude);
assert_equals(position.coords.accuracy, mockAccuracy);
continueTest();
}, function(e) {
testFailed('Error callback invoked unexpectedly');
finishJSTest();
});
function continueTest() {
mock.setGeolocationPosition(++mockLatitude,
++mockLongitude,
++mockAccuracy);
navigator.geolocation.getCurrentPosition(function(p) {
position = p;
assert_equals(position.coords.latitude, mockLatitude);
assert_equals(position.coords.longitude, mockLongitude);
assert_equals(position.coords.accuracy, mockAccuracy);
finishJSTest();
}, function(e) {
testFailed('Error callback invoked unexpectedly');
finishJSTest();
});
}
</script>
</body>
</html>