Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Side by Side Diff: content/test/accessibility_browser_test_utils.cc

Issue 273423004: Migrate accessibility from RenderView to RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/test/accessibility_browser_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer_host/render_view_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/common/view_message_enums.h" 14 #include "content/common/view_message_enums.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
18 #include "ui/accessibility/ax_node.h" 19 #include "ui/accessibility/ax_node.h"
19 20
20 namespace content { 21 namespace content {
21 22
22 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter(Shell* shell) 23 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter(Shell* shell)
23 : shell_(shell), 24 : shell_(shell),
24 event_to_wait_for_(ui::AX_EVENT_NONE), 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 view_host_ = static_cast<RenderViewHostImpl*>( 30 frame_host_ = static_cast<RenderFrameHostImpl*>(
30 web_contents->GetRenderViewHost()); 31 web_contents->GetMainFrame());
31 view_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 : shell_(shell), 41 : shell_(shell),
41 event_to_wait_for_(event_type), 42 event_to_wait_for_(event_type),
42 loop_runner_(new MessageLoopRunner()), 43 loop_runner_(new MessageLoopRunner()),
43 weak_factory_(this), 44 weak_factory_(this),
44 event_target_id_(0) { 45 event_target_id_(0) {
45 WebContents* web_contents = shell_->web_contents(); 46 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
46 view_host_ = static_cast<RenderViewHostImpl*>( 47 shell_->web_contents());
47 web_contents->GetRenderViewHost()); 48 frame_host_ = static_cast<RenderFrameHostImpl*>(
48 view_host_->SetAccessibilityCallbackForTesting( 49 web_contents->GetMainFrame());
50 frame_host_->SetAccessibilityCallbackForTesting(
49 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, 51 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent,
50 weak_factory_.GetWeakPtr())); 52 weak_factory_.GetWeakPtr()));
51 view_host_->AddAccessibilityMode(accessibility_mode); 53 web_contents->AddAccessibilityMode(accessibility_mode);
52 } 54 }
53 55
54 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() { 56 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() {
55 } 57 }
56 58
57 void AccessibilityNotificationWaiter::WaitForNotification() { 59 void AccessibilityNotificationWaiter::WaitForNotification() {
58 loop_runner_->Run(); 60 loop_runner_->Run();
59 61
60 // 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
61 // 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.
62 loop_runner_ = new MessageLoopRunner(); 64 loop_runner_ = new MessageLoopRunner();
63 } 65 }
64 66
65 const ui::AXTree& AccessibilityNotificationWaiter::GetAXTree() const { 67 const ui::AXTree& AccessibilityNotificationWaiter::GetAXTree() const {
66 return view_host_->ax_tree_for_testing(); 68 return *frame_host_->GetAXTreeForTesting();
67 } 69 }
68 70
69 void AccessibilityNotificationWaiter::OnAccessibilityEvent( 71 void AccessibilityNotificationWaiter::OnAccessibilityEvent(
70 ui::AXEvent event_type, int event_target_id) { 72 ui::AXEvent event_type, int event_target_id) {
71 if (!IsAboutBlank() && (event_to_wait_for_ == ui::AX_EVENT_NONE || 73 if (!IsAboutBlank() && (event_to_wait_for_ == ui::AX_EVENT_NONE ||
72 event_to_wait_for_ == event_type)) { 74 event_to_wait_for_ == event_type)) {
73 event_target_id_ = event_target_id; 75 event_target_id_ = event_target_id;
74 loop_runner_->Quit(); 76 loop_runner_->Quit();
75 } 77 }
76 } 78 }
77 79
78 bool AccessibilityNotificationWaiter::IsAboutBlank() { 80 bool AccessibilityNotificationWaiter::IsAboutBlank() {
79 // Skip any accessibility notifications related to "about:blank", 81 // Skip any accessibility notifications related to "about:blank",
80 // to avoid a possible race condition between the test beginning 82 // to avoid a possible race condition between the test beginning
81 // listening for accessibility events and "about:blank" loading. 83 // listening for accessibility events and "about:blank" loading.
82 const ui::AXNodeData& root = GetAXTree().GetRoot()->data(); 84 const ui::AXNodeData& root = GetAXTree().GetRoot()->data();
83 for (size_t i = 0; i < root.string_attributes.size(); ++i) { 85 for (size_t i = 0; i < root.string_attributes.size(); ++i) {
84 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) 86 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL)
85 continue; 87 continue;
86 const std::string& doc_url = root.string_attributes[i].second; 88 const std::string& doc_url = root.string_attributes[i].second;
87 return doc_url == url::kAboutBlankURL; 89 return doc_url == url::kAboutBlankURL;
88 } 90 }
89 return false; 91 return false;
90 } 92 }
91 93
92 } // namespace content 94 } // namespace content
OLDNEW
« no previous file with comments | « content/test/accessibility_browser_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698