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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Geolocation/coordinates-interface-attributes.html

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 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../../resources/js-test.js"></script> 4 <script src="../../../resources/js-test.js"></script>
5 <script src="../../../resources/mojo-helpers.js"></script>
6 <script src="resources/geolocation-mock.js"></script>
5 </head> 7 </head>
6 <body> 8 <body>
7 <script> 9 <script>
8 description("Test the attribute handling of the Coordinates interface"); 10 description("Test the attribute handling of the Coordinates interface");
9 window.jsTestIsAsync = true; 11 window.jsTestIsAsync = true;
10 12
11 if (!window.testRunner || !window.internals) 13 if (!window.testRunner || !window.mojo)
12 debug('This test can not run without testRunner or internals'); 14 debug('This test can not run without testRunner or mojo');
13
14 internals.setGeolocationClientMock(document);
15 internals.setGeolocationPermission(document, true);
16 15
17 // Format: [Input], [Expected] 16 // Format: [Input], [Expected]
18 // Input: latitude, longitude, accuracy, providesAltitude, altitude, providesAlt itudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed. 17 // Input: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, sp eed.
19 // Expected: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed. 18 // Expected: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed.
20 var testSet = [ 19 var testSet = [
21 [[1, 2, 3], [1, 2, 3, null, null, null, null]], 20 [[1, 2, 3], [1, 2, 3, null, null, null, null]],
22 [[2, 3, 4, undefined, undefined, undefined, 5], [2, 3, 4, null, null, null, 5]], 21 [[2, 3, 4, undefined, undefined, undefined, 5], [2, 3, 4, null, null, null, 5]],
23 [[3, 4, 5, undefined, 6, undefined, 7], [3, 4, 5, null, 6, null, 7]], 22 [[3, 4, 5, undefined, 6, undefined, 7], [3, 4, 5, null, 6, null, 7]],
24 [[4, 5, 6, undefined, 7, 8, 9], [4, 5, 6, null, 7, 8, 9]], 23 [[4, 5, 6, undefined, 7, 8, 9], [4, 5, 6, null, 7, 8, 9]],
25 [[5, 6, 7, 8, 9, 10, 11], [5, 6, 7, 8, 9, 10, 11]], 24 [[5, 6, 7, 8, 9, 10, 11], [5, 6, 7, 8, 9, 10, 11]],
26 ]; 25 ];
27 26
28 var currentTestIndex = -1; 27 var currentTestIndex = -1;
29 var globalCoordinates = null; 28 var globalCoordinates = null;
30 29
31 function runNextTest() 30 geolocationServiceMock.then(mock => {
32 { 31 mock.setGeolocationPermission(true);
33 ++currentTestIndex;
34 internals.setGeolocationPosition.apply(internals, [document].concat(testSet[ currentTestIndex][0]));
35 }
36 32
37 function verifyResults() 33 function runNextTest()
38 { 34 {
39 shouldBe('globalCoordinates.latitude', 'testSet[currentTestIndex][1][0]'); 35 ++currentTestIndex;
40 shouldBe('globalCoordinates.longitude', 'testSet[currentTestIndex][1][1]'); 36 mock.setGeolocationPosition(...testSet[currentTestIndex][0]);
41 shouldBe('globalCoordinates.accuracy', 'testSet[currentTestIndex][1][2]'); 37 }
42 shouldBe('globalCoordinates.altitude', 'testSet[currentTestIndex][1][3]');
43 shouldBe('globalCoordinates.altitudeAccuracy', 'testSet[currentTestIndex][1] [4]');
44 shouldBe('globalCoordinates.heading', 'testSet[currentTestIndex][1][5]');
45 shouldBe('globalCoordinates.speed', 'testSet[currentTestIndex][1][6]');
46 debug('');
47 }
48 38
49 var watchId = navigator.geolocation.watchPosition(function(position) { 39 function verifyResults()
50 globalCoordinates = position.coords; 40 {
51 verifyResults(); 41 shouldBe('globalCoordinates.latitude', 'testSet[currentTestIndex][1][0]' );
42 shouldBe('globalCoordinates.longitude', 'testSet[currentTestIndex][1][1] ');
43 shouldBe('globalCoordinates.accuracy', 'testSet[currentTestIndex][1][2]' );
44 shouldBe('globalCoordinates.altitude', 'testSet[currentTestIndex][1][3]' );
45 shouldBe('globalCoordinates.altitudeAccuracy', 'testSet[currentTestIndex ][1][4]');
46 shouldBe('globalCoordinates.heading', 'testSet[currentTestIndex][1][5]') ;
47 shouldBe('globalCoordinates.speed', 'testSet[currentTestIndex][1][6]');
48 debug('');
49 }
52 50
53 if (currentTestIndex + 1 === testSet.length) { 51 var watchId = navigator.geolocation.watchPosition(function(position) {
52 globalCoordinates = position.coords;
53 verifyResults();
54
55 if (currentTestIndex + 1 === testSet.length) {
56 finishJSTest();
57 return;
58 }
59 runNextTest();
60 }, function(e) {
61 debug("Error!: the error callback was called.");
54 finishJSTest(); 62 finishJSTest();
55 return; 63 });
56 } 64
57 runNextTest(); 65 runNextTest();
58 }, function(e) {
59 debug("Error!: the error callback was called.");
60 finishJSTest();
61 }); 66 });
62 67
63 runNextTest();
64
65 </script> 68 </script>
66 </body> 69 </body>
67 </html> 70 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698