| OLD | NEW |
| 1 description("Tests that when multiple requests are waiting for permission, no ca
llbacks are invoked until permission is denied."); | 1 description("Tests that when multiple requests are waiting for permission, no ca
llbacks are invoked until permission is denied."); |
| 2 | 2 |
| 3 if (!window.testRunner || !window.internals) | 3 if (!window.testRunner || !window.mojo) |
| 4 debug('This test can not run without testRunner or internals'); | 4 debug('This test can not run without testRunner or mojo'); |
| 5 | 5 |
| 6 internals.setGeolocationClientMock(document); | |
| 7 internals.setGeolocationPosition(document, 51.478, -0.166, 100); | |
| 8 | |
| 9 var permissionSet = false; | |
| 10 | |
| 11 function denyPermission() { | |
| 12 permissionSet = true; | |
| 13 internals.setGeolocationPermission(document, false); | |
| 14 } | |
| 15 | |
| 16 var watchCallbackInvoked = false; | |
| 17 var oneShotCallbackInvoked = false; | |
| 18 var error; | 6 var error; |
| 19 | 7 |
| 20 navigator.geolocation.watchPosition(function() { | 8 geolocationServiceMock.then(mock => { |
| 21 testFailed('Success callback invoked unexpectedly'); | 9 mock.setGeolocationPosition(51.478, -0.166, 100); |
| 22 finishJSTest(); | 10 |
| 23 }, function(e) { | 11 var permissionSet = false; |
| 24 if (permissionSet) { | 12 |
| 25 error = e; | 13 function denyPermission() { |
| 26 shouldBe('error.code', 'error.PERMISSION_DENIED'); | 14 permissionSet = true; |
| 27 shouldBe('error.message', '"User denied Geolocation"'); | 15 mock.setGeolocationPermission(false); |
| 28 watchCallbackInvoked = true; | |
| 29 maybeFinishTest(); | |
| 30 return; | |
| 31 } | 16 } |
| 32 testFailed('Error callback invoked unexpectedly'); | 17 |
| 33 finishJSTest(); | 18 var watchCallbackInvoked = false; |
| 19 var oneShotCallbackInvoked = false; |
| 20 |
| 21 navigator.geolocation.watchPosition(function() { |
| 22 testFailed('Success callback invoked unexpectedly'); |
| 23 finishJSTest(); |
| 24 }, function(e) { |
| 25 if (permissionSet) { |
| 26 error = e; |
| 27 shouldBe('error.code', 'error.PERMISSION_DENIED'); |
| 28 shouldBe('error.message', '"User denied Geolocation"'); |
| 29 watchCallbackInvoked = true; |
| 30 maybeFinishTest(); |
| 31 return; |
| 32 } |
| 33 testFailed('Error callback invoked unexpectedly'); |
| 34 finishJSTest(); |
| 35 }); |
| 36 |
| 37 navigator.geolocation.getCurrentPosition(function() { |
| 38 testFailed('Success callback invoked unexpectedly'); |
| 39 finishJSTest(); |
| 40 }, function(e) { |
| 41 if (permissionSet) { |
| 42 error = e; |
| 43 shouldBe('error.code', 'error.PERMISSION_DENIED'); |
| 44 shouldBe('error.message', '"User denied Geolocation"'); |
| 45 oneShotCallbackInvoked = true; |
| 46 maybeFinishTest(); |
| 47 return; |
| 48 } |
| 49 testFailed('Error callback invoked unexpectedly'); |
| 50 finishJSTest(); |
| 51 }); |
| 52 window.setTimeout(denyPermission, 100); |
| 53 |
| 54 function maybeFinishTest() { |
| 55 if (watchCallbackInvoked && oneShotCallbackInvoked) |
| 56 finishJSTest(); |
| 57 } |
| 34 }); | 58 }); |
| 35 | 59 |
| 36 navigator.geolocation.getCurrentPosition(function() { | |
| 37 testFailed('Success callback invoked unexpectedly'); | |
| 38 finishJSTest(); | |
| 39 }, function(e) { | |
| 40 if (permissionSet) { | |
| 41 error = e; | |
| 42 shouldBe('error.code', 'error.PERMISSION_DENIED'); | |
| 43 shouldBe('error.message', '"User denied Geolocation"'); | |
| 44 oneShotCallbackInvoked = true; | |
| 45 maybeFinishTest(); | |
| 46 return; | |
| 47 } | |
| 48 testFailed('Error callback invoked unexpectedly'); | |
| 49 finishJSTest(); | |
| 50 }); | |
| 51 window.setTimeout(denyPermission, 100); | |
| 52 | |
| 53 function maybeFinishTest() { | |
| 54 if (watchCallbackInvoked && oneShotCallbackInvoked) | |
| 55 finishJSTest(); | |
| 56 } | |
| 57 | |
| 58 window.jsTestIsAsync = true; | 60 window.jsTestIsAsync = true; |
| OLD | NEW |