[email protected] | 217e3f06 | 2013-11-29 21:53:13 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 | <html> |
| 3 | <head> |
tkent | c5e88f0 | 2017-02-06 22:47:31 | [diff] [blame] | 4 | <script src="../resources/js-test.js"></script> |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 5 | <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 Kim | 162c2d28 | 2019-03-13 07:23:52 | [diff] [blame] | 7 | <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> |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 9 | <script src="resources/geolocation-mock.js"></script> |
[email protected] | 217e3f06 | 2013-11-29 21:53:13 | [diff] [blame] | 10 | </head> |
| 11 | <body> |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 12 | <script> |
| 13 | description('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. |
| 16 | var reportCount = 0; |
| 17 | var isSuccess; |
| 18 | |
| 19 | function reportCallback(success, id) { |
| 20 | isSuccess = success; |
| 21 | shouldBeTrue('isSuccess'); |
| 22 | getCurrentPositionCallId = id; |
| 23 | shouldBe('getCurrentPositionCallId', 'reportCount'); |
| 24 | if (++reportCount >= 3) |
| 25 | finishJSTest(); |
| 26 | } |
| 27 | |
| 28 | var getCurrentPositionCall = 0; |
| 29 | function 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 Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 44 | let mock = geolocationMock; |
| 45 | mock.setGeolocationPosition(31.478, -0.166, 100); |
| 46 | mock.setGeolocationPermission(true); |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 47 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 48 | // Make a geolocation request to populate the cached value so requests with a |
| 49 | // timeout of 0 can succeed. |
| 50 | navigator.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 Kolosovskiy | 2291dbc | 2017-12-08 10:48:54 | [diff] [blame] | 59 | }); |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 60 | |
| 61 | window.jsTestIsAsync = true; |
| 62 | </script> |
[email protected] | 217e3f06 | 2013-11-29 21:53:13 | [diff] [blame] | 63 | </body> |
| 64 | </html> |