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

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

Issue 2649373002: Re-land: Update json_schema_compiler to handle the Automation extension API (Closed)
Patch Set: Fix presubmit 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([okButton, cancelButton], 63 assertEq(
64 rootNode.findAll({ role: RoleType.button })); 64 [okButton, cancelButton], 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([link, cancelButton], 84 assertEq(
85 rootNode.findAll({ state: { focusable: true }})); 85 [link, cancelButton], rootNode.findAll({state: {focusable: true}}));
86 86
87 // Find disabled buttons. 87 // Find disabled buttons.
88 assertEq(okButton, rootNode.find({ role: RoleType.button, 88 assertEq(
89 state: { disabled: true }})); 89 okButton,
90 assertEq([okButton], rootNode.findAll({ role: RoleType.button, 90 rootNode.find({role: RoleType.BUTTON, state: {disabled: true}}));
91 state: { disabled: true }})); 91 assertEq(
92 [okButton],
93 rootNode.findAll({role: RoleType.BUTTON, state: {disabled: true}}));
92 94
93 // Find enabled buttons. 95 // Find enabled buttons.
94 assertEq(cancelButton, rootNode.find({ role: RoleType.button, 96 assertEq(
95 state: { disabled: false }})); 97 cancelButton,
96 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button, 98 rootNode.find({role: RoleType.BUTTON, state: {disabled: false}}));
97 state: { disabled: false }})); 99 assertEq(
100 [cancelButton],
101 rootNode.findAll({role: RoleType.BUTTON, state: {disabled: false}}));
98 chrome.test.succeed(); 102 chrome.test.succeed();
99 }, 103 },
100 104
101 function testFindByAttribute() { 105 function testFindByAttribute() {
102 initializeNodes(rootNode); 106 initializeNodes(rootNode);
103 107
104 // Find by name attribute. 108 // Find by name attribute.
105 assertEq(okButton, rootNode.find({ attributes: { name: 'Ok' }})); 109 assertEq(okButton, rootNode.find({attributes: {name: 'Ok'}}));
106 assertEq(cancelButton, rootNode.find({ attributes: { name: 'Cancel' }})); 110 assertEq(cancelButton, rootNode.find({attributes: {name: 'Cancel'}}));
107 111
108 // String attributes must be exact match unless a regex is used. 112 // String attributes must be exact match unless a regex is used.
109 assertEq(null, rootNode.find({ attributes: { name: 'Canc' }})); 113 assertEq(null, rootNode.find({attributes: {name: 'Canc'}}));
110 assertEq(null, rootNode.find({ attributes: { name: 'ok' }})); 114 assertEq(null, rootNode.find({attributes: {name: 'ok'}}));
111 115
112 // Find by value attribute - regexp. 116 // Find by value attribute - regexp.
113 var query = { attributes: { name: /relationship/ }}; 117 var query = {attributes: {name: /relationship/}};
114 assertEq(p2, rootNode.find(query).parent); 118 assertEq(p2, rootNode.find(query).parent);
115 119
116 // Find by role and hierarchicalLevel attribute. 120 // Find by role and hierarchicalLevel attribute.
117 assertEq(h1, rootNode.find({ role: RoleType.heading, 121 assertEq(
118 attributes: { hierarchicalLevel: 1 }})); 122 h1, rootNode.find(
119 assertEq([], rootNode.findAll({ role: RoleType.heading, 123 {role: RoleType.HEADING, attributes: {hierarchicalLevel: 1}}));
120 attributes: { hierarchicalLevel: 2 }})); 124 assertEq(
125 [], rootNode.findAll(
126 {role: RoleType.HEADING, attributes: {hierarchicalLevel: 2}}));
121 127
122 // Searching for an attribute which no element has fails. 128 // Searching for an attribute which no element has fails.
123 assertEq(null, rootNode.find({ attributes: { charisma: 12 } })); 129 assertEq(null, rootNode.find({attributes: {charisma: 12}}));
124 130
125 // Searching for an attribute value of the wrong type fails (even if the 131 // Searching for an attribute value of the wrong type fails (even if the
126 // value is equivalent). 132 // value is equivalent).
127 assertEq(null, rootNode.find({ role: RoleType.heading, 133 assertEq(
128 attributes: { hierarchicalLevel: true }} )); 134 null,
135 rootNode.find(
136 {role: RoleType.HEADING, attributes: {hierarchicalLevel: true}}));
129 137
130 chrome.test.succeed(); 138 chrome.test.succeed();
131 }, 139 },
132 140
133 function testMatches() { 141 function testMatches() {
134 initializeNodes(rootNode); 142 initializeNodes(rootNode);
135 assertTrue(h1.matches({ role: RoleType.heading }), 143 assertTrue(
136 'h1 should match RoleType.heading'); 144 h1.matches({role: RoleType.HEADING}),
137 assertTrue(h1.matches({ role: RoleType.heading, 145 'h1 should match RoleType.HEADING');
138 attributes: { hierarchicalLevel: 1 } }), 146 assertTrue(
139 'h1 should match RoleType.heading and hierarchicalLevel: 1'); 147 h1.matches(
140 assertFalse(h1.matches({ role: RoleType.heading, 148 {role: RoleType.HEADING, attributes: {hierarchicalLevel: 1}}),
141 state: { focusable: true }, 149 'h1 should match RoleType.HEADING and hierarchicalLevel: 1');
142 attributes: { hierarchicalLevel: 1 } }), 150 assertFalse(
143 'h1 should not match focusable: true'); 151 h1.matches({
144 assertTrue(h1.matches({ role: RoleType.heading, 152 role: RoleType.HEADING,
145 state: { focusable: false }, 153 state: {focusable: true},
146 attributes: { hierarchicalLevel: 1 } }), 154 attributes: {hierarchicalLevel: 1}
147 'h1 should match focusable: false'); 155 }),
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');
148 164
149 var p2StaticText = p2.firstChild; 165 var p2StaticText = p2.firstChild;
150 assertTrue( 166 assertTrue(
151 p2StaticText.matches({ role: RoleType.staticText, 167 p2StaticText.matches(
152 attributes: { name: /relationship/ } }), 168 {role: RoleType.STATIC_TEXT, attributes: {name: /relationship/}}),
153 'p2StaticText should match name: /relationship/ (regex match)'); 169 'p2StaticText should match name: /relationship/ (regex match)');
154 assertFalse( 170 assertFalse(
155 p2StaticText.matches({ role: RoleType.staticText, 171 p2StaticText.matches(
156 attributes: { name: 'relationship' } }), 172 {role: RoleType.STATIC_TEXT, attributes: {name: 'relationship'}}),
157 'p2 should not match name: \'relationship'); 173 'p2 should not match name: \'relationship');
158 174
159 chrome.test.succeed(); 175 chrome.test.succeed();
160 } 176 }
161 ]; 177 ];
162 178
163 setUpAndRunTests(allTests, 'complex.html'); 179 setUpAndRunTests(allTests, 'complex.html');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698