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

Side by Side Diff: content/renderer/renderer_accessibility_browsertest.cc

Issue 12226061: Move renderer accessibility to subdir and add OWNERS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 10 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "content/common/accessibility_messages.h"
7 #include "content/common/accessibility_node_data.h"
8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_view_impl.h"
10 #include "content/public/test/render_view_test.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
14
15 namespace content {
16
17 class RendererAccessibilityTest : public RenderViewTest {
18 public:
19 RendererAccessibilityTest() {}
20
21 RenderViewImpl* view() {
22 return static_cast<RenderViewImpl*>(view_);
23 }
24
25 virtual void SetUp() {
26 RenderViewTest::SetUp();
27 sink_ = &render_thread_->sink();
28 }
29
30 void SetMode(AccessibilityMode mode) {
31 view()->OnSetAccessibilityMode(mode);
32 }
33
34 void GetLastAccNotification(
35 AccessibilityHostMsg_NotificationParams* params) {
36 const IPC::Message* message =
37 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Notifications::ID);
38 ASSERT_TRUE(message);
39 Tuple1<std::vector<AccessibilityHostMsg_NotificationParams> > param;
40 AccessibilityHostMsg_Notifications::Read(message, &param);
41 ASSERT_EQ(param.a.size(), 1U);
42 *params = param.a[0];
43 }
44
45 protected:
46 IPC::TestSink* sink_;
47
48 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest);
49 };
50
51 TEST_F(RendererAccessibilityTest, EditableTextModeFocusNotifications) {
52 SetMode(AccessibilityModeEditableTextOnly);
53
54 // Set a minimum size and give focus so simulated events work.
55 view()->webwidget()->resize(WebKit::WebSize(500, 500));
56 view()->webwidget()->setFocus(true);
57
58 std::string html =
59 "<body>"
60 " <input>"
61 " <textarea></textarea>"
62 " <p contentEditable>Editable</p>"
63 " <div tabindex=0 role=textbox>Textbox</div>"
64 " <button>Button</button>"
65 " <a href=#>Link</a>"
66 "</body>";
67
68 // Load the test page.
69 LoadHTML(html.c_str());
70
71 // We should have sent a message to the browser with the initial focus
72 // on the document.
73 {
74 SCOPED_TRACE("Initial focus on document");
75 AccessibilityHostMsg_NotificationParams notification;
76 GetLastAccNotification(&notification);
77 EXPECT_EQ(notification.notification_type,
78 AccessibilityNotificationLayoutComplete);
79 EXPECT_EQ(notification.includes_children, true);
80 EXPECT_EQ(notification.id, 1);
81 EXPECT_EQ(notification.acc_tree.id, 1);
82 EXPECT_EQ(notification.acc_tree.role,
83 AccessibilityNodeData::ROLE_ROOT_WEB_AREA);
84 EXPECT_EQ(notification.acc_tree.state,
85 (1U << AccessibilityNodeData::STATE_READONLY) |
86 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
87 (1U << AccessibilityNodeData::STATE_FOCUSED));
88 EXPECT_EQ(notification.acc_tree.children.size(), 1U);
89 }
90
91 // Now focus the input element, and check everything again.
92 {
93 SCOPED_TRACE("input");
94 sink_->ClearMessages();
95 ExecuteJavaScript("document.querySelector('input').focus();");
96 AccessibilityHostMsg_NotificationParams notification;
97 GetLastAccNotification(&notification);
98 EXPECT_EQ(notification.notification_type,
99 AccessibilityNotificationFocusChanged);
100 EXPECT_EQ(notification.includes_children, true);
101 EXPECT_EQ(notification.id, 3);
102 EXPECT_EQ(notification.acc_tree.id, 1);
103 EXPECT_EQ(notification.acc_tree.role,
104 AccessibilityNodeData::ROLE_ROOT_WEB_AREA);
105 EXPECT_EQ(notification.acc_tree.state,
106 (1U << AccessibilityNodeData::STATE_READONLY) |
107 (1U << AccessibilityNodeData::STATE_FOCUSABLE));
108 EXPECT_EQ(notification.acc_tree.children.size(), 1U);
109 EXPECT_EQ(notification.acc_tree.children[0].id, 3);
110 EXPECT_EQ(notification.acc_tree.children[0].role,
111 AccessibilityNodeData::ROLE_GROUP);
112 EXPECT_EQ(notification.acc_tree.children[0].state,
113 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
114 (1U << AccessibilityNodeData::STATE_FOCUSED));
115 }
116
117 // Check other editable text nodes.
118 {
119 SCOPED_TRACE("textarea");
120 sink_->ClearMessages();
121 ExecuteJavaScript("document.querySelector('textarea').focus();");
122 AccessibilityHostMsg_NotificationParams notification;
123 GetLastAccNotification(&notification);
124 EXPECT_EQ(notification.id, 4);
125 EXPECT_EQ(notification.acc_tree.children[0].state,
126 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
127 (1U << AccessibilityNodeData::STATE_FOCUSED));
128 }
129
130 {
131 SCOPED_TRACE("contentEditable");
132 sink_->ClearMessages();
133 ExecuteJavaScript("document.querySelector('p').focus();");
134 AccessibilityHostMsg_NotificationParams notification;
135 GetLastAccNotification(&notification);
136 EXPECT_EQ(notification.id, 5);
137 EXPECT_EQ(notification.acc_tree.children[0].state,
138 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
139 (1U << AccessibilityNodeData::STATE_FOCUSED));
140 }
141
142 {
143 SCOPED_TRACE("role=textarea");
144 sink_->ClearMessages();
145 ExecuteJavaScript("document.querySelector('div').focus();");
146 AccessibilityHostMsg_NotificationParams notification;
147 GetLastAccNotification(&notification);
148 EXPECT_EQ(notification.id, 6);
149 EXPECT_EQ(notification.acc_tree.children[0].state,
150 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
151 (1U << AccessibilityNodeData::STATE_FOCUSED));
152 }
153
154 // Try focusing things that aren't editable text.
155 {
156 SCOPED_TRACE("button");
157 sink_->ClearMessages();
158 ExecuteJavaScript("document.querySelector('button').focus();");
159 AccessibilityHostMsg_NotificationParams notification;
160 GetLastAccNotification(&notification);
161 EXPECT_EQ(notification.id, 7);
162 EXPECT_EQ(notification.acc_tree.children[0].state,
163 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
164 (1U << AccessibilityNodeData::STATE_FOCUSED) |
165 (1U << AccessibilityNodeData::STATE_READONLY));
166 }
167
168 {
169 SCOPED_TRACE("link");
170 sink_->ClearMessages();
171 ExecuteJavaScript("document.querySelector('a').focus();");
172 AccessibilityHostMsg_NotificationParams notification;
173 GetLastAccNotification(&notification);
174 EXPECT_EQ(notification.id, 8);
175 EXPECT_EQ(notification.acc_tree.children[0].state,
176 (1U << AccessibilityNodeData::STATE_FOCUSABLE) |
177 (1U << AccessibilityNodeData::STATE_FOCUSED) |
178 (1U << AccessibilityNodeData::STATE_READONLY));
179 }
180
181 // Clear focus.
182 {
183 SCOPED_TRACE("Back to document.");
184 sink_->ClearMessages();
185 ExecuteJavaScript("document.activeElement.blur()");
186 AccessibilityHostMsg_NotificationParams notification;
187 GetLastAccNotification(&notification);
188 EXPECT_EQ(notification.id, 1);
189 }
190 }
191
192 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/renderer_accessibility.cc ('k') | content/renderer/renderer_accessibility_complete.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698