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

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

Issue 2650733002: Revert of Update json_schema_compiler to handle the Automation extension API (Closed)
Patch Set: Created 3 years, 11 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 okButton; 12 var okButton;
13 var cancelButton; 13 var cancelButton;
14 14
15 function initializeNodes(rootNode) { 15 function initializeNodes(rootNode) {
16 group = rootNode.firstChild; 16 group = rootNode.firstChild;
17 assertEq(RoleType.GROUP, group.role); 17 assertEq(RoleType.group, group.role);
18 18
19 h1 = group.firstChild; 19 h1 = group.firstChild;
20 assertEq(RoleType.HEADING, h1.role); 20 assertEq(RoleType.heading, h1.role);
21 assertEq(1, h1.hierarchicalLevel); 21 assertEq(1, h1.hierarchicalLevel);
22 22
23 p1 = group.lastChild; 23 p1 = group.lastChild;
24 assertEq(RoleType.PARAGRAPH, p1.role); 24 assertEq(RoleType.paragraph, p1.role);
25 25
26 link = p1.children[1]; 26 link = p1.children[1];
27 assertEq(RoleType.LINK, link.role); 27 assertEq(RoleType.link, link.role);
28 28
29 main = rootNode.children[1]; 29 main = rootNode.children[1];
30 assertEq(RoleType.MAIN, main.role); 30 assertEq(RoleType.main, main.role);
31 31
32 p2 = main.firstChild; 32 p2 = main.firstChild;
33 assertEq(RoleType.PARAGRAPH, p2.role); 33 assertEq(RoleType.paragraph, p2.role);
34 34
35 p3 = main.lastChild; 35 p3 = main.lastChild;
36 assertEq(RoleType.PARAGRAPH, p3.role); 36 assertEq(RoleType.paragraph, p3.role);
37 37
38 okButton = rootNode.children[2]; 38 okButton = rootNode.children[2];
39 assertEq(RoleType.BUTTON, okButton.role); 39 assertEq(RoleType.button, okButton.role);
40 assertEq('Ok', okButton.name); 40 assertEq('Ok', okButton.name);
41 assertTrue(StateType.DISABLED in okButton.state); 41 assertTrue(StateType.disabled in okButton.state);
42 assertTrue(okButton.state.disabled); 42 assertTrue(okButton.state.disabled);
43 43
44 cancelButton = rootNode.children[3]; 44 cancelButton = rootNode.children[3];
45 assertEq(RoleType.BUTTON, cancelButton.role); 45 assertEq(RoleType.button, cancelButton.role);
46 assertEq('Cancel', cancelButton.name); 46 assertEq('Cancel', cancelButton.name);
47 assertFalse(StateType.DISABLED in cancelButton.state); 47 assertFalse(StateType.disabled in cancelButton.state);
48 } 48 }
49 49
50 var allTests = [ 50 var allTests = [
51 function testFindByRole() { 51 function testFindByRole() {
52 initializeNodes(rootNode); 52 initializeNodes(rootNode);
53 53
54 // Should find the only instance of this role. 54 // Should find the only instance of this role.
55 assertEq(h1, rootNode.find({role: RoleType.HEADING})); 55 assertEq(h1, rootNode.find({ role: RoleType.heading}));
56 assertEq([h1], rootNode.findAll({role: RoleType.HEADING})); 56 assertEq([h1], rootNode.findAll({ role: RoleType.heading}));
57 57
58 // find should find first instance only. 58 // find should find first instance only.
59 assertEq(okButton, rootNode.find({role: RoleType.BUTTON})); 59 assertEq(okButton, rootNode.find({ role: RoleType.button }));
60 assertEq(p1, rootNode.find({role: RoleType.PARAGRAPH})); 60 assertEq(p1, rootNode.find({ role: RoleType.paragraph }));
61 61
62 // findAll should find all instances. 62 // findAll should find all instances.
63 assertEq( 63 assertEq([okButton, cancelButton],
64 [okButton, cancelButton], rootNode.findAll({role: RoleType.BUTTON})); 64 rootNode.findAll({ role: RoleType.button }));
65 assertEq([p1, p2, p3], rootNode.findAll({role: RoleType.PARAGRAPH})); 65 assertEq([p1, p2, p3], rootNode.findAll({ role: RoleType.paragraph }));
66 66
67 // No instances: find should return null; findAll should return empty array. 67 // No instances: find should return null; findAll should return empty array.
68 assertEq(null, rootNode.find({role: RoleType.CHECKBOX})); 68 assertEq(null, rootNode.find({ role: RoleType.checkbox }));
69 assertEq([], rootNode.findAll({role: RoleType.CHECKBOX})); 69 assertEq([], rootNode.findAll({ role: RoleType.checkbox }));
70 70
71 // Calling from node should search only its subtree. 71 // Calling from node should search only its subtree.
72 assertEq(p1, group.find({role: RoleType.PARAGRAPH})); 72 assertEq(p1, group.find({ role: RoleType.paragraph }));
73 assertEq(p2, main.find({role: RoleType.PARAGRAPH})); 73 assertEq(p2, main.find({ role: RoleType.paragraph }));
74 assertEq([p2, p3], main.findAll({role: RoleType.PARAGRAPH})); 74 assertEq([p2, p3], main.findAll({ role: RoleType.paragraph }));
75 75
76 chrome.test.succeed(); 76 chrome.test.succeed();
77 }, 77 },
78 78
79 function testFindByStates() { 79 function testFindByStates() {
80 initializeNodes(rootNode); 80 initializeNodes(rootNode);
81 81
82 // Find all focusable elements (disabled button is not focusable). 82 // Find all focusable elements (disabled button is not focusable).
83 assertEq(link, rootNode.find({state: {focusable: true}})); 83 assertEq(link, rootNode.find({ state: { focusable: true }}));
84 assertEq( 84 assertEq([link, cancelButton],
85 [link, cancelButton], rootNode.findAll({state: {focusable: true}})); 85 rootNode.findAll({ state: { focusable: true }}));
86 86
87 // Find disabled buttons. 87 // Find disabled buttons.
88 assertEq( 88 assertEq(okButton, rootNode.find({ role: RoleType.button,
89 okButton, 89 state: { disabled: true }}));
90 rootNode.find({role: RoleType.BUTTON, state: {disabled: true}})); 90 assertEq([okButton], rootNode.findAll({ role: RoleType.button,
91 assertEq( 91 state: { disabled: true }}));
92 [okButton],
93 rootNode.findAll({role: RoleType.BUTTON, state: {disabled: true}}));
94 92
95 // Find enabled buttons. 93 // Find enabled buttons.
96 assertEq( 94 assertEq(cancelButton, rootNode.find({ role: RoleType.button,
97 cancelButton, 95 state: { disabled: false }}));
98 rootNode.find({role: RoleType.BUTTON, state: {disabled: false}})); 96 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button,
99 assertEq( 97 state: { disabled: false }}));
100 [cancelButton],
101 rootNode.findAll({role: RoleType.BUTTON, state: {disabled: false}}));
102 chrome.test.succeed(); 98 chrome.test.succeed();
103 }, 99 },
104 100
105 function testFindByAttribute() { 101 function testFindByAttribute() {
106 initializeNodes(rootNode); 102 initializeNodes(rootNode);
107 103
108 // Find by name attribute. 104 // Find by name attribute.
109 assertEq(okButton, rootNode.find({attributes: {name: 'Ok'}})); 105 assertEq(okButton, rootNode.find({ attributes: { name: 'Ok' }}));
110 assertEq(cancelButton, rootNode.find({attributes: {name: 'Cancel'}})); 106 assertEq(cancelButton, rootNode.find({ attributes: { name: 'Cancel' }}));
111 107
112 // String attributes must be exact match unless a regex is used. 108 // String attributes must be exact match unless a regex is used.
113 assertEq(null, rootNode.find({attributes: {name: 'Canc'}})); 109 assertEq(null, rootNode.find({ attributes: { name: 'Canc' }}));
114 assertEq(null, rootNode.find({attributes: {name: 'ok'}})); 110 assertEq(null, rootNode.find({ attributes: { name: 'ok' }}));
115 111
116 // Find by value attribute - regexp. 112 // Find by value attribute - regexp.
117 var query = {attributes: {name: /relationship/}}; 113 var query = { attributes: { name: /relationship/ }};
118 assertEq(p2, rootNode.find(query).parent); 114 assertEq(p2, rootNode.find(query).parent);
119 115
120 // Find by role and hierarchicalLevel attribute. 116 // Find by role and hierarchicalLevel attribute.
121 assertEq( 117 assertEq(h1, rootNode.find({ role: RoleType.heading,
122 h1, rootNode.find( 118 attributes: { hierarchicalLevel: 1 }}));
123 {role: RoleType.HEADING, attributes: {hierarchicalLevel: 1}})); 119 assertEq([], rootNode.findAll({ role: RoleType.heading,
124 assertEq( 120 attributes: { hierarchicalLevel: 2 }}));
125 [], rootNode.findAll(
126 {role: RoleType.HEADING, attributes: {hierarchicalLevel: 2}}));
127 121
128 // Searching for an attribute which no element has fails. 122 // Searching for an attribute which no element has fails.
129 assertEq(null, rootNode.find({attributes: {charisma: 12}})); 123 assertEq(null, rootNode.find({ attributes: { charisma: 12 } }));
130 124
131 // Searching for an attribute value of the wrong type fails (even if the 125 // Searching for an attribute value of the wrong type fails (even if the
132 // value is equivalent). 126 // value is equivalent).
133 assertEq( 127 assertEq(null, rootNode.find({ role: RoleType.heading,
134 null, 128 attributes: { hierarchicalLevel: true }} ));
135 rootNode.find(
136 {role: RoleType.HEADING, attributes: {hierarchicalLevel: true}}));
137 129
138 chrome.test.succeed(); 130 chrome.test.succeed();
139 }, 131 },
140 132
141 function testMatches() { 133 function testMatches() {
142 initializeNodes(rootNode); 134 initializeNodes(rootNode);
143 assertTrue( 135 assertTrue(h1.matches({ role: RoleType.heading }),
144 h1.matches({role: RoleType.HEADING}), 136 'h1 should match RoleType.heading');
145 'h1 should match RoleType.HEADING'); 137 assertTrue(h1.matches({ role: RoleType.heading,
146 assertTrue( 138 attributes: { hierarchicalLevel: 1 } }),
147 h1.matches( 139 'h1 should match RoleType.heading and hierarchicalLevel: 1');
148 {role: RoleType.HEADING, attributes: {hierarchicalLevel: 1}}), 140 assertFalse(h1.matches({ role: RoleType.heading,
149 'h1 should match RoleType.HEADING and hierarchicalLevel: 1'); 141 state: { focusable: true },
150 assertFalse( 142 attributes: { hierarchicalLevel: 1 } }),
151 h1.matches({ 143 'h1 should not match focusable: true');
152 role: RoleType.HEADING, 144 assertTrue(h1.matches({ role: RoleType.heading,
153 state: {focusable: true}, 145 state: { focusable: false },
154 attributes: {hierarchicalLevel: 1} 146 attributes: { hierarchicalLevel: 1 } }),
155 }), 147 'h1 should match focusable: false');
156 'h1 should not match focusable: true');
157 assertTrue(
158 h1.matches({
159 role: RoleType.HEADING,
160 state: {focusable: false},
161 attributes: {hierarchicalLevel: 1}
162 }),
163 'h1 should match focusable: false');
164 148
165 var p2StaticText = p2.firstChild; 149 var p2StaticText = p2.firstChild;
166 assertTrue( 150 assertTrue(
167 p2StaticText.matches( 151 p2StaticText.matches({ role: RoleType.staticText,
168 {role: RoleType.STATIC_TEXT, attributes: {name: /relationship/}}), 152 attributes: { name: /relationship/ } }),
169 'p2StaticText should match name: /relationship/ (regex match)'); 153 'p2StaticText should match name: /relationship/ (regex match)');
170 assertFalse( 154 assertFalse(
171 p2StaticText.matches( 155 p2StaticText.matches({ role: RoleType.staticText,
172 {role: RoleType.STATIC_TEXT, attributes: {name: 'relationship'}}), 156 attributes: { name: 'relationship' } }),
173 'p2 should not match name: \'relationship'); 157 'p2 should not match name: \'relationship');
174 158
175 chrome.test.succeed(); 159 chrome.test.succeed();
176 } 160 }
177 ]; 161 ];
178 162
179 setUpAndRunTests(allTests, 'complex.html'); 163 setUpAndRunTests(allTests, 'complex.html');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698