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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 static const int kProxyRoutingId = 13; | 308 static const int kProxyRoutingId = 13; |
308 | 309 |
309 // Creating a RendererAccessibilityComplete should send the tree | 310 // Creating a RendererAccessibilityComplete should send the tree |
310 // to the browser. | 311 // to the browser. |
311 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 312 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
312 new TestRendererAccessibilityComplete(view())); | 313 new TestRendererAccessibilityComplete(frame())); |
313 accessibility->SendPendingAccessibilityEvents(); | 314 accessibility->SendPendingAccessibilityEvents(); |
314 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); | 315 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); |
315 | 316 |
316 // Post a "value changed" event, but then swap out | 317 // Post a "value changed" event, but then swap out |
317 // before sending it. It shouldn't send the event while | 318 // before sending it. It shouldn't send the event while |
318 // swapped out. | 319 // swapped out. |
319 sink_->ClearMessages(); | 320 sink_->ClearMessages(); |
320 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 321 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
321 WebAXObject root_obj = document.accessibilityObject(); | 322 WebAXObject root_obj = document.accessibilityObject(); |
322 accessibility->HandleAXEvent( | 323 accessibility->HandleAXEvent( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 " <div role='group' id='A'>" | 356 " <div role='group' id='A'>" |
356 " <div role='group' id='B'>" | 357 " <div role='group' id='B'>" |
357 " <div role='group' id='C' style='visibility:visible'>" | 358 " <div role='group' id='C' style='visibility:visible'>" |
358 " </div>" | 359 " </div>" |
359 " </div>" | 360 " </div>" |
360 " </div>" | 361 " </div>" |
361 "</body>"; | 362 "</body>"; |
362 LoadHTML(html.c_str()); | 363 LoadHTML(html.c_str()); |
363 | 364 |
364 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 365 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
365 new TestRendererAccessibilityComplete(view())); | 366 new TestRendererAccessibilityComplete(frame())); |
366 accessibility->SendPendingAccessibilityEvents(); | 367 accessibility->SendPendingAccessibilityEvents(); |
367 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 368 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
368 | 369 |
369 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 370 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
370 WebAXObject root_obj = document.accessibilityObject(); | 371 WebAXObject root_obj = document.accessibilityObject(); |
371 WebAXObject node_a = root_obj.childAt(0); | 372 WebAXObject node_a = root_obj.childAt(0); |
372 WebAXObject node_b = node_a.childAt(0); | 373 WebAXObject node_b = node_a.childAt(0); |
373 WebAXObject node_c = node_b.childAt(0); | 374 WebAXObject node_c = node_b.childAt(0); |
374 | 375 |
375 // Hide node 'B' ('C' stays visible). | 376 // Hide node 'B' ('C' stays visible). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 " <div role='group' id='A'>" | 408 " <div role='group' id='A'>" |
408 " <div role='group' id='B' style='visibility:hidden'>" | 409 " <div role='group' id='B' style='visibility:hidden'>" |
409 " <div role='group' id='C' style='visibility:visible'>" | 410 " <div role='group' id='C' style='visibility:visible'>" |
410 " </div>" | 411 " </div>" |
411 " </div>" | 412 " </div>" |
412 " </div>" | 413 " </div>" |
413 "</body>"; | 414 "</body>"; |
414 LoadHTML(html.c_str()); | 415 LoadHTML(html.c_str()); |
415 | 416 |
416 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 417 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
417 new TestRendererAccessibilityComplete(view())); | 418 new TestRendererAccessibilityComplete(frame())); |
418 accessibility->SendPendingAccessibilityEvents(); | 419 accessibility->SendPendingAccessibilityEvents(); |
419 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 420 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
420 | 421 |
421 // Show node 'B', then send a childrenChanged on 'A'. | 422 // Show node 'B', then send a childrenChanged on 'A'. |
422 ExecuteJavaScript( | 423 ExecuteJavaScript( |
423 "document.getElementById('B').style.visibility = 'visible';"); | 424 "document.getElementById('B').style.visibility = 'visible';"); |
424 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); | 425 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); |
425 | 426 |
426 sink_->ClearMessages(); | 427 sink_->ClearMessages(); |
427 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 428 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
(...skipping 23 matching lines...) Expand all Loading... |
451 // proper event to the browser when an object in the tree | 452 // proper event to the browser when an object in the tree |
452 // is detached, but its children are not. This can happen when | 453 // is detached, but its children are not. This can happen when |
453 // a layout occurs and an anonymous render block is no longer needed. | 454 // a layout occurs and an anonymous render block is no longer needed. |
454 std::string html = | 455 std::string html = |
455 "<body aria-label='Body'>" | 456 "<body aria-label='Body'>" |
456 "<span>1</span><span style='display:block'>2</span>" | 457 "<span>1</span><span style='display:block'>2</span>" |
457 "</body>"; | 458 "</body>"; |
458 LoadHTML(html.c_str()); | 459 LoadHTML(html.c_str()); |
459 | 460 |
460 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 461 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
461 new TestRendererAccessibilityComplete(view())); | 462 new TestRendererAccessibilityComplete(frame())); |
462 accessibility->SendPendingAccessibilityEvents(); | 463 accessibility->SendPendingAccessibilityEvents(); |
463 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); | 464 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); |
464 | 465 |
465 // Initially, the accessibility tree looks like this: | 466 // Initially, the accessibility tree looks like this: |
466 // | 467 // |
467 // Document | 468 // Document |
468 // +--Body | 469 // +--Body |
469 // +--Anonymous Block | 470 // +--Anonymous Block |
470 // +--Static Text "1" | 471 // +--Static Text "1" |
471 // +--Inline Text Box "1" | 472 // +--Inline Text Box "1" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 520 |
520 TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) { | 521 TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) { |
521 // Test RendererAccessibilityComplete and make sure it doesn't send anything | 522 // Test RendererAccessibilityComplete and make sure it doesn't send anything |
522 // if we get a notification from Blink for an object that isn't in the | 523 // if we get a notification from Blink for an object that isn't in the |
523 // tree, like the scroll area that's the parent of the main document, | 524 // tree, like the scroll area that's the parent of the main document, |
524 // which we don't expose. | 525 // which we don't expose. |
525 std::string html = "<body><input></body>"; | 526 std::string html = "<body><input></body>"; |
526 LoadHTML(html.c_str()); | 527 LoadHTML(html.c_str()); |
527 | 528 |
528 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 529 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
529 new TestRendererAccessibilityComplete(view())); | 530 new TestRendererAccessibilityComplete(frame())); |
530 accessibility->SendPendingAccessibilityEvents(); | 531 accessibility->SendPendingAccessibilityEvents(); |
531 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 532 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
532 | 533 |
533 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 534 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
534 WebAXObject root_obj = document.accessibilityObject(); | 535 WebAXObject root_obj = document.accessibilityObject(); |
535 WebAXObject scroll_area = root_obj.parentObject(); | 536 WebAXObject scroll_area = root_obj.parentObject(); |
536 EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role()); | 537 EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role()); |
537 | 538 |
538 // Try to fire a message on the scroll area, and assert that we just | 539 // Try to fire a message on the scroll area, and assert that we just |
539 // ignore it. | 540 // ignore it. |
540 sink_->ClearMessages(); | 541 sink_->ClearMessages(); |
541 accessibility->HandleAXEvent(scroll_area, | 542 accessibility->HandleAXEvent(scroll_area, |
542 ui::AX_EVENT_VALUE_CHANGED); | 543 ui::AX_EVENT_VALUE_CHANGED); |
543 | 544 |
544 accessibility->SendPendingAccessibilityEvents(); | 545 accessibility->SendPendingAccessibilityEvents(); |
545 | 546 |
546 const IPC::Message* message = | 547 const IPC::Message* message = |
547 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); | 548 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
548 ASSERT_TRUE(message); | 549 ASSERT_TRUE(message); |
549 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; | 550 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; |
550 AccessibilityHostMsg_Events::Read(message, ¶m); | 551 AccessibilityHostMsg_Events::Read(message, ¶m); |
551 ASSERT_EQ(0U, param.a.size()); | 552 ASSERT_EQ(0U, param.a.size()); |
552 } | 553 } |
553 | 554 |
554 } // namespace content | 555 } // namespace content |
OLD | NEW |