Commit 334958fd authored by Nektarios Paisios's avatar Nektarios Paisios Committed by Commit Bot

Updated AccessibilityNotificationWaiter to also wait for focus events

AccessibilityNotificationWaiter is part of the accessibility browser tests infrastructure.
Focus events are fired via a different mechanism in BrowserAccessibilityManager than all other Blink-based or generated events.
In order to write effective tests that check if a focus event has been fired,
we need to modify AccessibilityNotificationWaiter to watch for focus events too.
R=aboxhall@chromium.org

Change-Id: I1e8730442cd733f51b7510592e0f9f0bc6f3c2a3
Bug: 982776
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1692104
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676140}
parent 3124cde5
...@@ -213,6 +213,7 @@ void BrowserAccessibilityManagerAndroid::FireGeneratedEvent( ...@@ -213,6 +213,7 @@ void BrowserAccessibilityManagerAndroid::FireGeneratedEvent(
case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED: case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED:
case ui::AXEventGenerator::Event::EXPANDED: case ui::AXEventGenerator::Event::EXPANDED:
case ui::AXEventGenerator::Event::ENABLED_CHANGED: case ui::AXEventGenerator::Event::ENABLED_CHANGED:
case ui::AXEventGenerator::Event::FOCUS_CHANGED:
case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED: case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED:
case ui::AXEventGenerator::Event::FLOW_TO_CHANGED: case ui::AXEventGenerator::Event::FLOW_TO_CHANGED:
case ui::AXEventGenerator::Event::GRABBED_CHANGED: case ui::AXEventGenerator::Event::GRABBED_CHANGED:
......
...@@ -383,6 +383,7 @@ void BrowserAccessibilityManagerMac::FireGeneratedEvent( ...@@ -383,6 +383,7 @@ void BrowserAccessibilityManagerMac::FireGeneratedEvent(
case ui::AXEventGenerator::Event::DOCUMENT_TITLE_CHANGED: case ui::AXEventGenerator::Event::DOCUMENT_TITLE_CHANGED:
case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED: case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED:
case ui::AXEventGenerator::Event::ENABLED_CHANGED: case ui::AXEventGenerator::Event::ENABLED_CHANGED:
case ui::AXEventGenerator::Event::FOCUS_CHANGED:
case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED: case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED:
case ui::AXEventGenerator::Event::FLOW_TO_CHANGED: case ui::AXEventGenerator::Event::FLOW_TO_CHANGED:
case ui::AXEventGenerator::Event::GRABBED_CHANGED: case ui::AXEventGenerator::Event::GRABBED_CHANGED:
......
...@@ -396,6 +396,7 @@ void BrowserAccessibilityManagerWin::FireGeneratedEvent( ...@@ -396,6 +396,7 @@ void BrowserAccessibilityManagerWin::FireGeneratedEvent(
break; break;
case ui::AXEventGenerator::Event::AUTO_COMPLETE_CHANGED: case ui::AXEventGenerator::Event::AUTO_COMPLETE_CHANGED:
case ui::AXEventGenerator::Event::DOCUMENT_TITLE_CHANGED: case ui::AXEventGenerator::Event::DOCUMENT_TITLE_CHANGED:
case ui::AXEventGenerator::Event::FOCUS_CHANGED:
case ui::AXEventGenerator::Event::LIVE_REGION_NODE_CHANGED: case ui::AXEventGenerator::Event::LIVE_REGION_NODE_CHANGED:
case ui::AXEventGenerator::Event::LOAD_START: case ui::AXEventGenerator::Event::LOAD_START:
case ui::AXEventGenerator::Event::MENU_ITEM_SELECTED: case ui::AXEventGenerator::Event::MENU_ITEM_SELECTED:
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/browser/accessibility/browser_accessibility.h"
#include "content/browser/accessibility/browser_accessibility_manager.h" #include "content/browser/accessibility/browser_accessibility_manager.h"
#include "content/browser/frame_host/render_frame_host_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/render_widget_host_view_base.h"
...@@ -151,6 +152,9 @@ void AccessibilityNotificationWaiter::BindOnGeneratedEvent( ...@@ -151,6 +152,9 @@ void AccessibilityNotificationWaiter::BindOnGeneratedEvent(
manager->SetGeneratedEventCallbackForTesting( manager->SetGeneratedEventCallbackForTesting(
base::BindRepeating(&AccessibilityNotificationWaiter::OnGeneratedEvent, base::BindRepeating(&AccessibilityNotificationWaiter::OnGeneratedEvent,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
manager->SetFocusChangeCallbackForTesting(
base::BindRepeating(&AccessibilityNotificationWaiter::OnFocusChanged,
weak_factory_.GetWeakPtr()));
} }
} }
...@@ -168,6 +172,20 @@ void AccessibilityNotificationWaiter::OnGeneratedEvent( ...@@ -168,6 +172,20 @@ void AccessibilityNotificationWaiter::OnGeneratedEvent(
} }
} }
// TODO(982776): Remove this method once we migrate to using AXEventGenerator
// for focus changed events.
void AccessibilityNotificationWaiter::OnFocusChanged() {
WebContentsImpl* web_contents_impl =
static_cast<WebContentsImpl*>(web_contents());
const BrowserAccessibilityManager* manager =
web_contents_impl->GetRootBrowserAccessibilityManager();
if (manager && manager->delegate() && manager->GetFocus()) {
OnGeneratedEvent(manager->delegate(),
ui::AXEventGenerator::Event::FOCUS_CHANGED,
manager->GetFocus()->GetId());
}
}
bool AccessibilityNotificationWaiter::IsAboutBlank() { bool AccessibilityNotificationWaiter::IsAboutBlank() {
// Skip any accessibility notifications related to "about:blank", // Skip any accessibility notifications related to "about:blank",
// to avoid a possible race condition between the test beginning // to avoid a possible race condition between the test beginning
......
...@@ -82,19 +82,25 @@ class AccessibilityNotificationWaiter : public WebContentsObserver { ...@@ -82,19 +82,25 @@ class AccessibilityNotificationWaiter : public WebContentsObserver {
// Helper to bind the OnAccessibilityEvent callback // Helper to bind the OnAccessibilityEvent callback
void BindOnAccessibilityEvent(RenderFrameHostImpl* frame_host); void BindOnAccessibilityEvent(RenderFrameHostImpl* frame_host);
// Helper to bind the OnGeneratedEvent callback
void BindOnGeneratedEvent(RenderFrameHostImpl* frame_host);
// Callback from RenderViewHostImpl. // Callback from RenderViewHostImpl.
void OnAccessibilityEvent(RenderFrameHostImpl* rfhi, void OnAccessibilityEvent(RenderFrameHostImpl* rfhi,
ax::mojom::Event event, ax::mojom::Event event,
int event_target_id); int event_target_id);
// Helper to bind the OnGeneratedEvent callback // Callback from BrowserAccessibilityManager for all generated events.
void BindOnGeneratedEvent(RenderFrameHostImpl* frame_host);
// Callback from BrowserAccessibilityManager
void OnGeneratedEvent(BrowserAccessibilityDelegate* delegate, void OnGeneratedEvent(BrowserAccessibilityDelegate* delegate,
ui::AXEventGenerator::Event event, ui::AXEventGenerator::Event event,
int event_target_id); int event_target_id);
// Callback from BrowserAccessibilityManager for the focus changed event.
//
// TODO(982776): Remove this method once we migrate to using AXEventGenerator
// for focus changed events.
void OnFocusChanged();
// Helper function to determine if the accessibility tree in // Helper function to determine if the accessibility tree in
// GetAXTree() is about the page with the url "about:blank". // GetAXTree() is about the page with the url "about:blank".
bool IsAboutBlank(); bool IsAboutBlank();
......
...@@ -198,6 +198,7 @@ api::automation::EventType ToAutomationEvent( ...@@ -198,6 +198,7 @@ api::automation::EventType ToAutomationEvent(
case ui::AXEventGenerator::Event::DESCRIPTION_CHANGED: case ui::AXEventGenerator::Event::DESCRIPTION_CHANGED:
case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED: case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED:
case ui::AXEventGenerator::Event::ENABLED_CHANGED: case ui::AXEventGenerator::Event::ENABLED_CHANGED:
case ui::AXEventGenerator::Event::FOCUS_CHANGED:
case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED: case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED:
case ui::AXEventGenerator::Event::FLOW_TO_CHANGED: case ui::AXEventGenerator::Event::FLOW_TO_CHANGED:
case ui::AXEventGenerator::Event::GRABBED_CHANGED: case ui::AXEventGenerator::Event::GRABBED_CHANGED:
......
...@@ -40,6 +40,7 @@ class AX_EXPORT AXEventGenerator : public AXTreeObserver { ...@@ -40,6 +40,7 @@ class AX_EXPORT AXEventGenerator : public AXTreeObserver {
DROPEFFECT_CHANGED, DROPEFFECT_CHANGED,
ENABLED_CHANGED, ENABLED_CHANGED,
EXPANDED, EXPANDED,
FOCUS_CHANGED,
FLOW_FROM_CHANGED, FLOW_FROM_CHANGED,
FLOW_TO_CHANGED, FLOW_TO_CHANGED,
GRABBED_CHANGED, GRABBED_CHANGED,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment