OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
2 <html> | |
3 <head> | |
4 <script src="../../../resources/js-test.js"></script> | |
5 <script src="../../../resources/mojo-helpers.js"></script> | |
6 <script src="resources/geolocation-mock.js"></script> | |
7 </head> | |
8 <body> | |
9 <script> | |
10 description("Tests that the PositionOptions.maximumAge parameter is correctly ap
plied."); | |
11 | |
12 var mockLatitude = 51.478; | |
13 var mockLongitude = -0.166; | |
14 var mockAccuracy = 100.0; | |
15 | |
16 var mockMessage = 'test'; | |
17 | |
18 var position; | |
19 var error; | |
20 | |
21 function checkPosition(p) { | |
22 debug(''); | |
23 position = p; | |
24 shouldBe('position.coords.latitude', 'mockLatitude'); | |
25 shouldBe('position.coords.longitude', 'mockLongitude'); | |
26 shouldBe('position.coords.accuracy', 'mockAccuracy'); | |
27 } | |
28 | |
29 function checkError(e) { | |
30 debug(''); | |
31 error = e; | |
32 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); | |
33 shouldBe('error.message', 'mockMessage'); | |
34 } | |
35 | |
36 geolocationServiceMock.then(mock => { | |
37 mock.setGeolocationPermission(true); | |
38 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); | |
39 | |
40 // Initialize the cached Position | |
41 navigator.geolocation.getCurrentPosition(function(p) { | |
42 checkPosition(p); | |
43 testZeroMaximumAge(); | |
44 }, function(e) { | |
45 testFailed('Error callback invoked unexpectedly'); | |
46 finishJSTest(); | |
47 }); | |
48 | |
49 function testZeroMaximumAge() { | |
50 // Update the position provided by the mock service. | |
51 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccur
acy); | |
52 // The default maximumAge is zero, so we expect the updated position fro
m the service. | |
53 navigator.geolocation.getCurrentPosition(function(p) { | |
54 checkPosition(p); | |
55 testNonZeroMaximumAge(); | |
56 }, function(e) { | |
57 testFailed('Error callback invoked unexpectedly'); | |
58 finishJSTest(); | |
59 }); | |
60 } | |
61 | |
62 function testNonZeroMaximumAge() { | |
63 // Update the mock service to report an error. | |
64 mock.setGeolocationPositionUnavailableError(mockMessage); | |
65 // The maximumAge is non-zero, so we expect the cached position, not the
error from the service. | |
66 navigator.geolocation.getCurrentPosition(function(p) { | |
67 checkPosition(p); | |
68 testNegativeValueMaximumAge(); | |
69 }, function(e) { | |
70 testFailed('Error callback invoked unexpectedly'); | |
71 finishJSTest(); | |
72 }, {maximumAge: 1000}); | |
73 } | |
74 | |
75 function testNegativeValueMaximumAge() { | |
76 // Update the position provided by the mock service. | |
77 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccur
acy); | |
78 // The maximumAge is same as zero, so we expect the updated position fro
m the service. | |
79 navigator.geolocation.getCurrentPosition(function(p) { | |
80 checkPosition(p); | |
81 testOverSignedIntMaximumAge(); | |
82 }, function(e) { | |
83 testFailed('Error callback invoked unexpectedly'); | |
84 finishJSTest(); | |
85 }, {maximumAge: -1000}); | |
86 } | |
87 | |
88 function testOverSignedIntMaximumAge() { | |
89 // Update the mock service to report an error. | |
90 mock.setGeolocationPositionUnavailableError(mockMessage); | |
91 // The maximumAge is non-zero, so we expect the cached position, not the
error from the service. | |
92 navigator.geolocation.getCurrentPosition(function(p) { | |
93 checkPosition(p); | |
94 testOverUnsignedIntMaximumAge(); | |
95 }, function(e) { | |
96 testFailed('Error callback invoked unexpectedly'); | |
97 finishJSTest(); | |
98 }, {maximumAge: 2147483648}); | |
99 } | |
100 | |
101 function testOverUnsignedIntMaximumAge() { | |
102 // Update the mock service to report an error. | |
103 mock.setGeolocationPositionUnavailableError(mockMessage); | |
104 // The maximumAge is max-value of unsigned, so we expect the cached posi
tion, not the error from the service. | |
105 navigator.geolocation.getCurrentPosition(function(p) { | |
106 checkPosition(p); | |
107 testZeroMaximumAgeError(); | |
108 }, function(e) { | |
109 testFailed('Error callback invoked unexpectedly'); | |
110 finishJSTest(); | |
111 }, {maximumAge: 4294967296}); | |
112 } | |
113 | |
114 function testZeroMaximumAgeError() { | |
115 // The default maximumAge is zero, so we expect the error from the servi
ce. | |
116 navigator.geolocation.getCurrentPosition(function(p) { | |
117 testFailed('Success callback invoked unexpectedly'); | |
118 finishJSTest(); | |
119 }, function(e) { | |
120 checkError(e); | |
121 finishJSTest(); | |
122 }); | |
123 } | |
124 }); | |
125 | |
126 window.jsTestIsAsync = true; | |
127 </script> | |
128 </body> | |
129 </html> | |
OLD | NEW |