OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
2 <html> | |
3 <head> | |
4 <script src="../../../resources/js-test.js"></script> | |
5 <script src="../../../resources/mojo-helpers.js"></script> | |
6 <script src="resources/geolocation-mock.js"></script> | |
7 </head> | |
8 <body> | |
9 <script> | |
10 description('Tests that when a cached position is available the callback for get
CurrentPosition is called only once. This is a regression test for http://crbug.
com/311876 .'); | |
11 | |
12 // Only one success callback should be reported per call to getCurrentPosition. | |
13 var reportCount = 0; | |
14 var isSuccess; | |
15 | |
16 function reportCallback(success, id) { | |
17 isSuccess = success; | |
18 shouldBeTrue('isSuccess'); | |
19 getCurrentPositionCallId = id; | |
20 shouldBe('getCurrentPositionCallId', 'reportCount'); | |
21 if (++reportCount >= 3) | |
22 finishJSTest(); | |
23 } | |
24 | |
25 var getCurrentPositionCall = 0; | |
26 function getPosition(milliseconds) { | |
27 var id = getCurrentPositionCall++; | |
28 var fn = function() { | |
29 navigator.geolocation.getCurrentPosition( | |
30 function(position) { | |
31 reportCallback(true, id); | |
32 }, | |
33 function(error) { | |
34 reportCallback(false, id); | |
35 }, | |
36 { maximumAge:600000, timeout:0 }); | |
37 }; | |
38 setTimeout(fn, milliseconds); | |
39 } | |
40 | |
41 geolocationServiceMock.then(mock => { | |
42 mock.setGeolocationPosition(31.478, -0.166, 100); | |
43 mock.setGeolocationPermission(true); | |
44 | |
45 // Make a geolocation request to populate the cached value so requests with
a | |
46 // timeout of 0 can succeed. | |
47 navigator.geolocation.getCurrentPosition(function(position) { | |
48 // The test terminates at the 3rd reported callback. If the bug still ex
ists | |
49 // this happens after the 2nd call to getCurrentPosition, one of them is
a | |
50 // repeat of the first. | |
51 getPosition(0); | |
52 getPosition(100); | |
53 getPosition(200); | |
54 }, function(error) { | |
55 testFailed('Error callback invoked unexpectedly'); | |
56 }); | |
57 }); | |
58 | |
59 window.jsTestIsAsync = true; | |
60 </script> | |
61 </body> | |
62 </html> | |
OLD | NEW |