Bug 1643253 - Part 2: Add telemetry mochitests r=jdescottes,Honza

Differential Revision: https://phabricator.services.mozilla.com/D82047
This commit is contained in:
Belén Albeza 2020-07-14 07:22:48 +00:00
Родитель 45746dd16b
Коммит ee49d74c3b
4 изменённых файлов: 183 добавлений и 0 удалений

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

@ -55,6 +55,10 @@ skip-if = asan || debug || !serviceworker_e10s # Bug 1559487, 1559591, 1608640
[browser_application_panel_manifest-load.js]
[browser_application_panel_manifest-open-json.js]
[browser_application_panel_manifest-reload.js]
# Telemetry tests
[browser_application_panel_telemetry-select-page.js]
[browser_application_panel_telemetry-workers.js]
skip-if = asan || debug || !serviceworker_e10s # Bug 1559487, 1559591, 1608640
# Misc tests
[browser_application_panel_open-links.js]
skip-if = true # Bug 1467256, 1559591

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

@ -0,0 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function() {
await enableApplicationPanel();
const TAB_URL = URL_ROOT + "resources/service-workers/empty.html";
const { panel, tab, target } = await openNewTabAndApplicationPanel(TAB_URL);
const doc = panel.panelWin.document;
setupTelemetryTest();
// make sure the default page is opened and then select a different one
await waitUntil(() => doc.querySelector(".js-service-workers-page") !== null);
ok(true, "Service Workers page was loaded per default.");
selectPage(panel, "manifest");
checkTelemetryEvent({ method: "select_page", page_type: "manifest" });
// close the tab
info("Closing the tab.");
await target.client.waitForRequestsToSettle();
await BrowserTestUtils.removeTab(tab);
});

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

@ -0,0 +1,117 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TAB_URL = URL_ROOT + "resources/service-workers/simple.html";
// check telemetry for unregistering a service worker
add_task(async function() {
await enableApplicationPanel();
const { panel, tab, target } = await openNewTabAndApplicationPanel(TAB_URL);
const doc = panel.panelWin.document;
selectPage(panel, "service-workers");
setupTelemetryTest();
info("Wait until the service worker appears in the application panel");
await waitUntil(() => getWorkerContainers(doc).length === 1);
const workerContainer = getWorkerContainers(doc)[0];
info("Wait until the unregister button is displayed for the service worker");
await waitUntil(() => workerContainer.querySelector(".js-unregister-button"));
info("Click the unregister button");
const button = workerContainer.querySelector(".js-unregister-button");
button.click();
checkTelemetryEvent({ method: "unregister_worker" });
// close the tab
info("Closing the tab.");
await target.client.waitForRequestsToSettle();
await BrowserTestUtils.removeTab(tab);
});
// check telemetry for starting a service worker
add_task(async function() {
info("Set a low service worker idle timeout");
await pushPref("dom.serviceWorkers.idle_timeout", 1000);
await pushPref("dom.serviceWorkers.idle_extended_timeout", 1000);
await enableApplicationPanel();
const { panel, tab, target } = await openNewTabAndApplicationPanel(TAB_URL);
const doc = panel.panelWin.document;
selectPage(panel, "service-workers");
await waitForWorkerRegistration(tab);
setupTelemetryTest();
info("Wait until the service worker appears in the application panel");
await waitUntil(() => getWorkerContainers(doc).length === 1);
info("Wait until the start button is displayed and enabled");
const container = getWorkerContainers(doc)[0];
await waitUntil(() => {
const button = container.querySelector(".js-start-button");
return button && !button.disabled;
});
info("Click the start button");
const button = container.querySelector(".js-start-button");
button.click();
checkTelemetryEvent({ method: "start_worker" });
// close the tab
info("Closing the tab.");
await target.client.waitForRequestsToSettle();
await BrowserTestUtils.removeTab(tab);
});
// check telemetry for debugging a service worker
add_task(async function() {
await enableApplicationPanel();
const { panel, tab, toolbox, target } = await openNewTabAndApplicationPanel(
TAB_URL
);
const doc = panel.panelWin.document;
selectPage(panel, "service-workers");
setupTelemetryTest();
info("Wait until the service worker appears in the application panel");
await waitUntil(() => getWorkerContainers(doc).length === 1);
const container = getWorkerContainers(doc)[0];
info("Wait until the debug button is displayed and enabled");
await waitUntil(() => {
const button = container.querySelector(".js-debug-button");
return button && !button.disabled;
});
info("Click on the debug button and wait for debugger to be ready");
const debugButton = container.querySelector(".js-debug-button");
debugButton.click();
await waitUntil(() => toolbox.getPanel("jsdebugger"));
const events = getTelemetryEvents("jsdebugger");
const openToolboxEvent = events.find(event => event.method == "enter");
ok(openToolboxEvent.session_id > 0, "Event has a valid session id");
is(
openToolboxEvent.start_state,
"application",
"Event has the 'application' start state"
);
// close the tab
info("Closing the tab.");
await target.client.waitForRequestsToSettle();
await BrowserTestUtils.removeTab(tab);
});

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

@ -53,6 +53,42 @@ async function enableApplicationPanel() {
await pushPref("devtools.application.enabled", true);
}
function setupTelemetryTest() {
// Reset all the counts
Services.telemetry.clearEvents();
// Ensure no events have been logged
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
ok(!snapshot.parent, "No events have been logged for the main process");
}
function getTelemetryEvents(objectName) {
// read the requested events only
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
// filter and transform the event data so the relevant info is in a single object:
// { method: "...", extraField: "...", anotherExtraField: "...", ... }
const events = snapshot.parent
.filter(event => event[1] === "devtools.main" && event[3] === objectName)
.map(event => ({ method: event[2], ...event[5] }));
return events;
}
function checkTelemetryEvent(expectedEvent, objectName = "application") {
info("Check telemetry event");
const events = getTelemetryEvents(objectName);
// assert we only got 1 event with a valid session ID
is(events.length, 1, "There was only 1 event logged");
const [event] = events;
ok(event.session_id > 0, "There is a valid session_id in the event");
// assert expected data
Assert.deepEqual(event, { ...expectedEvent, session_id: event.session_id });
}
function getWorkerContainers(doc) {
return doc.querySelectorAll(".js-sw-container");
}