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
3 // found in the LICENSE file.
5 chrome.test.runWithModuleSystem(function(moduleSystem) {
6 window.AutomationRootNode =
7 moduleSystem.require('automationNode').AutomationRootNode;
8 window.privates = moduleSystem.privates;
11 var assertEq = chrome.test.assertEq;
12 var assertFalse = chrome.test.assertFalse;
13 var assertTrue = chrome.test.assertTrue;
14 var assertIsDef = function(obj) {
15 assertTrue(obj !== null && obj !== undefined);
17 var assertIsNotDef = function(obj) {
18 assertTrue(obj === null || obj === undefined);
20 var succeed = chrome.test.succeed;
23 function testAutomationRootNode() {
24 var root = new AutomationRootNode();
25 assertTrue(root.isRootNode);
30 function testAriaRelationshipAttributes() {
32 'eventType': 'loadComplete',
33 'processID': 17, 'routingID': 2, 'targetID': 1,
34 'update': { 'nodeIdToClear': 0, 'nodes': [
36 'id': 1, 'role': 'rootWebArea',
37 'boolAttributes': {'docLoaded': true},
38 'childIds': [5, 6, 7, 8, 9, 10, 11]
41 'id': 11, 'role': 'div',
43 'htmlAttributes': {'id': 'target' }
46 'id': 5, 'role': 'div',
48 'htmlAttributes': {'aria-activedescendant': 'target',
49 'id': 'activedescendant'},
50 'intAttributes': {'activedescendantId': 11},
53 'id': 6, 'role': 'div',
55 'htmlAttributes': {'aria-controls': 'target', 'id': 'controlledBy'},
56 'intlistAttributes': {'controlsIds': [11]},
59 'id': 7, 'role': 'div',
61 'htmlAttributes': {'aria-describedby': 'target', 'id': 'describedBy'},
62 'intlistAttributes': {'describedbyIds': [11, 6]},
65 'id': 8, 'role': 'div',
67 'htmlAttributes': {'aria-flowto': 'target', 'id': 'flowTo'},
68 'intlistAttributes': {'flowtoIds': [11]},
71 'id': 9, 'role': 'div',
73 'htmlAttributes': {'aria-labelledby': 'target', 'id': 'labelledBy'},
74 'intlistAttributes': {'labelledbyIds': [11]}
77 'id': 10, 'role': 'div',
79 'htmlAttributes': {'aria-owns': 'target', 'id': 'owns'},
80 'intlistAttributes': {'ownsIds': [11]},
85 var tree = new AutomationRootNode();
86 privates(tree).impl.onAccessibilityEvent(data);
88 var activedescendant = tree.firstChild();
89 assertIsDef(activedescendant);
90 assertEq('activedescendant', activedescendant.attributes.id);
93 activedescendant.attributes['aria-activedescendant'].attributes.id);
94 assertIsNotDef(activedescendant.attributes.activedescendantId);
96 var controlledBy = activedescendant.nextSibling();
97 assertIsDef(controlledBy);
98 assertEq('controlledBy', controlledBy.attributes.id);
100 controlledBy.attributes['aria-controls'][0].attributes.id);
101 assertEq(1, controlledBy.attributes['aria-controls'].length);
102 assertIsNotDef(controlledBy.attributes.controlledbyIds);
104 var describedBy = controlledBy.nextSibling();
105 assertIsDef(describedBy);
106 assertEq('describedBy', describedBy.attributes.id);
108 describedBy.attributes['aria-describedby'][0].attributes.id);
109 assertEq('controlledBy',
110 describedBy.attributes['aria-describedby'][1].attributes.id);
111 assertEq(2, describedBy.attributes['aria-describedby'].length);
112 assertIsNotDef(describedBy.attributes.describedbyIds);
114 var flowTo = describedBy.nextSibling();
116 assertEq('flowTo', flowTo.attributes.id);
118 flowTo.attributes['aria-flowto'][0].attributes.id);
119 assertEq(1, flowTo.attributes['aria-flowto'].length);
120 assertIsNotDef(flowTo.attributes.flowtoIds);
122 var labelledBy = flowTo.nextSibling();
123 assertIsDef(labelledBy);
124 assertEq('labelledBy', labelledBy.attributes.id);
126 labelledBy.attributes['aria-labelledby'][0].attributes.id);
127 assertEq(1, labelledBy.attributes['aria-labelledby'].length);
128 assertIsNotDef(labelledBy.attributes.labelledbyIds);
130 var owns = labelledBy.nextSibling();
132 assertEq('owns', owns.attributes.id);
133 assertEq('target', owns.attributes['aria-owns'][0].attributes.id);
134 assertEq(1, owns.attributes['aria-owns'].length);
135 assertIsNotDef(owns.attributes.ownsIds);
140 function testCannotSetAttribute() {
143 'nodeIdToClear': 0, 'nodes': [
145 'id': 1, 'role': 'rootWebArea',
146 'boolAttributes': {'docLoaded': true},
150 'id': 11, 'role': 'button',
151 'stringAttributes': {'name': 'foo'},
156 var tree = new AutomationRootNode();
157 assertTrue(privates(tree).impl.unserialize(update));
158 var button = tree.firstChild();
159 assertEq('button', button.role);
160 assertEq('foo', button.attributes.name);
161 button.attributes.name = 'bar';
162 assertEq('foo', button.attributes.name);
167 function testBadUpdateInvalidChildIds() {
170 'nodeIdToClear': 0, 'nodes': [
172 'id': 1, 'role': 'rootWebArea',
173 'boolAttributes': {'docLoaded': true},
174 'childIds': [5, 6, 7, 8, 9, 10, 11]
178 var tree = new AutomationRootNode();
180 // This is a bad update because the root references non existent child ids.
181 assertFalse(privates(tree).impl.unserialize(update));
186 function testMultipleUpdateNameChanged() {
189 'nodeIdToClear': 0, 'nodes': [
191 'id': 1, 'role': 'rootWebArea',
192 'boolAttributes': {'docLoaded': true},
196 'id': 11, 'role': 'button',
197 'stringAttributes': {'name': 'foo'},
202 // First, setup the initial tree.
203 var tree = new AutomationRootNode();
204 assertTrue(privates(tree).impl.unserialize(update));
205 var button = tree.firstChild();
206 assertEq('button', button.role);
207 assertEq('foo', button.attributes.name);
209 // Now, apply an update that changes the button's name.
210 // Remove the root since the native serializer stops at the LCA.
211 update.nodes.splice(0, 1);
212 update.nodes[0].stringAttributes.name = 'bar';
214 // Make sure the name changes.
215 assertTrue(privates(tree).impl.unserialize(update));
216 assertEq('bar', button.attributes.name);
222 chrome.test.runTests(tests);