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

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager.cc

Issue 2897943003: Fix DumpAccessibilityEvents tests on Mac and improve test coverage (Closed)
Patch Set: Rebaseline one more windows test Created 3 years, 6 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 "content/browser/accessibility/browser_accessibility_manager.h" 5 #include "content/browser/accessibility/browser_accessibility_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 30 matching lines...) Expand all
41 // Map from AXTreeID to BrowserAccessibilityManager 41 // Map from AXTreeID to BrowserAccessibilityManager
42 using AXTreeIDMap = base::hash_map<ui::AXTreeIDRegistry::AXTreeID, 42 using AXTreeIDMap = base::hash_map<ui::AXTreeIDRegistry::AXTreeID,
43 BrowserAccessibilityManager*>; 43 BrowserAccessibilityManager*>;
44 base::LazyInstance<AXTreeIDMap>::DestructorAtExit g_ax_tree_id_map = 44 base::LazyInstance<AXTreeIDMap>::DestructorAtExit g_ax_tree_id_map =
45 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
46 46
47 // A function to call when focus changes, for testing only. 47 // A function to call when focus changes, for testing only.
48 base::LazyInstance<base::Closure>::DestructorAtExit 48 base::LazyInstance<base::Closure>::DestructorAtExit
49 g_focus_change_callback_for_testing = LAZY_INSTANCE_INITIALIZER; 49 g_focus_change_callback_for_testing = LAZY_INSTANCE_INITIALIZER;
50 50
51 // A flag for use in tests to ensure focus events aren't suppressed.
52 bool g_never_suppress_focus_events_for_testing = false;
53
54 } // namespace 51 } // namespace
55 52
56 ui::AXTreeUpdate MakeAXTreeUpdate( 53 ui::AXTreeUpdate MakeAXTreeUpdate(
57 const ui::AXNodeData& node1, 54 const ui::AXNodeData& node1,
58 const ui::AXNodeData& node2 /* = ui::AXNodeData() */, 55 const ui::AXNodeData& node2 /* = ui::AXNodeData() */,
59 const ui::AXNodeData& node3 /* = ui::AXNodeData() */, 56 const ui::AXNodeData& node3 /* = ui::AXNodeData() */,
60 const ui::AXNodeData& node4 /* = ui::AXNodeData() */, 57 const ui::AXNodeData& node4 /* = ui::AXNodeData() */,
61 const ui::AXNodeData& node5 /* = ui::AXNodeData() */, 58 const ui::AXNodeData& node5 /* = ui::AXNodeData() */,
62 const ui::AXNodeData& node6 /* = ui::AXNodeData() */, 59 const ui::AXNodeData& node6 /* = ui::AXNodeData() */,
63 const ui::AXNodeData& node7 /* = ui::AXNodeData() */, 60 const ui::AXNodeData& node7 /* = ui::AXNodeData() */,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (!tree_->Unserialize(initial_tree)) { 177 if (!tree_->Unserialize(initial_tree)) {
181 if (delegate_) { 178 if (delegate_) {
182 LOG(ERROR) << tree_->error(); 179 LOG(ERROR) << tree_->error();
183 delegate_->AccessibilityFatalError(); 180 delegate_->AccessibilityFatalError();
184 } else { 181 } else {
185 LOG(FATAL) << tree_->error(); 182 LOG(FATAL) << tree_->error();
186 } 183 }
187 } 184 }
188 } 185 }
189 186
187 // A flag for use in tests to ensure events aren't suppressed or delayed.
188 // static
189 bool BrowserAccessibilityManager::never_suppress_or_delay_events_for_testing_ =
190 false;
191
190 // static 192 // static
191 ui::AXTreeUpdate 193 ui::AXTreeUpdate
192 BrowserAccessibilityManager::GetEmptyDocument() { 194 BrowserAccessibilityManager::GetEmptyDocument() {
193 ui::AXNodeData empty_document; 195 ui::AXNodeData empty_document;
194 empty_document.id = 0; 196 empty_document.id = 0;
195 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; 197 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA;
196 ui::AXTreeUpdate update; 198 ui::AXTreeUpdate update;
197 update.nodes.push_back(empty_document); 199 update.nodes.push_back(empty_document);
198 return update; 200 return update;
199 } 201 }
200 202
201 void BrowserAccessibilityManager::NotifyAccessibilityEvent( 203 void BrowserAccessibilityManager::NotifyAccessibilityEvent(
202 BrowserAccessibilityEvent::Source source, 204 BrowserAccessibilityEvent::Source source,
203 ui::AXEvent event_type, 205 ui::AXEvent event_type,
204 BrowserAccessibility* node) { 206 BrowserAccessibility* node) {
205 BrowserAccessibilityEvent::Create(source, event_type, node)->Fire(); 207 BrowserAccessibilityEvent::Create(source, event_type, node)->Fire();
206 } 208 }
207 209
208 void BrowserAccessibilityManager::FireFocusEventsIfNeeded( 210 void BrowserAccessibilityManager::FireFocusEventsIfNeeded(
209 BrowserAccessibilityEvent::Source source) { 211 BrowserAccessibilityEvent::Source source) {
210 BrowserAccessibility* focus = GetFocus(); 212 BrowserAccessibility* focus = GetFocus();
211 213
212 // Don't fire focus events if the window itself doesn't have focus. 214 // Don't fire focus events if the window itself doesn't have focus.
213 // Bypass this check for some tests. 215 // Bypass this check for some tests.
214 if (!g_never_suppress_focus_events_for_testing && 216 if (!never_suppress_or_delay_events_for_testing_ &&
215 !g_focus_change_callback_for_testing.Get()) { 217 !g_focus_change_callback_for_testing.Get()) {
216 if (delegate_ && !delegate_->AccessibilityViewHasFocus()) 218 if (delegate_ && !delegate_->AccessibilityViewHasFocus())
217 focus = nullptr; 219 focus = nullptr;
218 220
219 if (!CanFireEvents()) 221 if (!CanFireEvents())
220 focus = nullptr; 222 focus = nullptr;
221 } 223 }
222 224
223 // Don't allow the document to be focused if it has no children and 225 // Don't allow the document to be focused if it has no children and
224 // hasn't finished loading yet. Wait for at least a tiny bit of content, 226 // hasn't finished loading yet. Wait for at least a tiny bit of content,
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 tree_->UpdateData(data); 612 tree_->UpdateData(data);
611 } 613 }
612 614
613 // static 615 // static
614 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting( 616 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting(
615 const base::Closure& callback) { 617 const base::Closure& callback) {
616 g_focus_change_callback_for_testing.Get() = callback; 618 g_focus_change_callback_for_testing.Get() = callback;
617 } 619 }
618 620
619 // static 621 // static
620 void BrowserAccessibilityManager::NeverSuppressFocusEventsForTesting() { 622 void BrowserAccessibilityManager::NeverSuppressOrDelayEventsForTesting() {
621 g_never_suppress_focus_events_for_testing = true; 623 never_suppress_or_delay_events_for_testing_ = true;
622 } 624 }
623 625
624 void BrowserAccessibilityManager::Decrement( 626 void BrowserAccessibilityManager::Decrement(
625 const BrowserAccessibility& node) { 627 const BrowserAccessibility& node) {
626 if (!delegate_) 628 if (!delegate_)
627 return; 629 return;
628 630
629 ui::AXActionData action_data; 631 ui::AXActionData action_data;
630 action_data.action = ui::AX_ACTION_DECREMENT; 632 action_data.action = ui::AX_ACTION_DECREMENT;
631 action_data.target_node_id = node.GetId(); 633 action_data.target_node_id = node.GetId();
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 hit_test_result = parent; 1290 hit_test_result = parent;
1289 parent = parent->PlatformGetParent(); 1291 parent = parent->PlatformGetParent();
1290 } 1292 }
1291 1293
1292 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); 1294 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id();
1293 last_hover_node_id_ = hit_test_result->GetId(); 1295 last_hover_node_id_ = hit_test_result->GetId();
1294 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); 1296 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect();
1295 } 1297 }
1296 1298
1297 } // namespace content 1299 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698