Commit 3cef24e0 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: fix internal error on updating unwired element tree

The main ElementsTreeOutline in ElementsPanel is wired to DOMModel
updates, but ETOutlines in Console / elsewhere are not.

In the unwired case, nodes in the tree may have null `children()`.
This can result in internal errors.

Bug: 896445
Change-Id: Ie903fdddb76b31a5460ce2dd4b753be7ba7eeb56
Reviewed-on: https://chromium-review.googlesource.com/c/1286860Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Erik Luo <luoe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607419}
parent d1f914d0
Tests that removed Elements logged in the Console are properly formatted.
Adding element
console-expand-removed-node.js:19 <div>…</div>
Removing element
Expanding element in Console
console-expand-removed-node.js:19 <div></div>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(`Tests that removed Elements logged in the Console are properly formatted.\n`);
await TestRunner.loadModule('console_test_runner');
await TestRunner.showPanel('console');
TestRunner.addResult(`Adding element`);
await TestRunner.evaluateInPagePromise(`
var el = document.createElement('div');
var child = document.createElement('span');
el.appendChild(child);
document.body.appendChild(el);
undefined;
`);
const nodePromise = TestRunner.addSnifferPromise(Console.ConsoleViewMessage.prototype, '_formattedParameterAsNodeForTest');
TestRunner.evaluateInPagePromise(`console.log(el)`);
await nodePromise;
await ConsoleTestRunner.waitForPendingViewportUpdates();
ConsoleTestRunner.dumpConsoleMessages();
TestRunner.addResult(`Removing element`);
await TestRunner.evaluateInPagePromise(`el.remove()`);
TestRunner.addResult(`Expanding element in Console`);
await ConsoleTestRunner.expandConsoleMessagesPromise();
await ConsoleTestRunner.waitForRemoteObjectsConsoleMessagesPromise();
ConsoleTestRunner.dumpConsoleMessages();
TestRunner.completeTest();
})();
...@@ -1229,7 +1229,8 @@ Elements.ElementsTreeOutline = class extends UI.TreeOutline { ...@@ -1229,7 +1229,8 @@ Elements.ElementsTreeOutline = class extends UI.TreeOutline {
visibleChildren.push(beforePseudoElement); visibleChildren.push(beforePseudoElement);
if (node.childNodeCount()) { if (node.childNodeCount()) {
let children = node.children(); // Children may be stale when the outline is not wired to receive DOMModel updates.
let children = node.children() || [];
if (!this._showHTMLCommentsSetting.get()) if (!this._showHTMLCommentsSetting.get())
children = children.filter(n => n.nodeType() !== Node.COMMENT_NODE); children = children.filter(n => n.nodeType() !== Node.COMMENT_NODE);
visibleChildren = visibleChildren.concat(children); visibleChildren = visibleChildren.concat(children);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment