Skip to content

Commit c6f27ce

Browse files
hanselfmu-chromiumDevtools-frontend LUCI CQ
authored andcommitted
Migrate ARIAAttributesView test from web layout test to unit test
Bug: 40262388 Change-Id: I22bee08f23bdc204c4ccfae58061cd5fc28e83ab Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6862798 Commit-Queue: Eric Leese <[email protected]> Reviewed-by: Eric Leese <[email protected]> Auto-Submit: Changhao Han <[email protected]> Commit-Queue: Changhao Han <[email protected]>
1 parent e066304 commit c6f27ce

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2025 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import * as SDK from '../../core/sdk/sdk.js';
6+
import {renderElementIntoDOM} from '../../testing/DOMHelpers.js';
7+
import {createTarget, stubNoopSettings} from '../../testing/EnvironmentHelpers.js';
8+
import {describeWithMockConnection} from '../../testing/MockConnection.js';
9+
10+
import * as Accessibility from './accessibility.js';
11+
12+
describeWithMockConnection('ARIAAttributesView', () => {
13+
let target: SDK.Target.Target;
14+
let domModel: SDK.DOMModel.DOMModel;
15+
let node: SDK.DOMModel.DOMNode;
16+
let setAttributeValueSpy: sinon.SinonSpy;
17+
18+
beforeEach(() => {
19+
stubNoopSettings();
20+
target = createTarget();
21+
domModel = target.model(SDK.DOMModel.DOMModel) as SDK.DOMModel.DOMModel;
22+
node = new SDK.DOMModel.DOMNode(domModel);
23+
node.setAttributesPayload(['role', 'checkbox', 'aria-checked', 'true']);
24+
setAttributeValueSpy = sinon.spy(node, 'setAttributeValue');
25+
});
26+
27+
const modifyAttribute =
28+
(view: Accessibility.ARIAAttributesView.ARIAAttributesPane, childIndex: number, newValue: string) => {
29+
const treeOutline = view.getTreeOutlineForTesting();
30+
assert.exists(treeOutline);
31+
const treeElement =
32+
treeOutline.rootElement().childAt(childIndex) as Accessibility.ARIAAttributesView.ARIAAttributesTreeElement;
33+
assert.exists(treeElement);
34+
treeElement.listItemElement.querySelector('span')?.click();
35+
36+
const prompt = treeElement.getPromptForTesting();
37+
assert.exists(prompt);
38+
const proxyElement = prompt.element();
39+
(proxyElement as HTMLElement).textContent = newValue;
40+
41+
proxyElement.dispatchEvent(new FocusEvent('blur'));
42+
};
43+
44+
it('can modify an ARIA attribute value', () => {
45+
const view = new Accessibility.ARIAAttributesView.ARIAAttributesPane();
46+
renderElementIntoDOM(view);
47+
view.setNode(node);
48+
49+
modifyAttribute(view, 1, 'false');
50+
51+
sinon.assert.calledOnceWithExactly(setAttributeValueSpy, 'aria-checked', 'false');
52+
});
53+
54+
it('can modify an ARIA role', () => {
55+
const view = new Accessibility.ARIAAttributesView.ARIAAttributesPane();
56+
renderElementIntoDOM(view);
57+
view.setNode(node);
58+
59+
modifyAttribute(view, 0, 'radio');
60+
61+
sinon.assert.calledOnceWithExactly(setAttributeValueSpy, 'role', 'radio');
62+
});
63+
});
64+
65+
describe('ARIAAttributesTreeElement', () => {
66+
it('should create a value element with the correct class and text content', () => {
67+
const value = 'test value';
68+
const element = Accessibility.ARIAAttributesView.ARIAAttributesTreeElement.createARIAValueElement(value);
69+
assert.strictEqual(element.textContent, value);
70+
assert.isTrue(element.classList.contains('monospace'));
71+
});
72+
73+
it('should append a name element with the correct classes and text content', () => {
74+
const parentPane = {} as Accessibility.ARIAAttributesView.ARIAAttributesPane;
75+
const attribute = {name: 'aria-label', value: 'test'} as SDK.DOMModel.Attribute;
76+
const target = {} as SDK.Target.Target;
77+
const treeElement = new Accessibility.ARIAAttributesView.ARIAAttributesTreeElement(parentPane, attribute, target);
78+
treeElement.onattach();
79+
80+
treeElement.appendNameElement('aria-label');
81+
82+
const nameElement = treeElement.listItemElement.querySelector('.ax-name');
83+
assert.exists(nameElement);
84+
assert.strictEqual(nameElement.textContent, 'aria-label');
85+
assert.isTrue(nameElement.classList.contains('monospace'));
86+
});
87+
88+
it('should append a value element with the correct text content', () => {
89+
const parentPane = {} as Accessibility.ARIAAttributesView.ARIAAttributesPane;
90+
const attribute = {name: 'aria-label', value: 'test'} as SDK.DOMModel.Attribute;
91+
const target = {} as SDK.Target.Target;
92+
const treeElement = new Accessibility.ARIAAttributesView.ARIAAttributesTreeElement(parentPane, attribute, target);
93+
treeElement.onattach();
94+
95+
treeElement.appendAttributeValueElement('test');
96+
97+
const valueElement = treeElement.listItemElement.querySelector('span:not(.ax-name):not(.separator)');
98+
assert.exists(valueElement);
99+
assert.strictEqual(valueElement.textContent, 'test');
100+
});
101+
});

front_end/panels/accessibility/ARIAAttributesView.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export class ARIAAttributesPane extends AccessibilitySubPane {
6161
this.treeOutline.element.classList.toggle('hidden', !foundAttributes);
6262
}
6363

64+
getTreeOutlineForTesting(): Readonly<UI.TreeOutline.TreeOutline>|undefined {
65+
return this.treeOutline;
66+
}
67+
6468
private isARIAAttribute(attribute: SDK.DOMModel.Attribute): boolean {
6569
return ATTRIBUTES.has(attribute.name);
6670
}
@@ -95,6 +99,10 @@ export class ARIAAttributesTreeElement extends UI.TreeOutline.TreeElement {
9599
this.listItemElement.addEventListener('click', this.mouseClick.bind(this));
96100
}
97101

102+
getPromptForTesting(): Readonly<ARIAAttributePrompt>|undefined {
103+
return this.prompt;
104+
}
105+
98106
private populateListItem(): void {
99107
this.listItemElement.removeChildren();
100108
this.appendNameElement(this.attribute.name);

front_end/panels/accessibility/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ devtools_entrypoint("meta") {
7777
ts_library("unittests") {
7878
testonly = true
7979

80-
sources = [ "AccessibilitySidebarView.test.ts" ]
80+
sources = [
81+
"ARIAAttributesView.test.ts",
82+
"AccessibilitySidebarView.test.ts",
83+
]
8184

8285
deps = [
8386
":bundle",

0 commit comments

Comments
 (0)