| 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" |
| 11 #include "content/browser/frame_host/render_frame_host_impl.h" | 11 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 12 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/view_message_enums.h" | 14 #include "content/common/view_message_enums.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
| 18 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 19 #include "ui/accessibility/ax_node.h" | 19 #include "ui/accessibility/ax_node.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter(Shell* shell) | 23 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter(Shell* shell) |
| 24 : event_to_wait_for_(ui::AX_EVENT_NONE), | 24 : shell_(shell), |
| 25 event_to_wait_for_(ui::AX_EVENT_NONE), |
| 25 loop_runner_(new MessageLoopRunner()), | 26 loop_runner_(new MessageLoopRunner()), |
| 26 weak_factory_(this), | 27 weak_factory_(this), |
| 27 event_target_id_(0) { | 28 event_target_id_(0) { |
| 28 WebContents* web_contents = shell->web_contents(); | 29 WebContents* web_contents = shell_->web_contents(); |
| 29 frame_host_ = static_cast<RenderFrameHostImpl*>( | 30 frame_host_ = static_cast<RenderFrameHostImpl*>( |
| 30 web_contents->GetMainFrame()); | 31 web_contents->GetMainFrame()); |
| 31 frame_host_->SetAccessibilityCallbackForTesting( | 32 frame_host_->SetAccessibilityCallbackForTesting( |
| 32 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, | 33 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, |
| 33 weak_factory_.GetWeakPtr())); | 34 weak_factory_.GetWeakPtr())); |
| 34 } | 35 } |
| 35 | 36 |
| 36 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter( | 37 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter( |
| 37 Shell* shell, | 38 Shell* shell, |
| 38 AccessibilityMode accessibility_mode, | 39 AccessibilityMode accessibility_mode, |
| 39 ui::AXEvent event_type) | 40 ui::AXEvent event_type) |
| 40 : event_to_wait_for_(event_type), | 41 : shell_(shell), |
| 42 event_to_wait_for_(event_type), |
| 41 loop_runner_(new MessageLoopRunner()), | 43 loop_runner_(new MessageLoopRunner()), |
| 42 weak_factory_(this), | 44 weak_factory_(this), |
| 43 event_target_id_(0) { | 45 event_target_id_(0) { |
| 44 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 46 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 45 shell->web_contents()); | 47 shell_->web_contents()); |
| 46 frame_host_ = static_cast<RenderFrameHostImpl*>( | 48 frame_host_ = static_cast<RenderFrameHostImpl*>( |
| 47 web_contents->GetMainFrame()); | 49 web_contents->GetMainFrame()); |
| 48 frame_host_->SetAccessibilityCallbackForTesting( | 50 frame_host_->SetAccessibilityCallbackForTesting( |
| 49 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, | 51 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, |
| 50 weak_factory_.GetWeakPtr())); | 52 weak_factory_.GetWeakPtr())); |
| 51 web_contents->AddAccessibilityMode(accessibility_mode); | 53 web_contents->AddAccessibilityMode(accessibility_mode); |
| 52 } | 54 } |
| 53 | 55 |
| 54 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter( | |
| 55 RenderFrameHostImpl* frame_host, | |
| 56 ui::AXEvent event_type) | |
| 57 : frame_host_(frame_host), | |
| 58 event_to_wait_for_(event_type), | |
| 59 loop_runner_(new MessageLoopRunner()), | |
| 60 weak_factory_(this), | |
| 61 event_target_id_(0) { | |
| 62 frame_host_->SetAccessibilityCallbackForTesting( | |
| 63 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, | |
| 64 weak_factory_.GetWeakPtr())); | |
| 65 } | |
| 66 | |
| 67 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() { | 56 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() { |
| 68 } | 57 } |
| 69 | 58 |
| 70 void AccessibilityNotificationWaiter::WaitForNotification() { | 59 void AccessibilityNotificationWaiter::WaitForNotification() { |
| 71 loop_runner_->Run(); | 60 loop_runner_->Run(); |
| 72 | 61 |
| 73 // Each loop runner can only be called once. Create a new one in case | 62 // Each loop runner can only be called once. Create a new one in case |
| 74 // the caller wants to call this again to wait for the next notification. | 63 // the caller wants to call this again to wait for the next notification. |
| 75 loop_runner_ = new MessageLoopRunner(); | 64 loop_runner_ = new MessageLoopRunner(); |
| 76 } | 65 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 96 for (size_t i = 0; i < root.string_attributes.size(); ++i) { | 85 for (size_t i = 0; i < root.string_attributes.size(); ++i) { |
| 97 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) | 86 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) |
| 98 continue; | 87 continue; |
| 99 const std::string& doc_url = root.string_attributes[i].second; | 88 const std::string& doc_url = root.string_attributes[i].second; |
| 100 return doc_url == url::kAboutBlankURL; | 89 return doc_url == url::kAboutBlankURL; |
| 101 } | 90 } |
| 102 return false; | 91 return false; |
| 103 } | 92 } |
| 104 | 93 |
| 105 } // namespace content | 94 } // namespace content |
| OLD | NEW |