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