blob: 01f971bdecda9d7cf35e312c4b00ff8d8a5d3ccf [file] [log] [blame]
[email protected]35ce76c2013-06-14 17:52:241// Copyright 2013 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#ifndef CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_
6#define CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_
7
avi66a07722015-12-25 23:38:128#include "base/macros.h"
[email protected]35ce76c2013-06-14 17:52:249#include "base/memory/weak_ptr.h"
dougtcd3dad732017-03-14 03:26:2310#include "content/common/accessibility_mode.h"
[email protected]5eec2f52014-01-06 22:30:5411#include "ui/accessibility/ax_node_data.h"
12#include "ui/accessibility/ax_tree.h"
[email protected]35ce76c2013-06-14 17:52:2413
14namespace content {
15
16class MessageLoopRunner;
[email protected]95640212014-07-26 18:14:3017class RenderFrameHostImpl;
dmazzoni25af8422016-06-28 20:29:5418class WebContents;
[email protected]35ce76c2013-06-14 17:52:2419
20// Create an instance of this class *before* doing any operation that
21// might generate an accessibility event (like a page navigation or
22// clicking on a button). Then call WaitForNotification
23// afterwards to block until the specified accessibility notification has been
24// received.
25class AccessibilityNotificationWaiter {
26 public:
dmazzoni25af8422016-06-28 20:29:5427 explicit AccessibilityNotificationWaiter(WebContents* web_contents);
[email protected]35ce76c2013-06-14 17:52:2428 AccessibilityNotificationWaiter(
dmazzoni25af8422016-06-28 20:29:5429 WebContents* web_contents,
[email protected]35ce76c2013-06-14 17:52:2430 AccessibilityMode accessibility_mode,
[email protected]5eec2f52014-01-06 22:30:5431 ui::AXEvent event);
dmazzoni0b5d2482014-09-10 19:45:5732 AccessibilityNotificationWaiter(
33 RenderFrameHostImpl* frame_host,
34 ui::AXEvent event);
[email protected]35ce76c2013-06-14 17:52:2435 ~AccessibilityNotificationWaiter();
36
dmazzoni1efe8792015-08-07 01:02:1537 void ListenToAdditionalFrame(RenderFrameHostImpl* frame_host);
38
[email protected]35ce76c2013-06-14 17:52:2439 // Blocks until the specific accessibility notification registered in
40 // AccessibilityNotificationWaiter is received. Ignores notifications for
41 // "about:blank".
42 void WaitForNotification();
43
44 // After WaitForNotification has returned, this will retrieve
45 // the tree of accessibility nodes received from the renderer process.
[email protected]5eec2f52014-01-06 22:30:5446 const ui::AXTree& GetAXTree() const;
[email protected]35ce76c2013-06-14 17:52:2447
[email protected]3fa09012014-05-22 15:42:1948 // After WaitForNotification returns, use this to retrieve the id of the
49 // node that was the target of the event.
dmazzonia04ec052016-04-01 08:41:0850 int event_target_id() const { return event_target_id_; }
51
52 // After WaitForNotification returns, use this to retrieve the
53 // RenderFrameHostImpl that was the target of the event.
54 RenderFrameHostImpl* event_render_frame_host() const {
55 return event_render_frame_host_;
56 }
[email protected]3fa09012014-05-22 15:42:1957
[email protected]35ce76c2013-06-14 17:52:2458 private:
59 // Callback from RenderViewHostImpl.
dmazzonia04ec052016-04-01 08:41:0860 void OnAccessibilityEvent(content::RenderFrameHostImpl* rfhi,
61 ui::AXEvent event,
62 int event_target_id);
[email protected]35ce76c2013-06-14 17:52:2463
64 // Helper function to determine if the accessibility tree in
[email protected]5eec2f52014-01-06 22:30:5465 // GetAXTree() is about the page with the url "about:blank".
[email protected]35ce76c2013-06-14 17:52:2466 bool IsAboutBlank();
67
[email protected]95640212014-07-26 18:14:3068 RenderFrameHostImpl* frame_host_;
[email protected]5eec2f52014-01-06 22:30:5469 ui::AXEvent event_to_wait_for_;
[email protected]35ce76c2013-06-14 17:52:2470 scoped_refptr<MessageLoopRunner> loop_runner_;
[email protected]3fa09012014-05-22 15:42:1971 int event_target_id_;
dmazzonia04ec052016-04-01 08:41:0872 RenderFrameHostImpl* event_render_frame_host_;
[email protected]35ce76c2013-06-14 17:52:2473
mohan.reddy6993ff92014-09-12 09:52:4074 base::WeakPtrFactory<AccessibilityNotificationWaiter> weak_factory_;
75
[email protected]35ce76c2013-06-14 17:52:2476 DISALLOW_COPY_AND_ASSIGN(AccessibilityNotificationWaiter);
77};
78
79} // namespace content
80
81#endif // CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_