diff --git a/toolkit/components/extensions/test/xpcshell/head_telemetry.js b/toolkit/components/extensions/test/xpcshell/head_telemetry.js deleted file mode 100644 index 98b87d14d54d..000000000000 --- a/toolkit/components/extensions/test/xpcshell/head_telemetry.js +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set sts=2 sw=2 et tw=80: */ -"use strict"; - -/* exported IS_OOP, arraySum, clearHistograms, getSnapshots, promiseTelemetryRecorded */ - -XPCOMUtils.defineLazyModuleGetter(this, "ContentTaskUtils", - "resource://testing-common/ContentTaskUtils.jsm"); - -const IS_OOP = Services.prefs.getBoolPref("extensions.webextensions.remote"); - -function arraySum(arr) { - return arr.reduce((a, b) => a + b, 0); -} - -function clearHistograms() { - Services.telemetry.snapshotSubsessionHistograms(true); -} - -function getSnapshots(process) { - return Services.telemetry.snapshotSubsessionHistograms()[process]; -} - -// There is no good way to make sure that the parent received the histogram -// entries from the extension and content processes. -// Let's stick to the ugly, spinning the event loop until we have a good -// approach (Bug 1357509). -function promiseTelemetryRecorded(id, process, expectedCount) { - let condition = () => { - let snapshot = Services.telemetry.snapshotSubsessionHistograms()[process][id]; - return snapshot && arraySum(snapshot.counts) >= expectedCount; - }; - return ContentTaskUtils.waitForCondition(condition); -} diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js b/toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js index fc71a40a6f10..91dae96deabf 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js @@ -41,35 +41,32 @@ add_task(async function test_telemetry() { }, }); - clearHistograms(); - - let process = IS_OOP ? "content" : "parent"; - ok(!(HISTOGRAM in getSnapshots(process)), `No data recorded for histogram: ${HISTOGRAM}.`); + let histogram = Services.telemetry.getHistogramById(HISTOGRAM); + histogram.clear(); + equal(histogram.snapshot().sum, 0, + `No data recorded for histogram: ${HISTOGRAM}.`); await extension1.startup(); - ok(!(HISTOGRAM in getSnapshots(process)), - `No data recorded for histogram after startup: ${HISTOGRAM}.`); + equal(histogram.snapshot().sum, 0, + `No data recorded for histogram after startup: ${HISTOGRAM}.`); let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`); await extension1.awaitMessage("content-script-run"); - await promiseTelemetryRecorded(HISTOGRAM, process, 1); - - equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 1, - `Data recorded for histogram: ${HISTOGRAM}.`); + let histogramSum = histogram.snapshot().sum; + ok(histogramSum > 0, + `Data recorded for first extension for histogram: ${HISTOGRAM}.`); await contentPage.close(); await extension1.unload(); await extension2.startup(); - equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 1, + equal(histogram.snapshot().sum, histogramSum, `No data recorded for histogram after startup: ${HISTOGRAM}.`); contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`); await extension2.awaitMessage("content-script-run"); - await promiseTelemetryRecorded(HISTOGRAM, process, 2); - - equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 2, - `Data recorded for histogram: ${HISTOGRAM}.`); + ok(histogram.snapshot().sum > histogramSum, + `Data recorded for second extension for histogram: ${HISTOGRAM}.`); await contentPage.close(); await extension2.unload(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js b/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js index cce0499c4378..3d335cf756dc 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js @@ -6,6 +6,10 @@ const HISTOGRAM_IDS = [ "WEBEXT_STORAGE_LOCAL_SET_MS", "WEBEXT_STORAGE_LOCAL_GET_MS", ]; +function arraySum(arr) { + return arr.reduce((a, b) => a + b, 0); +} + add_task(async function test_telemetry_background() { const server = createHttpServer(); server.registerDirectory("/data/", do_get_file("data")); @@ -45,58 +49,44 @@ add_task(async function test_telemetry_background() { let extension1 = ExtensionTestUtils.loadExtension(extInfo); let extension2 = ExtensionTestUtils.loadExtension(extInfo); - clearHistograms(); - - let process = IS_OOP ? "extension" : "parent"; - let snapshots = getSnapshots(process); + // Initialize and clear histograms. + let histograms = {}; for (let id of HISTOGRAM_IDS) { - ok(!(id in snapshots), `No data recorded for histogram: ${id}.`); + histograms[id] = Services.telemetry.getHistogramById(id); + histograms[id].clear(); + equal(arraySum(histograms[id].snapshot().counts), 0, + `No data recorded for histogram: ${id}.`); } await extension1.startup(); await extension1.awaitMessage("backgroundDone"); - for (let id of HISTOGRAM_IDS) { - await promiseTelemetryRecorded(id, process, 1); - } // Telemetry from extension1's background page should be recorded. - snapshots = getSnapshots(process); - for (let id of HISTOGRAM_IDS) { - equal(arraySum(snapshots[id].counts), 1, + for (let id in histograms) { + equal(arraySum(histograms[id].snapshot().counts), 1, `Data recorded for histogram: ${id}.`); } await extension2.startup(); await extension2.awaitMessage("backgroundDone"); - for (let id of HISTOGRAM_IDS) { - await promiseTelemetryRecorded(id, process, 2); - } // Telemetry from extension2's background page should be recorded. - snapshots = getSnapshots(process); - for (let id of HISTOGRAM_IDS) { - equal(arraySum(snapshots[id].counts), 2, + for (let id in histograms) { + equal(arraySum(histograms[id].snapshot().counts), 2, `Additional data recorded for histogram: ${id}.`); } await extension2.unload(); // Run a content script. - process = IS_OOP ? "content" : "parent"; - let expectedCount = IS_OOP ? 1 : 3; let contentScriptPromise = extension1.awaitMessage("contentDone"); let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`); await contentScriptPromise; await contentPage.close(); - for (let id of HISTOGRAM_IDS) { - await promiseTelemetryRecorded(id, process, expectedCount); - } - // Telemetry from extension1's content script should be recorded. - snapshots = getSnapshots(process); - for (let id of HISTOGRAM_IDS) { - equal(arraySum(snapshots[id].counts), expectedCount, + for (let id in histograms) { + equal(arraySum(histograms[id].snapshot().counts), 3, `Data recorded in content script for histogram: ${id}.`); } diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini index cdcec1149805..c8f290f67347 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini @@ -13,7 +13,6 @@ skip-if = os == "android" # Android does not use Places for history. [test_ext_background_telemetry.js] [test_ext_background_window_properties.js] skip-if = os == "android" -[test_ext_browserSettings.js] [test_ext_contextual_identities.js] skip-if = os == "android" # Containers are not exposed to android. [test_ext_debugging_utils.js] @@ -28,7 +27,6 @@ skip-if = os == "android" [test_ext_extension.js] [test_ext_extensionPreferencesManager.js] [test_ext_extensionSettingsStore.js] -[test_ext_extension_content_telemetry.js] [test_ext_extension_startup_telemetry.js] [test_ext_idle.js] [test_ext_legacy_extension_context.js] @@ -58,7 +56,6 @@ head = head.js head_sync.js skip-if = os == "android" [test_ext_storage_sync_crypto.js] skip-if = os == "android" -[test_ext_storage_telemetry.js] [test_ext_topSites.js] skip-if = os == "android" [test_native_messaging.js] diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini b/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini index 31cec2a7e1c0..8af28a476edc 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini @@ -1,5 +1,5 @@ [DEFAULT] -head = head.js head_remote.js head_e10s.js head_telemetry.js +head = head.js head_remote.js head_e10s.js tail = firefox-appdir = browser skip-if = appname == "thunderbird" || os == "android" diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell.ini b/toolkit/components/extensions/test/xpcshell/xpcshell.ini index c5d4680c0786..b9ee0c04a497 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini +++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini @@ -1,5 +1,5 @@ [DEFAULT] -head = head.js head_telemetry.js +head = head.js firefox-appdir = browser skip-if = appname == "thunderbird" dupe-manifest =