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

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

Issue 651593002: Remove RendererAccessibilityFocusOnly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert patch set #4 Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/time/time.h" 6 #include "base/time/time.h"
7 #include "content/common/frame_messages.h" 7 #include "content/common/frame_messages.h"
8 #include "content/common/view_message_enums.h" 8 #include "content/common/view_message_enums.h"
9 #include "content/public/test/render_view_test.h" 9 #include "content/public/test/render_view_test.h"
10 #include "content/renderer/accessibility/renderer_accessibility_complete.h" 10 #include "content/renderer/accessibility/renderer_accessibility_complete.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return event.update.nodes.size(); 71 return event.update.nodes.size();
72 } 72 }
73 73
74 protected: 74 protected:
75 IPC::TestSink* sink_; 75 IPC::TestSink* sink_;
76 76
77 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest); 77 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest);
78 78
79 }; 79 };
80 80
81 TEST_F(RendererAccessibilityTest, EditableTextModeFocusEvents) {
82 // This is not a test of true web accessibility, it's a test of
83 // a mode used on Windows 8 in Metro mode where an extremely simplified
84 // accessibility tree containing only the current focused node is
85 // generated.
86 SetMode(AccessibilityModeEditableTextOnly);
87
88 // Set a minimum size and give focus so simulated events work.
89 view()->webwidget()->resize(blink::WebSize(500, 500));
90 view()->webwidget()->setFocus(true);
91
92 std::string html =
93 "<body>"
94 " <input>"
95 " <textarea></textarea>"
96 " <p contentEditable>Editable</p>"
97 " <div tabindex=0 role=textbox>Textbox</div>"
98 " <button>Button</button>"
99 " <a href=#>Link</a>"
100 "</body>";
101
102 // Load the test page.
103 LoadHTML(html.c_str());
104
105 // We should have sent a message to the browser with the initial focus
106 // on the document.
107 {
108 SCOPED_TRACE("Initial focus on document");
109 AccessibilityHostMsg_EventParams event;
110 GetLastAccEvent(&event);
111 EXPECT_EQ(event.event_type,
112 ui::AX_EVENT_LAYOUT_COMPLETE);
113 EXPECT_EQ(event.id, 1);
114 EXPECT_EQ(event.update.nodes.size(), 2U);
115 EXPECT_EQ(event.update.nodes[0].id, 1);
116 EXPECT_EQ(event.update.nodes[0].role,
117 ui::AX_ROLE_ROOT_WEB_AREA);
118 EXPECT_EQ(event.update.nodes[0].state,
119 (1U << ui::AX_STATE_READ_ONLY) |
120 (1U << ui::AX_STATE_FOCUSABLE) |
121 (1U << ui::AX_STATE_FOCUSED));
122 EXPECT_EQ(event.update.nodes[0].child_ids.size(), 1U);
123 }
124
125 // Now focus the input element, and check everything again.
126 {
127 SCOPED_TRACE("input");
128 sink_->ClearMessages();
129 ExecuteJavaScript("document.querySelector('input').focus();");
130 AccessibilityHostMsg_EventParams event;
131 GetLastAccEvent(&event);
132 EXPECT_EQ(event.event_type,
133 ui::AX_EVENT_FOCUS);
134 EXPECT_EQ(event.id, 3);
135 EXPECT_EQ(event.update.nodes[0].id, 1);
136 EXPECT_EQ(event.update.nodes[0].role,
137 ui::AX_ROLE_ROOT_WEB_AREA);
138 EXPECT_EQ(event.update.nodes[0].state,
139 (1U << ui::AX_STATE_READ_ONLY) |
140 (1U << ui::AX_STATE_FOCUSABLE));
141 EXPECT_EQ(event.update.nodes[0].child_ids.size(), 1U);
142 EXPECT_EQ(event.update.nodes[1].id, 3);
143 EXPECT_EQ(event.update.nodes[1].role,
144 ui::AX_ROLE_GROUP);
145 EXPECT_EQ(event.update.nodes[1].state,
146 (1U << ui::AX_STATE_FOCUSABLE) |
147 (1U << ui::AX_STATE_FOCUSED));
148 }
149
150 // Check other editable text nodes.
151 {
152 SCOPED_TRACE("textarea");
153 sink_->ClearMessages();
154 ExecuteJavaScript("document.querySelector('textarea').focus();");
155 AccessibilityHostMsg_EventParams event;
156 GetLastAccEvent(&event);
157 EXPECT_EQ(event.id, 4);
158 EXPECT_EQ(event.update.nodes[1].state,
159 (1U << ui::AX_STATE_FOCUSABLE) |
160 (1U << ui::AX_STATE_FOCUSED));
161 }
162
163 {
164 SCOPED_TRACE("contentEditable");
165 sink_->ClearMessages();
166 ExecuteJavaScript("document.querySelector('p').focus();");
167 AccessibilityHostMsg_EventParams event;
168 GetLastAccEvent(&event);
169 EXPECT_EQ(event.id, 5);
170 EXPECT_EQ(event.update.nodes[1].state,
171 (1U << ui::AX_STATE_FOCUSABLE) |
172 (1U << ui::AX_STATE_FOCUSED));
173 }
174
175 {
176 SCOPED_TRACE("role=textarea");
177 sink_->ClearMessages();
178 ExecuteJavaScript("document.querySelector('div').focus();");
179 AccessibilityHostMsg_EventParams event;
180 GetLastAccEvent(&event);
181 EXPECT_EQ(event.id, 6);
182 EXPECT_EQ(event.update.nodes[1].state,
183 (1U << ui::AX_STATE_FOCUSABLE) |
184 (1U << ui::AX_STATE_FOCUSED));
185 }
186
187 // Try focusing things that aren't editable text.
188 {
189 SCOPED_TRACE("button");
190 sink_->ClearMessages();
191 ExecuteJavaScript("document.querySelector('button').focus();");
192 AccessibilityHostMsg_EventParams event;
193 GetLastAccEvent(&event);
194 EXPECT_EQ(event.id, 7);
195 EXPECT_EQ(event.update.nodes[1].state,
196 (1U << ui::AX_STATE_FOCUSABLE) |
197 (1U << ui::AX_STATE_FOCUSED) |
198 (1U << ui::AX_STATE_READ_ONLY));
199 }
200
201 {
202 SCOPED_TRACE("link");
203 sink_->ClearMessages();
204 ExecuteJavaScript("document.querySelector('a').focus();");
205 AccessibilityHostMsg_EventParams event;
206 GetLastAccEvent(&event);
207 EXPECT_EQ(event.id, 8);
208 EXPECT_EQ(event.update.nodes[1].state,
209 (1U << ui::AX_STATE_FOCUSABLE) |
210 (1U << ui::AX_STATE_FOCUSED) |
211 (1U << ui::AX_STATE_READ_ONLY));
212 }
213
214 // Clear focus.
215 {
216 SCOPED_TRACE("Back to document.");
217 sink_->ClearMessages();
218 ExecuteJavaScript("document.activeElement.blur()");
219 AccessibilityHostMsg_EventParams event;
220 GetLastAccEvent(&event);
221 EXPECT_EQ(event.id, 1);
222 }
223 }
224
225 TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) { 81 TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) {
226 // The job of RendererAccessibilityComplete is to serialize the 82 // The job of RendererAccessibilityComplete is to serialize the
227 // accessibility tree built by WebKit and send it to the browser. 83 // accessibility tree built by WebKit and send it to the browser.
228 // When the accessibility tree changes, it tries to send only 84 // When the accessibility tree changes, it tries to send only
229 // the nodes that actually changed or were reparented. This test 85 // the nodes that actually changed or were reparented. This test
230 // ensures that the messages sent are correct in cases when a page 86 // ensures that the messages sent are correct in cases when a page
231 // reloads, and that internal state is properly garbage-collected. 87 // reloads, and that internal state is properly garbage-collected.
232 std::string html = 88 std::string html =
233 "<body>" 89 "<body>"
234 " <div role='group' id='A'>" 90 " <div role='group' id='A'>"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 405
550 const IPC::Message* message = 406 const IPC::Message* message =
551 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID); 407 sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID);
552 ASSERT_TRUE(message); 408 ASSERT_TRUE(message);
553 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param; 409 Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param;
554 AccessibilityHostMsg_Events::Read(message, &param); 410 AccessibilityHostMsg_Events::Read(message, &param);
555 ASSERT_EQ(0U, param.a.size()); 411 ASSERT_EQ(0U, param.a.size());
556 } 412 }
557 413
558 } // namespace content 414 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698