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/frame_messages.h" | 6 #include "content/common/frame_messages.h" |
7 #include "content/common/view_message_enums.h" | 7 #include "content/common/view_message_enums.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_frame_impl.h" |
10 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/public/platform/WebSize.h" | 13 #include "third_party/WebKit/public/platform/WebSize.h" |
13 #include "third_party/WebKit/public/web/WebAXObject.h" | 14 #include "third_party/WebKit/public/web/WebAXObject.h" |
14 #include "third_party/WebKit/public/web/WebDocument.h" | 15 #include "third_party/WebKit/public/web/WebDocument.h" |
15 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
16 #include "ui/accessibility/ax_node_data.h" | 17 #include "ui/accessibility/ax_node_data.h" |
17 | 18 |
18 using blink::WebAXObject; | 19 using blink::WebAXObject; |
19 using blink::WebDocument; | 20 using blink::WebDocument; |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { | 24 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { |
24 public: | 25 public: |
25 explicit TestRendererAccessibilityComplete(RenderViewImpl* render_view) | 26 explicit TestRendererAccessibilityComplete(RenderFrameImpl* render_frame) |
26 : RendererAccessibilityComplete(render_view) { | 27 : RendererAccessibilityComplete(render_frame) { |
27 } | 28 } |
28 | 29 |
29 void SendPendingAccessibilityEvents() { | 30 void SendPendingAccessibilityEvents() { |
30 RendererAccessibilityComplete::SendPendingAccessibilityEvents(); | 31 RendererAccessibilityComplete::SendPendingAccessibilityEvents(); |
31 } | 32 } |
32 }; | 33 }; |
33 | 34 |
34 class RendererAccessibilityTest : public RenderViewTest { | 35 class RendererAccessibilityTest : public RenderViewTest { |
35 public: | 36 public: |
36 RendererAccessibilityTest() {} | 37 RendererAccessibilityTest() {} |
37 | 38 |
38 RenderViewImpl* view() { | 39 RenderViewImpl* view() { |
39 return static_cast<RenderViewImpl*>(view_); | 40 return static_cast<RenderViewImpl*>(view_); |
40 } | 41 } |
41 | 42 |
42 RenderFrameImpl* frame() { | 43 RenderFrameImpl* frame() { |
43 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); | 44 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); |
44 } | 45 } |
45 | 46 |
46 virtual void SetUp() { | 47 virtual void SetUp() { |
47 RenderViewTest::SetUp(); | 48 RenderViewTest::SetUp(); |
48 sink_ = &render_thread_->sink(); | 49 sink_ = &render_thread_->sink(); |
49 } | 50 } |
50 | 51 |
51 void SetMode(AccessibilityMode mode) { | 52 void SetMode(AccessibilityMode mode) { |
52 view()->OnSetAccessibilityMode(mode); | 53 frame()->OnSetAccessibilityMode(mode); |
53 } | 54 } |
54 | 55 |
55 void GetLastAccEvent( | 56 void GetLastAccEvent( |
56 AccessibilityHostMsg_EventParams* params) { | 57 AccessibilityHostMsg_EventParams* params) { |
57 const IPC::Message* message = | 58 const IPC::Message* message = |
58 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); | 59 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
59 ASSERT_TRUE(message); | 60 ASSERT_TRUE(message); |
60 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; | 61 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; |
61 AccessibilityHostMsg_Events::Read(message, ¶m); | 62 AccessibilityHostMsg_Events::Read(message, ¶m); |
62 ASSERT_GE(param.a.size(), 1U); | 63 ASSERT_GE(param.a.size(), 1U); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 " <div role='group' id='A'>" | 233 " <div role='group' id='A'>" |
233 " <div role='group' id='A1'></div>" | 234 " <div role='group' id='A1'></div>" |
234 " <div role='group' id='A2'></div>" | 235 " <div role='group' id='A2'></div>" |
235 " </div>" | 236 " </div>" |
236 "</body>"; | 237 "</body>"; |
237 LoadHTML(html.c_str()); | 238 LoadHTML(html.c_str()); |
238 | 239 |
239 // Creating a RendererAccessibilityComplete should sent the tree | 240 // Creating a RendererAccessibilityComplete should sent the tree |
240 // to the browser. | 241 // to the browser. |
241 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 242 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
242 new TestRendererAccessibilityComplete(view())); | 243 new TestRendererAccessibilityComplete(frame())); |
243 accessibility->SendPendingAccessibilityEvents(); | 244 accessibility->SendPendingAccessibilityEvents(); |
244 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 245 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
245 | 246 |
246 // If we post another event but the tree doesn't change, | 247 // If we post another event but the tree doesn't change, |
247 // we should only send 1 node to the browser. | 248 // we should only send 1 node to the browser. |
248 sink_->ClearMessages(); | 249 sink_->ClearMessages(); |
249 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 250 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
250 WebAXObject root_obj = document.accessibilityObject(); | 251 WebAXObject root_obj = document.accessibilityObject(); |
251 accessibility->HandleAXEvent( | 252 accessibility->HandleAXEvent( |
252 root_obj, | 253 root_obj, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 MAYBE_AccessibilityMessagesQueueWhileSwappedOut) { | 302 MAYBE_AccessibilityMessagesQueueWhileSwappedOut) { |
302 std::string html = | 303 std::string html = |
303 "<body>" | 304 "<body>" |
304 " <p>Hello, world.</p>" | 305 " <p>Hello, world.</p>" |
305 "</body>"; | 306 "</body>"; |
306 LoadHTML(html.c_str()); | 307 LoadHTML(html.c_str()); |
307 | 308 |
308 // Creating a RendererAccessibilityComplete should send the tree | 309 // Creating a RendererAccessibilityComplete should send the tree |
309 // to the browser. | 310 // to the browser. |
310 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 311 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
311 new TestRendererAccessibilityComplete(view())); | 312 new TestRendererAccessibilityComplete(frame())); |
312 accessibility->SendPendingAccessibilityEvents(); | 313 accessibility->SendPendingAccessibilityEvents(); |
313 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); | 314 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); |
314 | 315 |
315 // Post a "value changed" event, but then swap out | 316 // Post a "value changed" event, but then swap out |
316 // before sending it. It shouldn't send the event while | 317 // before sending it. It shouldn't send the event while |
317 // swapped out. | 318 // swapped out. |
318 sink_->ClearMessages(); | 319 sink_->ClearMessages(); |
319 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 320 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
320 WebAXObject root_obj = document.accessibilityObject(); | 321 WebAXObject root_obj = document.accessibilityObject(); |
321 accessibility->HandleAXEvent( | 322 accessibility->HandleAXEvent( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 " <div role='group' id='A'>" | 355 " <div role='group' id='A'>" |
355 " <div role='group' id='B'>" | 356 " <div role='group' id='B'>" |
356 " <div role='group' id='C' style='visibility:visible'>" | 357 " <div role='group' id='C' style='visibility:visible'>" |
357 " </div>" | 358 " </div>" |
358 " </div>" | 359 " </div>" |
359 " </div>" | 360 " </div>" |
360 "</body>"; | 361 "</body>"; |
361 LoadHTML(html.c_str()); | 362 LoadHTML(html.c_str()); |
362 | 363 |
363 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 364 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
364 new TestRendererAccessibilityComplete(view())); | 365 new TestRendererAccessibilityComplete(frame())); |
365 accessibility->SendPendingAccessibilityEvents(); | 366 accessibility->SendPendingAccessibilityEvents(); |
366 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 367 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
367 | 368 |
368 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 369 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
369 WebAXObject root_obj = document.accessibilityObject(); | 370 WebAXObject root_obj = document.accessibilityObject(); |
370 WebAXObject node_a = root_obj.childAt(0); | 371 WebAXObject node_a = root_obj.childAt(0); |
371 WebAXObject node_b = node_a.childAt(0); | 372 WebAXObject node_b = node_a.childAt(0); |
372 WebAXObject node_c = node_b.childAt(0); | 373 WebAXObject node_c = node_b.childAt(0); |
373 | 374 |
374 // Hide node 'B' ('C' stays visible). | 375 // Hide node 'B' ('C' stays visible). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 " <div role='group' id='A'>" | 407 " <div role='group' id='A'>" |
407 " <div role='group' id='B' style='visibility:hidden'>" | 408 " <div role='group' id='B' style='visibility:hidden'>" |
408 " <div role='group' id='C' style='visibility:visible'>" | 409 " <div role='group' id='C' style='visibility:visible'>" |
409 " </div>" | 410 " </div>" |
410 " </div>" | 411 " </div>" |
411 " </div>" | 412 " </div>" |
412 "</body>"; | 413 "</body>"; |
413 LoadHTML(html.c_str()); | 414 LoadHTML(html.c_str()); |
414 | 415 |
415 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 416 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
416 new TestRendererAccessibilityComplete(view())); | 417 new TestRendererAccessibilityComplete(frame())); |
417 accessibility->SendPendingAccessibilityEvents(); | 418 accessibility->SendPendingAccessibilityEvents(); |
418 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 419 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
419 | 420 |
420 // Show node 'B', then send a childrenChanged on 'A'. | 421 // Show node 'B', then send a childrenChanged on 'A'. |
421 ExecuteJavaScript( | 422 ExecuteJavaScript( |
422 "document.getElementById('B').style.visibility = 'visible';"); | 423 "document.getElementById('B').style.visibility = 'visible';"); |
423 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); | 424 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); |
424 | 425 |
425 sink_->ClearMessages(); | 426 sink_->ClearMessages(); |
426 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 427 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
(...skipping 23 matching lines...) Expand all Loading... |
450 // proper event to the browser when an object in the tree | 451 // proper event to the browser when an object in the tree |
451 // is detached, but its children are not. This can happen when | 452 // is detached, but its children are not. This can happen when |
452 // a layout occurs and an anonymous render block is no longer needed. | 453 // a layout occurs and an anonymous render block is no longer needed. |
453 std::string html = | 454 std::string html = |
454 "<body aria-label='Body'>" | 455 "<body aria-label='Body'>" |
455 "<span>1</span><span style='display:block'>2</span>" | 456 "<span>1</span><span style='display:block'>2</span>" |
456 "</body>"; | 457 "</body>"; |
457 LoadHTML(html.c_str()); | 458 LoadHTML(html.c_str()); |
458 | 459 |
459 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 460 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
460 new TestRendererAccessibilityComplete(view())); | 461 new TestRendererAccessibilityComplete(frame())); |
461 accessibility->SendPendingAccessibilityEvents(); | 462 accessibility->SendPendingAccessibilityEvents(); |
462 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); | 463 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); |
463 | 464 |
464 // Initially, the accessibility tree looks like this: | 465 // Initially, the accessibility tree looks like this: |
465 // | 466 // |
466 // Document | 467 // Document |
467 // +--Body | 468 // +--Body |
468 // +--Anonymous Block | 469 // +--Anonymous Block |
469 // +--Static Text "1" | 470 // +--Static Text "1" |
470 // +--Inline Text Box "1" | 471 // +--Inline Text Box "1" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 GetLastAccEvent(&event); | 511 GetLastAccEvent(&event); |
511 ASSERT_EQ(5U, event.update.nodes.size()); | 512 ASSERT_EQ(5U, event.update.nodes.size()); |
512 | 513 |
513 EXPECT_EQ(body.axID(), event.update.nodes[0].id); | 514 EXPECT_EQ(body.axID(), event.update.nodes[0].id); |
514 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id); | 515 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id); |
515 // The third event is to update text_2, but its id changes | 516 // The third event is to update text_2, but its id changes |
516 // so we don't have a test expectation for it. | 517 // so we don't have a test expectation for it. |
517 } | 518 } |
518 | 519 |
519 } // namespace content | 520 } // namespace content |
OLD | NEW |