OLD | NEW |
1 description("Tests that the PositionOptions.maximumAge parameter is correctly ap
plied."); | 1 description("Tests that the PositionOptions.maximumAge parameter is correctly ap
plied."); |
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 debug(''); | 13 debug(''); |
14 position = p; | 14 position = p; |
15 shouldBe('position.coords.latitude', 'mockLatitude'); | 15 shouldBe('position.coords.latitude', 'mockLatitude'); |
16 shouldBe('position.coords.longitude', 'mockLongitude'); | 16 shouldBe('position.coords.longitude', 'mockLongitude'); |
17 shouldBe('position.coords.accuracy', 'mockAccuracy'); | 17 shouldBe('position.coords.accuracy', 'mockAccuracy'); |
18 } | 18 } |
19 | 19 |
20 function checkError(e) { | 20 function checkError(e) { |
21 debug(''); | 21 debug(''); |
22 error = e; | 22 error = e; |
23 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); | 23 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); |
24 shouldBe('error.message', 'mockMessage'); | 24 shouldBe('error.message', 'mockMessage'); |
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 // Initialize the cached Position | 34 // Initialize the cached Position |
35 navigator.geolocation.getCurrentPosition(function(p) { | |
36 checkPosition(p); | |
37 testZeroMaximumAge(); | |
38 }, function(e) { | |
39 testFailed('Error callback invoked unexpectedly'); | |
40 finishJSTest(); | |
41 }); | |
42 | |
43 function testZeroMaximumAge() { | |
44 // Update the position provided by the mock service. | |
45 internals.setGeolocationPosition(document, ++mockLatitude, ++mockLongitude,
++mockAccuracy); | |
46 // The default maximumAge is zero, so we expect the updated position from th
e service. | |
47 navigator.geolocation.getCurrentPosition(function(p) { | 35 navigator.geolocation.getCurrentPosition(function(p) { |
48 checkPosition(p); | 36 checkPosition(p); |
49 testNonZeroMaximumAge(); | 37 testZeroMaximumAge(); |
50 }, function(e) { | 38 }, function(e) { |
51 testFailed('Error callback invoked unexpectedly'); | 39 testFailed('Error callback invoked unexpectedly'); |
52 finishJSTest(); | 40 finishJSTest(); |
53 }); | 41 }); |
54 } | |
55 | 42 |
56 function testNonZeroMaximumAge() { | 43 function testZeroMaximumAge() { |
57 // Update the mock service to report an error. | 44 // Update the position provided by the mock service. |
58 internals.setGeolocationPositionUnavailableError(document, mockMessage); | 45 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccur
acy); |
59 // The maximumAge is non-zero, so we expect the cached position, not the err
or from the service. | 46 // The default maximumAge is zero, so we expect the updated position fro
m the service. |
60 navigator.geolocation.getCurrentPosition(function(p) { | 47 navigator.geolocation.getCurrentPosition(function(p) { |
61 checkPosition(p); | 48 checkPosition(p); |
62 testNegativeValueMaximumAge(); | 49 testNonZeroMaximumAge(); |
63 }, function(e) { | 50 }, function(e) { |
64 testFailed('Error callback invoked unexpectedly'); | 51 testFailed('Error callback invoked unexpectedly'); |
65 finishJSTest(); | 52 finishJSTest(); |
66 }, {maximumAge: 1000}); | 53 }); |
67 } | 54 } |
68 | 55 |
69 function testNegativeValueMaximumAge() { | 56 function testNonZeroMaximumAge() { |
70 // Update the position provided by the mock service. | 57 // Update the mock service to report an error. |
71 internals.setGeolocationPosition(document, ++mockLatitude, ++mockLongitude,
++mockAccuracy); | 58 mock.setGeolocationPositionUnavailableError(mockMessage); |
72 // The maximumAge is same as zero, so we expect the updated position from th
e service. | 59 // The maximumAge is non-zero, so we expect the cached position, not the
error from the service. |
73 navigator.geolocation.getCurrentPosition(function(p) { | 60 navigator.geolocation.getCurrentPosition(function(p) { |
74 checkPosition(p); | 61 checkPosition(p); |
75 testOverSignedIntMaximumAge(); | 62 testNegativeValueMaximumAge(); |
76 }, function(e) { | 63 }, function(e) { |
77 testFailed('Error callback invoked unexpectedly'); | 64 testFailed('Error callback invoked unexpectedly'); |
78 finishJSTest(); | 65 finishJSTest(); |
79 }, {maximumAge: -1000}); | 66 }, {maximumAge: 1000}); |
80 } | 67 } |
81 | 68 |
82 function testOverSignedIntMaximumAge() { | 69 function testNegativeValueMaximumAge() { |
83 // Update the mock service to report an error. | 70 // Update the position provided by the mock service. |
84 internals.setGeolocationPositionUnavailableError(document, mockMessage); | 71 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccur
acy); |
85 // The maximumAge is non-zero, so we expect the cached position, not the err
or from the service. | 72 // The maximumAge is same as zero, so we expect the updated position fro
m the service. |
86 navigator.geolocation.getCurrentPosition(function(p) { | 73 navigator.geolocation.getCurrentPosition(function(p) { |
87 checkPosition(p); | 74 checkPosition(p); |
88 testOverUnsignedIntMaximumAge(); | 75 testOverSignedIntMaximumAge(); |
89 }, function(e) { | 76 }, function(e) { |
90 testFailed('Error callback invoked unexpectedly'); | 77 testFailed('Error callback invoked unexpectedly'); |
91 finishJSTest(); | 78 finishJSTest(); |
92 }, {maximumAge: 2147483648}); | 79 }, {maximumAge: -1000}); |
93 } | 80 } |
94 | 81 |
95 function testOverUnsignedIntMaximumAge() { | 82 function testOverSignedIntMaximumAge() { |
96 // Update the mock service to report an error. | 83 // Update the mock service to report an error. |
97 internals.setGeolocationPositionUnavailableError(document, mockMessage); | 84 mock.setGeolocationPositionUnavailableError(mockMessage); |
98 // The maximumAge is max-value of unsigned, so we expect the cached position
, not the error from the service. | 85 // The maximumAge is non-zero, so we expect the cached position, not the
error from the service. |
99 navigator.geolocation.getCurrentPosition(function(p) { | 86 navigator.geolocation.getCurrentPosition(function(p) { |
100 checkPosition(p); | 87 checkPosition(p); |
101 testZeroMaximumAgeError(); | 88 testOverUnsignedIntMaximumAge(); |
102 }, function(e) { | 89 }, function(e) { |
103 testFailed('Error callback invoked unexpectedly'); | 90 testFailed('Error callback invoked unexpectedly'); |
104 finishJSTest(); | 91 finishJSTest(); |
105 }, {maximumAge: 4294967296}); | 92 }, {maximumAge: 2147483648}); |
106 } | 93 } |
107 | 94 |
108 function testZeroMaximumAgeError() { | 95 function testOverUnsignedIntMaximumAge() { |
109 // The default maximumAge is zero, so we expect the error from the service. | 96 // Update the mock service to report an error. |
110 navigator.geolocation.getCurrentPosition(function(p) { | 97 mock.setGeolocationPositionUnavailableError(mockMessage); |
111 testFailed('Success callback invoked unexpectedly'); | 98 // The maximumAge is max-value of unsigned, so we expect the cached posi
tion, not the error from the service. |
112 finishJSTest(); | 99 navigator.geolocation.getCurrentPosition(function(p) { |
113 }, function(e) { | 100 checkPosition(p); |
114 checkError(e); | 101 testZeroMaximumAgeError(); |
115 finishJSTest(); | 102 }, function(e) { |
116 }); | 103 testFailed('Error callback invoked unexpectedly'); |
117 } | 104 finishJSTest(); |
| 105 }, {maximumAge: 4294967296}); |
| 106 } |
| 107 |
| 108 function testZeroMaximumAgeError() { |
| 109 // The default maximumAge is zero, so we expect the error from the servi
ce. |
| 110 navigator.geolocation.getCurrentPosition(function(p) { |
| 111 testFailed('Success callback invoked unexpectedly'); |
| 112 finishJSTest(); |
| 113 }, function(e) { |
| 114 checkError(e); |
| 115 finishJSTest(); |
| 116 }); |
| 117 } |
| 118 }); |
118 | 119 |
119 window.jsTestIsAsync = true; | 120 window.jsTestIsAsync = true; |
OLD | NEW |