| 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 "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_complete.h" |
| 11 #include "content/renderer/render_frame_impl.h" | |
| 12 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/public/platform/WebSize.h" | 13 #include "third_party/WebKit/public/platform/WebSize.h" |
| 15 #include "third_party/WebKit/public/web/WebAXObject.h" | 14 #include "third_party/WebKit/public/web/WebAXObject.h" |
| 16 #include "third_party/WebKit/public/web/WebDocument.h" | 15 #include "third_party/WebKit/public/web/WebDocument.h" |
| 17 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
| 18 #include "ui/accessibility/ax_node_data.h" | 17 #include "ui/accessibility/ax_node_data.h" |
| 19 | 18 |
| 20 using blink::WebAXObject; | 19 using blink::WebAXObject; |
| 21 using blink::WebDocument; | 20 using blink::WebDocument; |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 | 23 |
| 25 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { | 24 class TestRendererAccessibilityComplete : public RendererAccessibilityComplete { |
| 26 public: | 25 public: |
| 27 explicit TestRendererAccessibilityComplete(RenderFrameImpl* render_frame) | 26 explicit TestRendererAccessibilityComplete(RenderViewImpl* render_view) |
| 28 : RendererAccessibilityComplete(render_frame) { | 27 : RendererAccessibilityComplete(render_view) { |
| 29 } | 28 } |
| 30 | 29 |
| 31 void SendPendingAccessibilityEvents() { | 30 void SendPendingAccessibilityEvents() { |
| 32 RendererAccessibilityComplete::SendPendingAccessibilityEvents(); | 31 RendererAccessibilityComplete::SendPendingAccessibilityEvents(); |
| 33 } | 32 } |
| 34 }; | 33 }; |
| 35 | 34 |
| 36 class RendererAccessibilityTest : public RenderViewTest { | 35 class RendererAccessibilityTest : public RenderViewTest { |
| 37 public: | 36 public: |
| 38 RendererAccessibilityTest() {} | 37 RendererAccessibilityTest() {} |
| 39 | 38 |
| 40 RenderViewImpl* view() { | 39 RenderViewImpl* view() { |
| 41 return static_cast<RenderViewImpl*>(view_); | 40 return static_cast<RenderViewImpl*>(view_); |
| 42 } | 41 } |
| 43 | 42 |
| 44 RenderFrameImpl* frame() { | 43 RenderFrameImpl* frame() { |
| 45 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); | 44 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); |
| 46 } | 45 } |
| 47 | 46 |
| 48 virtual void SetUp() { | 47 virtual void SetUp() { |
| 49 RenderViewTest::SetUp(); | 48 RenderViewTest::SetUp(); |
| 50 sink_ = &render_thread_->sink(); | 49 sink_ = &render_thread_->sink(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void SetMode(AccessibilityMode mode) { | 52 void SetMode(AccessibilityMode mode) { |
| 54 frame()->OnSetAccessibilityMode(mode); | 53 view()->OnSetAccessibilityMode(mode); |
| 55 } | 54 } |
| 56 | 55 |
| 57 void GetLastAccEvent( | 56 void GetLastAccEvent( |
| 58 AccessibilityHostMsg_EventParams* params) { | 57 AccessibilityHostMsg_EventParams* params) { |
| 59 const IPC::Message* message = | 58 const IPC::Message* message = |
| 60 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); | 59 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
| 61 ASSERT_TRUE(message); | 60 ASSERT_TRUE(message); |
| 62 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; | 61 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; |
| 63 AccessibilityHostMsg_Events::Read(message, ¶m); | 62 AccessibilityHostMsg_Events::Read(message, ¶m); |
| 64 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... |
| 234 " <div role='group' id='A'>" | 233 " <div role='group' id='A'>" |
| 235 " <div role='group' id='A1'></div>" | 234 " <div role='group' id='A1'></div>" |
| 236 " <div role='group' id='A2'></div>" | 235 " <div role='group' id='A2'></div>" |
| 237 " </div>" | 236 " </div>" |
| 238 "</body>"; | 237 "</body>"; |
| 239 LoadHTML(html.c_str()); | 238 LoadHTML(html.c_str()); |
| 240 | 239 |
| 241 // Creating a RendererAccessibilityComplete should sent the tree | 240 // Creating a RendererAccessibilityComplete should sent the tree |
| 242 // to the browser. | 241 // to the browser. |
| 243 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 242 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
| 244 new TestRendererAccessibilityComplete(frame())); | 243 new TestRendererAccessibilityComplete(view())); |
| 245 accessibility->SendPendingAccessibilityEvents(); | 244 accessibility->SendPendingAccessibilityEvents(); |
| 246 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 245 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
| 247 | 246 |
| 248 // If we post another event but the tree doesn't change, | 247 // If we post another event but the tree doesn't change, |
| 249 // we should only send 1 node to the browser. | 248 // we should only send 1 node to the browser. |
| 250 sink_->ClearMessages(); | 249 sink_->ClearMessages(); |
| 251 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 250 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| 252 WebAXObject root_obj = document.accessibilityObject(); | 251 WebAXObject root_obj = document.accessibilityObject(); |
| 253 accessibility->HandleAXEvent( | 252 accessibility->HandleAXEvent( |
| 254 root_obj, | 253 root_obj, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 std::string html = | 303 std::string html = |
| 305 "<body>" | 304 "<body>" |
| 306 " <p>Hello, world.</p>" | 305 " <p>Hello, world.</p>" |
| 307 "</body>"; | 306 "</body>"; |
| 308 LoadHTML(html.c_str()); | 307 LoadHTML(html.c_str()); |
| 309 static const int kProxyRoutingId = 13; | 308 static const int kProxyRoutingId = 13; |
| 310 | 309 |
| 311 // Creating a RendererAccessibilityComplete should send the tree | 310 // Creating a RendererAccessibilityComplete should send the tree |
| 312 // to the browser. | 311 // to the browser. |
| 313 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 312 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
| 314 new TestRendererAccessibilityComplete(frame())); | 313 new TestRendererAccessibilityComplete(view())); |
| 315 accessibility->SendPendingAccessibilityEvents(); | 314 accessibility->SendPendingAccessibilityEvents(); |
| 316 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); | 315 EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser()); |
| 317 | 316 |
| 318 // Post a "value changed" event, but then swap out | 317 // Post a "value changed" event, but then swap out |
| 319 // before sending it. It shouldn't send the event while | 318 // before sending it. It shouldn't send the event while |
| 320 // swapped out. | 319 // swapped out. |
| 321 sink_->ClearMessages(); | 320 sink_->ClearMessages(); |
| 322 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 321 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| 323 WebAXObject root_obj = document.accessibilityObject(); | 322 WebAXObject root_obj = document.accessibilityObject(); |
| 324 accessibility->HandleAXEvent( | 323 accessibility->HandleAXEvent( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 " <div role='group' id='A'>" | 357 " <div role='group' id='A'>" |
| 359 " <div role='group' id='B'>" | 358 " <div role='group' id='B'>" |
| 360 " <div role='group' id='C' style='visibility:visible'>" | 359 " <div role='group' id='C' style='visibility:visible'>" |
| 361 " </div>" | 360 " </div>" |
| 362 " </div>" | 361 " </div>" |
| 363 " </div>" | 362 " </div>" |
| 364 "</body>"; | 363 "</body>"; |
| 365 LoadHTML(html.c_str()); | 364 LoadHTML(html.c_str()); |
| 366 | 365 |
| 367 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 366 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
| 368 new TestRendererAccessibilityComplete(frame())); | 367 new TestRendererAccessibilityComplete(view())); |
| 369 accessibility->SendPendingAccessibilityEvents(); | 368 accessibility->SendPendingAccessibilityEvents(); |
| 370 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 369 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
| 371 | 370 |
| 372 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 371 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| 373 WebAXObject root_obj = document.accessibilityObject(); | 372 WebAXObject root_obj = document.accessibilityObject(); |
| 374 WebAXObject node_a = root_obj.childAt(0); | 373 WebAXObject node_a = root_obj.childAt(0); |
| 375 WebAXObject node_b = node_a.childAt(0); | 374 WebAXObject node_b = node_a.childAt(0); |
| 376 WebAXObject node_c = node_b.childAt(0); | 375 WebAXObject node_c = node_b.childAt(0); |
| 377 | 376 |
| 378 // Hide node 'B' ('C' stays visible). | 377 // Hide node 'B' ('C' stays visible). |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 " <div role='group' id='A'>" | 409 " <div role='group' id='A'>" |
| 411 " <div role='group' id='B' style='visibility:hidden'>" | 410 " <div role='group' id='B' style='visibility:hidden'>" |
| 412 " <div role='group' id='C' style='visibility:visible'>" | 411 " <div role='group' id='C' style='visibility:visible'>" |
| 413 " </div>" | 412 " </div>" |
| 414 " </div>" | 413 " </div>" |
| 415 " </div>" | 414 " </div>" |
| 416 "</body>"; | 415 "</body>"; |
| 417 LoadHTML(html.c_str()); | 416 LoadHTML(html.c_str()); |
| 418 | 417 |
| 419 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 418 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
| 420 new TestRendererAccessibilityComplete(frame())); | 419 new TestRendererAccessibilityComplete(view())); |
| 421 accessibility->SendPendingAccessibilityEvents(); | 420 accessibility->SendPendingAccessibilityEvents(); |
| 422 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 421 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
| 423 | 422 |
| 424 // Show node 'B', then send a childrenChanged on 'A'. | 423 // Show node 'B', then send a childrenChanged on 'A'. |
| 425 ExecuteJavaScript( | 424 ExecuteJavaScript( |
| 426 "document.getElementById('B').style.visibility = 'visible';"); | 425 "document.getElementById('B').style.visibility = 'visible';"); |
| 427 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); | 426 ExecuteJavaScript("document.getElementById('B').offsetLeft;"); |
| 428 | 427 |
| 429 sink_->ClearMessages(); | 428 sink_->ClearMessages(); |
| 430 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 429 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 454 // proper event to the browser when an object in the tree | 453 // proper event to the browser when an object in the tree |
| 455 // is detached, but its children are not. This can happen when | 454 // is detached, but its children are not. This can happen when |
| 456 // a layout occurs and an anonymous render block is no longer needed. | 455 // a layout occurs and an anonymous render block is no longer needed. |
| 457 std::string html = | 456 std::string html = |
| 458 "<body aria-label='Body'>" | 457 "<body aria-label='Body'>" |
| 459 "<span>1</span><span style='display:block'>2</span>" | 458 "<span>1</span><span style='display:block'>2</span>" |
| 460 "</body>"; | 459 "</body>"; |
| 461 LoadHTML(html.c_str()); | 460 LoadHTML(html.c_str()); |
| 462 | 461 |
| 463 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 462 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
| 464 new TestRendererAccessibilityComplete(frame())); | 463 new TestRendererAccessibilityComplete(view())); |
| 465 accessibility->SendPendingAccessibilityEvents(); | 464 accessibility->SendPendingAccessibilityEvents(); |
| 466 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); | 465 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); |
| 467 | 466 |
| 468 // Initially, the accessibility tree looks like this: | 467 // Initially, the accessibility tree looks like this: |
| 469 // | 468 // |
| 470 // Document | 469 // Document |
| 471 // +--Body | 470 // +--Body |
| 472 // +--Anonymous Block | 471 // +--Anonymous Block |
| 473 // +--Static Text "1" | 472 // +--Static Text "1" |
| 474 // +--Inline Text Box "1" | 473 // +--Inline Text Box "1" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 521 |
| 523 TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) { | 522 TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) { |
| 524 // Test RendererAccessibilityComplete and make sure it doesn't send anything | 523 // Test RendererAccessibilityComplete and make sure it doesn't send anything |
| 525 // if we get a notification from Blink for an object that isn't in the | 524 // if we get a notification from Blink for an object that isn't in the |
| 526 // tree, like the scroll area that's the parent of the main document, | 525 // tree, like the scroll area that's the parent of the main document, |
| 527 // which we don't expose. | 526 // which we don't expose. |
| 528 std::string html = "<body><input></body>"; | 527 std::string html = "<body><input></body>"; |
| 529 LoadHTML(html.c_str()); | 528 LoadHTML(html.c_str()); |
| 530 | 529 |
| 531 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | 530 scoped_ptr<TestRendererAccessibilityComplete> accessibility( |
| 532 new TestRendererAccessibilityComplete(frame())); | 531 new TestRendererAccessibilityComplete(view())); |
| 533 accessibility->SendPendingAccessibilityEvents(); | 532 accessibility->SendPendingAccessibilityEvents(); |
| 534 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 533 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
| 535 | 534 |
| 536 WebDocument document = view()->GetWebView()->mainFrame()->document(); | 535 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| 537 WebAXObject root_obj = document.accessibilityObject(); | 536 WebAXObject root_obj = document.accessibilityObject(); |
| 538 WebAXObject scroll_area = root_obj.parentObject(); | 537 WebAXObject scroll_area = root_obj.parentObject(); |
| 539 EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role()); | 538 EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role()); |
| 540 | 539 |
| 541 // Try to fire a message on the scroll area, and assert that we just | 540 // Try to fire a message on the scroll area, and assert that we just |
| 542 // ignore it. | 541 // ignore it. |
| 543 sink_->ClearMessages(); | 542 sink_->ClearMessages(); |
| 544 accessibility->HandleAXEvent(scroll_area, | 543 accessibility->HandleAXEvent(scroll_area, |
| 545 ui::AX_EVENT_VALUE_CHANGED); | 544 ui::AX_EVENT_VALUE_CHANGED); |
| 546 | 545 |
| 547 accessibility->SendPendingAccessibilityEvents(); | 546 accessibility->SendPendingAccessibilityEvents(); |
| 548 | 547 |
| 549 const IPC::Message* message = | 548 const IPC::Message* message = |
| 550 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); | 549 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
| 551 ASSERT_TRUE(message); | 550 ASSERT_TRUE(message); |
| 552 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; | 551 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; |
| 553 AccessibilityHostMsg_Events::Read(message, ¶m); | 552 AccessibilityHostMsg_Events::Read(message, ¶m); |
| 554 ASSERT_EQ(0U, param.a.size()); | 553 ASSERT_EQ(0U, param.a.size()); |
| 555 } | 554 } |
| 556 | 555 |
| 557 } // namespace content | 556 } // namespace content |
| OLD | NEW |