Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Geolocation / script-tests / delayed-permission-allowed-for-multiple-requests.js
blobe19e79c11b8e5206d5c09120922ad25a4a0231ee
1 description("Tests that when multiple requests are waiting for permission, no callbacks are invoked until permission is allowed.");
3 if (!window.testRunner || !window.internals)
4 debug('This test can not run without testRunner or internals');
6 internals.setGeolocationClientMock(document);
7 internals.setGeolocationPosition(document, 51.478, -0.166, 100);
9 var permissionSet = false;
11 function allowPermission() {
12 permissionSet = true;
13 internals.setGeolocationPermission(document, true);
16 var watchCallbackInvoked = false;
17 var oneShotCallbackInvoked = false;
19 navigator.geolocation.watchPosition(function() {
20 if (permissionSet) {
21 testPassed('Success callback invoked');
22 watchCallbackInvoked = true;
23 maybeFinishTest();
24 return;
26 testFailed('Success callback invoked unexpectedly');
27 finishJSTest();
28 }, function(err) {
29 testFailed('Error callback invoked unexpectedly');
30 finishJSTest();
31 });
33 navigator.geolocation.getCurrentPosition(function() {
34 if (permissionSet) {
35 testPassed('Success callback invoked');
36 oneShotCallbackInvoked = true;
37 maybeFinishTest();
38 return;
40 testFailed('Success callback invoked unexpectedly');
41 finishJSTest();
42 }, function(err) {
43 testFailed('Error callback invoked unexpectedly');
44 finishJSTest();
45 });
47 window.setTimeout(allowPermission, 100);
49 function maybeFinishTest() {
50 if (watchCallbackInvoked && oneShotCallbackInvoked)
51 finishJSTest();
54 window.jsTestIsAsync = true;