forked from mirrors/gecko-dev
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
116 lines
2.8 KiB
JavaScript
116 lines
2.8 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_telemetry_activate_rdm.js";
|
|
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
|
|
const DATA = [
|
|
{
|
|
timestamp: null,
|
|
category: "devtools.main",
|
|
method: "activate",
|
|
object: "responsive_design",
|
|
value: null,
|
|
extra: {
|
|
host: "none",
|
|
width: "1300",
|
|
},
|
|
},
|
|
{
|
|
timestamp: null,
|
|
category: "devtools.main",
|
|
method: "deactivate",
|
|
object: "responsive_design",
|
|
value: null,
|
|
extra: {
|
|
host: "none",
|
|
width: "1300",
|
|
},
|
|
},
|
|
{
|
|
timestamp: null,
|
|
category: "devtools.main",
|
|
method: "activate",
|
|
object: "responsive_design",
|
|
value: null,
|
|
extra: {
|
|
host: "bottom",
|
|
width: "1300",
|
|
},
|
|
},
|
|
{
|
|
timestamp: null,
|
|
category: "devtools.main",
|
|
method: "deactivate",
|
|
object: "responsive_design",
|
|
value: null,
|
|
extra: {
|
|
host: "bottom",
|
|
width: "1300",
|
|
},
|
|
},
|
|
];
|
|
|
|
addRDMTask(
|
|
null,
|
|
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);
|
|
|
|
await openCloseRDM(tab);
|
|
await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
|
|
await openCloseRDM(tab);
|
|
await checkResults();
|
|
},
|
|
{ onlyPrefAndTask: true }
|
|
);
|
|
|
|
async function openCloseRDM(tab) {
|
|
const { ui } = await openRDM(tab);
|
|
await waitForDeviceAndViewportState(ui);
|
|
|
|
const clientClosed = waitForClientClose(ui);
|
|
|
|
closeRDM(tab, {
|
|
reason: "TabClose",
|
|
});
|
|
|
|
// This flag is set at the end of `ResponsiveUI.destroy`. If it is true
|
|
// without waiting for `closeRDM` above, then we must have closed
|
|
// synchronously.
|
|
is(ui.destroyed, true, "RDM closed synchronously");
|
|
|
|
await clientClosed;
|
|
}
|
|
|
|
async function checkResults() {
|
|
const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
|
|
const events = snapshot.parent.filter(
|
|
event =>
|
|
event[1] === "devtools.main" &&
|
|
(event[2] === "activate" || event[2] === "deactivate")
|
|
);
|
|
|
|
for (const i in events) {
|
|
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");
|
|
}
|
|
}
|