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/accessibility_messages.h" | 7 #include "content/common/accessibility_messages.h" |
8 #include "content/common/frame_messages.h" | 8 #include "content/common/frame_messages.h" |
9 #include "content/common/site_isolation_policy.h" | 9 #include "content/common/site_isolation_policy.h" |
10 #include "content/common/view_message_enums.h" | 10 #include "content/common/view_message_enums.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // http://crbug.com/328552 | 59 // http://crbug.com/328552 |
60 __lsan_do_leak_check(); | 60 __lsan_do_leak_check(); |
61 #endif | 61 #endif |
62 RenderViewTest::TearDown(); | 62 RenderViewTest::TearDown(); |
63 } | 63 } |
64 | 64 |
65 void SetMode(AccessibilityMode mode) { | 65 void SetMode(AccessibilityMode mode) { |
66 frame()->OnSetAccessibilityMode(mode); | 66 frame()->OnSetAccessibilityMode(mode); |
67 } | 67 } |
68 | 68 |
69 void GetLastAccEvent( | 69 void GetAllAccEvents( |
70 AccessibilityHostMsg_EventParams* params) { | 70 std::vector<AccessibilityHostMsg_EventParams>* param_list) { |
71 const IPC::Message* message = | 71 const IPC::Message* message = |
72 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); | 72 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
73 ASSERT_TRUE(message); | 73 ASSERT_TRUE(message); |
74 base::Tuple<std::vector<AccessibilityHostMsg_EventParams>, int> param; | 74 base::Tuple<std::vector<AccessibilityHostMsg_EventParams>, int> param; |
75 AccessibilityHostMsg_Events::Read(message, ¶m); | 75 AccessibilityHostMsg_Events::Read(message, ¶m); |
76 ASSERT_GE(base::get<0>(param).size(), 1U); | 76 *param_list = base::get<0>(param); |
77 *params = base::get<0>(param)[0]; | 77 } |
| 78 |
| 79 void GetLastAccEvent( |
| 80 AccessibilityHostMsg_EventParams* params) { |
| 81 std::vector<AccessibilityHostMsg_EventParams> param_list; |
| 82 GetAllAccEvents(¶m_list); |
| 83 ASSERT_GE(param_list.size(), 1U); |
| 84 *params = param_list[0]; |
78 } | 85 } |
79 | 86 |
80 int CountAccessibilityNodesSentToBrowser() { | 87 int CountAccessibilityNodesSentToBrowser() { |
81 AccessibilityHostMsg_EventParams event; | 88 AccessibilityHostMsg_EventParams event; |
82 GetLastAccEvent(&event); | 89 GetLastAccEvent(&event); |
83 return event.update.nodes.size(); | 90 return event.update.nodes.size(); |
84 } | 91 } |
85 | 92 |
86 protected: | 93 protected: |
87 IPC::TestSink* sink_; | 94 IPC::TestSink* sink_; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 accessibility->SendPendingAccessibilityEvents(); | 428 accessibility->SendPendingAccessibilityEvents(); |
422 | 429 |
423 const IPC::Message* message = | 430 const IPC::Message* message = |
424 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); | 431 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); |
425 ASSERT_TRUE(message); | 432 ASSERT_TRUE(message); |
426 base::Tuple<std::vector<AccessibilityHostMsg_EventParams>, int> param; | 433 base::Tuple<std::vector<AccessibilityHostMsg_EventParams>, int> param; |
427 AccessibilityHostMsg_Events::Read(message, ¶m); | 434 AccessibilityHostMsg_Events::Read(message, ¶m); |
428 ASSERT_EQ(0U, base::get<0>(param).size()); | 435 ASSERT_EQ(0U, base::get<0>(param).size()); |
429 } | 436 } |
430 | 437 |
| 438 TEST_F(RendererAccessibilityTest, TextSelectionShouldSendRoot) { |
| 439 // A text selection change in a text field will be reflected in attributes |
| 440 // of the root node. Verify that the root node is updated as the result |
| 441 // of a text change event. |
| 442 std::string html = |
| 443 "<body>" |
| 444 " <div role='group'>" |
| 445 " <input id='input' type='text' value='hello there'>" |
| 446 " </div>" |
| 447 "</body>"; |
| 448 LoadHTML(html.c_str()); |
| 449 |
| 450 scoped_ptr<TestRendererAccessibility> accessibility( |
| 451 new TestRendererAccessibility(frame())); |
| 452 accessibility->SendPendingAccessibilityEvents(); |
| 453 sink_->ClearMessages(); |
| 454 |
| 455 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| 456 WebAXObject root_obj = document.accessibilityObject(); |
| 457 WebAXObject input_obj = |
| 458 document.getElementById("input").accessibilityObject(); |
| 459 ASSERT_EQ(blink::WebAXRoleTextField, input_obj.role()); |
| 460 ExecuteJavaScriptForTests("document.getElementById('input').focus();"); |
| 461 accessibility->HandleAXEvent( |
| 462 input_obj, |
| 463 ui::AX_EVENT_TEXT_SELECTION_CHANGED); |
| 464 accessibility->SendPendingAccessibilityEvents(); |
| 465 std::vector<AccessibilityHostMsg_EventParams> all_events; |
| 466 GetAllAccEvents(&all_events); |
| 467 EXPECT_EQ(2U, all_events.size()); |
| 468 bool had_root_update = false, had_input_update = false; |
| 469 for (auto i = all_events.begin(); i != all_events.end(); ++i) { |
| 470 ASSERT_EQ(ui::AX_EVENT_TEXT_SELECTION_CHANGED, i->event_type); |
| 471 ASSERT_EQ(1U, i->update.nodes.size()); |
| 472 if (root_obj.axID() == i->update.nodes[0].id) |
| 473 had_root_update = true; |
| 474 if (input_obj.axID() == i->update.nodes[0].id) |
| 475 had_input_update = true; |
| 476 } |
| 477 ASSERT_TRUE(had_root_update); |
| 478 ASSERT_TRUE(had_input_update); |
| 479 } |
431 } // namespace content | 480 } // namespace content |
OLD | NEW |