diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js b/devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js new file mode 100644 index 0000000000..171f4f8e7f --- /dev/null +++ b/devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js @@ -0,0 +1,123 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Testing that clicking the pick button switches the toolbox to the inspector +// panel. + +const TEST_URI = + "data:text/html;charset=UTF-8,<!DOCTYPE html><script>console.log(`hello`)</script><p>Switch to inspector on pick</p>"; +const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS; + +const DATA = [ + { + timestamp: 3562, + category: "devtools.main", + method: "enter", + object: "webconsole", + extra: { + host: "bottom", + start_state: "initial_panel", + panel_name: "webconsole", + cold: "true", + message_count: "1", + width: "1300", + }, + }, + { + timestamp: 3671, + category: "devtools.main", + method: "exit", + object: "webconsole", + extra: { + host: "bottom", + width: "1300", + panel_name: "webconsole", + next_panel: "inspector", + reason: "inspect_dom", + }, + }, + { + timestamp: 3671, + category: "devtools.main", + method: "enter", + object: "inspector", + extra: { + host: "bottom", + start_state: "inspect_dom", + panel_name: "inspector", + cold: "true", + width: "1300", + }, + }, +]; + +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(TEST_URI); + const toolbox = await openToolbox(tab); + + await startPickerAndAssertSwitchToInspector(toolbox); + + info("Stopping element picker."); + await toolbox.nodePicker.stop({ canceled: true }); + + checkResults(); +}); + +async function openToolbox(tab) { + info("Opening webconsole."); + return gDevTools.showToolboxForTab(tab, { toolId: "webconsole" }); +} + +async function startPickerAndAssertSwitchToInspector(toolbox) { + info("Clicking element picker button."); + const pickButton = toolbox.doc.querySelector("#command-button-pick"); + pickButton.click(); + + info("Waiting for inspector to be selected."); + await toolbox.once("inspector-selected"); + is(toolbox.currentToolId, "inspector", "Switched to the inspector"); +} + +function checkResults() { + const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); + const events = snapshot.parent.filter( + event => + (event[1] === "devtools.main" && event[2] === "enter") || + event[2] === "exit" + ); + + for (const i in DATA) { + const [timestamp, category, method, object, value, extra] = events[i]; + const expected = DATA[i]; + + // ignore timestamp + Assert.greater(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, null, "value is correct"); + ok(extra.width > 0, "width is greater than 0"); + + checkExtra("host", extra, expected); + checkExtra("start_state", extra, expected); + checkExtra("reason", extra, expected); + checkExtra("panel_name", extra, expected); + checkExtra("next_panel", extra, expected); + checkExtra("message_count", extra, expected); + checkExtra("cold", extra, expected); + } +} + +function checkExtra(propName, extra, expected) { + if (extra[propName]) { + is(extra[propName], expected.extra[propName], `${propName} is correct`); + } +} |