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

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: Fix more compile errors Created 6 years, 7 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
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 WebContents* web_contents = shell_->web_contents(); 28 WebContents* web_contents = shell_->web_contents();
28 view_host_ = static_cast<RenderViewHostImpl*>( 29 frame_host_ = static_cast<RenderFrameHostImpl*>(
29 web_contents->GetRenderViewHost()); 30 web_contents->GetMainFrame());
30 view_host_->SetAccessibilityCallbackForTesting( 31 frame_host_->SetAccessibilityCallbackForTesting(
31 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, 32 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent,
32 weak_factory_.GetWeakPtr())); 33 weak_factory_.GetWeakPtr()));
33 } 34 }
34 35
35 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter( 36 AccessibilityNotificationWaiter::AccessibilityNotificationWaiter(
36 Shell* shell, 37 Shell* shell,
37 AccessibilityMode accessibility_mode, 38 AccessibilityMode accessibility_mode,
38 ui::AXEvent event_type) 39 ui::AXEvent event_type)
39 : shell_(shell), 40 : shell_(shell),
40 event_to_wait_for_(event_type), 41 event_to_wait_for_(event_type),
41 loop_runner_(new MessageLoopRunner()), 42 loop_runner_(new MessageLoopRunner()),
42 weak_factory_(this) { 43 weak_factory_(this) {
43 WebContents* web_contents = shell_->web_contents(); 44 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
44 view_host_ = static_cast<RenderViewHostImpl*>( 45 shell_->web_contents());
45 web_contents->GetRenderViewHost()); 46 frame_host_ = static_cast<RenderFrameHostImpl*>(
46 view_host_->SetAccessibilityCallbackForTesting( 47 web_contents->GetMainFrame());
48 frame_host_->SetAccessibilityCallbackForTesting(
47 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent, 49 base::Bind(&AccessibilityNotificationWaiter::OnAccessibilityEvent,
48 weak_factory_.GetWeakPtr())); 50 weak_factory_.GetWeakPtr()));
49 view_host_->AddAccessibilityMode(accessibility_mode); 51 web_contents->AddAccessibilityMode(accessibility_mode);
50 } 52 }
51 53
52 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() { 54 AccessibilityNotificationWaiter::~AccessibilityNotificationWaiter() {
53 } 55 }
54 56
55 void AccessibilityNotificationWaiter::WaitForNotification() { 57 void AccessibilityNotificationWaiter::WaitForNotification() {
56 loop_runner_->Run(); 58 loop_runner_->Run();
57 } 59 }
58 60
59 const ui::AXTree& AccessibilityNotificationWaiter::GetAXTree() const { 61 const ui::AXTree& AccessibilityNotificationWaiter::GetAXTree() const {
60 return view_host_->ax_tree_for_testing(); 62 return *frame_host_->GetAXTreeForTesting();
61 } 63 }
62 64
63 void AccessibilityNotificationWaiter::OnAccessibilityEvent( 65 void AccessibilityNotificationWaiter::OnAccessibilityEvent(
64 ui::AXEvent event_type) { 66 ui::AXEvent event_type) {
65 if (!IsAboutBlank() && (event_to_wait_for_ == ui::AX_EVENT_NONE || 67 if (!IsAboutBlank() && (event_to_wait_for_ == ui::AX_EVENT_NONE ||
66 event_to_wait_for_ == event_type)) { 68 event_to_wait_for_ == event_type)) {
67 loop_runner_->Quit(); 69 loop_runner_->Quit();
68 } 70 }
69 } 71 }
70 72
71 bool AccessibilityNotificationWaiter::IsAboutBlank() { 73 bool AccessibilityNotificationWaiter::IsAboutBlank() {
72 // Skip any accessibility notifications related to "about:blank", 74 // Skip any accessibility notifications related to "about:blank",
73 // to avoid a possible race condition between the test beginning 75 // to avoid a possible race condition between the test beginning
74 // listening for accessibility events and "about:blank" loading. 76 // listening for accessibility events and "about:blank" loading.
75 const ui::AXNodeData& root = GetAXTree().GetRoot()->data(); 77 const ui::AXNodeData& root = GetAXTree().GetRoot()->data();
76 for (size_t i = 0; i < root.string_attributes.size(); ++i) { 78 for (size_t i = 0; i < root.string_attributes.size(); ++i) {
77 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) 79 if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL)
78 continue; 80 continue;
79 const std::string& doc_url = root.string_attributes[i].second; 81 const std::string& doc_url = root.string_attributes[i].second;
80 return doc_url == kAboutBlankURL; 82 return doc_url == kAboutBlankURL;
81 } 83 }
82 return false; 84 return false;
83 } 85 }
84 86
85 } // namespace content 87 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698