diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/shared/test/browser_telemetry_sidebar.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/shared/test/browser_telemetry_sidebar.js')
-rw-r--r-- | devtools/client/shared/test/browser_telemetry_sidebar.js | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/devtools/client/shared/test/browser_telemetry_sidebar.js b/devtools/client/shared/test/browser_telemetry_sidebar.js new file mode 100644 index 0000000000..04aa67b0d0 --- /dev/null +++ b/devtools/client/shared/test/browser_telemetry_sidebar.js @@ -0,0 +1,233 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +/* eslint-disable mozilla/no-arbitrary-setTimeout */ + +"use strict"; + +const TEST_URI = + "data:text/html;charset=utf-8,<p>browser_telemetry_sidebar.js</p>"; +const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS; + +// Because we need to gather stats for the period of time that a tool has been +// opened we make use of setTimeout() to create tool active times. +const TOOL_DELAY = 200; + +const DATA = [ + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "layoutview", + newpanel: "animationinspector", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "animationinspector", + newpanel: "fontinspector", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "fontinspector", + newpanel: "layoutview", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "layoutview", + newpanel: "computedview", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "computedview", + newpanel: "animationinspector", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "animationinspector", + newpanel: "fontinspector", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "fontinspector", + newpanel: "layoutview", + }, + }, + { + timestamp: null, + category: "devtools.main", + method: "sidepanel_changed", + object: "inspector", + value: null, + extra: { + oldpanel: "layoutview", + newpanel: "computedview", + }, + }, +]; + +add_task(async function () { + // Let's reset the counts. + Services.telemetry.clearEvents(); + + // Ensure no events have been logged + const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); + ok(!snapshot.parent, "No events have been logged for the main process"); + + await addTab(TEST_URI); + startTelemetry(); + + const tab = gBrowser.selectedTab; + const toolbox = await gDevTools.showToolboxForTab(tab, { + toolId: "inspector", + }); + info("inspector opened"); + + await testSidebar(toolbox); + checkResults(); + checkEventTelemetry(); + + await toolbox.destroy(); + gBrowser.removeCurrentTab(); +}); + +function testSidebar(toolbox) { + info("Testing sidebar"); + + const inspector = toolbox.getCurrentPanel(); + let sidebarTools = [ + "computedview", + "layoutview", + "fontinspector", + "animationinspector", + ]; + + // Concatenate the array with itself so that we can open each tool twice. + sidebarTools = [...sidebarTools, ...sidebarTools]; + + return new Promise(resolve => { + // See TOOL_DELAY for why we need setTimeout here + setTimeout(function selectSidebarTab() { + const tool = sidebarTools.pop(); + if (tool) { + inspector.sidebar.select(tool); + setTimeout(function () { + setTimeout(selectSidebarTab, TOOL_DELAY); + }, TOOL_DELAY); + } else { + resolve(); + } + }, TOOL_DELAY); + }); +} + +function checkResults() { + // For help generating these tests use generateTelemetryTests("DEVTOOLS_") + // here. + checkTelemetry( + "DEVTOOLS_INSPECTOR_OPENED_COUNT", + "", + { 0: 1, 1: 0 }, + "array" + ); + checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", { 0: 1, 1: 0 }, "array"); + checkTelemetry( + "DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT", + "", + { 0: 2, 1: 0 }, + "array" + ); + checkTelemetry( + "DEVTOOLS_LAYOUTVIEW_OPENED_COUNT", + "", + { 0: 3, 1: 0 }, + "array" + ); + checkTelemetry( + "DEVTOOLS_FONTINSPECTOR_OPENED_COUNT", + "", + { 0: 2, 1: 0 }, + "array" + ); + checkTelemetry( + "DEVTOOLS_COMPUTEDVIEW_TIME_ACTIVE_SECONDS", + "", + null, + "hasentries" + ); + checkTelemetry( + "DEVTOOLS_LAYOUTVIEW_TIME_ACTIVE_SECONDS", + "", + null, + "hasentries" + ); + checkTelemetry( + "DEVTOOLS_FONTINSPECTOR_TIME_ACTIVE_SECONDS", + "", + null, + "hasentries" + ); +} + +function checkEventTelemetry() { + const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); + const events = snapshot.parent.filter( + event => + event[1] === "devtools.main" && + event[2] === "sidepanel_changed" && + event[3] === "inspector" && + event[4] === null + ); + + for (const i in DATA) { + const [timestamp, category, method, object, value, extra] = events[i]; + const expected = DATA[i]; + + // ignore timestamp + ok(timestamp > 0, "timestamp is greater than 0"); + is(category, expected.category, "category is correct"); + is(method, expected.method, "method is correct"); + is(object, expected.object, "object is correct"); + is(value, expected.value, "value is correct"); + + is(extra.oldpanel, expected.extra.oldpanel, "oldpanel is correct"); + is(extra.newpanel, expected.extra.newpanel, "newpanel is correct"); + } +} |