Files
firefox/devtools/client/framework/test/browser_toolbox_telemetry_exit.js
T
Julian Descottes bfb875751c Bug 1694140 - [devtools] Stop using TargetFactory forTab in devtools browser mochitests r=nchevobbe
Depends on D105999

This patch is mostly a mechanical rewrite of:
```lang=javascript
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
```
to
```lang=javascript
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
```

The main changes are:
- if the target was actually used in the test, it is now retrieved from toolbox.target
- the arguments for showToolboxForTab are using an option argument, to avoid the occasional showToolbox("inspector", null, null, null, startTime, null, reason);

I suspect that any signature rewrite mistake would have been caught on try.
There a few less mechanical changes:
- devtools/client/framework/test/browser_toolbox_screenshot_tool.js the toolId "console" was omitted because this id doesn't match any tool (author probably meant "webconsole")
- a few tests were: 1/ first creating a target, 2/ looping on tool definitions to get supported tools 3/ opening the toolbox with each supported tool. To support this I extracted a helper called `getSupportedToolIds` which opens a temporary toolbox to list all supported tool ids
- all the tests under storage/ use a single helper to start the test, which can open toolboxes for both tab targets and other targets. This made it more complicated to refactor. We could also drop this part and just refactor each test when we actually modify forTab/showToolbox to only work with descriptors

All in all the goal of this stack is to pave the way to stop handling targets when using forTab/showToolbox, and behind the scenes stop replying on targets to cache open toolboxes. We don't aim to kill all the call sites, just get them to a smaller number so that the next refactors will be easier.

Differential Revision: https://phabricator.services.mozilla.com/D106000
2021-02-25 18:02:52 +00:00

130 lines
3.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const URL = "data:text/html;charset=utf8,browser_toolbox_telemetry_enter.js";
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
const DATA = [
{
timestamp: null,
category: "devtools.main",
method: "exit",
object: "inspector",
value: null,
extra: {
host: "bottom",
width: 1300,
panel_name: "inspector",
next_panel: "jsdebugger",
reason: "toolbox_show",
},
},
{
timestamp: null,
category: "devtools.main",
method: "exit",
object: "jsdebugger",
value: null,
extra: {
host: "bottom",
width: 1300,
panel_name: "jsdebugger",
next_panel: "styleeditor",
reason: "toolbox_show",
},
},
{
timestamp: null,
category: "devtools.main",
method: "exit",
object: "styleeditor",
value: null,
extra: {
host: "bottom",
width: 1300,
panel_name: "styleeditor",
next_panel: "netmonitor",
reason: "toolbox_show",
},
},
{
timestamp: null,
category: "devtools.main",
method: "exit",
object: "netmonitor",
value: null,
extra: {
host: "bottom",
width: 1300,
panel_name: "netmonitor",
next_panel: "storage",
reason: "toolbox_show",
},
},
{
timestamp: null,
category: "devtools.main",
method: "exit",
object: "storage",
value: null,
extra: {
host: "bottom",
width: 1300,
panel_name: "storage",
next_panel: "netmonitor",
reason: "toolbox_show",
},
},
];
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");
const tab = await addTab(URL);
// Open the toolbox
await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
// Switch between a few tools
await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
await gDevTools.showToolboxForTab(tab, { toolId: "styleeditor" });
await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
await gDevTools.showToolboxForTab(tab, { toolId: "storage" });
await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
await checkResults();
});
async function checkResults() {
const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
const events = snapshot.parent.filter(
event =>
event[1] === "devtools.main" && event[2] === "exit" && 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");
// extras
is(extra.host, expected.extra.host, "host is correct");
ok(extra.width > 0, "width is greater than 0");
is(extra.panel_name, expected.extra.panel_name, "panel_name is correct");
is(extra.next_panel, expected.extra.next_panel, "next_panel is correct");
is(extra.reason, expected.extra.reason, "reason is correct");
}
}