[email protected] | a4ca426 | 2010-08-17 16:54:23 | [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] | a4ca426 | 2010-08-17 16:54:23 | [diff] [blame] | 9 | </head> |
| 10 | <body> |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 11 | <script> |
| 12 | description("Tests that when multiple requests are waiting for permission, no callbacks are invoked until permission is denied."); |
| 13 | |
| 14 | var error; |
| 15 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 16 | let mock = geolocationMock; |
| 17 | mock.setGeolocationPosition(51.478, -0.166, 100); |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 18 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 19 | var permissionSet = false; |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 20 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 21 | function denyPermission() { |
| 22 | permissionSet = true; |
| 23 | mock.setGeolocationPermission(false); |
| 24 | } |
| 25 | |
| 26 | var watchCallbackInvoked = false; |
| 27 | var oneShotCallbackInvoked = false; |
| 28 | |
| 29 | navigator.geolocation.watchPosition(function() { |
| 30 | testFailed('Success callback invoked unexpectedly'); |
| 31 | finishJSTest(); |
| 32 | }, function(e) { |
| 33 | if (permissionSet) { |
| 34 | error = e; |
| 35 | shouldBe('error.code', 'error.PERMISSION_DENIED'); |
| 36 | shouldBe('error.message', '"User denied Geolocation"'); |
| 37 | watchCallbackInvoked = true; |
| 38 | maybeFinishTest(); |
| 39 | return; |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 40 | } |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 41 | testFailed('Error callback invoked unexpectedly'); |
| 42 | finishJSTest(); |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 43 | }); |
| 44 | |
Reilly Grant | be310ab | 2017-07-11 01:51:26 | [diff] [blame] | 45 | navigator.geolocation.getCurrentPosition(function() { |
| 46 | testFailed('Success callback invoked unexpectedly'); |
| 47 | finishJSTest(); |
| 48 | }, function(e) { |
| 49 | if (permissionSet) { |
| 50 | error = e; |
| 51 | shouldBe('error.code', 'error.PERMISSION_DENIED'); |
| 52 | shouldBe('error.message', '"User denied Geolocation"'); |
| 53 | oneShotCallbackInvoked = true; |
| 54 | maybeFinishTest(); |
| 55 | return; |
| 56 | } |
| 57 | testFailed('Error callback invoked unexpectedly'); |
| 58 | finishJSTest(); |
| 59 | }); |
| 60 | window.setTimeout(denyPermission, 100); |
| 61 | |
| 62 | function maybeFinishTest() { |
| 63 | if (watchCallbackInvoked && oneShotCallbackInvoked) |
| 64 | finishJSTest(); |
| 65 | } |
| 66 | |
tkent | 98122ee | 2017-02-02 07:38:51 | [diff] [blame] | 67 | window.jsTestIsAsync = true; |
| 68 | </script> |
[email protected] | a4ca426 | 2010-08-17 16:54:23 | [diff] [blame] | 69 | </body> |
| 70 | </html> |