[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 1 | // 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 | |||||
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 10 | #include "content/common/accessibility_mode.h" |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 11 | #include "ui/accessibility/ax_node_data.h" |
12 | #include "ui/accessibility/ax_tree.h" | ||||
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 13 | |
14 | namespace content { | ||||
15 | |||||
16 | class MessageLoopRunner; | ||||
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 17 | class RenderFrameHostImpl; |
dmazzoni | 25af842 | 2016-06-28 20:29:54 | [diff] [blame] | 18 | class WebContents; |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 19 | |
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. | ||||
25 | class AccessibilityNotificationWaiter { | ||||
26 | public: | ||||
dmazzoni | 25af842 | 2016-06-28 20:29:54 | [diff] [blame] | 27 | explicit AccessibilityNotificationWaiter(WebContents* web_contents); |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 28 | AccessibilityNotificationWaiter( |
dmazzoni | 25af842 | 2016-06-28 20:29:54 | [diff] [blame] | 29 | WebContents* web_contents, |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 30 | AccessibilityMode accessibility_mode, |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 31 | ui::AXEvent event); |
dmazzoni | 0b5d248 | 2014-09-10 19:45:57 | [diff] [blame] | 32 | AccessibilityNotificationWaiter( |
33 | RenderFrameHostImpl* frame_host, | ||||
34 | ui::AXEvent event); | ||||
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 35 | ~AccessibilityNotificationWaiter(); |
36 | |||||
dmazzoni | 1efe879 | 2015-08-07 01:02:15 | [diff] [blame] | 37 | void ListenToAdditionalFrame(RenderFrameHostImpl* frame_host); |
38 | |||||
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 39 | // 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] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 46 | const ui::AXTree& GetAXTree() const; |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 47 | |
[email protected] | 3fa0901 | 2014-05-22 15:42:19 | [diff] [blame] | 48 | // After WaitForNotification returns, use this to retrieve the id of the |
49 | // node that was the target of the event. | ||||
dmazzoni | a04ec05 | 2016-04-01 08:41:08 | [diff] [blame] | 50 | 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] | 3fa0901 | 2014-05-22 15:42:19 | [diff] [blame] | 57 | |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 58 | private: |
59 | // Callback from RenderViewHostImpl. | ||||
dmazzoni | a04ec05 | 2016-04-01 08:41:08 | [diff] [blame] | 60 | void OnAccessibilityEvent(content::RenderFrameHostImpl* rfhi, |
61 | ui::AXEvent event, | ||||
62 | int event_target_id); | ||||
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 63 | |
64 | // Helper function to determine if the accessibility tree in | ||||
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 65 | // GetAXTree() is about the page with the url "about:blank". |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 66 | bool IsAboutBlank(); |
67 | |||||
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 68 | RenderFrameHostImpl* frame_host_; |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 69 | ui::AXEvent event_to_wait_for_; |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 70 | scoped_refptr<MessageLoopRunner> loop_runner_; |
[email protected] | 3fa0901 | 2014-05-22 15:42:19 | [diff] [blame] | 71 | int event_target_id_; |
dmazzoni | a04ec05 | 2016-04-01 08:41:08 | [diff] [blame] | 72 | RenderFrameHostImpl* event_render_frame_host_; |
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 73 | |
mohan.reddy | 6993ff9 | 2014-09-12 09:52:40 | [diff] [blame] | 74 | base::WeakPtrFactory<AccessibilityNotificationWaiter> weak_factory_; |
75 | |||||
[email protected] | 35ce76c | 2013-06-14 17:52:24 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(AccessibilityNotificationWaiter); |
77 | }; | ||||
78 | |||||
79 | } // namespace content | ||||
80 | |||||
81 | #endif // CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_ |