Bug 1419292 - Add a test for object behaviour in the sidebar; r=bgrins.
This adds a test to ensure a message in the console sidebar can
still be expanded after the message it comes from was pruned (the
log limit was hit).
MozReview-Commit-ID: 8CyJlXkgcJL
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -327,16 +327,17 @@ subsuite = clipboard
[browser_webconsole_repeat_different_objects.js]
[browser_webconsole_sandbox_update_after_navigation.js]
[browser_webconsole_script_errordoc_urls.js]
[browser_webconsole_scroll.js]
[browser_webconsole_select_all.js]
[browser_webconsole_show_subresource_security_errors.js]
[browser_webconsole_shows_reqs_from_netmonitor.js]
[browser_webconsole_shows_reqs_in_netmonitor.js]
+[browser_webconsole_sidebar_object_expand_when_message_pruned.js]
[browser_webconsole_sourcemap_css.js]
[browser_webconsole_sourcemap_error.js]
[browser_webconsole_sourcemap_invalid.js]
[browser_webconsole_sourcemap_nosource.js]
[browser_webconsole_split.js]
[browser_webconsole_split_escape_key.js]
[browser_webconsole_split_focus.js]
[browser_webconsole_split_persist.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_sidebar_object_expand_when_message_pruned.js
@@ -0,0 +1,80 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Test that an object in the sidebar can still be expanded after the message where it was
+// logged is pruned.
+
+"use strict";
+
+const TEST_URI = "data:text/html;charset=utf8," +
+ "<script>console.log({a:1,b:2,c:[3,4,5]});</script>";
+
+add_task(async function() {
+ // Should be removed when sidebar work is complete (Bug 1447235)
+ await pushPref("devtools.webconsole.sidebarToggle", true);
+ // Set the loglimit to 1 so message gets pruned as soon as another message is displayed.
+ await pushPref("devtools.hud.loglimit", 1);
+
+ let hud = await openNewTabAndConsole(TEST_URI);
+
+ let message = await waitFor(() => findMessage(hud, "Object"));
+ let object = message.querySelector(".object-inspector .objectBox-object");
+
+ const sidebar = await showSidebarWithContextMenu(hud, object, true);
+
+ let oi = sidebar.querySelector(".object-inspector");
+ let oiNodes = oi.querySelectorAll(".node");
+ if (oiNodes.length === 1) {
+ // If this is the case, we wait for the properties to be fetched and displayed.
+ await waitFor(() => oi.querySelectorAll(".node").length > 1);
+ oiNodes = oi.querySelectorAll(".node");
+ }
+
+ info("Log a message so the original one gets pruned");
+ const messageText = "hello world";
+ const onMessage = waitForMessage(hud, messageText);
+ ContentTask.spawn(gBrowser.selectedBrowser, messageText, async function(str) {
+ content.console.log(str);
+ });
+ await onMessage;
+
+ ok(!findMessage(hud, "Object"), "Message with object was pruned");
+
+ info("Expand the 'c' node in the sidebar");
+ // Here's what the object in the sidebar looks like:
+ // ▼ {…}
+ // a: 1
+ // b: 2
+ // ▶︎ c: (3) […]
+ // ▶︎ <prototype>: {…}
+ const cNode = oiNodes[3];
+ const onNodeExpanded = waitFor(() => oi.querySelectorAll(".node").length > 5);
+ cNode.click();
+ await onNodeExpanded;
+
+ // Here's what the object in the sidebar should look like:
+ // ▼ {…}
+ // a: 1
+ // b: 2
+ // ▼ c: (3) […]
+ // 0: 3
+ // 1: 4
+ // 2: 5
+ // length: 3
+ // ▶︎ <prototype>: []
+ // ▶︎ <prototype>: {…}
+ is(oi.querySelectorAll(".node").length, 10, "The 'c' property was expanded");
+});
+
+async function showSidebarWithContextMenu(hud, node) {
+ let wrapper = hud.ui.document.querySelector(".webconsole-output-wrapper");
+ let onSidebarShown = waitFor(() => wrapper.querySelector(".sidebar"));
+
+ let contextMenu = await openContextMenu(hud, node);
+ let openInSidebar = contextMenu.querySelector("#console-menu-open-sidebar");
+ openInSidebar.click();
+ await onSidebarShown;
+ await hideContextMenu(hud);
+ return onSidebarShown;
+}