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

Side by Side Diff: content/renderer/accessibility/renderer_accessibility_browsertest.cc

Issue 688173002: Refactor RendererAccessibiltiyComplete back into RendererAccessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (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 "base/time/time.h" 6 #include "base/time/time.h"
7 #include "content/common/frame_messages.h" 7 #include "content/common/frame_messages.h"
8 #include "content/common/view_message_enums.h" 8 #include "content/common/view_message_enums.h"
9 #include "content/public/test/render_view_test.h" 9 #include "content/public/test/render_view_test.h"
10 #include "content/renderer/accessibility/renderer_accessibility_complete.h" 10 #include "content/renderer/accessibility/renderer_accessibility.h"
11 #include "content/renderer/render_frame_impl.h" 11 #include "content/renderer/render_frame_impl.h"
12 #include "content/renderer/render_view_impl.h" 12 #include "content/renderer/render_view_impl.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebSize.h" 14 #include "third_party/WebKit/public/platform/WebSize.h"
15 #include "third_party/WebKit/public/web/WebAXObject.h" 15 #include "third_party/WebKit/public/web/WebAXObject.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebView.h" 17 #include "third_party/WebKit/public/web/WebView.h"
18 #include "ui/accessibility/ax_node_data.h" 18 #include "ui/accessibility/ax_node_data.h"
19 19
20 using blink::WebAXObject; 20 using blink::WebAXObject;
21 using blink::WebDocument; 21 using blink::WebDocument;
22 22
23 namespace content { 23 namespace content {
24 24
25 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { 25 class TestRendererAccessibility : public RendererAccessibility {
26 public: 26 public:
27 explicit TestRendererAccessibilityComplete(RenderFrameImpl* render_frame) 27 explicit TestRendererAccessibility(RenderFrameImpl* render_frame)
28 : RendererAccessibilityComplete(render_frame) { 28 : RendererAccessibility(render_frame) {
29 } 29 }
30 30
31 void SendPendingAccessibilityEvents() { 31 void SendPendingAccessibilityEvents() {
32 RendererAccessibilityComplete::SendPendingAccessibilityEvents(); 32 RendererAccessibility::SendPendingAccessibilityEvents();
33 } 33 }
34 }; 34 };
35 35
36 class RendererAccessibilityTest : public RenderViewTest { 36 class RendererAccessibilityTest : public RenderViewTest {
37 public: 37 public:
38 RendererAccessibilityTest() {} 38 RendererAccessibilityTest() {}
39 39
40 RenderViewImpl* view() { 40 RenderViewImpl* view() {
41 return static_cast<RenderViewImpl*>(view_); 41 return static_cast<RenderViewImpl*>(view_);
42 } 42 }
(...skipping 29 matching lines...) Expand all
72 } 72 }
73 73
74 protected: 74 protected:
75 IPC::TestSink* sink_; 75 IPC::TestSink* sink_;
76 76
77 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest); 77 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest);
78 78
79 }; 79 };
80 80
81 TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) { 81 TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) {
82 // The job of RendererAccessibilityComplete is to serialize the 82 // The job of RendererAccessibility is to serialize the
83 // accessibility tree built by WebKit and send it to the browser. 83 // accessibility tree built by WebKit and send it to the browser.
84 // When the accessibility tree changes, it tries to send only 84 // When the accessibility tree changes, it tries to send only
85 // the nodes that actually changed or were reparented. This test 85 // the nodes that actually changed or were reparented. This test
86 // ensures that the messages sent are correct in cases when a page 86 // ensures that the messages sent are correct in cases when a page
87 // reloads, and that internal state is properly garbage-collected. 87 // reloads, and that internal state is properly garbage-collected.
88 std::string html = 88 std::string html =
89 "<body>" 89 "<body>"
90 " <div role='group' id='A'>" 90 " <div role='group' id='A'>"
91 " <div role='group' id='A1'></div>" 91 " <div role='group' id='A1'></div>"
92 " <div role='group' id='A2'></div>" 92 " <div role='group' id='A2'></div>"
93 " </div>" 93 " </div>"
94 "</body>"; 94 "</body>";
95 LoadHTML(html.c_str()); 95 LoadHTML(html.c_str());
96 96
97 // Creating a RendererAccessibilityComplete should sent the tree 97 // Creating a RendererAccessibility should sent the tree to the browser.
98 // to the browser. 98 scoped_ptr<TestRendererAccessibility> accessibility(
99 scoped_ptr<TestRendererAccessibilityComplete> accessibility( 99 new TestRendererAccessibility(frame()));
100 new TestRendererAccessibilityComplete(frame()));
101 accessibility->SendPendingAccessibilityEvents(); 100 accessibility->SendPendingAccessibilityEvents();
102 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); 101 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser());
103 102
104 // If we post another event but the tree doesn't change, 103 // If we post another event but the tree doesn't change,
105 // we should only send 1 node to the browser. 104 // we should only send 1 node to the browser.
106 sink_->ClearMessages(); 105 sink_->ClearMessages();
107 WebDocument document = view()->GetWebView()->mainFrame()->document(); 106 WebDocument document = view()->GetWebView()->mainFrame()->document();
108 WebAXObject root_obj = document.accessibilityObject(); 107 WebAXObject root_obj = document.accessibilityObject();
109 accessibility->HandleAXEvent( 108 accessibility->HandleAXEvent(
110 root_obj, 109 root_obj,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 156
158 TEST_F(RendererAccessibilityTest, 157 TEST_F(RendererAccessibilityTest,
159 MAYBE_AccessibilityMessagesQueueWhileSwappedOut) { 158 MAYBE_AccessibilityMessagesQueueWhileSwappedOut) {
160 std::string html = 159 std::string html =
161 "<body>" 160 "<body>"
162 " <p>Hello, world.</p>" 161 " <p>Hello, world.</p>"
163 "</body>"; 162 "</body>";
164 LoadHTML(html.c_str()); 163 LoadHTML(html.c_str());
165 static const int kProxyRoutingId = 13; 164 static const int kProxyRoutingId = 13;
166 165
167 // Creating a RendererAccessibilityComplete should send the tree 166 // Creating a RendererAccessibility should send the tree to the browser.
168 // to the browser. 167 scoped_ptr<TestRendererAccessibility> accessibility(
169 scoped_ptr<TestRendererAccessibilityComplete> accessibility( 168 new TestRendererAccessibility(frame()));
170 new TestRendererAccessibilityComplete(frame()));
171 accessibility->SendPendingAccessibilityEvents(); 169 accessibility->SendPendingAccessibilityEvents();
172 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); 170 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser());
173 171
174 // Post a "value changed" event, but then swap out 172 // Post a "value changed" event, but then swap out
175 // before sending it. It shouldn't send the event while 173 // before sending it. It shouldn't send the event while
176 // swapped out. 174 // swapped out.
177 sink_->ClearMessages(); 175 sink_->ClearMessages();
178 WebDocument document = view()->GetWebView()->mainFrame()->document(); 176 WebDocument document = view()->GetWebView()->mainFrame()->document();
179 WebAXObject root_obj = document.accessibilityObject(); 177 WebAXObject root_obj = document.accessibilityObject();
180 accessibility->HandleAXEvent( 178 accessibility->HandleAXEvent(
(...skipping 19 matching lines...) Expand all
200 nav_params.page_id = -1; 198 nav_params.page_id = -1;
201 nav_params.commit_params.browser_navigation_start = 199 nav_params.commit_params.browser_navigation_start =
202 base::TimeTicks::FromInternalValue(1); 200 base::TimeTicks::FromInternalValue(1);
203 frame()->OnNavigate(nav_params); 201 frame()->OnNavigate(nav_params);
204 accessibility->SendPendingAccessibilityEvents(); 202 accessibility->SendPendingAccessibilityEvents();
205 EXPECT_TRUE(sink_->GetUniqueMessageMatching( 203 EXPECT_TRUE(sink_->GetUniqueMessageMatching(
206 AccessibilityHostMsg_Events::ID)); 204 AccessibilityHostMsg_Events::ID));
207 } 205 }
208 206
209 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { 207 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) {
210 // Test RendererAccessibilityComplete and make sure it sends the 208 // Test RendererAccessibility and make sure it sends the
211 // proper event to the browser when an object in the tree 209 // proper event to the browser when an object in the tree
212 // is hidden, but its children are not. 210 // is hidden, but its children are not.
213 std::string html = 211 std::string html =
214 "<body>" 212 "<body>"
215 " <div role='group' id='A'>" 213 " <div role='group' id='A'>"
216 " <div role='group' id='B'>" 214 " <div role='group' id='B'>"
217 " <div role='group' id='C' style='visibility:visible'>" 215 " <div role='group' id='C' style='visibility:visible'>"
218 " </div>" 216 " </div>"
219 " </div>" 217 " </div>"
220 " </div>" 218 " </div>"
221 "</body>"; 219 "</body>";
222 LoadHTML(html.c_str()); 220 LoadHTML(html.c_str());
223 221
224 scoped_ptr<TestRendererAccessibilityComplete> accessibility( 222 scoped_ptr<TestRendererAccessibility> accessibility(
225 new TestRendererAccessibilityComplete(frame())); 223 new TestRendererAccessibility(frame()));
226 accessibility->SendPendingAccessibilityEvents(); 224 accessibility->SendPendingAccessibilityEvents();
227 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); 225 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser());
228 226
229 WebDocument document = view()->GetWebView()->mainFrame()->document(); 227 WebDocument document = view()->GetWebView()->mainFrame()->document();
230 WebAXObject root_obj = document.accessibilityObject(); 228 WebAXObject root_obj = document.accessibilityObject();
231 WebAXObject node_a = root_obj.childAt(0); 229 WebAXObject node_a = root_obj.childAt(0);
232 WebAXObject node_b = node_a.childAt(0); 230 WebAXObject node_b = node_a.childAt(0);
233 WebAXObject node_c = node_b.childAt(0); 231 WebAXObject node_c = node_b.childAt(0);
234 232
235 // Hide node 'B' ('C' stays visible). 233 // Hide node 'B' ('C' stays visible).
236 ExecuteJavaScript( 234 ExecuteJavaScript(
237 "document.getElementById('B').style.visibility = 'hidden';"); 235 "document.getElementById('B').style.visibility = 'hidden';");
238 // Force layout now. 236 // Force layout now.
239 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); 237 ExecuteJavaScript("document.getElementById('B').offsetLeft;");
240 238
241 // Send a childrenChanged on 'A'. 239 // Send a childrenChanged on 'A'.
242 sink_->ClearMessages(); 240 sink_->ClearMessages();
243 accessibility->HandleAXEvent( 241 accessibility->HandleAXEvent(
244 node_a, 242 node_a,
245 ui::AX_EVENT_CHILDREN_CHANGED); 243 ui::AX_EVENT_CHILDREN_CHANGED);
246 244
247 accessibility->SendPendingAccessibilityEvents(); 245 accessibility->SendPendingAccessibilityEvents();
248 AccessibilityHostMsg_EventParams event; 246 AccessibilityHostMsg_EventParams event;
249 GetLastAccEvent(&event); 247 GetLastAccEvent(&event);
250 ASSERT_EQ(2U, event.update.nodes.size()); 248 ASSERT_EQ(2U, event.update.nodes.size());
251 249
252 // RendererAccessibilityComplete notices that 'C' is being reparented, 250 // RendererAccessibility notices that 'C' is being reparented,
253 // so it clears the subtree rooted at 'A', then updates 'A' and then 'C'. 251 // so it clears the subtree rooted at 'A', then updates 'A' and then 'C'.
254 EXPECT_EQ(node_a.axID(), event.update.node_id_to_clear); 252 EXPECT_EQ(node_a.axID(), event.update.node_id_to_clear);
255 EXPECT_EQ(node_a.axID(), event.update.nodes[0].id); 253 EXPECT_EQ(node_a.axID(), event.update.nodes[0].id);
256 EXPECT_EQ(node_c.axID(), event.update.nodes[1].id); 254 EXPECT_EQ(node_c.axID(), event.update.nodes[1].id);
257 EXPECT_EQ(2, CountAccessibilityNodesSentToBrowser()); 255 EXPECT_EQ(2, CountAccessibilityNodesSentToBrowser());
258 } 256 }
259 257
260 TEST_F(RendererAccessibilityTest, ShowAccessibilityObject) { 258 TEST_F(RendererAccessibilityTest, ShowAccessibilityObject) {
261 // Test RendererAccessibilityComplete and make sure it sends the 259 // Test RendererAccessibility and make sure it sends the
262 // proper event to the browser when an object in the tree 260 // proper event to the browser when an object in the tree
263 // is shown, causing its own already-visible children to be 261 // is shown, causing its own already-visible children to be
264 // reparented to it. 262 // reparented to it.
265 std::string html = 263 std::string html =
266 "<body>" 264 "<body>"
267 " <div role='group' id='A'>" 265 " <div role='group' id='A'>"
268 " <div role='group' id='B' style='visibility:hidden'>" 266 " <div role='group' id='B' style='visibility:hidden'>"
269 " <div role='group' id='C' style='visibility:visible'>" 267 " <div role='group' id='C' style='visibility:visible'>"
270 " </div>" 268 " </div>"
271 " </div>" 269 " </div>"
272 " </div>" 270 " </div>"
273 "</body>"; 271 "</body>";
274 LoadHTML(html.c_str()); 272 LoadHTML(html.c_str());
275 273
276 scoped_ptr<TestRendererAccessibilityComplete> accessibility( 274 scoped_ptr<TestRendererAccessibility> accessibility(
277 new TestRendererAccessibilityComplete(frame())); 275 new TestRendererAccessibility(frame()));
278 accessibility->SendPendingAccessibilityEvents(); 276 accessibility->SendPendingAccessibilityEvents();
279 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); 277 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser());
280 278
281 // Show node 'B', then send a childrenChanged on 'A'. 279 // Show node 'B', then send a childrenChanged on 'A'.
282 ExecuteJavaScript( 280 ExecuteJavaScript(
283 "document.getElementById('B').style.visibility = 'visible';"); 281 "document.getElementById('B').style.visibility = 'visible';");
284 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); 282 ExecuteJavaScript("document.getElementById('B').offsetLeft;");
285 283
286 sink_->ClearMessages(); 284 sink_->ClearMessages();
287 WebDocument document = view()->GetWebView()->mainFrame()->document(); 285 WebDocument document = view()->GetWebView()->mainFrame()->document();
(...skipping 12 matching lines...) Expand all
300 298
301 ASSERT_EQ(3U, event.update.nodes.size()); 299 ASSERT_EQ(3U, event.update.nodes.size());
302 EXPECT_EQ(node_a.axID(), event.update.node_id_to_clear); 300 EXPECT_EQ(node_a.axID(), event.update.node_id_to_clear);
303 EXPECT_EQ(node_a.axID(), event.update.nodes[0].id); 301 EXPECT_EQ(node_a.axID(), event.update.nodes[0].id);
304 EXPECT_EQ(node_b.axID(), event.update.nodes[1].id); 302 EXPECT_EQ(node_b.axID(), event.update.nodes[1].id);
305 EXPECT_EQ(node_c.axID(), event.update.nodes[2].id); 303 EXPECT_EQ(node_c.axID(), event.update.nodes[2].id);
306 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); 304 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser());
307 } 305 }
308 306
309 TEST_F(RendererAccessibilityTest, DetachAccessibilityObject) { 307 TEST_F(RendererAccessibilityTest, DetachAccessibilityObject) {
310 // Test RendererAccessibilityComplete and make sure it sends the 308 // Test RendererAccessibility and make sure it sends the
311 // proper event to the browser when an object in the tree 309 // proper event to the browser when an object in the tree
312 // is detached, but its children are not. This can happen when 310 // is detached, but its children are not. This can happen when
313 // a layout occurs and an anonymous render block is no longer needed. 311 // a layout occurs and an anonymous render block is no longer needed.
314 std::string html = 312 std::string html =
315 "<body aria-label='Body'>" 313 "<body aria-label='Body'>"
316 "<span>1</span><span style='display:block'>2</span>" 314 "<span>1</span><span style='display:block'>2</span>"
317 "</body>"; 315 "</body>";
318 LoadHTML(html.c_str()); 316 LoadHTML(html.c_str());
319 317
320 scoped_ptr<TestRendererAccessibilityComplete> accessibility( 318 scoped_ptr<TestRendererAccessibility> accessibility(
321 new TestRendererAccessibilityComplete(frame())); 319 new TestRendererAccessibility(frame()));
322 accessibility->SendPendingAccessibilityEvents(); 320 accessibility->SendPendingAccessibilityEvents();
323 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); 321 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser());
324 322
325 // Initially, the accessibility tree looks like this: 323 // Initially, the accessibility tree looks like this:
326 // 324 //
327 // Document 325 // Document
328 // +--Body 326 // +--Body
329 // +--Anonymous Block 327 // +--Anonymous Block
330 // +--Static Text "1" 328 // +--Static Text "1"
331 // +--Inline Text Box "1" 329 // +--Inline Text Box "1"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 GetLastAccEvent(&event); 369 GetLastAccEvent(&event);
372 ASSERT_EQ(5U, event.update.nodes.size()); 370 ASSERT_EQ(5U, event.update.nodes.size());
373 371
374 EXPECT_EQ(body.axID(), event.update.nodes[0].id); 372 EXPECT_EQ(body.axID(), event.update.nodes[0].id);
375 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id); 373 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id);
376 // The third event is to update text_2, but its id changes 374 // The third event is to update text_2, but its id changes
377 // so we don't have a test expectation for it. 375 // so we don't have a test expectation for it.
378 } 376 }
379 377
380 TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) { 378 TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) {
381 // Test RendererAccessibilityComplete and make sure it doesn't send anything 379 // Test RendererAccessibility and make sure it doesn't send anything
382 // if we get a notification from Blink for an object that isn't in the 380 // if we get a notification from Blink for an object that isn't in the
383 // tree, like the scroll area that's the parent of the main document, 381 // tree, like the scroll area that's the parent of the main document,
384 // which we don't expose. 382 // which we don't expose.
385 std::string html = "<body><input></body>"; 383 std::string html = "<body><input></body>";
386 LoadHTML(html.c_str()); 384 LoadHTML(html.c_str());
387 385
388 scoped_ptr<TestRendererAccessibilityComplete> accessibility( 386 scoped_ptr<TestRendererAccessibility> accessibility(
389 new TestRendererAccessibilityComplete(frame())); 387 new TestRendererAccessibility(frame()));
390 accessibility->SendPendingAccessibilityEvents(); 388 accessibility->SendPendingAccessibilityEvents();
391 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); 389 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser());
392 390
393 WebDocument document = view()->GetWebView()->mainFrame()->document(); 391 WebDocument document = view()->GetWebView()->mainFrame()->document();
394 WebAXObject root_obj = document.accessibilityObject(); 392 WebAXObject root_obj = document.accessibilityObject();
395 WebAXObject scroll_area = root_obj.parentObject(); 393 WebAXObject scroll_area = root_obj.parentObject();
396 EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role()); 394 EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role());
397 395
398 // Try to fire a message on the scroll area, and assert that we just 396 // Try to fire a message on the scroll area, and assert that we just
399 // ignore it. 397 // ignore it.
400 sink_->ClearMessages(); 398 sink_->ClearMessages();
401 accessibility->HandleAXEvent(scroll_area, 399 accessibility->HandleAXEvent(scroll_area,
402 ui::AX_EVENT_VALUE_CHANGED); 400 ui::AX_EVENT_VALUE_CHANGED);
403 401
404 accessibility->SendPendingAccessibilityEvents(); 402 accessibility->SendPendingAccessibilityEvents();
405 403
406 const IPC::Message* message = 404 const IPC::Message* message =
407 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); 405 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID);
408 ASSERT_TRUE(message); 406 ASSERT_TRUE(message);
409 Tuple2<std::vector<AccessibilityHostMsg_EventParams>, int> param; 407 Tuple2<std::vector<AccessibilityHostMsg_EventParams>, int> param;
410 AccessibilityHostMsg_Events::Read(message, &param); 408 AccessibilityHostMsg_Events::Read(message, &param);
411 ASSERT_EQ(0U, param.a.size()); 409 ASSERT_EQ(0U, param.a.size());
412 } 410 }
413 411
414 } // namespace content 412 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698