Home | History | Annotate | Download | only in script-tests
      1 description("Tests that when Geolocation permission has been denied prior to a call to a Geolocation method, the error callback is invoked with code PERMISSION_DENIED, when the Geolocation service encounters an error.");
      2 
      3 // Prime the Geolocation instance by denying permission.
      4 if (window.layoutTestController) {
      5     layoutTestController.setGeolocationPermission(false);
      6     layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
      7 } else
      8     debug('This test can not be run without the LayoutTestController');
      9 
     10 var error;
     11 navigator.geolocation.getCurrentPosition(function(p) {
     12     testFailed('Success callback invoked unexpectedly');
     13     finishJSTest();
     14 }, function(e) {
     15     error = e;
     16     shouldBe('error.code', 'error.PERMISSION_DENIED');
     17     shouldBe('error.message', '"User denied Geolocation"');
     18     debug('');
     19     continueTest();
     20 });
     21 
     22 function continueTest()
     23 {
     24     // Make another request, with permission already denied.
     25     if (window.layoutTestController)
     26         layoutTestController.setMockGeolocationError(2, 'test');
     27 
     28     navigator.geolocation.getCurrentPosition(function(p) {
     29         testFailed('Success callback invoked unexpectedly');
     30         finishJSTest();
     31     }, function(e) {
     32         error = e;
     33         shouldBe('error.code', 'error.PERMISSION_DENIED');
     34         shouldBe('error.message', '"User denied Geolocation"');
     35         finishJSTest();
     36     });
     37 }
     38 
     39 window.jsTestIsAsync = true;
     40 window.successfullyParsed = true;
     41