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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Geolocation/script-tests/watch.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 watchPosition correctly reports position updates and err ors from the Geolocation service."); 1 description("Tests that watchPosition correctly reports position updates and err ors from the Geolocation service.");
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.0; 5 var mockAccuracy = 100.0;
6 6
7 var mockMessage = 'test'; 7 var mockMessage = 'test';
8 8
9 var position; 9 var position;
10 var error; 10 var error;
11 11
12 function checkPosition(p) { 12 function checkPosition(p) {
13 position = p; 13 position = p;
14 shouldBe('position.coords.latitude', 'mockLatitude'); 14 shouldBe('position.coords.latitude', 'mockLatitude');
15 shouldBe('position.coords.longitude', 'mockLongitude'); 15 shouldBe('position.coords.longitude', 'mockLongitude');
16 shouldBe('position.coords.accuracy', 'mockAccuracy'); 16 shouldBe('position.coords.accuracy', 'mockAccuracy');
17 debug(''); 17 debug('');
18 } 18 }
19 19
20 function checkError(e) { 20 function checkError(e) {
21 error = e; 21 error = e;
22 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); 22 shouldBe('error.code', 'error.POSITION_UNAVAILABLE');
23 shouldBe('error.message', 'mockMessage'); 23 shouldBe('error.message', 'mockMessage');
24 debug(''); 24 debug('');
25 } 25 }
26 26
27 if (!window.testRunner || !window.internals) 27 if (!window.testRunner || !window.mojo)
28 debug('This test can not run without testRunner or internals'); 28 debug('This test can not run without testRunner or mojo');
29 29
30 internals.setGeolocationClientMock(document); 30 geolocationServiceMock.then(mock => {
31 internals.setGeolocationPermission(document, true); 31 mock.setGeolocationPermission(true);
32 internals.setGeolocationPosition(document, mockLatitude, mockLongitude, mockAccu racy); 32 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
33 33
34 var state = 0; 34 var state = 0;
35 navigator.geolocation.watchPosition(function(p) { 35 navigator.geolocation.watchPosition(function(p) {
36 switch (state++) { 36 switch (state++) {
37 case 0: 37 case 0:
38 checkPosition(p); 38 checkPosition(p);
39 internals.setGeolocationPosition(document, ++mockLatitude, ++mockLon gitude, ++mockAccuracy); 39 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++m ockAccuracy);
40 break; 40 break;
41 case 1: 41 case 1:
42 checkPosition(p); 42 checkPosition(p);
43 internals.setGeolocationPositionUnavailableError(document, mockMessa ge); 43 mock.setGeolocationPositionUnavailableError(mockMessage);
44 break; 44 break;
45 case 3: 45 case 3:
46 checkPosition(p); 46 checkPosition(p);
47 finishJSTest(); 47 finishJSTest();
48 break; 48 break;
49 default: 49 default:
50 testFailed('Success callback invoked unexpectedly'); 50 testFailed('Success callback invoked unexpectedly');
51 finishJSTest(); 51 finishJSTest();
52 } 52 }
53 }, function(e) { 53 }, function(e) {
54 switch (state++) { 54 switch (state++) {
55 case 2: 55 case 2:
56 checkError(e); 56 checkError(e);
57 internals.setGeolocationPosition(document, ++mockLatitude, ++mockLon gitude, ++mockAccuracy); 57 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++m ockAccuracy);
58 break; 58 break;
59 default: 59 default:
60 testFailed('Error callback invoked unexpectedly'); 60 testFailed('Error callback invoked unexpectedly');
61 finishJSTest(); 61 finishJSTest();
62 } 62 }
63 });
63 }); 64 });
64 65
65 window.jsTestIsAsync = true; 66 window.jsTestIsAsync = true;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698