[email protected] | 64ad898 | 2010-06-11 08:50:22 | [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> |
| 7 | <script src="file:///gen/third_party/WebKit/public/platform/modules/permissions/permission.mojom.js"></script> |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 8 | <script src="resources/geolocation-mock.js"></script> |
[email protected] | 64ad898 | 2010-06-11 08:50:22 | [diff] [blame] | 9 | </head> |
| 10 | <body> |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 11 | <script> |
| 12 | description("Tests that Geolocation correctly handles multiple concurrent requests."); |
| 13 | |
| 14 | var mockLatitude = 51.478; |
| 15 | var mockLongitude = -0.166; |
| 16 | var mockAccuracy = 100; |
| 17 | |
| 18 | var position; |
| 19 | var watchCallbackInvoked = false; |
| 20 | var oneShotCallbackInvoked = false; |
| 21 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 22 | let mock = geolocationMock; |
| 23 | mock.setGeolocationPermission(true); |
| 24 | mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 25 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 26 | navigator.geolocation.watchPosition(function(p) { |
| 27 | shouldBeFalse('watchCallbackInvoked'); |
| 28 | watchCallbackInvoked = true; |
| 29 | maybeFinishTest(p); |
| 30 | }, function() { |
| 31 | testFailed('Error callback invoked unexpectedly'); |
| 32 | finishJSTest(); |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 33 | }); |
| 34 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 35 | navigator.geolocation.getCurrentPosition(function(p) { |
| 36 | shouldBeFalse('oneShotCallbackInvoked'); |
| 37 | oneShotCallbackInvoked = true; |
| 38 | maybeFinishTest(p); |
| 39 | }, function() { |
| 40 | testFailed('Error callback invoked unexpectedly'); |
| 41 | finishJSTest(); |
| 42 | }); |
| 43 | |
| 44 | function maybeFinishTest(p) { |
| 45 | position = p; |
| 46 | shouldBe('position.coords.latitude', 'mockLatitude'); |
| 47 | shouldBe('position.coords.longitude', 'mockLongitude'); |
| 48 | shouldBe('position.coords.accuracy', 'mockAccuracy'); |
| 49 | if (watchCallbackInvoked && oneShotCallbackInvoked) |
| 50 | finishJSTest(); |
| 51 | } |
| 52 | |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 53 | window.jsTestIsAsync = true; |
| 54 | </script> |
[email protected] | 64ad898 | 2010-06-11 08:50:22 | [diff] [blame] | 55 | </body> |
| 56 | </html> |