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

--HG--
extra : rebase_source : e9ee1720fd42844e1fa81e3d068de87543981a41
This commit is contained in:
Bob Silverberg 2017-07-24 08:57:50 -04:00
Родитель 2d82f2c5e6
Коммит d257fe68cb
6 изменённых файлов: 80 добавлений и 30 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -41,32 +41,35 @@ add_task(async function test_telemetry() {
},
});
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();

Просмотреть файл

@ -6,10 +6,6 @@ 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"));
@ -49,44 +45,58 @@ add_task(async function test_telemetry_background() {
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}.`);
}

Просмотреть файл

@ -13,6 +13,7 @@ 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]
@ -27,6 +28,7 @@ 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]
@ -56,6 +58,7 @@ 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]

Просмотреть файл

@ -1,5 +1,5 @@
[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"

Просмотреть файл

@ -1,5 +1,5 @@
[DEFAULT]
head = head.js
head = head.js head_telemetry.js
firefox-appdir = browser
skip-if = appname == "thunderbird"
dupe-manifest =