зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset b66d6544ad5a (bug 1663501) for payment-reporting.https.html failures CLOSED TREE
This commit is contained in:
Родитель
3667467db8
Коммит
1b8a2c18be
|
@ -483,10 +483,6 @@ NetworkGeolocationProvider.prototype = {
|
|||
|
||||
let compareUrl = Services.urlFormatter.formatURL(this._wifiCompareURL);
|
||||
let compare = await this.makeRequest(compareUrl, wifiData);
|
||||
if (!compare.location) {
|
||||
LOG("Backup location service didnt report location");
|
||||
return;
|
||||
}
|
||||
let distance = LocationHelper.distance(result.location, compare.location);
|
||||
LOG(
|
||||
`compare reported reported: ${compare.location.lng}:${compare.location.lat}`
|
||||
|
|
|
@ -61,20 +61,6 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
false
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"updateDebounce",
|
||||
"browser.region.update.debounce",
|
||||
60 * 60 * 24
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"lastUpdated",
|
||||
"browser.region.update.updated",
|
||||
0
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"localGeocodingEnabled",
|
||||
|
@ -82,13 +68,6 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
false
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
"timerManager",
|
||||
"@mozilla.org/updates/timer-manager;1",
|
||||
"nsIUpdateTimerManager"
|
||||
);
|
||||
|
||||
const log = console.createInstance({
|
||||
prefix: "Region.jsm",
|
||||
maxLogLevel: loggingEnabled ? "All" : "Warn",
|
||||
|
@ -96,7 +75,6 @@ const log = console.createInstance({
|
|||
|
||||
const REGION_PREF = "browser.search.region";
|
||||
const COLLECTION_ID = "regions";
|
||||
const GEOLOCATION_TOPIC = "geolocation-position-events";
|
||||
|
||||
// Prefix for all the region updating related preferences.
|
||||
const UPDATE_PREFIX = "browser.region.update";
|
||||
|
@ -108,11 +86,6 @@ const UPDATE_INTERVAL = 60 * 60 * 24 * 14;
|
|||
|
||||
const MAX_RETRIES = 3;
|
||||
|
||||
// If the user never uses geolocation, schedule a periodic
|
||||
// update to check the current location (in seconds).
|
||||
const UPDATE_CHECK_NAME = "region-update-timer";
|
||||
const UPDATE_CHECK_INTERVAL = 60 * 60 * 24 * 7;
|
||||
|
||||
/**
|
||||
* This module keeps track of the users current region (country).
|
||||
* so the SearchService and other consumers can apply region
|
||||
|
@ -130,8 +103,6 @@ class RegionDetector {
|
|||
// Keep track of how many times we have tried to fetch
|
||||
// the users region during failure.
|
||||
_retryCount = 0;
|
||||
// Let tests wait for init to complete.
|
||||
_initPromise = null;
|
||||
// Topic for Observer events fired by Region.jsm.
|
||||
REGION_TOPIC = "browser-region";
|
||||
// Verb for event fired when we update the region.
|
||||
|
@ -148,26 +119,16 @@ class RegionDetector {
|
|||
* Read currently stored region data and if needed trigger background
|
||||
* region detection.
|
||||
*/
|
||||
async init() {
|
||||
if (this._initPromise) {
|
||||
return this._initPromise;
|
||||
}
|
||||
if (cacheBustEnabled) {
|
||||
timerManager.registerTimer(
|
||||
UPDATE_CHECK_NAME,
|
||||
() => this._updateTimer(),
|
||||
UPDATE_CHECK_INTERVAL
|
||||
);
|
||||
}
|
||||
let promises = [];
|
||||
init() {
|
||||
this._home = Services.prefs.getCharPref(REGION_PREF, null);
|
||||
if (!this._home) {
|
||||
promises.push(this._idleDispatch(() => this._fetchRegion()));
|
||||
if (cacheBustEnabled || !this._home) {
|
||||
Services.tm.idleDispatchToMainThread(this._fetchRegion.bind(this));
|
||||
}
|
||||
if (localGeocodingEnabled) {
|
||||
promises.push(this._idleDispatch(() => this._setupRemoteSettings()));
|
||||
Services.tm.idleDispatchToMainThread(
|
||||
this._setupRemoteSettings.bind(this)
|
||||
);
|
||||
}
|
||||
return (this._initPromise = Promise.all(promises));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,10 +272,7 @@ class RegionDetector {
|
|||
log.info("Setting current region:", region);
|
||||
this._current = region;
|
||||
|
||||
let now = Math.round(Date.now() / 1000);
|
||||
let prefs = Services.prefs;
|
||||
prefs.setIntPref(`${UPDATE_PREFIX}.updated`, now);
|
||||
|
||||
// Interval is in seconds.
|
||||
let interval = prefs.getIntPref(
|
||||
`${UPDATE_PREFIX}.interval`,
|
||||
|
@ -331,11 +289,14 @@ class RegionDetector {
|
|||
// considered home, then keep track of when we first
|
||||
// seen the new location.
|
||||
prefs.setCharPref(`${UPDATE_PREFIX}.region`, region);
|
||||
prefs.setIntPref(`${UPDATE_PREFIX}.first-seen`, now);
|
||||
prefs.setIntPref(
|
||||
`${UPDATE_PREFIX}.first-seen`,
|
||||
Math.round(Date.now() / 1000)
|
||||
);
|
||||
} else if (region != this._home && region == seenRegion) {
|
||||
// If we have been in the new region for longer than
|
||||
// a specified time period, then set that as the new home.
|
||||
if (now >= firstSeen + interval) {
|
||||
if (Math.round(Date.now() / 1000) >= firstSeen + interval) {
|
||||
this._setHomeRegion(region);
|
||||
}
|
||||
} else {
|
||||
|
@ -425,9 +386,6 @@ class RegionDetector {
|
|||
this._rsClient = RemoteSettings(COLLECTION_ID);
|
||||
this._rsClient.on("sync", this._onRegionFilesSync.bind(this));
|
||||
await this._ensureRegionFilesDownloaded();
|
||||
// Start listening to geolocation events only after
|
||||
// we know the maps are downloded.
|
||||
Services.obs.addObserver(this, GEOLOCATION_TOPIC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -780,60 +738,6 @@ class RegionDetector {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user is using geolocation then we will see frequent updates
|
||||
* debounce those so we aren't processing them constantly.
|
||||
*
|
||||
* @returns {bool}
|
||||
* Whether we should continue the update check.
|
||||
*/
|
||||
_needsUpdateCheck() {
|
||||
let sinceUpdate = Math.round(Date.now() / 1000) - lastUpdated;
|
||||
let needsUpdate = sinceUpdate >= updateDebounce;
|
||||
if (!needsUpdate) {
|
||||
log.info(`Ignoring update check, last seen ${sinceUpdate} seconds ago`);
|
||||
}
|
||||
return needsUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a promise returning function to the main thread and
|
||||
* resolve when it is completed.
|
||||
*/
|
||||
_idleDispatch(fun) {
|
||||
return new Promise(resolve => {
|
||||
Services.tm.idleDispatchToMainThread(fun().then(resolve));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* timerManager will call this periodically to update the region
|
||||
* in case the user never users geolocation.
|
||||
*/
|
||||
async _updateTimer() {
|
||||
if (this._needsUpdateCheck()) {
|
||||
await this._fetchRegion();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we see geolocation updates.
|
||||
* in case the user never users geolocation.
|
||||
*
|
||||
* @param {Object} location
|
||||
* A location object containing lat + lng coordinates.
|
||||
*
|
||||
*/
|
||||
async _seenLocation(location) {
|
||||
log.info(`Got location update: ${location.lat}:${location.lng}`);
|
||||
if (this._needsUpdateCheck()) {
|
||||
let region = await this._geoCode(location);
|
||||
if (region) {
|
||||
this._setCurrentRegion(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onChange(accessPoints) {
|
||||
log.info("onChange called");
|
||||
if (!accessPoints || !this._wifiDataPromise) {
|
||||
|
@ -851,27 +755,6 @@ class RegionDetector {
|
|||
this._wifiDataPromise = null;
|
||||
}
|
||||
}
|
||||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
log.info(`Observed ${aTopic}`);
|
||||
switch (aTopic) {
|
||||
case GEOLOCATION_TOPIC:
|
||||
// aSubject from GeoLocation.cpp will be a GeoPosition
|
||||
// DOM Object, but from tests we will receive a
|
||||
// wrappedJSObject so handle both here.
|
||||
let coords = aSubject.coords || aSubject.wrappedJSObject.coords;
|
||||
this._seenLocation({
|
||||
lat: coords.latitude,
|
||||
lng: coords.longitude,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// For tests to create blank new instances.
|
||||
newInstance() {
|
||||
return new RegionDetector();
|
||||
}
|
||||
}
|
||||
|
||||
let Region = new RegionDetector();
|
||||
|
|
|
@ -145,7 +145,6 @@ TESTING_JS_MODULES += [
|
|||
"tests/modules/OSKeyStoreTestUtils.jsm",
|
||||
"tests/modules/PromiseTestUtils.jsm",
|
||||
"tests/modules/Task.jsm",
|
||||
"tests/xpcshell/RegionTestUtils.jsm",
|
||||
"tests/xpcshell/TestIntegration.jsm",
|
||||
]
|
||||
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const EXPORTED_SYMBOLS = ["RegionTestUtils"];
|
||||
|
||||
const RegionTestUtils = Object.freeze({
|
||||
REGION_URL_PREF: "browser.region.network.url",
|
||||
|
||||
setNetworkRegion(region) {
|
||||
Services.prefs.setCharPref(
|
||||
this.REGION_URL_PREF,
|
||||
`data:application/json,{"country_code": "${region}"}`
|
||||
);
|
||||
},
|
||||
});
|
|
@ -10,10 +10,7 @@ const { TestUtils } = ChromeUtils.import(
|
|||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
RegionTestUtils: "resource://testing-common/RegionTestUtils.jsm",
|
||||
});
|
||||
|
||||
const REGION_PREF = "browser.region.network.url";
|
||||
const INTERVAL_PREF = "browser.region.update.interval";
|
||||
|
||||
const RESPONSE_DELAY = 500;
|
||||
|
@ -23,44 +20,53 @@ const histogram = Services.telemetry.getHistogramById(
|
|||
"SEARCH_SERVICE_COUNTRY_FETCH_RESULT"
|
||||
);
|
||||
|
||||
// Add notification observer, it will return a promise that will resolve once a notification is fired.
|
||||
function waitForNotificationSubject(topic) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Services.obs.addObserver(function observe(aSubject, aTopic, aData) {
|
||||
// wrap the subject as a nsISupports
|
||||
let subject = aSubject.QueryInterface(Ci.nsISupportsString);
|
||||
Services.obs.removeObserver(observe, topic);
|
||||
resolve(subject);
|
||||
}, topic);
|
||||
});
|
||||
}
|
||||
|
||||
// Region.jsm will call init() on startup and sent a background
|
||||
// task to fetch the region, ensure we have completed this before
|
||||
// running the rest of the tests.
|
||||
add_task(async function test_startup() {
|
||||
RegionTestUtils.setNetworkRegion("UK");
|
||||
setNetworkRegion("UK");
|
||||
await checkTelemetry(Region.TELEMETRY.SUCCESS);
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
add_task(async function test_basic() {
|
||||
let srv = useHttpServer(RegionTestUtils.REGION_URL_PREF);
|
||||
Region._home = null;
|
||||
let srv = useHttpServer(REGION_PREF);
|
||||
srv.registerPathHandler("/", (req, res) => {
|
||||
res.setStatusLine("1.1", 200, "OK");
|
||||
send(res, { country_code: "UK" });
|
||||
});
|
||||
// start to listen the notification
|
||||
let updateRegion = TestUtils.topicObserved("browser-region");
|
||||
let notificationSubjectPromise = waitForNotificationSubject("browser-region");
|
||||
await Region._fetchRegion();
|
||||
let [subject] = await updateRegion;
|
||||
let notificationSub = await notificationSubjectPromise;
|
||||
|
||||
Assert.ok(true, "Region fetch should succeed");
|
||||
Assert.equal(Region.home, "UK", "Region fetch should return correct result");
|
||||
Assert.equal(
|
||||
subject,
|
||||
notificationSub,
|
||||
Region.home,
|
||||
"Notification should be sent with the correct region"
|
||||
);
|
||||
|
||||
await cleanup(srv);
|
||||
await new Promise(r => srv.stop(r));
|
||||
});
|
||||
|
||||
add_task(async function test_invalid_url() {
|
||||
histogram.clear();
|
||||
Services.prefs.setIntPref("browser.region.retry-timeout", 0);
|
||||
Services.prefs.setCharPref(
|
||||
RegionTestUtils.REGION_URL_PREF,
|
||||
"http://localhost:0"
|
||||
);
|
||||
Services.prefs.setCharPref(REGION_PREF, "http://localhost:0");
|
||||
let result = await Region._fetchRegion();
|
||||
Assert.ok(!result, "Should return no result");
|
||||
await checkTelemetry(Region.TELEMETRY.NO_RESULT);
|
||||
|
@ -69,7 +75,7 @@ add_task(async function test_invalid_url() {
|
|||
add_task(async function test_invalid_json() {
|
||||
histogram.clear();
|
||||
Services.prefs.setCharPref(
|
||||
RegionTestUtils.REGION_URL_PREF,
|
||||
REGION_PREF,
|
||||
'data:application/json,{"country_code"'
|
||||
);
|
||||
let result = await Region._fetchRegion();
|
||||
|
@ -81,7 +87,7 @@ add_task(async function test_timeout() {
|
|||
histogram.clear();
|
||||
Services.prefs.setIntPref("browser.region.retry-timeout", 0);
|
||||
Services.prefs.setIntPref("browser.region.timeout", RESPONSE_TIMEOUT);
|
||||
let srv = useHttpServer(RegionTestUtils.REGION_URL_PREF);
|
||||
let srv = useHttpServer(REGION_PREF);
|
||||
srv.registerPathHandler("/", (req, res) => {
|
||||
res.processAsync();
|
||||
do_timeout(RESPONSE_DELAY, () => {
|
||||
|
@ -94,7 +100,7 @@ add_task(async function test_timeout() {
|
|||
Assert.equal(result, null, "Region fetch should return null");
|
||||
|
||||
await checkTelemetry(Region.TELEMETRY.TIMEOUT);
|
||||
await cleanup(srv);
|
||||
await new Promise(r => srv.stop(r));
|
||||
});
|
||||
|
||||
add_task(async function test_mismatched_probe() {
|
||||
|
@ -107,7 +113,7 @@ add_task(async function test_mismatched_probe() {
|
|||
histogram.clear();
|
||||
Region._home = null;
|
||||
|
||||
RegionTestUtils.setNetworkRegion("AU");
|
||||
setNetworkRegion("AU");
|
||||
await Region._fetchRegion();
|
||||
Assert.equal(Region.home, "AU", "Should have correct region");
|
||||
await checkTelemetry(Region.TELEMETRY.SUCCESS);
|
||||
|
@ -120,8 +126,6 @@ add_task(async function test_mismatched_probe() {
|
|||
}
|
||||
let snapshot = probeHistogram.snapshot();
|
||||
deepEqual(snapshot.values, probeDetails.expectedResult);
|
||||
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
add_task(async function test_location() {
|
||||
|
@ -136,15 +140,15 @@ add_task(async function test_location() {
|
|||
Assert.ok(true, "Region fetch should succeed");
|
||||
Assert.deepEqual(result, location, "Location is returned");
|
||||
|
||||
await cleanup(srv);
|
||||
await new Promise(r => srv.stop(r));
|
||||
});
|
||||
|
||||
add_task(async function test_update() {
|
||||
Region._home = null;
|
||||
RegionTestUtils.setNetworkRegion("FR");
|
||||
setNetworkRegion("FR");
|
||||
await Region._fetchRegion();
|
||||
Assert.equal(Region.home, "FR", "Should have correct region");
|
||||
RegionTestUtils.setNetworkRegion("DE");
|
||||
setNetworkRegion("DE");
|
||||
await Region._fetchRegion();
|
||||
Assert.equal(Region.home, "FR", "Shouldnt have changed yet");
|
||||
// Thie first fetchRegion will set the prefs to determine when
|
||||
|
@ -157,8 +161,6 @@ add_task(async function test_update() {
|
|||
await new Promise(resolve => setTimeout(resolve, 1100));
|
||||
await Region._fetchRegion();
|
||||
Assert.equal(Region.home, "DE", "Should have updated now");
|
||||
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
add_task(async function test_max_retry() {
|
||||
|
@ -166,7 +168,7 @@ add_task(async function test_max_retry() {
|
|||
let requestsSeen = 0;
|
||||
Services.prefs.setIntPref("browser.region.retry-timeout", RESPONSE_TIMEOUT);
|
||||
Services.prefs.setIntPref("browser.region.timeout", RESPONSE_TIMEOUT);
|
||||
let srv = useHttpServer(RegionTestUtils.REGION_URL_PREF);
|
||||
let srv = useHttpServer(REGION_PREF);
|
||||
srv.registerPathHandler("/", (req, res) => {
|
||||
requestsSeen++;
|
||||
res.setStatusLine("1.1", 200, "OK");
|
||||
|
@ -183,7 +185,7 @@ add_task(async function test_max_retry() {
|
|||
Assert.equal(requestsSeen, 3, "Retried 4 times");
|
||||
|
||||
Region._retryCount = 0;
|
||||
await cleanup(srv);
|
||||
await new Promise(r => srv.stop(r));
|
||||
});
|
||||
|
||||
add_task(async function test_retry() {
|
||||
|
@ -191,7 +193,7 @@ add_task(async function test_retry() {
|
|||
let requestsSeen = 0;
|
||||
Services.prefs.setIntPref("browser.region.retry-timeout", RESPONSE_TIMEOUT);
|
||||
Services.prefs.setIntPref("browser.region.timeout", RESPONSE_TIMEOUT);
|
||||
let srv = useHttpServer(RegionTestUtils.REGION_URL_PREF);
|
||||
let srv = useHttpServer(REGION_PREF);
|
||||
srv.registerPathHandler("/", (req, res) => {
|
||||
res.setStatusLine("1.1", 200, "OK");
|
||||
if (++requestsSeen == 2) {
|
||||
|
@ -211,35 +213,16 @@ add_task(async function test_retry() {
|
|||
Assert.equal(Region.home, "UK", "failed to fetch region");
|
||||
Assert.equal(requestsSeen, 2, "Retried 2 times");
|
||||
|
||||
await cleanup(srv);
|
||||
Region._retryCount = 0;
|
||||
await new Promise(r => srv.stop(r));
|
||||
});
|
||||
|
||||
add_task(async function test_timerManager() {
|
||||
RegionTestUtils.setNetworkRegion("FR");
|
||||
|
||||
// Ensure the home region updates immediately, but the update
|
||||
// check will only happen once per second.
|
||||
Services.prefs.setIntPref("browser.region.update.interval", 0);
|
||||
Services.prefs.setIntPref("browser.region.update.debounce", 1);
|
||||
|
||||
let region = Region.newInstance();
|
||||
await region.init();
|
||||
Assert.equal(region.home, "FR", "Should have correct initial region");
|
||||
|
||||
// Updates are being debounced, these should be ignored.
|
||||
RegionTestUtils.setNetworkRegion("DE");
|
||||
await region._updateTimer();
|
||||
await region._updateTimer();
|
||||
Assert.equal(region.home, "FR", "Ignored updates to region");
|
||||
|
||||
// Set the debounce interval to 0 so these updates are used.
|
||||
Services.prefs.setIntPref("browser.region.update.debounce", 0);
|
||||
RegionTestUtils.setNetworkRegion("AU");
|
||||
await region._updateTimer();
|
||||
await region._updateTimer();
|
||||
Assert.equal(region.home, "AU", "region has been updated");
|
||||
await cleanup();
|
||||
});
|
||||
function setNetworkRegion(region) {
|
||||
Services.prefs.setCharPref(
|
||||
REGION_PREF,
|
||||
`data:application/json,{"country_code": "${region}"}`
|
||||
);
|
||||
}
|
||||
|
||||
function useHttpServer(pref) {
|
||||
let server = new HttpServer();
|
||||
|
@ -257,13 +240,6 @@ function send(res, json) {
|
|||
res.write(JSON.stringify(json));
|
||||
}
|
||||
|
||||
async function cleanup(srv = null) {
|
||||
Services.prefs.clearUserPref("browser.search.region");
|
||||
if (srv) {
|
||||
await new Promise(r => srv.stop(r));
|
||||
}
|
||||
}
|
||||
|
||||
async function checkTelemetry(aExpectedValue) {
|
||||
// Wait until there is 1 result.
|
||||
await TestUtils.waitForCondition(() => {
|
||||
|
|
|
@ -3,13 +3,6 @@
|
|||
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
const { Region } = ChromeUtils.import("resource://gre/modules/Region.jsm");
|
||||
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
|
||||
const { TestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
RegionTestUtils: "resource://testing-common/RegionTestUtils.jsm",
|
||||
});
|
||||
|
||||
async function readFile(file) {
|
||||
let decoder = new TextDecoder();
|
||||
|
@ -24,20 +17,15 @@ function setLocation(location) {
|
|||
);
|
||||
}
|
||||
|
||||
async function stubMap(obj, path, fun) {
|
||||
async function stubMap(path, fun) {
|
||||
let map = await readFile(do_get_file(path));
|
||||
sinon.stub(obj, fun).resolves(JSON.parse(map));
|
||||
}
|
||||
|
||||
async function stubMaps(obj) {
|
||||
await stubMap(obj, "regions/world.geojson", "_getPlainMap");
|
||||
await stubMap(obj, "regions/world-buffered.geojson", "_getBufferedMap");
|
||||
sinon.stub(Region, fun).resolves(JSON.parse(map));
|
||||
}
|
||||
|
||||
add_task(async function test_setup() {
|
||||
Services.prefs.setBoolPref("browser.region.log", true);
|
||||
Services.prefs.setBoolPref("browser.region.local-geocoding", true);
|
||||
await stubMaps(Region);
|
||||
await stubMap("regions/world.geojson", "_getPlainMap");
|
||||
await stubMap("regions/world-buffered.geojson", "_getBufferedMap");
|
||||
});
|
||||
|
||||
const LOCATIONS = [
|
||||
|
@ -52,13 +40,25 @@ const LOCATIONS = [
|
|||
{ lat: 35.4411368, lng: -41.5372973, expectedRegion: null },
|
||||
];
|
||||
|
||||
add_task(async function test_local_basic() {
|
||||
add_task(async function test_mls_results() {
|
||||
setLocation({ lat: -5.066019, lng: 39.1026251 });
|
||||
let expectedRegion = "TZ";
|
||||
let region = await Region._getRegionLocally();
|
||||
Assert.equal(region, expectedRegion);
|
||||
});
|
||||
|
||||
/*add_task(async function test_basic() {
|
||||
for (const { lat, lng, expectedRegion } of LOCATIONS) {
|
||||
setLocation({ lat, lng });
|
||||
let region = await Region._getRegionLocally();
|
||||
Assert.equal(
|
||||
region,
|
||||
expectedRegion,
|
||||
`Got the expected region at ${lat},${lng}`
|
||||
);
|
||||
}
|
||||
});*/
|
||||
|
||||
add_task(async function test_mls_results() {
|
||||
let data = await readFile(do_get_file("regions/mls-lookup-results.csv"));
|
||||
for (const row of data.split("\n")) {
|
||||
|
@ -72,31 +72,3 @@ add_task(async function test_mls_results() {
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_geolocation_update() {
|
||||
RegionTestUtils.setNetworkRegion("AU");
|
||||
|
||||
// Enable immediate region updates.
|
||||
Services.prefs.setBoolPref("browser.region.update.enabled", true);
|
||||
Services.prefs.setIntPref("browser.region.update.interval", 0);
|
||||
Services.prefs.setIntPref("browser.region.update.debounce", 0);
|
||||
|
||||
let region = Region.newInstance();
|
||||
await stubMaps(region);
|
||||
await region.init();
|
||||
Assert.equal(region.home, "AU", "Correct initial region");
|
||||
|
||||
Services.obs.notifyObservers(
|
||||
{ coords: { latitude: -5.066019, longitude: 39.1026251 } },
|
||||
"geolocation-position-events"
|
||||
);
|
||||
Assert.equal(region.home, "AU", "First update will mark new region as seen");
|
||||
|
||||
let regionUpdate = TestUtils.topicObserved("browser-region");
|
||||
Services.obs.notifyObservers(
|
||||
{ coords: { latitude: -5.066019, longitude: 39.1026251 } },
|
||||
"geolocation-position-events"
|
||||
);
|
||||
await regionUpdate;
|
||||
Assert.equal(region.home, "TZ", "Second update will change location");
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче