/* global is ok registerCleanupFunction Services */
"use strict";
// We try to avoid polluting the global scope as far as possible by defining // constants in the methods that use them because this script is not sandboxed // meaning that it is loaded via Services.scriptloader.loadSubScript()
/** * Clears Telemetry Histograms. * * @param {Function} snapshotFunc * The function used to take the snapshot. This can be one of the * following: * - Services.telemetry.getSnapshotForHistograms * - Services.telemetry.getSnapshotForKeyedHistograms
*/
clearHistograms(snapshotFunc) {
snapshotFunc("main", true);
}
/** * Check the value of a given telemetry histogram. * * @param {String} histId * Histogram id * @param {String} key * Keyed histogram key * @param {Array|Number} expected * Expected value * @param {String} checkType * "array" (default) - Check that an array matches the histogram data. * "hasentries" - For non-enumerated linear and exponential * histograms. This checks for at least one entry. * "scalar" - Telemetry type is a scalar. * "keyedscalar" - Telemetry type is a keyed scalar.
*/
checkTelemetry(histId, key, expected, checkType) {
let actual;
let msg;
if (checkType === "array" || checkType === "hasentries") { if (key) { const keyedHistogram = Services.telemetry
.getKeyedHistogramById(histId)
.snapshot(); const result = keyedHistogram[key];
if (result) {
actual = result.values;
} else {
ok(false, `${histId}[${key}] exists`); return;
}
} else {
actual = Services.telemetry.getHistogramById(histId).snapshot().values;
}
}
switch (checkType) { case"array":
msg = key ? `${histId}["${key}"] correct.` : `${histId} correct.`;
is(JSON.stringify(actual), JSON.stringify(expected), msg); break; case"hasentries": const hasEntry = Object.values(actual).some(num => num > 0); if (key) {
ok(hasEntry, `${histId}["${key}"] has at least one entry.`);
} else {
ok(hasEntry, `${histId} has at least one entry.`);
} break; case"scalar": const scalars = Services.telemetry.getSnapshotForScalars( "main", false
).parent;
/** * Generates the inner contents of a test's checkTelemetry() method. * * @param {HistogramSnapshot} snapshot * A snapshot of a telemetry chart obtained via getSnapshotForHistograms or * similar. * @param {String} key * Only used for keyed histograms. This is the key we are interested in * checking. * @param {String} histId * The histogram ID. * @param {Array|String|Boolean} actual * The value of the histogram data.
*/
displayDataFromHistogramSnapshot(snapshot, key, histId, actual) {
key = key ? `"${key}"` : `""`;
switch (snapshot.histogram_type) { case Services.telemetry.HISTOGRAM_EXPONENTIAL: case Services.telemetry.HISTOGRAM_LINEAR:
let total = 0; for (const val of Object.values(actual)) {
total += val;
}
if (histId.endsWith("_ENUMERATED")) { if (total > 0) {
actual = actual.toSource();
dump(`checkTelemetry("${histId}", ${key}, ${actual}, "array");\n`);
} return;
}
dump(`checkTelemetry("${histId}", ${key}, null, "hasentries");\n`); break; case Services.telemetry.HISTOGRAM_BOOLEAN:
actual = actual.toSource();
if (actual !== "({})") {
dump(`checkTelemetry("${histId}", ${key}, ${actual}, "array");\n`);
} break; case Services.telemetry.HISTOGRAM_FLAG:
actual = actual.toSource();
if (actual !== "({0:1, 1:0})") {
dump(`checkTelemetry("${histId}", ${key}, ${actual}, "array");\n`);
} break; case Services.telemetry.HISTOGRAM_COUNT:
actual = actual.toSource();
// "exports"... because this is a helper and not imported via require we need to // expose the three main methods that should be used by tests. The reason this // is not imported via require is because it needs access to test methods // (is, ok etc).
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.