[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 | <html> |
| 3 | <head> |
tkent | c5e88f0 | 2017-02-06 22:47:31 | [diff] [blame^] | 4 | <script src="../resources/js-test.js"></script> |
| 5 | <script src="../resources/mojo-helpers.js"></script> |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 6 | <script src="resources/geolocation-mock.js"></script> |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 7 | </head> |
| 8 | <body> |
| 9 | <script> |
| 10 | description("Test the attribute handling of the Coordinates interface"); |
| 11 | window.jsTestIsAsync = true; |
| 12 | |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 13 | // Format: [Input], [Expected] |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 14 | // Input: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed. |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 15 | // Expected: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed. |
| 16 | var testSet = [ |
| 17 | [[1, 2, 3], [1, 2, 3, null, null, null, null]], |
| 18 | [[2, 3, 4, undefined, undefined, undefined, 5], [2, 3, 4, null, null, null, 5]], |
| 19 | [[3, 4, 5, undefined, 6, undefined, 7], [3, 4, 5, null, 6, null, 7]], |
| 20 | [[4, 5, 6, undefined, 7, 8, 9], [4, 5, 6, null, 7, 8, 9]], |
| 21 | [[5, 6, 7, 8, 9, 10, 11], [5, 6, 7, 8, 9, 10, 11]], |
| 22 | ]; |
| 23 | |
| 24 | var currentTestIndex = -1; |
| 25 | var globalCoordinates = null; |
| 26 | |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 27 | geolocationServiceMock.then(mock => { |
| 28 | mock.setGeolocationPermission(true); |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 29 | |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 30 | function runNextTest() |
| 31 | { |
| 32 | ++currentTestIndex; |
| 33 | mock.setGeolocationPosition(...testSet[currentTestIndex][0]); |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 34 | } |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 35 | |
sammc | e668780 | 2016-05-13 04:06:57 | [diff] [blame] | 36 | function verifyResults() |
| 37 | { |
| 38 | shouldBe('globalCoordinates.latitude', 'testSet[currentTestIndex][1][0]'); |
| 39 | shouldBe('globalCoordinates.longitude', 'testSet[currentTestIndex][1][1]'); |
| 40 | shouldBe('globalCoordinates.accuracy', 'testSet[currentTestIndex][1][2]'); |
| 41 | shouldBe('globalCoordinates.altitude', 'testSet[currentTestIndex][1][3]'); |
| 42 | shouldBe('globalCoordinates.altitudeAccuracy', 'testSet[currentTestIndex][1][4]'); |
| 43 | shouldBe('globalCoordinates.heading', 'testSet[currentTestIndex][1][5]'); |
| 44 | shouldBe('globalCoordinates.speed', 'testSet[currentTestIndex][1][6]'); |
| 45 | debug(''); |
| 46 | } |
| 47 | |
| 48 | var watchId = navigator.geolocation.watchPosition(function(position) { |
| 49 | globalCoordinates = position.coords; |
| 50 | verifyResults(); |
| 51 | |
| 52 | if (currentTestIndex + 1 === testSet.length) { |
| 53 | finishJSTest(); |
| 54 | return; |
| 55 | } |
| 56 | runNextTest(); |
| 57 | }, function(e) { |
| 58 | debug("Error!: the error callback was called."); |
| 59 | finishJSTest(); |
| 60 | }); |
| 61 | |
| 62 | runNextTest(); |
| 63 | }); |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 64 | |
| 65 | </script> |
[email protected] | b12e2ba | 2012-10-04 19:10:18 | [diff] [blame] | 66 | </body> |
| 67 | </html> |