Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Geolocation/script-tests/multiple-requests.js

Issue 1948033003: Convert most geolocation layout tests to use a JS mock implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-disconnect
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 description("Tests that Geolocation correctly handles multiple concurrent reques ts."); 1 description("Tests that Geolocation correctly handles multiple concurrent reques ts.");
2 2
3 var mockLatitude = 51.478; 3 var mockLatitude = 51.478;
4 var mockLongitude = -0.166; 4 var mockLongitude = -0.166;
5 var mockAccuracy = 100; 5 var mockAccuracy = 100;
6 6
7 if (!window.testRunner || !window.internals) 7 if (!window.testRunner || !window.mojo)
8 debug('This test can not run without testRunner or internals'); 8 debug('This test can not run without testRunner or mojo');
9 9
10 internals.setGeolocationClientMock(document); 10 var position;
11 internals.setGeolocationPermission(document, true);
12 internals.setGeolocationPosition(document, mockLatitude, mockLongitude, mockAccu racy);
13
14 var watchCallbackInvoked = false; 11 var watchCallbackInvoked = false;
15 var oneShotCallbackInvoked = false; 12 var oneShotCallbackInvoked = false;
16 13
17 navigator.geolocation.watchPosition(function(p) { 14 geolocationServiceMock.then(mock => {
18 shouldBeFalse('watchCallbackInvoked'); 15 mock.setGeolocationPermission(true);
19 watchCallbackInvoked = true; 16 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
20 maybeFinishTest(p); 17
21 }, function() { 18 navigator.geolocation.watchPosition(function(p) {
22 testFailed('Error callback invoked unexpectedly'); 19 shouldBeFalse('watchCallbackInvoked');
23 finishJSTest(); 20 watchCallbackInvoked = true;
21 maybeFinishTest(p);
22 }, function() {
23 testFailed('Error callback invoked unexpectedly');
24 finishJSTest();
25 });
26
27 navigator.geolocation.getCurrentPosition(function(p) {
28 shouldBeFalse('oneShotCallbackInvoked');
29 oneShotCallbackInvoked = true;
30 maybeFinishTest(p);
31 }, function() {
32 testFailed('Error callback invoked unexpectedly');
33 finishJSTest();
34 });
35
36 function maybeFinishTest(p) {
37 position = p;
38 shouldBe('position.coords.latitude', 'mockLatitude');
39 shouldBe('position.coords.longitude', 'mockLongitude');
40 shouldBe('position.coords.accuracy', 'mockAccuracy');
41 if (watchCallbackInvoked && oneShotCallbackInvoked)
42 finishJSTest();
43 }
24 }); 44 });
25 45
26 navigator.geolocation.getCurrentPosition(function(p) {
27 shouldBeFalse('oneShotCallbackInvoked');
28 oneShotCallbackInvoked = true;
29 maybeFinishTest(p);
30 }, function() {
31 testFailed('Error callback invoked unexpectedly');
32 finishJSTest();
33 });
34
35 var position;
36 function maybeFinishTest(p) {
37 position = p;
38 shouldBe('position.coords.latitude', 'mockLatitude');
39 shouldBe('position.coords.longitude', 'mockLongitude');
40 shouldBe('position.coords.accuracy', 'mockAccuracy');
41 if (watchCallbackInvoked && oneShotCallbackInvoked)
42 finishJSTest();
43 }
44
45 window.jsTestIsAsync = true; 46 window.jsTestIsAsync = true;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698