Home | History | Annotate | Download | only in script-tests
      1 description("Tests that reentrant calls to Geolocation methods from the error callback are OK.");
      2 
      3 var mockCode = 2;
      4 var mockMessage = 'test';
      5 
      6 if (window.layoutTestController) {
      7     layoutTestController.setGeolocationPermission(true);
      8     layoutTestController.setMockGeolocationError(mockCode, mockMessage);
      9 } else
     10     debug('This test can not be run without the LayoutTestController');
     11 
     12 var error;
     13 var errorCallbackInvoked = false;
     14 navigator.geolocation.getCurrentPosition(function(p) {
     15     testFailed('Success callback invoked unexpectedly');
     16     finishJSTest();
     17 }, function(e) {
     18     if (errorCallbackInvoked) {
     19         testFailed('Error callback invoked unexpectedly');
     20         finishJSTest();
     21     }
     22     errorCallbackInvoked = true;
     23 
     24     error = e;
     25     shouldBe('error.code', 'mockCode');
     26     shouldBe('error.message', 'mockMessage');
     27     debug('');
     28     continueTest();
     29 });
     30 
     31 function continueTest() {
     32     mockMessage += ' repeat';
     33 
     34     if (window.layoutTestController)
     35         layoutTestController.setMockGeolocationError(mockCode, mockMessage);
     36 
     37     navigator.geolocation.getCurrentPosition(function(p) {
     38         testFailed('Success callback invoked unexpectedly');
     39         finishJSTest();
     40     }, function(e) {
     41         error = e;
     42         shouldBe('error.code', 'mockCode');
     43         shouldBe('error.message', 'mockMessage');
     44         finishJSTest();
     45     });
     46 }
     47 
     48 window.jsTestIsAsync = true;
     49 window.successfullyParsed = true;
     50