豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 2b465ca

Browse files
Eric LeeseDevtools-frontend LUCI CQ
authored andcommitted
Group adopted style sheets under an #adopted-style-sheets node
Updates display of adopted style sheets in the DOM tree to be under an #adopted-style-sheets node so that they don't create clutter when there are a lot of them and the user isn't interested in them. Drive-by: Move the generated package.json file up a level because the hosted server needs it too to support running e2e tests in a full chromium checkout. Fixed: 476399197 Change-Id: Ia7208bcf3bb9c9b1621ec6b103a6390d218b9f9e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7549168 Commit-Queue: Eric Leese <leese@chromium.org> Auto-Submit: Eric Leese <leese@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
1 parent 007f7fd commit 2b465ca

File tree

7 files changed

+96
-29
lines changed

7 files changed

+96
-29
lines changed

BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,6 @@ copy_to_gen("favicon") {
212212
group("mcp") {
213213
deps = [ "./mcp" ]
214214
}
215+
216+
# TODO(@nvitkov): When http://b/469573569 is fixed
217+
write_file("$target_gen_dir/package.json", "{}")

front_end/panels/elements/AdoptedStyleSheetTreeElement.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ describeWithMockConnection('AdoptedStyleSheetTreeElement highlighting', () => {
9898
length: initialCSS.length,
9999
loadingFailed: false,
100100
});
101-
const adoptedStyleSheetTreeElement =
102-
new Elements.AdoptedStyleSheetTreeElement.AdoptedStyleSheetTreeElement(adoptedSheet);
103-
shadowRootTreeElement.appendChild(adoptedStyleSheetTreeElement);
101+
const adoptedStyleSheetSetTreeElement =
102+
new Elements.AdoptedStyleSheetTreeElement.AdoptedStyleSheetSetTreeElement([adoptedSheet]);
103+
shadowRootTreeElement.appendChild(adoptedStyleSheetSetTreeElement);
104104
await shadowRootTreeElement.onpopulate();
105105
shadowRootTreeElement.expand();
106106
assert.strictEqual(shadowRootTreeElement.childCount(), 1);
107-
assert.strictEqual(shadowRootTreeElement.children()[0], adoptedStyleSheetTreeElement);
107+
assert.strictEqual(shadowRootTreeElement.children()[0], adoptedStyleSheetSetTreeElement);
108+
await adoptedStyleSheetSetTreeElement.onpopulate();
109+
adoptedStyleSheetSetTreeElement.expand();
110+
assert.strictEqual(adoptedStyleSheetSetTreeElement.childCount(), 1);
111+
const adoptedStyleSheetTreeElement = adoptedStyleSheetSetTreeElement.children()[0] as
112+
Elements.AdoptedStyleSheetTreeElement.AdoptedStyleSheetTreeElement;
108113
await adoptedStyleSheetTreeElement.onpopulate();
109114
adoptedStyleSheetTreeElement.expand();
110115
assert.strictEqual(adoptedStyleSheetTreeElement.childCount(), 1);

front_end/panels/elements/AdoptedStyleSheetTreeElement.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import {PanelUtils} from '../utils/utils.js';
1313

1414
import type {EditorHandles} from './ElementsTreeElement.js';
1515

16+
export class AdoptedStyleSheetSetTreeElement extends UI.TreeOutline.TreeElement {
17+
constructor(readonly adoptedStyleSheets: SDK.DOMModel.AdoptedStyleSheet[]) {
18+
super('');
19+
const documentElement = this.listItemElement.createChild('span');
20+
UI.UIUtils.createTextChild(documentElement, '#adopted-style-sheets');
21+
for (const adoptedStyleSheet of adoptedStyleSheets) {
22+
this.appendChild(new AdoptedStyleSheetTreeElement(adoptedStyleSheet));
23+
}
24+
}
25+
}
26+
1627
export class AdoptedStyleSheetTreeElement extends UI.TreeOutline.TreeElement {
1728
private eventListener: Common.EventTarget.EventDescriptor|null = null;
1829

front_end/panels/elements/ElementsTreeOutline.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import * as UI from '../../ui/legacy/legacy.js';
4747
import {html, nothing, render} from '../../ui/lit/lit.js';
4848
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
4949

50-
import {AdoptedStyleSheetTreeElement} from './AdoptedStyleSheetTreeElement.js';
50+
import {AdoptedStyleSheetSetTreeElement, AdoptedStyleSheetTreeElement} from './AdoptedStyleSheetTreeElement.js';
5151
import {getElementIssueDetails} from './ElementIssueUtils.js';
5252
import {ElementsPanel} from './ElementsPanel.js';
5353
import {ElementsTreeElement, InitialChildrenLimit, isOpeningTag} from './ElementsTreeElement.js';
@@ -917,15 +917,21 @@ export class ElementsTreeOutline extends
917917
}
918918

919919
highlightAdoptedStyleSheet(adoptedStyleSheet: SDK.DOMModel.AdoptedStyleSheet): void {
920-
const parentNode = !this.includeRootDOMNode && adoptedStyleSheet.parent === this.rootDOMNode && this.rootDOMNode ?
920+
const parentDOMNode =
921+
!this.includeRootDOMNode && adoptedStyleSheet.parent === this.rootDOMNode && this.rootDOMNode ?
921922
this.rootElement() :
922923
this.createTreeElementFor(adoptedStyleSheet.parent);
923-
if (!parentNode) {
924+
if (!parentDOMNode) {
925+
return;
926+
}
927+
const parentNode = parentDOMNode.firstChild();
928+
if (!(parentNode && parentNode instanceof AdoptedStyleSheetSetTreeElement)) {
924929
return;
925930
}
926931

927932
for (const child of parentNode.children()) {
928933
if (child instanceof AdoptedStyleSheetTreeElement && child.adoptedStyleSheet === adoptedStyleSheet) {
934+
parentNode.expand();
929935
child.highlight();
930936
return;
931937
}
@@ -980,8 +986,8 @@ export class ElementsTreeOutline extends
980986
this.dispatchEventToListeners(ElementsTreeOutline.Events.ElementsTreeUpdated, nodes);
981987
}
982988

983-
findTreeElement(node: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet): ElementsTreeElement|null {
984-
if (node instanceof SDK.DOMModel.AdoptedStyleSheet) {
989+
findTreeElement(node: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[]): ElementsTreeElement|null {
990+
if (node instanceof Array) {
985991
return null;
986992
}
987993
let treeElement = this.lookUpTreeElement(node);
@@ -1768,10 +1774,10 @@ export class ElementsTreeOutline extends
17681774
}
17691775
}
17701776

1771-
private createElementTreeElement(node: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet, isClosingTag?: boolean):
1777+
private createElementTreeElement(node: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[], isClosingTag?: boolean):
17721778
UI.TreeOutline.TreeElement {
1773-
if (node instanceof SDK.DOMModel.AdoptedStyleSheet) {
1774-
return new AdoptedStyleSheetTreeElement(node);
1779+
if (node instanceof Array) {
1780+
return new AdoptedStyleSheetSetTreeElement(node);
17751781
}
17761782
const treeElement = new ElementsTreeElement(node, isClosingTag);
17771783
treeElement.setExpandable(!isClosingTag && this.hasVisibleChildren(node));
@@ -1800,8 +1806,12 @@ export class ElementsTreeOutline extends
18001806
return treeElement.childAt(index) as ElementsTreeElement;
18011807
}
18021808

1803-
private visibleChildren(node: SDK.DOMModel.DOMNode): Array<SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet> {
1804-
let visibleChildren = [...node.adoptedStyleSheetsForNode, ...ElementsTreeElement.visibleShadowRoots(node)];
1809+
private visibleChildren(node: SDK.DOMModel.DOMNode): Array<SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[]> {
1810+
const visibleChildren: Array<SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[]> = [];
1811+
if (node.adoptedStyleSheetsForNode.length) {
1812+
visibleChildren.push(node.adoptedStyleSheetsForNode);
1813+
}
1814+
visibleChildren.push(...ElementsTreeElement.visibleShadowRoots(node));
18051815

18061816
const contentDocument = node.contentDocument();
18071817
if (contentDocument) {
@@ -1838,7 +1848,7 @@ export class ElementsTreeOutline extends
18381848
if (!this.showHTMLCommentsSetting.get()) {
18391849
children = children.filter(n => n.nodeType() !== Node.COMMENT_NODE);
18401850
}
1841-
visibleChildren = visibleChildren.concat(children);
1851+
visibleChildren.push(...children);
18421852
}
18431853

18441854
const afterPseudoElement = node.afterPseudoElement();
@@ -1927,7 +1937,7 @@ export class ElementsTreeOutline extends
19271937
}
19281938

19291939
insertChildElement(
1930-
treeElement: ElementsTreeElement|TopLayerContainer, child: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet,
1940+
treeElement: ElementsTreeElement|TopLayerContainer, child: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[],
19311941
index: number, isClosingTag?: boolean): UI.TreeOutline.TreeElement {
19321942
const newElement = this.createElementTreeElement(child, isClosingTag);
19331943
treeElement.insertChild(newElement, index);
@@ -1957,12 +1967,12 @@ export class ElementsTreeOutline extends
19571967

19581968
const node = treeElement.node();
19591969
const visibleChildren = this.visibleChildren(node);
1960-
const visibleChildrenSet = new Set<SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet>(visibleChildren);
1970+
const visibleChildrenSet = new Set<SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[]>(visibleChildren);
19611971

19621972
// Remove any tree elements that no longer have this node as their parent and save
19631973
// all existing elements that could be reused. This also removes closing tag element.
1964-
const existingTreeElements =
1965-
new Map<SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet, UI.TreeOutline.TreeElement&ElementsTreeElement>();
1974+
const existingTreeElements = new Map<
1975+
SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet[], UI.TreeOutline.TreeElement&ElementsTreeElement>();
19661976
for (let i = treeElement.childCount() - 1; i >= 0; --i) {
19671977
const existingTreeElement = treeElement.childAt(i);
19681978
if (!(existingTreeElement instanceof ElementsTreeElement)) {

test/BUILD.gn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ node_ts_library("run") {
3232
deps = [ "shared" ]
3333
}
3434

35-
# TODO(@nvitkov): When http://b/469573569 is fixed
36-
write_file("$target_gen_dir/package.json", "{}")
37-
3835
source_root = rebase_path("//$devtools_location", target_gen_dir)
3936
checkout_root = rebase_path("//", target_gen_dir)
4037
build_root = rebase_path(root_build_dir, target_gen_dir)

test/e2e/elements/adopted-stylesheets.test.ts

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import {assert} from 'chai';
66

77
import {
8+
elementWithPartialText,
89
getContentOfSelectedNode,
910
waitForAndClickTreeElementWithPartialText,
1011
waitForChildrenOfSelectedElementNode,
@@ -21,14 +22,14 @@ describe('The Elements tab', function() {
2122
await inspectedPage.goToResource('elements/adopted-stylesheet.html');
2223
const tree = await devToolsPage.waitForAria('Page DOM');
2324
const treeContent = await devToolsPage.waitForTextNotMatching(tree, /^\<html\>/);
24-
const expectedAdoptedStyleSheet = '#adopted-style-sheet/* For document */';
25+
const expectedAdoptedStyleSheet = '#adopted-style-sheets#adopted-style-sheet/* For document */';
2526
assertStartsWith(treeContent, expectedAdoptedStyleSheet);
2627
});
2728

2829
it('updates adopted stylesheets in document root', async ({devToolsPage, inspectedPage}) => {
2930
await inspectedPage.goToResource('elements/adopted-stylesheet.html');
3031
const tree = await devToolsPage.waitForAria('Page DOM');
31-
const initialAdoptedStyleSheet = '#adopted-style-sheet/* For document */';
32+
const initialAdoptedStyleSheet = '#adopted-style-sheets#adopted-style-sheet/* For document */';
3233
assertStartsWith(await tree.evaluate(e => e.textContent), initialAdoptedStyleSheet);
3334
await inspectedPage.evaluate(() => {
3435
document.adoptedStyleSheets = [];
@@ -38,13 +39,15 @@ describe('The Elements tab', function() {
3839
document.adoptedStyleSheets = [new CSSStyleSheet(), new CSSStyleSheet()];
3940
});
4041
assertStartsWith(
41-
await devToolsPage.waitForTextNotMatching(tree, /^\<html\>/), '#adopted-style-sheet#adopted-style-sheet<html>');
42+
await devToolsPage.waitForTextNotMatching(tree, /^\<html\>/),
43+
'#adopted-style-sheets#adopted-style-sheet#adopted-style-sheet<html>');
4244
await inspectedPage.evaluate(() => {
4345
document.adoptedStyleSheets[0].replaceSync('/**/');
4446
});
4547
assertStartsWith(
46-
await devToolsPage.waitForTextNotMatching(tree, /^#adopted-style-sheet#adopted-style-sheet/),
47-
'#adopted-style-sheet/**/#adopted-style-sheet<html>');
48+
await devToolsPage.waitForTextNotMatching(
49+
tree, /^#adopted-style-sheets#adopted-style-sheet#adopted-style-sheet/),
50+
'#adopted-style-sheets#adopted-style-sheet/**/#adopted-style-sheet<html>');
4851
});
4952

5053
it('shows link to imported stylesheet', async ({devToolsPage, inspectedPage}) => {
@@ -71,15 +74,53 @@ describe('The Elements tab', function() {
7174
await devToolsPage.pressKey('ArrowRight');
7275
await waitForPartialContentOfSelectedElementsNode('#shadow-root', devToolsPage);
7376

77+
// One more time to get the adopted stylesheet set.
78+
await devToolsPage.pressKey('ArrowRight');
79+
await waitForChildrenOfSelectedElementNode(devToolsPage);
80+
await devToolsPage.pressKey('ArrowRight');
81+
await waitForPartialContentOfSelectedElementsNode('#adopted-style-sheets', devToolsPage);
82+
7483
// One more time to get the adopted stylesheet.
7584
await devToolsPage.pressKey('ArrowRight');
7685
await waitForChildrenOfSelectedElementNode(devToolsPage);
7786
await devToolsPage.pressKey('ArrowRight');
78-
await waitForPartialContentOfSelectedElementsNode('#adopted-style-sheet', devToolsPage);
87+
await waitForPartialContentOfSelectedElementsNode('#adopted-style-sheet \(', devToolsPage);
7988

8089
// Check that the link to the imported stylesheet is present.
8190
assert.match(
8291
await getContentOfSelectedNode(devToolsPage),
8392
/#adopted-style-sheet \(https?:\/\/.*\/test\/e2e\/resources\/elements\/adopted-style.css\)/);
8493
});
94+
95+
it('reveals adopted stylesheets in document root when clicking link from styles pane',
96+
async ({devToolsPage, inspectedPage}) => {
97+
await inspectedPage.goToResource('elements/adopted-stylesheet.html');
98+
const tree = await devToolsPage.waitForAria('Page DOM');
99+
await devToolsPage.waitForTextNotMatching(tree, /^\<html\>/);
100+
const styleSheets = await elementWithPartialText('#adopted-style-sheets', devToolsPage);
101+
assert.isOk(styleSheets);
102+
const expectExpanded = async (expanded: boolean) =>
103+
assert.strictEqual(await styleSheets.evaluate(e => e.getAttribute('aria-expanded')), `${expanded}`);
104+
await expectExpanded(false);
105+
106+
// Check to make sure we have the correct node selected after opening a file
107+
await waitForPartialContentOfSelectedElementsNode('<body>', devToolsPage);
108+
// This isn't consistently expanded, so this arrow right might expand it
109+
// or it might move the selected node, but either way it should change
110+
// the text of the selected node.
111+
const bodyNodeText = await getContentOfSelectedNode(devToolsPage);
112+
await devToolsPage.pressKey('ArrowRight');
113+
await waitForSelectedNodeChange(bodyNodeText, devToolsPage);
114+
115+
// Click the node for this test.
116+
await waitForAndClickTreeElementWithPartialText('"from-document"', devToolsPage);
117+
118+
// Click the link to the adopted stylesheet in the styles pane.
119+
await devToolsPage.click(
120+
'.matched-styles[aria-label=".from-document, css selector"] > .styles-section-subtitle > devtools-widget');
121+
122+
// The adopted stylesheet set should now be expanded.
123+
await devToolsPage.waitForClass(styleSheets, 'expanded');
124+
await expectExpanded(true);
125+
});
85126
});

test/e2e/helpers/elements-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export const waitForElementWithPartialText = async (text: string, devToolsPage:
281281
return await devToolsPage.waitForFunction(async () => await elementWithPartialText(text, devToolsPage));
282282
};
283283

284-
const elementWithPartialText = async (text: string, devToolsPage: DevToolsPage) => {
284+
export const elementWithPartialText = async (text: string, devToolsPage: DevToolsPage) => {
285285
const tree = await devToolsPage.waitFor('Page DOM[role="tree"]', undefined, undefined, 'aria');
286286
const elements = await devToolsPage.$$('[role="treeitem"]', tree, 'aria');
287287
for (const handle of elements) {

0 commit comments

Comments
 (0)