OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "content/common/accessibility_node_data.h" | 6 #include "content/common/accessibility_node_data.h" |
7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.h" |
8 #include "content/public/test/render_view_test.h" | 8 #include "content/public/test/render_view_test.h" |
9 #include "content/renderer/accessibility/renderer_accessibility_complete.h" | 9 #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/public/platform/WebSize.h" | 12 #include "third_party/WebKit/public/platform/WebSize.h" |
13 #include "third_party/WebKit/public/web/WebAccessibilityObject.h" | 13 #include "third_party/WebKit/public/web/WebAXObject.h" |
14 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
15 #include "third_party/WebKit/public/web/WebView.h" | 15 #include "third_party/WebKit/public/web/WebView.h" |
16 | 16 |
17 using WebKit::WebAccessibilityObject; | 17 using WebKit::WebAXObject; |
18 using WebKit::WebDocument; | 18 using WebKit::WebDocument; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { | 22 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { |
23 public: | 23 public: |
24 explicit TestRendererAccessibilityComplete(RenderViewImpl* render_view) | 24 explicit TestRendererAccessibilityComplete(RenderViewImpl* render_view) |
25 : RendererAccessibilityComplete(render_view), | 25 : RendererAccessibilityComplete(render_view), |
26 browser_tree_node_count_(0) { | 26 browser_tree_node_count_(0) { |
27 } | 27 } |
(...skipping 11 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 TestRendererAccessibilityComplete* owner_; | 42 TestRendererAccessibilityComplete* owner_; |
43 }; | 43 }; |
44 | 44 |
45 virtual BrowserTreeNode* CreateBrowserTreeNode() OVERRIDE { | 45 virtual BrowserTreeNode* CreateBrowserTreeNode() OVERRIDE { |
46 return new TestBrowserTreeNode(this); | 46 return new TestBrowserTreeNode(this); |
47 } | 47 } |
48 | 48 |
49 void SendPendingAccessibilityNotifications() { | 49 void SendPendingAccessibilityEvents() { |
50 RendererAccessibilityComplete::SendPendingAccessibilityNotifications(); | 50 RendererAccessibilityComplete::SendPendingAccessibilityEvents(); |
51 } | 51 } |
52 | 52 |
53 private: | 53 private: |
54 int browser_tree_node_count_; | 54 int browser_tree_node_count_; |
55 }; | 55 }; |
56 | 56 |
57 class RendererAccessibilityTest : public RenderViewTest { | 57 class RendererAccessibilityTest : public RenderViewTest { |
58 public: | 58 public: |
59 RendererAccessibilityTest() {} | 59 RendererAccessibilityTest() {} |
60 | 60 |
61 RenderViewImpl* view() { | 61 RenderViewImpl* view() { |
62 return static_cast<RenderViewImpl*>(view_); | 62 return static_cast<RenderViewImpl*>(view_); |
63 } | 63 } |
64 | 64 |
65 virtual void SetUp() { | 65 virtual void SetUp() { |
66 RenderViewTest::SetUp(); | 66 RenderViewTest::SetUp(); |
67 sink_ = &render_thread_->sink(); | 67 sink_ = &render_thread_->sink(); |
68 } | 68 } |
69 | 69 |
70 void SetMode(AccessibilityMode mode) { | 70 void SetMode(AccessibilityMode mode) { |
71 view()->OnSetAccessibilityMode(mode); | 71 view()->OnSetAccessibilityMode(mode); |
72 } | 72 } |
73 | 73 |
74 void GetLastAccNotification( | 74 void GetLastAccEvent( |
75 AccessibilityHostMsg_NotificationParams* params) { | 75 AccessibilityHostMsg_EventParams* params) { |
76 const IPC::Message* message = | 76 const IPC::Message* message = |
77 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Notifications::ID); | 77 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
78 ASSERT_TRUE(message); | 78 ASSERT_TRUE(message); |
79 Tuple1<std::vector<AccessibilityHostMsg_NotificationParams> > param; | 79 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; |
80 AccessibilityHostMsg_Notifications::Read(message, ¶m); | 80 AccessibilityHostMsg_Events::Read(message, ¶m); |
81 ASSERT_GE(param.a.size(), 1U); | 81 ASSERT_GE(param.a.size(), 1U); |
82 *params = param.a[0]; | 82 *params = param.a[0]; |
83 } | 83 } |
84 | 84 |
85 int CountAccessibilityNodesSentToBrowser() { | 85 int CountAccessibilityNodesSentToBrowser() { |
86 AccessibilityHostMsg_NotificationParams notification; | 86 AccessibilityHostMsg_EventParams event; |
87 GetLastAccNotification(¬ification); | 87 GetLastAccEvent(&event); |
88 return notification.nodes.size(); | 88 return event.nodes.size(); |
89 } | 89 } |
90 | 90 |
91 protected: | 91 protected: |
92 IPC::TestSink* sink_; | 92 IPC::TestSink* sink_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest); | 94 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest); |
95 }; | 95 }; |
96 | 96 |
97 TEST_F(RendererAccessibilityTest, EditableTextModeFocusNotifications) { | 97 TEST_F(RendererAccessibilityTest, EditableTextModeFocusEvents) { |
98 // This is not a test of true web accessibility, it's a test of | 98 // This is not a test of true web accessibility, it's a test of |
99 // a mode used on Windows 8 in Metro mode where an extremely simplified | 99 // a mode used on Windows 8 in Metro mode where an extremely simplified |
100 // accessibility tree containing only the current focused node is | 100 // accessibility tree containing only the current focused node is |
101 // generated. | 101 // generated. |
102 SetMode(AccessibilityModeEditableTextOnly); | 102 SetMode(AccessibilityModeEditableTextOnly); |
103 | 103 |
104 // Set a minimum size and give focus so simulated events work. | 104 // Set a minimum size and give focus so simulated events work. |
105 view()->webwidget()->resize(WebKit::WebSize(500, 500)); | 105 view()->webwidget()->resize(WebKit::WebSize(500, 500)); |
106 view()->webwidget()->setFocus(true); | 106 view()->webwidget()->setFocus(true); |
107 | 107 |
108 std::string html = | 108 std::string html = |
109 "<body>" | 109 "<body>" |
110 " <input>" | 110 " <input>" |
111 " <textarea></textarea>" | 111 " <textarea></textarea>" |
112 " <p contentEditable>Editable</p>" | 112 " <p contentEditable>Editable</p>" |
113 " <div tabindex=0 role=textbox>Textbox</div>" | 113 " <div tabindex=0 role=textbox>Textbox</div>" |
114 " <button>Button</button>" | 114 " <button>Button</button>" |
115 " <a href=#>Link</a>" | 115 " <a href=#>Link</a>" |
116 "</body>"; | 116 "</body>"; |
117 | 117 |
118 // Load the test page. | 118 // Load the test page. |
119 LoadHTML(html.c_str()); | 119 LoadHTML(html.c_str()); |
120 | 120 |
121 // We should have sent a message to the browser with the initial focus | 121 // We should have sent a message to the browser with the initial focus |
122 // on the document. | 122 // on the document. |
123 { | 123 { |
124 SCOPED_TRACE("Initial focus on document"); | 124 SCOPED_TRACE("Initial focus on document"); |
125 AccessibilityHostMsg_NotificationParams notification; | 125 AccessibilityHostMsg_EventParams event; |
126 GetLastAccNotification(¬ification); | 126 GetLastAccEvent(&event); |
127 EXPECT_EQ(notification.notification_type, | 127 EXPECT_EQ(event.event_type, |
128 AccessibilityNotificationLayoutComplete); | 128 WebKit::WebAXEventLayoutComplete); |
129 EXPECT_EQ(notification.id, 1); | 129 EXPECT_EQ(event.id, 1); |
130 EXPECT_EQ(notification.nodes.size(), 2U); | 130 EXPECT_EQ(event.nodes.size(), 2U); |
131 EXPECT_EQ(notification.nodes[0].id, 1); | 131 EXPECT_EQ(event.nodes[0].id, 1); |
132 EXPECT_EQ(notification.nodes[0].role, | 132 EXPECT_EQ(event.nodes[0].role, |
133 AccessibilityNodeData::ROLE_ROOT_WEB_AREA); | 133 WebKit::WebAXRoleRootWebArea); |
134 EXPECT_EQ(notification.nodes[0].state, | 134 EXPECT_EQ(event.nodes[0].state, |
135 (1U << AccessibilityNodeData::STATE_READONLY) | | 135 (1U << WebKit::WebAXStateReadonly) | |
136 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 136 (1U << WebKit::WebAXStateFocusable) | |
137 (1U << AccessibilityNodeData::STATE_FOCUSED)); | 137 (1U << WebKit::WebAXStateFocused)); |
138 EXPECT_EQ(notification.nodes[0].child_ids.size(), 1U); | 138 EXPECT_EQ(event.nodes[0].child_ids.size(), 1U); |
139 } | 139 } |
140 | 140 |
141 // Now focus the input element, and check everything again. | 141 // Now focus the input element, and check everything again. |
142 { | 142 { |
143 SCOPED_TRACE("input"); | 143 SCOPED_TRACE("input"); |
144 sink_->ClearMessages(); | 144 sink_->ClearMessages(); |
145 ExecuteJavaScript("document.querySelector('input').focus();"); | 145 ExecuteJavaScript("document.querySelector('input').focus();"); |
146 AccessibilityHostMsg_NotificationParams notification; | 146 AccessibilityHostMsg_EventParams event; |
147 GetLastAccNotification(¬ification); | 147 GetLastAccEvent(&event); |
148 EXPECT_EQ(notification.notification_type, | 148 EXPECT_EQ(event.event_type, |
149 AccessibilityNotificationFocusChanged); | 149 WebKit::WebAXEventFocus); |
150 EXPECT_EQ(notification.id, 3); | 150 EXPECT_EQ(event.id, 3); |
151 EXPECT_EQ(notification.nodes[0].id, 1); | 151 EXPECT_EQ(event.nodes[0].id, 1); |
152 EXPECT_EQ(notification.nodes[0].role, | 152 EXPECT_EQ(event.nodes[0].role, |
153 AccessibilityNodeData::ROLE_ROOT_WEB_AREA); | 153 WebKit::WebAXRoleRootWebArea); |
154 EXPECT_EQ(notification.nodes[0].state, | 154 EXPECT_EQ(event.nodes[0].state, |
155 (1U << AccessibilityNodeData::STATE_READONLY) | | 155 (1U << WebKit::WebAXStateReadonly) | |
156 (1U << AccessibilityNodeData::STATE_FOCUSABLE)); | 156 (1U << WebKit::WebAXStateFocusable)); |
157 EXPECT_EQ(notification.nodes[0].child_ids.size(), 1U); | 157 EXPECT_EQ(event.nodes[0].child_ids.size(), 1U); |
158 EXPECT_EQ(notification.nodes[1].id, 3); | 158 EXPECT_EQ(event.nodes[1].id, 3); |
159 EXPECT_EQ(notification.nodes[1].role, | 159 EXPECT_EQ(event.nodes[1].role, |
160 AccessibilityNodeData::ROLE_GROUP); | 160 WebKit::WebAXRoleGroup); |
161 EXPECT_EQ(notification.nodes[1].state, | 161 EXPECT_EQ(event.nodes[1].state, |
162 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 162 (1U << WebKit::WebAXStateFocusable) | |
163 (1U << AccessibilityNodeData::STATE_FOCUSED)); | 163 (1U << WebKit::WebAXStateFocused)); |
164 } | 164 } |
165 | 165 |
166 // Check other editable text nodes. | 166 // Check other editable text nodes. |
167 { | 167 { |
168 SCOPED_TRACE("textarea"); | 168 SCOPED_TRACE("textarea"); |
169 sink_->ClearMessages(); | 169 sink_->ClearMessages(); |
170 ExecuteJavaScript("document.querySelector('textarea').focus();"); | 170 ExecuteJavaScript("document.querySelector('textarea').focus();"); |
171 AccessibilityHostMsg_NotificationParams notification; | 171 AccessibilityHostMsg_EventParams event; |
172 GetLastAccNotification(¬ification); | 172 GetLastAccEvent(&event); |
173 EXPECT_EQ(notification.id, 4); | 173 EXPECT_EQ(event.id, 4); |
174 EXPECT_EQ(notification.nodes[1].state, | 174 EXPECT_EQ(event.nodes[1].state, |
175 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 175 (1U << WebKit::WebAXStateFocusable) | |
176 (1U << AccessibilityNodeData::STATE_FOCUSED)); | 176 (1U << WebKit::WebAXStateFocused)); |
177 } | 177 } |
178 | 178 |
179 { | 179 { |
180 SCOPED_TRACE("contentEditable"); | 180 SCOPED_TRACE("contentEditable"); |
181 sink_->ClearMessages(); | 181 sink_->ClearMessages(); |
182 ExecuteJavaScript("document.querySelector('p').focus();"); | 182 ExecuteJavaScript("document.querySelector('p').focus();"); |
183 AccessibilityHostMsg_NotificationParams notification; | 183 AccessibilityHostMsg_EventParams event; |
184 GetLastAccNotification(¬ification); | 184 GetLastAccEvent(&event); |
185 EXPECT_EQ(notification.id, 5); | 185 EXPECT_EQ(event.id, 5); |
186 EXPECT_EQ(notification.nodes[1].state, | 186 EXPECT_EQ(event.nodes[1].state, |
187 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 187 (1U << WebKit::WebAXStateFocusable) | |
188 (1U << AccessibilityNodeData::STATE_FOCUSED)); | 188 (1U << WebKit::WebAXStateFocused)); |
189 } | 189 } |
190 | 190 |
191 { | 191 { |
192 SCOPED_TRACE("role=textarea"); | 192 SCOPED_TRACE("role=textarea"); |
193 sink_->ClearMessages(); | 193 sink_->ClearMessages(); |
194 ExecuteJavaScript("document.querySelector('div').focus();"); | 194 ExecuteJavaScript("document.querySelector('div').focus();"); |
195 AccessibilityHostMsg_NotificationParams notification; | 195 AccessibilityHostMsg_EventParams event; |
196 GetLastAccNotification(¬ification); | 196 GetLastAccEvent(&event); |
197 EXPECT_EQ(notification.id, 6); | 197 EXPECT_EQ(event.id, 6); |
198 EXPECT_EQ(notification.nodes[1].state, | 198 EXPECT_EQ(event.nodes[1].state, |
199 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 199 (1U << WebKit::WebAXStateFocusable) | |
200 (1U << AccessibilityNodeData::STATE_FOCUSED)); | 200 (1U << WebKit::WebAXStateFocused)); |
201 } | 201 } |
202 | 202 |
203 // Try focusing things that aren't editable text. | 203 // Try focusing things that aren't editable text. |
204 { | 204 { |
205 SCOPED_TRACE("button"); | 205 SCOPED_TRACE("button"); |
206 sink_->ClearMessages(); | 206 sink_->ClearMessages(); |
207 ExecuteJavaScript("document.querySelector('button').focus();"); | 207 ExecuteJavaScript("document.querySelector('button').focus();"); |
208 AccessibilityHostMsg_NotificationParams notification; | 208 AccessibilityHostMsg_EventParams event; |
209 GetLastAccNotification(¬ification); | 209 GetLastAccEvent(&event); |
210 EXPECT_EQ(notification.id, 7); | 210 EXPECT_EQ(event.id, 7); |
211 EXPECT_EQ(notification.nodes[1].state, | 211 EXPECT_EQ(event.nodes[1].state, |
212 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 212 (1U << WebKit::WebAXStateFocusable) | |
213 (1U << AccessibilityNodeData::STATE_FOCUSED) | | 213 (1U << WebKit::WebAXStateFocused) | |
214 (1U << AccessibilityNodeData::STATE_READONLY)); | 214 (1U << WebKit::WebAXStateReadonly)); |
215 } | 215 } |
216 | 216 |
217 { | 217 { |
218 SCOPED_TRACE("link"); | 218 SCOPED_TRACE("link"); |
219 sink_->ClearMessages(); | 219 sink_->ClearMessages(); |
220 ExecuteJavaScript("document.querySelector('a').focus();"); | 220 ExecuteJavaScript("document.querySelector('a').focus();"); |
221 AccessibilityHostMsg_NotificationParams notification; | 221 AccessibilityHostMsg_EventParams event; |
222 GetLastAccNotification(¬ification); | 222 GetLastAccEvent(&event); |
223 EXPECT_EQ(notification.id, 8); | 223 EXPECT_EQ(event.id, 8); |
224 EXPECT_EQ(notification.nodes[1].state, | 224 EXPECT_EQ(event.nodes[1].state, |
225 (1U << AccessibilityNodeData::STATE_FOCUSABLE) | | 225 (1U << WebKit::WebAXStateFocusable) | |
226 (1U << AccessibilityNodeData::STATE_FOCUSED) | | 226 (1U << WebKit::WebAXStateFocused) | |
227 (1U << AccessibilityNodeData::STATE_READONLY)); | 227 (1U << WebKit::WebAXStateReadonly)); |
228 } | 228 } |
229 | 229 |
230 // Clear focus. | 230 // Clear focus. |
231 { | 231 { |
232 SCOPED_TRACE("Back to document."); | 232 SCOPED_TRACE("Back to document."); |
233 sink_->ClearMessages(); | 233 sink_->ClearMessages(); |
234 ExecuteJavaScript("document.activeElement.blur()"); | 234 ExecuteJavaScript("document.activeElement.blur()"); |
235 AccessibilityHostMsg_NotificationParams notification; | 235 AccessibilityHostMsg_EventParams event; |
236 GetLastAccNotification(¬ification); | 236 GetLastAccEvent(&event); |
237 EXPECT_EQ(notification.id, 1); | 237 EXPECT_EQ(event.id, 1); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) { | 241 TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) { |
242 // The job of RendererAccessibilityComplete is to serialize the | 242 // The job of RendererAccessibilityComplete is to serialize the |
243 // accessibility tree built by WebKit and send it to the browser. | 243 // accessibility tree built by WebKit and send it to the browser. |
244 // When the accessibility tree changes, it tries to send only | 244 // When the accessibility tree changes, it tries to send only |
245 // the nodes that actually changed or were reparented. This test | 245 // the nodes that actually changed or were reparented. This test |
246 // ensures that the messages sent are correct in cases when a page | 246 // ensures that the messages sent are correct in cases when a page |
247 // reloads, and that internal state is properly garbage-collected. | 247 // reloads, and that internal state is properly garbage-collected. |
248 std::string html = | 248 std::string html = |
249 "<body>" | 249 "<body>" |
250 " <div role='group' id='A'>" | 250 " <div role='group' id='A'>" |
251 " <div role='group' id='A1'></div>" | 251 " <div role='group' id='A1'></div>" |
252 " <div role='group' id='A2'></div>" | 252 " <div role='group' id='A2'></div>" |
253 " </div>" | 253 " </div>" |
254 "</body>"; | 254 "</body>"; |
255 LoadHTML(html.c_str()); | 255 LoadHTML(html.c_str()); |
256 | 256 |
257 // Creating a RendererAccessibilityComplete should sent the tree | 257 // Creating a RendererAccessibilityComplete should sent the tree |
258 // to the browser. | 258 // to the browser. |
259 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 259 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
260 new TestRendererAccessibilityComplete(view())); | 260 new TestRendererAccessibilityComplete(view())); |
261 accessibility->SendPendingAccessibilityNotifications(); | 261 accessibility->SendPendingAccessibilityEvents(); |
262 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 262 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
263 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 263 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
264 | 264 |
265 // If we post another notification but the tree doesn't change, | 265 // If we post another event but the tree doesn't change, |
266 // we should only send 1 node to the browser. | 266 // we should only send 1 node to the browser. |
267 sink_->ClearMessages(); | 267 sink_->ClearMessages(); |
268 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 268 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
269 WebAccessibilityObject root_obj = document.accessibilityObject(); | 269 WebAXObject root_obj = document.accessibilityObject(); |
270 accessibility->HandleWebAccessibilityNotification( | 270 accessibility->HandleWebAccessibilityEvent( |
271 root_obj, | 271 root_obj, |
272 WebKit::WebAccessibilityNotificationLayoutComplete); | 272 WebKit::WebAXEventLayoutComplete); |
273 accessibility->SendPendingAccessibilityNotifications(); | 273 accessibility->SendPendingAccessibilityEvents(); |
274 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 274 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
275 EXPECT_EQ(1, CountAccessibilityNodesSentToBrowser()); | 275 EXPECT_EQ(1, CountAccessibilityNodesSentToBrowser()); |
276 { | 276 { |
277 // Make sure it's the root object that was updated. | 277 // Make sure it's the root object that was updated. |
278 AccessibilityHostMsg_NotificationParams notification; | 278 AccessibilityHostMsg_EventParams event; |
279 GetLastAccNotification(¬ification); | 279 GetLastAccEvent(&event); |
280 EXPECT_EQ(root_obj.axID(), notification.nodes[0].id); | 280 EXPECT_EQ(root_obj.axID(), event.nodes[0].id); |
281 } | 281 } |
282 | 282 |
283 // If we reload the page and send a notification, we should send | 283 // If we reload the page and send a event, we should send |
284 // all 4 nodes to the browser. Also double-check that we didn't | 284 // all 4 nodes to the browser. Also double-check that we didn't |
285 // leak any of the old BrowserTreeNodes. | 285 // leak any of the old BrowserTreeNodes. |
286 LoadHTML(html.c_str()); | 286 LoadHTML(html.c_str()); |
287 document = view()->GetWebView()->mainFrame()->document(); | 287 document = view()->GetWebView()->mainFrame()->document(); |
288 root_obj = document.accessibilityObject(); | 288 root_obj = document.accessibilityObject(); |
289 sink_->ClearMessages(); | 289 sink_->ClearMessages(); |
290 accessibility->HandleWebAccessibilityNotification( | 290 accessibility->HandleWebAccessibilityEvent( |
291 root_obj, | 291 root_obj, |
292 WebKit::WebAccessibilityNotificationLayoutComplete); | 292 WebKit::WebAXEventLayoutComplete); |
293 accessibility->SendPendingAccessibilityNotifications(); | 293 accessibility->SendPendingAccessibilityEvents(); |
294 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 294 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
295 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 295 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
296 | 296 |
297 // Even if the first notification is sent on an element other than | 297 // Even if the first event is sent on an element other than |
298 // the root, the whole tree should be updated because we know | 298 // the root, the whole tree should be updated because we know |
299 // the browser doesn't have the root element. | 299 // the browser doesn't have the root element. |
300 LoadHTML(html.c_str()); | 300 LoadHTML(html.c_str()); |
301 document = view()->GetWebView()->mainFrame()->document(); | 301 document = view()->GetWebView()->mainFrame()->document(); |
302 root_obj = document.accessibilityObject(); | 302 root_obj = document.accessibilityObject(); |
303 sink_->ClearMessages(); | 303 sink_->ClearMessages(); |
304 const WebAccessibilityObject& first_child = root_obj.childAt(0); | 304 const WebAXObject& first_child = root_obj.childAt(0); |
305 accessibility->HandleWebAccessibilityNotification( | 305 accessibility->HandleWebAccessibilityEvent( |
306 first_child, | 306 first_child, |
307 WebKit::WebAccessibilityNotificationLiveRegionChanged); | 307 WebKit::WebAXEventLiveRegionChanged); |
308 accessibility->SendPendingAccessibilityNotifications(); | 308 accessibility->SendPendingAccessibilityEvents(); |
309 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 309 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
310 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 310 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
311 } | 311 } |
312 | 312 |
313 // http://crbug.com/253537 | 313 // http://crbug.com/253537 |
314 #if defined(OS_ANDROID) | 314 #if defined(OS_ANDROID) |
315 #define MAYBE_AccessibilityMessagesQueueWhileSwappedOut \ | 315 #define MAYBE_AccessibilityMessagesQueueWhileSwappedOut \ |
316 DISABLED_AccessibilityMessagesQueueWhileSwappedOut | 316 DISABLED_AccessibilityMessagesQueueWhileSwappedOut |
317 #else | 317 #else |
318 #define MAYBE_AccessibilityMessagesQueueWhileSwappedOut \ | 318 #define MAYBE_AccessibilityMessagesQueueWhileSwappedOut \ |
319 AccessibilityMessagesQueueWhileSwappedOut | 319 AccessibilityMessagesQueueWhileSwappedOut |
320 #endif | 320 #endif |
321 | 321 |
322 TEST_F(RendererAccessibilityTest, | 322 TEST_F(RendererAccessibilityTest, |
323 MAYBE_AccessibilityMessagesQueueWhileSwappedOut) { | 323 MAYBE_AccessibilityMessagesQueueWhileSwappedOut) { |
324 std::string html = | 324 std::string html = |
325 "<body>" | 325 "<body>" |
326 " <p>Hello, world.</p>" | 326 " <p>Hello, world.</p>" |
327 "</body>"; | 327 "</body>"; |
328 LoadHTML(html.c_str()); | 328 LoadHTML(html.c_str()); |
329 | 329 |
330 // Creating a RendererAccessibilityComplete should send the tree | 330 // Creating a RendererAccessibilityComplete should send the tree |
331 // to the browser. | 331 // to the browser. |
332 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 332 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
333 new TestRendererAccessibilityComplete(view())); | 333 new TestRendererAccessibilityComplete(view())); |
334 accessibility->SendPendingAccessibilityNotifications(); | 334 accessibility->SendPendingAccessibilityEvents(); |
335 EXPECT_EQ(3, accessibility->browser_tree_node_count()); | 335 EXPECT_EQ(3, accessibility->browser_tree_node_count()); |
336 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 336 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
337 | 337 |
338 // Post a "value changed" notification, but then swap out | 338 // Post a "value changed" event, but then swap out |
339 // before sending it. It shouldn't send the notification while | 339 // before sending it. It shouldn't send the event while |
340 // swapped out. | 340 // swapped out. |
341 sink_->ClearMessages(); | 341 sink_->ClearMessages(); |
342 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 342 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
343 WebAccessibilityObject root_obj = document.accessibilityObject(); | 343 WebAXObject root_obj = document.accessibilityObject(); |
344 accessibility->HandleWebAccessibilityNotification( | 344 accessibility->HandleWebAccessibilityEvent( |
345 root_obj, | 345 root_obj, |
346 WebKit::WebAccessibilityNotificationValueChanged); | 346 WebKit::WebAXEventValueChanged); |
347 view()->OnSwapOut(); | 347 view()->OnSwapOut(); |
348 accessibility->SendPendingAccessibilityNotifications(); | 348 accessibility->SendPendingAccessibilityEvents(); |
349 EXPECT_FALSE(sink_->GetUniqueMessageMatching( | 349 EXPECT_FALSE(sink_->GetUniqueMessageMatching( |
350 AccessibilityHostMsg_Notifications::ID)); | 350 AccessibilityHostMsg_Events::ID)); |
351 | 351 |
352 // Navigate, so we're not swapped out anymore. Now we should | 352 // Navigate, so we're not swapped out anymore. Now we should |
353 // send accessibility notifications again. Note that the | 353 // send accessibility events again. Note that the |
354 // message that was queued up before will be quickly discarded | 354 // message that was queued up before will be quickly discarded |
355 // because the element it was referring to no longer exists, | 355 // because the element it was referring to no longer exists, |
356 // so the notification here is from loading this new page. | 356 // so the event here is from loading this new page. |
357 ViewMsg_Navigate_Params nav_params; | 357 ViewMsg_Navigate_Params nav_params; |
358 nav_params.url = GURL("data:text/html,<p>Hello, again.</p>"); | 358 nav_params.url = GURL("data:text/html,<p>Hello, again.</p>"); |
359 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 359 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
360 nav_params.transition = PAGE_TRANSITION_TYPED; | 360 nav_params.transition = PAGE_TRANSITION_TYPED; |
361 nav_params.current_history_list_length = 1; | 361 nav_params.current_history_list_length = 1; |
362 nav_params.current_history_list_offset = 0; | 362 nav_params.current_history_list_offset = 0; |
363 nav_params.pending_history_list_offset = 1; | 363 nav_params.pending_history_list_offset = 1; |
364 nav_params.page_id = -1; | 364 nav_params.page_id = -1; |
365 view()->OnNavigate(nav_params); | 365 view()->OnNavigate(nav_params); |
366 accessibility->SendPendingAccessibilityNotifications(); | 366 accessibility->SendPendingAccessibilityEvents(); |
367 EXPECT_TRUE(sink_->GetUniqueMessageMatching( | 367 EXPECT_TRUE(sink_->GetUniqueMessageMatching( |
368 AccessibilityHostMsg_Notifications::ID)); | 368 AccessibilityHostMsg_Events::ID)); |
369 } | 369 } |
370 | 370 |
371 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { | 371 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { |
372 // Test RendererAccessibilityComplete and make sure it sends the | 372 // Test RendererAccessibilityComplete and make sure it sends the |
373 // proper notification to the browser when an object in the tree | 373 // proper event to the browser when an object in the tree |
374 // is hidden, but its children are not. | 374 // is hidden, but its children are not. |
375 std::string html = | 375 std::string html = |
376 "<body>" | 376 "<body>" |
377 " <div role='group' id='A'>" | 377 " <div role='group' id='A'>" |
378 " <div role='group' id='B'>" | 378 " <div role='group' id='B'>" |
379 " <div role='group' id='C' style='visibility:visible'>" | 379 " <div role='group' id='C' style='visibility:visible'>" |
380 " </div>" | 380 " </div>" |
381 " </div>" | 381 " </div>" |
382 " </div>" | 382 " </div>" |
383 "</body>"; | 383 "</body>"; |
384 LoadHTML(html.c_str()); | 384 LoadHTML(html.c_str()); |
385 | 385 |
386 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 386 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
387 new TestRendererAccessibilityComplete(view())); | 387 new TestRendererAccessibilityComplete(view())); |
388 accessibility->SendPendingAccessibilityNotifications(); | 388 accessibility->SendPendingAccessibilityEvents(); |
389 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 389 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
390 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 390 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
391 | 391 |
392 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 392 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
393 WebAccessibilityObject root_obj = document.accessibilityObject(); | 393 WebAXObject root_obj = document.accessibilityObject(); |
394 WebAccessibilityObject node_a = root_obj.childAt(0); | 394 WebAXObject node_a = root_obj.childAt(0); |
395 WebAccessibilityObject node_b = node_a.childAt(0); | 395 WebAXObject node_b = node_a.childAt(0); |
396 WebAccessibilityObject node_c = node_b.childAt(0); | 396 WebAXObject node_c = node_b.childAt(0); |
397 | 397 |
398 // Hide node 'B' ('C' stays visible). | 398 // Hide node 'B' ('C' stays visible). |
399 ExecuteJavaScript( | 399 ExecuteJavaScript( |
400 "document.getElementById('B').style.visibility = 'hidden';"); | 400 "document.getElementById('B').style.visibility = 'hidden';"); |
401 // Force layout now. | 401 // Force layout now. |
402 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); | 402 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); |
403 | 403 |
404 // Send a childrenChanged on 'A'. | 404 // Send a childrenChanged on 'A'. |
405 sink_->ClearMessages(); | 405 sink_->ClearMessages(); |
406 accessibility->HandleWebAccessibilityNotification( | 406 accessibility->HandleWebAccessibilityEvent( |
407 node_a, | 407 node_a, |
408 WebKit::WebAccessibilityNotificationChildrenChanged); | 408 WebKit::WebAXEventChildrenChanged); |
409 | 409 |
410 accessibility->SendPendingAccessibilityNotifications(); | 410 accessibility->SendPendingAccessibilityEvents(); |
411 EXPECT_EQ(3, accessibility->browser_tree_node_count()); | 411 EXPECT_EQ(3, accessibility->browser_tree_node_count()); |
412 AccessibilityHostMsg_NotificationParams notification; | 412 AccessibilityHostMsg_EventParams event; |
413 GetLastAccNotification(¬ification); | 413 GetLastAccEvent(&event); |
414 ASSERT_EQ(3U, notification.nodes.size()); | 414 ASSERT_EQ(3U, event.nodes.size()); |
415 | 415 |
416 // RendererAccessibilityComplete notices that 'C' is being reparented, | 416 // RendererAccessibilityComplete notices that 'C' is being reparented, |
417 // so it updates 'B' first to remove 'C' as a child, then 'A' to add it, | 417 // so it updates 'B' first to remove 'C' as a child, then 'A' to add it, |
418 // and finally it updates 'C'. | 418 // and finally it updates 'C'. |
419 EXPECT_EQ(node_b.axID(), notification.nodes[0].id); | 419 EXPECT_EQ(node_b.axID(), event.nodes[0].id); |
420 EXPECT_EQ(node_a.axID(), notification.nodes[1].id); | 420 EXPECT_EQ(node_a.axID(), event.nodes[1].id); |
421 EXPECT_EQ(node_c.axID(), notification.nodes[2].id); | 421 EXPECT_EQ(node_c.axID(), event.nodes[2].id); |
422 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 422 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
423 } | 423 } |
424 | 424 |
425 TEST_F(RendererAccessibilityTest, ShowAccessibilityObject) { | 425 TEST_F(RendererAccessibilityTest, ShowAccessibilityObject) { |
426 // Test RendererAccessibilityComplete and make sure it sends the | 426 // Test RendererAccessibilityComplete and make sure it sends the |
427 // proper notification to the browser when an object in the tree | 427 // proper event to the browser when an object in the tree |
428 // is shown, causing its own already-visible children to be | 428 // is shown, causing its own already-visible children to be |
429 // reparented to it. | 429 // reparented to it. |
430 std::string html = | 430 std::string html = |
431 "<body>" | 431 "<body>" |
432 " <div role='group' id='A'>" | 432 " <div role='group' id='A'>" |
433 " <div role='group' id='B' style='visibility:hidden'>" | 433 " <div role='group' id='B' style='visibility:hidden'>" |
434 " <div role='group' id='C' style='visibility:visible'>" | 434 " <div role='group' id='C' style='visibility:visible'>" |
435 " </div>" | 435 " </div>" |
436 " </div>" | 436 " </div>" |
437 " </div>" | 437 " </div>" |
438 "</body>"; | 438 "</body>"; |
439 LoadHTML(html.c_str()); | 439 LoadHTML(html.c_str()); |
440 | 440 |
441 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 441 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
442 new TestRendererAccessibilityComplete(view())); | 442 new TestRendererAccessibilityComplete(view())); |
443 accessibility->SendPendingAccessibilityNotifications(); | 443 accessibility->SendPendingAccessibilityEvents(); |
444 EXPECT_EQ(3, accessibility->browser_tree_node_count()); | 444 EXPECT_EQ(3, accessibility->browser_tree_node_count()); |
445 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 445 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
446 | 446 |
447 // Show node 'B', then send a childrenChanged on 'A'. | 447 // Show node 'B', then send a childrenChanged on 'A'. |
448 ExecuteJavaScript( | 448 ExecuteJavaScript( |
449 "document.getElementById('B').style.visibility = 'visible';"); | 449 "document.getElementById('B').style.visibility = 'visible';"); |
450 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); | 450 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); |
451 | 451 |
452 sink_->ClearMessages(); | 452 sink_->ClearMessages(); |
453 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 453 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
454 WebAccessibilityObject root_obj = document.accessibilityObject(); | 454 WebAXObject root_obj = document.accessibilityObject(); |
455 WebAccessibilityObject node_a = root_obj.childAt(0); | 455 WebAXObject node_a = root_obj.childAt(0); |
456 accessibility->HandleWebAccessibilityNotification( | 456 accessibility->HandleWebAccessibilityEvent( |
457 node_a, | 457 node_a, |
458 WebKit::WebAccessibilityNotificationChildrenChanged); | 458 WebKit::WebAXEventChildrenChanged); |
459 | 459 |
460 accessibility->SendPendingAccessibilityNotifications(); | 460 accessibility->SendPendingAccessibilityEvents(); |
461 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 461 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
462 AccessibilityHostMsg_NotificationParams notification; | 462 AccessibilityHostMsg_EventParams event; |
463 GetLastAccNotification(¬ification); | 463 GetLastAccEvent(&event); |
464 ASSERT_EQ(3U, notification.nodes.size()); | 464 ASSERT_EQ(3U, event.nodes.size()); |
465 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 465 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
466 } | 466 } |
467 | 467 |
468 } // namespace content | 468 } // namespace content |
OLD | NEW |