|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=478911 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for getCurrentPosition </title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="geolocation_common.js"></script> |
|
10 |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=777594">Mozilla Bug 777594</a> |
|
15 <p id="display"></p> |
|
16 <div id="content" style="display: none"> |
|
17 |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script class="testbody" type="text/javascript"> |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 resume_geolocationProvider(function() { |
|
25 force_prompt(true, test1); |
|
26 }); |
|
27 |
|
28 if (SpecialPowers.isMainProcess()) { |
|
29 SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm"); |
|
30 } |
|
31 |
|
32 function test1() { |
|
33 //This pushPermissions call is after pushPrefEnv call and pushPrefEnv calls follow after this |
|
34 SpecialPowers.pushPermissions([{'type': 'settings-read', 'allow': true, 'context': document}, {'type': 'settings-write', 'allow': true, 'context': document}], test2); |
|
35 } |
|
36 |
|
37 function test2() { |
|
38 ok(navigator.geolocation, "get geolocation object"); |
|
39 |
|
40 toggleGeolocationSetting(false, function() { |
|
41 ok(true, "turned off geolocation via mozSettings"); |
|
42 setTimeout(function() { |
|
43 navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOff, |
|
44 failureCallbackAfterMozsettingOff); |
|
45 }, 500); // need to wait a bit for all of these async callbacks to finish |
|
46 }); |
|
47 } |
|
48 |
|
49 function successCallbackAfterMozsettingOff(position) { |
|
50 ok(false, "Success callback should not have been called after setting geolocation.enabled to false."); |
|
51 |
|
52 toggleGeolocationSetting(true, function() { |
|
53 ok(true, "turned on geolocation via mozSettings"); |
|
54 setTimeout(function() { |
|
55 navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn, |
|
56 failureCallbackAfterMozsettingOn); |
|
57 }, 500); // need to wait a bit for all of these async callbacks to finish |
|
58 }); |
|
59 } |
|
60 |
|
61 function failureCallbackAfterMozsettingOff(error) { |
|
62 ok(true, "Geolocation didn't work after setting geolocation.enabled to false."); |
|
63 |
|
64 toggleGeolocationSetting(true, function() { |
|
65 ok(true, "turned on geolocation via mozSettings"); |
|
66 setTimeout(function() { |
|
67 navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn, |
|
68 failureCallbackAfterMozsettingOn); |
|
69 }, 500); // need to wait a bit for all of these async callbacks to finish |
|
70 }); |
|
71 } |
|
72 |
|
73 function successCallbackAfterMozsettingOn(position) { |
|
74 ok(true, "Geolocation worked after setting geolocation.enabled to true."); |
|
75 SimpleTest.finish(); |
|
76 } |
|
77 |
|
78 function failureCallbackAfterMozsettingOn(error) { |
|
79 ok(false, "Geolocation didn't work after setting geolocation.enabled to true."); |
|
80 SimpleTest.finish(); |
|
81 } |
|
82 |
|
83 </script> |
|
84 </pre> |
|
85 </body> |
|
86 </html> |
|
87 |