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