Bug 1383728 - Add missing tests back into manifests, r?mixedpuppy
The following tests were removed from the test manifest in https://hg.mozilla.org/mozilla-central/rev/9704283b0e3a and never added back:
toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js
toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js
A bunch of changes were needed to the telemetry tests to make them work in OOP mode as well.
MozReview-Commit-ID: LPOrGb8OxNL
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/head_telemetry.js
@@ -0,0 +1,34 @@
+/* -*- 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);
+}
--- a/toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_extension_content_telemetry.js
@@ -36,38 +36,41 @@ add_task(async function test_telemetry()
}],
},
files: {
"content_script.js": contentScript,
},
});
- let histogram = Services.telemetry.getHistogramById(HISTOGRAM);
- histogram.clear();
- equal(histogram.snapshot().sum, 0,
- `No data recorded for histogram: ${HISTOGRAM}.`);
+ clearHistograms();
+
+ let process = IS_OOP ? "content" : "parent";
+ ok(!(HISTOGRAM in getSnapshots(process)), `No data recorded for histogram: ${HISTOGRAM}.`);
await extension1.startup();
- equal(histogram.snapshot().sum, 0,
- `No data recorded for histogram after startup: ${HISTOGRAM}.`);
+ ok(!(HISTOGRAM in getSnapshots(process)),
+ `No data recorded for histogram after startup: ${HISTOGRAM}.`);
let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
await extension1.awaitMessage("content-script-run");
- let histogramSum = histogram.snapshot().sum;
- ok(histogramSum > 0,
- `Data recorded for first extension for histogram: ${HISTOGRAM}.`);
+ await promiseTelemetryRecorded(HISTOGRAM, process, 1);
+
+ equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 1,
+ `Data recorded for histogram: ${HISTOGRAM}.`);
await contentPage.close();
await extension1.unload();
await extension2.startup();
- equal(histogram.snapshot().sum, histogramSum,
+ equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 1,
`No data recorded for histogram after startup: ${HISTOGRAM}.`);
contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
await extension2.awaitMessage("content-script-run");
- ok(histogram.snapshot().sum > histogramSum,
- `Data recorded for second extension for histogram: ${HISTOGRAM}.`);
+ await promiseTelemetryRecorded(HISTOGRAM, process, 2);
+
+ equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 2,
+ `Data recorded for histogram: ${HISTOGRAM}.`);
await contentPage.close();
await extension2.unload();
});
--- a/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js
@@ -1,20 +1,16 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
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"));
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
async function contentScript() {
await browser.storage.local.set({a: "b"});
@@ -44,51 +40,65 @@ add_task(async function test_telemetry_b
files: {
"content_script.js": contentScript,
},
};
let extension1 = ExtensionTestUtils.loadExtension(extInfo);
let extension2 = ExtensionTestUtils.loadExtension(extInfo);
- // Initialize and clear histograms.
- let histograms = {};
+ clearHistograms();
+
+ let process = IS_OOP ? "extension" : "parent";
+ let snapshots = getSnapshots(process);
for (let id of HISTOGRAM_IDS) {
- histograms[id] = Services.telemetry.getHistogramById(id);
- histograms[id].clear();
- equal(arraySum(histograms[id].snapshot().counts), 0,
- `No data recorded for histogram: ${id}.`);
+ ok(!(id in snapshots), `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.
- for (let id in histograms) {
- equal(arraySum(histograms[id].snapshot().counts), 1,
+ snapshots = getSnapshots(process);
+ for (let id of HISTOGRAM_IDS) {
+ equal(arraySum(snapshots[id].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.
- for (let id in histograms) {
- equal(arraySum(histograms[id].snapshot().counts), 2,
+ snapshots = getSnapshots(process);
+ for (let id of HISTOGRAM_IDS) {
+ equal(arraySum(snapshots[id].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.
- for (let id in histograms) {
- equal(arraySum(histograms[id].snapshot().counts), 3,
+ snapshots = getSnapshots(process);
+ for (let id of HISTOGRAM_IDS) {
+ equal(arraySum(snapshots[id].counts), expectedCount,
`Data recorded in content script for histogram: ${id}.`);
}
await extension1.unload();
});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -8,30 +8,33 @@
[test_ext_background_global_history.js]
skip-if = os == "android" # Android does not use Places for history.
[test_ext_background_private_browsing.js]
[test_ext_background_runtime_connect_params.js]
[test_ext_background_sub_windows.js]
[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]
[test_ext_downloads.js]
[test_ext_downloads_download.js]
skip-if = os == "android"
[test_ext_downloads_misc.js]
skip-if = os == "android" || (os=='linux' && bits==32) # linux32: bug 1324870
[test_ext_downloads_search.js]
skip-if = os == "android"
[test_ext_experiments.js]
[test_ext_extension.js]
[test_ext_extensionPreferencesManager.js]
[test_ext_extensionSettingsStore.js]
+[test_ext_extension_content_telemetry.js]
+skip-if = os == "android" # checking for telemetry needs to be updated: 1384923
[test_ext_extension_startup_telemetry.js]
[test_ext_idle.js]
[test_ext_legacy_extension_context.js]
[test_ext_legacy_extension_embedding.js]
[test_ext_localStorage.js]
[test_ext_management.js]
[test_ext_management_uninstall_self.js]
[test_ext_onmessage_removelistener.js]
@@ -51,12 +54,14 @@ skip-if = true # This test no longer tes
[test_ext_simple.js]
[test_ext_startup_cache.js]
[test_ext_storage.js]
[test_ext_storage_sync.js]
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]
+skip-if = os == "android" # checking for telemetry needs to be updated: 1384923
[test_ext_topSites.js]
skip-if = os == "android"
[test_native_messaging.js]
skip-if = os == "android"
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini
@@ -1,10 +1,10 @@
[DEFAULT]
-head = head.js head_remote.js head_e10s.js
+head = head.js head_remote.js head_e10s.js head_telemetry.js
tail =
firefox-appdir = browser
skip-if = appname == "thunderbird" || os == "android"
dupe-manifest =
support-files =
data/**
xpcshell-content.ini
tags = webextensions remote-webextensions
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -1,10 +1,10 @@
[DEFAULT]
-head = head.js
+head = head.js head_telemetry.js
firefox-appdir = browser
skip-if = appname == "thunderbird"
dupe-manifest =
support-files =
data/**
head_sync.js
xpcshell-content.ini
tags = webextensions in-process-webextensions