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;
10 window.automationUtil = function() {};
11 window.automationUtil.storeTreeCallback = function() {};
14 var assertEq = chrome.test.assertEq;
15 var assertFalse = chrome.test.assertFalse;
16 var assertTrue = chrome.test.assertTrue;
17 var assertIsDef = function(obj) {
18 assertTrue(obj !== null && obj !== undefined);
20 var assertIsNotDef = function(obj) {
21 assertTrue(obj === null || obj === undefined);
23 var succeed = chrome.test.succeed;
26 function testAutomationRootNode() {
27 var root = new AutomationRootNode();
28 assertTrue(root.isRootNode);
33 function testAriaRelationshipAttributes() {
35 'eventType': 'loadComplete',
36 'processID': 17, 'routingID': 2, 'targetID': 1,
37 'update': { 'nodeIdToClear': 0, 'nodes': [
39 'id': 1, 'role': 'rootWebArea',
40 'boolAttributes': {'docLoaded': true},
41 'childIds': [5, 6, 7, 8, 9, 10, 11]
44 'id': 11, 'role': 'div',
46 'htmlAttributes': {'id': 'target' }
49 'id': 5, 'role': 'div',
51 'htmlAttributes': {'aria-activedescendant': 'target',
52 'id': 'activedescendant'},
53 'intAttributes': {'activedescendantId': 11},
56 'id': 6, 'role': 'div',
58 'htmlAttributes': {'aria-controls': 'target', 'id': 'controlledBy'},
59 'intlistAttributes': {'controlsIds': [11]},
62 'id': 7, 'role': 'div',
64 'htmlAttributes': {'aria-describedby': 'target', 'id': 'describedBy'},
65 'intlistAttributes': {'describedbyIds': [11, 6]},
68 'id': 8, 'role': 'div',
70 'htmlAttributes': {'aria-flowto': 'target', 'id': 'flowTo'},
71 'intlistAttributes': {'flowtoIds': [11]},
74 'id': 9, 'role': 'div',
76 'htmlAttributes': {'aria-labelledby': 'target', 'id': 'labelledBy'},
77 'intlistAttributes': {'labelledbyIds': [11]}
80 'id': 10, 'role': 'div',
82 'htmlAttributes': {'aria-owns': 'target', 'id': 'owns'},
83 'intlistAttributes': {'ownsIds': [11]},
88 var tree = new AutomationRootNode();
89 privates(tree).impl.onAccessibilityEvent(data);
91 var activedescendant = tree.firstChild();
92 assertIsDef(activedescendant);
93 assertEq('activedescendant', activedescendant.attributes.id);
96 activedescendant.attributes['aria-activedescendant'].attributes.id);
97 assertIsNotDef(activedescendant.attributes.activedescendantId);
99 var controlledBy = activedescendant.nextSibling();
100 assertIsDef(controlledBy);
101 assertEq('controlledBy', controlledBy.attributes.id);
103 controlledBy.attributes['aria-controls'][0].attributes.id);
104 assertEq(1, controlledBy.attributes['aria-controls'].length);
105 assertIsNotDef(controlledBy.attributes.controlledbyIds);
107 var describedBy = controlledBy.nextSibling();
108 assertIsDef(describedBy);
109 assertEq('describedBy', describedBy.attributes.id);
111 describedBy.attributes['aria-describedby'][0].attributes.id);
112 assertEq('controlledBy',
113 describedBy.attributes['aria-describedby'][1].attributes.id);
114 assertEq(2, describedBy.attributes['aria-describedby'].length);
115 assertIsNotDef(describedBy.attributes.describedbyIds);
117 var flowTo = describedBy.nextSibling();
119 assertEq('flowTo', flowTo.attributes.id);
121 flowTo.attributes['aria-flowto'][0].attributes.id);
122 assertEq(1, flowTo.attributes['aria-flowto'].length);
123 assertIsNotDef(flowTo.attributes.flowtoIds);
125 var labelledBy = flowTo.nextSibling();
126 assertIsDef(labelledBy);
127 assertEq('labelledBy', labelledBy.attributes.id);
129 labelledBy.attributes['aria-labelledby'][0].attributes.id);
130 assertEq(1, labelledBy.attributes['aria-labelledby'].length);
131 assertIsNotDef(labelledBy.attributes.labelledbyIds);
133 var owns = labelledBy.nextSibling();
135 assertEq('owns', owns.attributes.id);
136 assertEq('target', owns.attributes['aria-owns'][0].attributes.id);
137 assertEq(1, owns.attributes['aria-owns'].length);
138 assertIsNotDef(owns.attributes.ownsIds);
143 function testCannotSetAttribute() {
146 'nodeIdToClear': 0, 'nodes': [
148 'id': 1, 'role': 'rootWebArea',
149 'boolAttributes': {'docLoaded': true},
153 'id': 11, 'role': 'button',
154 'stringAttributes': {'name': 'foo'},
159 var tree = new AutomationRootNode();
160 assertTrue(privates(tree).impl.unserialize(update));
161 var button = tree.firstChild();
162 assertEq('button', button.role);
163 assertEq('foo', button.attributes.name);
164 button.attributes.name = 'bar';
165 assertEq('foo', button.attributes.name);
170 function testBadUpdateInvalidChildIds() {
173 'nodeIdToClear': 0, 'nodes': [
175 'id': 1, 'role': 'rootWebArea',
176 'boolAttributes': {'docLoaded': true},
177 'childIds': [5, 6, 7, 8, 9, 10, 11]
181 var tree = new AutomationRootNode();
183 // This is a bad update because the root references non existent child ids.
184 assertFalse(privates(tree).impl.unserialize(update));
189 function testMultipleUpdateNameChanged() {
192 'nodeIdToClear': 0, 'nodes': [
194 'id': 1, 'role': 'rootWebArea',
195 'boolAttributes': {'docLoaded': true},
199 'id': 11, 'role': 'button',
200 'stringAttributes': {'name': 'foo'},
205 // First, setup the initial tree.
206 var tree = new AutomationRootNode();
207 assertTrue(privates(tree).impl.unserialize(update));
208 var button = tree.firstChild();
209 assertEq('button', button.role);
210 assertEq('foo', button.attributes.name);
212 // Now, apply an update that changes the button's name.
213 // Remove the root since the native serializer stops at the LCA.
214 update.nodes.splice(0, 1);
215 update.nodes[0].stringAttributes.name = 'bar';
217 // Make sure the name changes.
218 assertTrue(privates(tree).impl.unserialize(update));
219 assertEq('bar', button.attributes.name);
225 chrome.test.runTests(tests);