Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/test/data/extensions/api_test/automation/tests/tabs/find.js

Issue 2439203003: Reland of Accessibility: Ignore all anonymous blocks (Closed)
Patch Set: Rebased. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var group; 5 var group;
6 var h1; 6 var h1;
7 var p1; 7 var p1;
8 var link; 8 var link;
9 var main; 9 var main;
10 var p2; 10 var p2;
11 var p3; 11 var p3;
12 var anonGroup;
13 var okButton; 12 var okButton;
14 var cancelButton; 13 var cancelButton;
15 14
16 function initializeNodes(rootNode) { 15 function initializeNodes(rootNode) {
17 group = rootNode.firstChild; 16 group = rootNode.firstChild;
18 assertEq(RoleType.group, group.role); 17 assertEq(RoleType.group, group.role);
19 18
20 h1 = group.firstChild; 19 h1 = group.firstChild;
21 assertEq(RoleType.heading, h1.role); 20 assertEq(RoleType.heading, h1.role);
22 assertEq(1, h1.hierarchicalLevel); 21 assertEq(1, h1.hierarchicalLevel);
23 22
24 p1 = group.lastChild; 23 p1 = group.lastChild;
25 assertEq(RoleType.paragraph, p1.role); 24 assertEq(RoleType.paragraph, p1.role);
26 25
27 link = p1.children[1]; 26 link = p1.children[1];
28 assertEq(RoleType.link, link.role); 27 assertEq(RoleType.link, link.role);
29 28
30 main = rootNode.children[1]; 29 main = rootNode.children[1];
31 assertEq(RoleType.main, main.role); 30 assertEq(RoleType.main, main.role);
32 31
33 p2 = main.firstChild; 32 p2 = main.firstChild;
34 assertEq(RoleType.paragraph, p2.role); 33 assertEq(RoleType.paragraph, p2.role);
35 34
36 p3 = main.lastChild; 35 p3 = main.lastChild;
37 assertEq(RoleType.paragraph, p3.role); 36 assertEq(RoleType.paragraph, p3.role);
38 37
39 anonGroup = rootNode.lastChild; 38 okButton = rootNode.children[2];
40 assertEq(RoleType.group, anonGroup.role);
41
42 okButton = anonGroup.firstChild;
43 assertEq(RoleType.button, okButton.role); 39 assertEq(RoleType.button, okButton.role);
44 assertEq('Ok', okButton.name); 40 assertEq('Ok', okButton.name);
45 assertTrue(StateType.disabled in okButton.state); 41 assertTrue(StateType.disabled in okButton.state);
46 assertTrue(okButton.state.disabled); 42 assertTrue(okButton.state.disabled);
47 43
48 cancelButton = anonGroup.lastChild; 44 cancelButton = rootNode.children[3];
49 assertEq(RoleType.button, cancelButton.role); 45 assertEq(RoleType.button, cancelButton.role);
50 assertEq('Cancel', cancelButton.name); 46 assertEq('Cancel', cancelButton.name);
51 assertFalse(StateType.disabled in cancelButton.state); 47 assertFalse(StateType.disabled in cancelButton.state);
52 } 48 }
53 49
54 var allTests = [ 50 var allTests = [
55 function testFindByRole() { 51 function testFindByRole() {
56 initializeNodes(rootNode); 52 initializeNodes(rootNode);
57 53
58 // Should find the only instance of this role. 54 // Should find the only instance of this role.
(...skipping 11 matching lines...) Expand all
70 66
71 // No instances: find should return null; findAll should return empty array. 67 // No instances: find should return null; findAll should return empty array.
72 assertEq(null, rootNode.find({ role: RoleType.checkbox })); 68 assertEq(null, rootNode.find({ role: RoleType.checkbox }));
73 assertEq([], rootNode.findAll({ role: RoleType.checkbox })); 69 assertEq([], rootNode.findAll({ role: RoleType.checkbox }));
74 70
75 // Calling from node should search only its subtree. 71 // Calling from node should search only its subtree.
76 assertEq(p1, group.find({ role: RoleType.paragraph })); 72 assertEq(p1, group.find({ role: RoleType.paragraph }));
77 assertEq(p2, main.find({ role: RoleType.paragraph })); 73 assertEq(p2, main.find({ role: RoleType.paragraph }));
78 assertEq([p2, p3], main.findAll({ role: RoleType.paragraph })); 74 assertEq([p2, p3], main.findAll({ role: RoleType.paragraph }));
79 75
80 // Unlike querySelector, can search from an anonymous group without
81 // unexpected results.
82 assertEq(okButton, anonGroup.find({ role: RoleType.button }));
83 assertEq([okButton, cancelButton],
84 anonGroup.findAll({ role: RoleType.button }));
85 assertEq(null, anonGroup.find({ role: RoleType.heading }));
86
87 chrome.test.succeed(); 76 chrome.test.succeed();
88 }, 77 },
89 78
90 function testFindByStates() { 79 function testFindByStates() {
91 initializeNodes(rootNode); 80 initializeNodes(rootNode);
92 81
93 // Find all focusable elements (disabled button is not focusable). 82 // Find all focusable elements (disabled button is not focusable).
94 assertEq(link, rootNode.find({ state: { focusable: true }})); 83 assertEq(link, rootNode.find({ state: { focusable: true }}));
95 assertEq([link, cancelButton], 84 assertEq([link, cancelButton],
96 rootNode.findAll({ state: { focusable: true }})); 85 rootNode.findAll({ state: { focusable: true }}));
97 86
98 // Find disabled buttons. 87 // Find disabled buttons.
99 assertEq(okButton, rootNode.find({ role: RoleType.button, 88 assertEq(okButton, rootNode.find({ role: RoleType.button,
100 state: { disabled: true }})); 89 state: { disabled: true }}));
101 assertEq([okButton], rootNode.findAll({ role: RoleType.button, 90 assertEq([okButton], rootNode.findAll({ role: RoleType.button,
102 state: { disabled: true }})); 91 state: { disabled: true }}));
103 92
104 // Find disabled buttons within a portion of the tree.
105 assertEq(okButton, anonGroup.find({ role: RoleType.button,
106 state: { disabled: true }}));
107 assertEq([okButton], anonGroup.findAll({ role: RoleType.button,
108 state: { disabled: true }}));
109
110 // Find enabled buttons. 93 // Find enabled buttons.
111 assertEq(cancelButton, rootNode.find({ role: RoleType.button, 94 assertEq(cancelButton, rootNode.find({ role: RoleType.button,
112 state: { disabled: false }})); 95 state: { disabled: false }}));
113 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button, 96 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button,
114 state: { disabled: false }})); 97 state: { disabled: false }}));
115 chrome.test.succeed(); 98 chrome.test.succeed();
116 }, 99 },
117 100
118 function testFindByAttribute() { 101 function testFindByAttribute() {
119 initializeNodes(rootNode); 102 initializeNodes(rootNode);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 assertFalse( 154 assertFalse(
172 p2StaticText.matches({ role: RoleType.staticText, 155 p2StaticText.matches({ role: RoleType.staticText,
173 attributes: { name: 'relationship' } }), 156 attributes: { name: 'relationship' } }),
174 'p2 should not match name: \'relationship'); 157 'p2 should not match name: \'relationship');
175 158
176 chrome.test.succeed(); 159 chrome.test.succeed();
177 } 160 }
178 ]; 161 ];
179 162
180 setUpAndRunTests(allTests, 'complex.html'); 163 setUpAndRunTests(allTests, 'complex.html');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698