зеркало из https://github.com/mozilla/gecko-dev.git
144 строки
4.2 KiB
HTML
144 строки
4.2 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1637402
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for Bug 1637402</title>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
<script type="application/javascript">
|
|
|
|
SimpleTest.requestLongerTimeout(2);
|
|
|
|
const BASE_GEO_URL = "http://mochi.test:8888/tests/dom/system/tests/location_service.sjs";
|
|
|
|
const GEO_PREF = "geo.provider.network.url";
|
|
const BACKUP_PREF = "geo.provider.network.compare.url";
|
|
|
|
const PARENT = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("location_services_parent.js"));
|
|
|
|
function sendToParent(msg, options) {
|
|
return new Promise(resolve => {
|
|
PARENT.addMessageListener(msg, events => {
|
|
PARENT.removeMessageListener(msg);
|
|
resolve(events);
|
|
});
|
|
PARENT.sendAsyncMessage(msg, options);
|
|
});
|
|
}
|
|
|
|
function getCurrentPosition() {
|
|
return new Promise(function(resolve, reject) {
|
|
navigator.geolocation.getCurrentPosition(resolve, reject);
|
|
});
|
|
}
|
|
|
|
let tries = 0;
|
|
let MAX_RETRIES = 500;
|
|
async function waitFor(fun) {
|
|
let passing = false;
|
|
while (!passing && ++tries < MAX_RETRIES) {
|
|
passing = await fun();
|
|
}
|
|
tries = 0;
|
|
if (!passing) {
|
|
ok(false, "waitFor condition never passed");
|
|
}
|
|
}
|
|
|
|
// Keeps track of how many telemetry results we have
|
|
// seen so we can wait for new ones.
|
|
let telemetryResultCount = 0;
|
|
async function newTelemetryResult() {
|
|
let results = await sendToParent("getTelemetryEvents");
|
|
let total = Object.values(results.values)
|
|
.reduce((val, acc) => acc + val, 0);
|
|
if (total <= telemetryResultCount) {
|
|
return false;
|
|
}
|
|
telemetryResultCount++;
|
|
return true;
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
window.onload = () => {
|
|
SimpleTest.waitForFocus(() => {
|
|
SpecialPowers.pushPrefEnv({"set":
|
|
[
|
|
["geo.prompt.testing", true],
|
|
["geo.prompt.testing.allow", true],
|
|
["geo.provider.network.logging.enabled", true],
|
|
["geo.provider.network.debug.requestCache.enabled", false]
|
|
],
|
|
}, doTest);
|
|
}, window);
|
|
};
|
|
|
|
const BASE_LOCATION = {lat: 55.867055, lng: -4.271041};
|
|
const LOCATIONS = [
|
|
{lat: "foo", lng: "bar", skipWait: true}, // Nan
|
|
{lat: 55.867055, lng: -4.271041}, // 0M
|
|
{lat: 50.8251639, lng: -0.1622551}, // 623KM
|
|
{lat: 55.9438948, lng: -3.1845417}, // 68KM
|
|
{lat: 39.4780911, lng: -0.3821706}, // 1844KM
|
|
{lat: 55.867160, lng: -4.271041}, // 10M
|
|
{lat: 41.8769913, lng: 12.4835351}, // 1969KM
|
|
{lat: 55.867055, lng: -4.271041}, // 0M
|
|
]
|
|
|
|
async function setLocations(main, backup) {
|
|
await SpecialPowers.setCharPref(
|
|
GEO_PREF,
|
|
`${BASE_GEO_URL}?lat=${main.lat}&lng=${main.lng}`
|
|
);
|
|
await SpecialPowers.setCharPref(
|
|
BACKUP_PREF,
|
|
`${BASE_GEO_URL}?lat=${backup.lat}&lng=${backup.lng}`
|
|
);
|
|
}
|
|
|
|
async function doTest() {
|
|
// Not all treeherder builds can collect telemetry.
|
|
if (!SpecialPowers.Services.telemetry.canRecordPrereleaseData) {
|
|
ok(true, "Cant run any tests without telemetry");
|
|
SimpleTest.finish();
|
|
return;
|
|
}
|
|
await sendToParent("clear");
|
|
|
|
for (let location of LOCATIONS) {
|
|
await setLocations(BASE_LOCATION, location);
|
|
await getCurrentPosition();
|
|
// Not all requests (NaN) will report telemetry.
|
|
if (!location.skipWait) {
|
|
await waitFor(newTelemetryResult, "");
|
|
}
|
|
}
|
|
|
|
let res = await sendToParent("getTelemetryEvents");
|
|
let total = Object.values(res.values)
|
|
.reduce((val, acc) => acc + val, 0);
|
|
|
|
is(total, 7, "Should have correct number of results");
|
|
is(res.values["0"], 2, "Two results were same location");
|
|
// Telemetry could change how exact bucketing
|
|
// implementation, so check the low bucket
|
|
// and that the rest are spead out.
|
|
is(
|
|
Object.keys(res.values).length,
|
|
6,
|
|
"Split the rest of the results across buckets"
|
|
);
|
|
|
|
SimpleTest.finish();
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1637402">Mozilla Bug </a>
|
|
<pre id="test"></pre>
|
|
</body>
|
|
</html>
|