1 description("Tests that when multiple requests are waiting for permission, no callbacks are invoked until permission is denied."); 2 3 if (window.layoutTestController) 4 window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100); 5 6 function denyPermission() { 7 permissionSet = true; 8 if (window.layoutTestController) 9 layoutTestController.setGeolocationPermission(false); 10 } 11 12 var watchCallbackInvoked = false; 13 var oneShotCallbackInvoked = false; 14 var error; 15 16 navigator.geolocation.watchPosition(function() { 17 testFailed('Success callback invoked unexpectedly'); 18 finishJSTest(); 19 }, function(e) { 20 if (permissionSet) { 21 error = e; 22 shouldBe('error.code', 'error.PERMISSION_DENIED'); 23 shouldBe('error.message', '"User denied Geolocation"'); 24 watchCallbackInvoked = true; 25 maybeFinishTest(); 26 return; 27 } 28 testFailed('Error callback invoked unexpectedly'); 29 finishJSTest(); 30 }); 31 32 navigator.geolocation.getCurrentPosition(function() { 33 testFailed('Success callback invoked unexpectedly'); 34 finishJSTest(); 35 }, function(e) { 36 if (permissionSet) { 37 error = e; 38 shouldBe('error.code', 'error.PERMISSION_DENIED'); 39 shouldBe('error.message', '"User denied Geolocation"'); 40 oneShotCallbackInvoked = true; 41 maybeFinishTest(); 42 return; 43 } 44 testFailed('Error callback invoked unexpectedly'); 45 finishJSTest(); 46 }); 47 window.setTimeout(denyPermission, 100); 48 49 function maybeFinishTest() { 50 if (watchCallbackInvoked && oneShotCallbackInvoked) 51 finishJSTest(); 52 } 53 54 window.jsTestIsAsync = true; 55 window.successfullyParsed = true; 56