blob: 6db76c2182c2c20c2e7cce770b787c26ad9d8509 [file] [log] [blame]
[email protected]b12e2ba2012-10-04 19:10:181<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2<html>
3<head>
tkentc5e88f02017-02-06 22:47:314<script src="../resources/js-test.js"></script>
5<script src="../resources/mojo-helpers.js"></script>
sammce6687802016-05-13 04:06:576<script src="resources/geolocation-mock.js"></script>
[email protected]b12e2ba2012-10-04 19:10:187</head>
8<body>
9<script>
10description("Test the attribute handling of the Coordinates interface");
11window.jsTestIsAsync = true;
12
[email protected]b12e2ba2012-10-04 19:10:1813// Format: [Input], [Expected]
sammce6687802016-05-13 04:06:5714// Input: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed.
[email protected]b12e2ba2012-10-04 19:10:1815// Expected: latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed.
16var 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
24var currentTestIndex = -1;
25var globalCoordinates = null;
26
sammce6687802016-05-13 04:06:5727geolocationServiceMock.then(mock => {
28 mock.setGeolocationPermission(true);
[email protected]b12e2ba2012-10-04 19:10:1829
sammce6687802016-05-13 04:06:5730 function runNextTest()
31 {
32 ++currentTestIndex;
33 mock.setGeolocationPosition(...testSet[currentTestIndex][0]);
[email protected]b12e2ba2012-10-04 19:10:1834 }
[email protected]b12e2ba2012-10-04 19:10:1835
sammce6687802016-05-13 04:06:5736 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]b12e2ba2012-10-04 19:10:1864
65</script>
[email protected]b12e2ba2012-10-04 19:10:1866</body>
67</html>