dom/tests/unit/test_geolocation_reset_accuracy.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:111f3448b9e8
1 const Cc = Components.classes;
2 const Ci = Components.interfaces;
3
4 const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
5 const providerContract = "@mozilla.org/geolocation/provider;1";
6
7 const categoryName = "geolocation-provider";
8
9 var provider = {
10 QueryInterface: function eventsink_qi(iid) {
11 if (iid.equals(Components.interfaces.nsISupports) ||
12 iid.equals(Components.interfaces.nsIFactory) ||
13 iid.equals(Components.interfaces.nsIGeolocationProvider))
14 return this;
15 throw Components.results.NS_ERROR_NO_INTERFACE;
16 },
17 createInstance: function eventsink_ci(outer, iid) {
18 if (outer)
19 throw Components.results.NS_ERROR_NO_AGGREGATION;
20 return this.QueryInterface(iid);
21 },
22 lockFactory: function eventsink_lockf(lock) {
23 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
24 },
25 startup: function() {
26 },
27 watch: function() {
28 },
29 shutdown: function() {
30 },
31 setHighAccuracy: function(enable) {
32 this._isHigh = enable;
33 if (enable) {
34 this._seenHigh = true;
35 do_execute_soon(stop_high_accuracy_watch);
36 }
37 },
38 _isHigh: false,
39 _seenHigh: false
40 };
41
42 let runningInParent = true;
43 try {
44 runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
45 getService(Components.interfaces.nsIXULRuntime).processType
46 == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
47 }
48 catch (e) { }
49
50 function successCallback()
51 {
52 do_check_true(false);
53 do_test_finished();
54 }
55
56 function errorCallback()
57 {
58 do_check_true(false);
59 do_test_finished();
60 }
61
62 var geolocation;
63 var watchID2;
64
65 function run_test()
66 {
67 if (runningInParent) {
68 // XPCShell does not get a profile by default. The geolocation service
69 // depends on the settings service which uses IndexedDB and IndexedDB
70 // needs a place where it can store databases.
71 do_get_profile();
72
73 Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
74 "Unit test geo provider", providerContract, provider);
75 var catMan = Components.classes["@mozilla.org/categorymanager;1"]
76 .getService(Components.interfaces.nsICategoryManager);
77 catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
78 providerContract, false, true);
79
80 var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
81 prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
82 prefs.setBoolPref("geo.wifi.scan", false);
83 }
84
85 do_test_pending();
86
87 geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
88 let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
89 watchID2 = geolocation.watchPosition(successCallback, errorCallback,
90 {enableHighAccuracy: true});
91
92 if (!runningInParent) {
93 do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch);
94 }
95 }
96
97 function stop_high_accuracy_watch() {
98 geolocation.clearWatch(watchID2);
99 check_results();
100 }
101
102 function check_results()
103 {
104 if (runningInParent) {
105 // check the provider was set to high accuracy during the test
106 do_check_true(provider._seenHigh);
107 // check the provider is not currently set to high accuracy
108 do_check_false(provider._isHigh);
109 }
110 do_test_finished();
111 }

mercurial