summaryrefslogtreecommitdiffstats
path: root/dom/tests/unit/test_geolocation_reset_accuracy.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/tests/unit/test_geolocation_reset_accuracy.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/unit/test_geolocation_reset_accuracy.js')
-rw-r--r--dom/tests/unit/test_geolocation_reset_accuracy.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/dom/tests/unit/test_geolocation_reset_accuracy.js b/dom/tests/unit/test_geolocation_reset_accuracy.js
new file mode 100644
index 0000000000..8aa50bc4b5
--- /dev/null
+++ b/dom/tests/unit/test_geolocation_reset_accuracy.js
@@ -0,0 +1,101 @@
+const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
+const providerContract = "@mozilla.org/geolocation/provider;1";
+
+const categoryName = "geolocation-provider";
+
+var provider = {
+ QueryInterface: ChromeUtils.generateQI([
+ "nsIFactory",
+ "nsIGeolocationProvider",
+ ]),
+ createInstance: function eventsink_ci(outer, iid) {
+ if (outer) {
+ throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
+ }
+ return this.QueryInterface(iid);
+ },
+ lockFactory: function eventsink_lockf(lock) {
+ throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
+ },
+ startup() {},
+ watch() {},
+ shutdown() {},
+ setHighAccuracy(enable) {
+ this._isHigh = enable;
+ if (enable) {
+ this._seenHigh = true;
+ executeSoon(stop_high_accuracy_watch);
+ }
+ },
+ _isHigh: false,
+ _seenHigh: false,
+};
+
+function successCallback() {
+ Assert.ok(false);
+ do_test_finished();
+}
+
+function errorCallback() {
+ Assert.ok(false);
+ do_test_finished();
+}
+
+var geolocation;
+var watchID2;
+
+function run_test() {
+ if (runningInParent) {
+ // XPCShell does not get a profile by default. The geolocation service
+ // depends on the settings service which uses IndexedDB and IndexedDB
+ // needs a place where it can store databases.
+ do_get_profile();
+
+ Components.manager.nsIComponentRegistrar.registerFactory(
+ providerCID,
+ "Unit test geo provider",
+ providerContract,
+ provider
+ );
+
+ Services.catMan.nsICategoryManager.addCategoryEntry(
+ categoryName,
+ "unit test",
+ providerContract,
+ false,
+ true
+ );
+
+ Services.prefs.setBoolPref("geo.provider.network.scan", false);
+ }
+
+ do_test_pending();
+
+ geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
+ geolocation.watchPosition(successCallback, errorCallback);
+ watchID2 = geolocation.watchPosition(successCallback, errorCallback, {
+ enableHighAccuracy: true,
+ });
+
+ if (!runningInParent) {
+ do_await_remote_message("high_acc_enabled", stop_high_accuracy_watch);
+ }
+}
+
+function stop_high_accuracy_watch() {
+ geolocation.clearWatch(watchID2);
+ check_results();
+ do_test_finished();
+}
+
+function check_results() {
+ if (runningInParent) {
+ // check the provider was set to high accuracy during the test
+ Assert.ok(provider._seenHigh);
+ // check the provider is not currently set to high accuracy
+ Assert.ok(!provider._isHigh);
+ }
+ do_test_finished();
+}