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