| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/test/accessibility_browser_test_utils.h" | 5 #include "content/test/accessibility_browser_test_utils.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, | 49 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, |
| 50 weak_factory_.GetWeakPtr())); | 50 weak_factory_.GetWeakPtr())); |
| 51 view_host_->AddAccessibilityMode(accessibility_mode); | 51 view_host_->AddAccessibilityMode(accessibility_mode); |
| 52 } | 52 } |
| 53 | 53 |
| 54 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() { | 54 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() { |
| 55 } | 55 } |
| 56 | 56 |
| 57 void AccessibilityNotificationWaiter::WaitForNotification() { | 57 void AccessibilityNotificationWaiter::WaitForNotification() { |
| 58 loop_runner_->Run(); | 58 loop_runner_->Run(); |
| 59 |
| 60 // Each loop runner can only be called once. Create a new one in case |
| 61 // the caller wants to call this again to wait for the next notification. |
| 62 loop_runner_ = new MessageLoopRunner(); |
| 59 } | 63 } |
| 60 | 64 |
| 61 const ui::AXTree& AccessibilityNotificationWaiter::GetAXTree() const { | 65 const ui::AXTree& AccessibilityNotificationWaiter::GetAXTree() const { |
| 62 return view_host_->ax_tree_for_testing(); | 66 return view_host_->ax_tree_for_testing(); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void AccessibilityNotificationWaiter::OnAccessibilityEvent( | 69 void AccessibilityNotificationWaiter::OnAccessibilityEvent( |
| 66 ui::AXEvent event_type, int event_target_id) { | 70 ui::AXEvent event_type, int event_target_id) { |
| 67 if (!IsAboutBlank() && (event_to_wait_for_ == ui::AX_EVENT_NONE || | 71 if (!IsAboutBlank() && (event_to_wait_for_ == ui::AX_EVENT_NONE || |
| 68 event_to_wait_for_ == event_type)) { | 72 event_to_wait_for_ == event_type)) { |
| 69 event_target_id_ = event_target_id; | 73 event_target_id_ = event_target_id; |
| 70 loop_runner_->Quit(); | 74 loop_runner_->Quit(); |
| 71 } | 75 } |
| 72 } | 76 } |
| 73 | 77 |
| 74 bool AccessibilityNotificationWaiter::IsAboutBlank() { | 78 bool AccessibilityNotificationWaiter::IsAboutBlank() { |
| 75 // Skip any accessibility notifications related to "about:blank", | 79 // Skip any accessibility notifications related to "about:blank", |
| 76 // to avoid a possible race condition between the test beginning | 80 // to avoid a possible race condition between the test beginning |
| 77 // listening for accessibility events and "about:blank" loading. | 81 // listening for accessibility events and "about:blank" loading. |
| 78 const ui::AXNodeData& root = GetAXTree().GetRoot()->data(); | 82 const ui::AXNodeData& root = GetAXTree().GetRoot()->data(); |
| 79 for (size_t i = 0; i < root.string_attributes.size(); ++i) { | 83 for (size_t i = 0; i < root.string_attributes.size(); ++i) { |
| 80 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) | 84 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) |
| 81 continue; | 85 continue; |
| 82 const std::string& doc_url = root.string_attributes[i].second; | 86 const std::string& doc_url = root.string_attributes[i].second; |
| 83 return doc_url == url::kAboutBlankURL; | 87 return doc_url == url::kAboutBlankURL; |
| 84 } | 88 } |
| 85 return false; | 89 return false; |
| 86 } | 90 } |
| 87 | 91 |
| 88 } // namespace content | 92 } // namespace content |
| OLD | NEW |