17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file.
47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_
67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/memory/weak_ptr.h"
9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/common/accessibility_mode_enums.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/accessibility/ax_node_data.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/accessibility/ax_tree.h"
127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace content {
147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class MessageLoopRunner;
16116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass RenderFrameHostImpl;
177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class Shell;
187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Create an instance of this class *before* doing any operation that
207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// might generate an accessibility event (like a page navigation or
217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// clicking on a button). Then call WaitForNotification
227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// afterwards to block until the specified accessibility notification has been
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// received.
247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class AccessibilityNotificationWaiter {
257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public:
26effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  explicit AccessibilityNotificationWaiter(Shell* shell);
277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  AccessibilityNotificationWaiter(
287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      Shell* shell,
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      AccessibilityMode accessibility_mode,
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ui::AXEvent event);
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AccessibilityNotificationWaiter(
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      RenderFrameHostImpl* frame_host,
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci       ui::AXEvent event);
347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ~AccessibilityNotificationWaiter();
357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Blocks until the specific accessibility notification registered in
377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // AccessibilityNotificationWaiter is received. Ignores notifications for
387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // "about:blank".
397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void WaitForNotification();
407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // After WaitForNotification has returned, this will retrieve
427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // the tree of accessibility nodes received from the renderer process.
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const ui::AXTree& GetAXTree() const;
447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // After WaitForNotification returns, use this to retrieve the id of the
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // node that was the target of the event.
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int event_target_id() { return event_target_id_; }
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private:
507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Callback from RenderViewHostImpl.
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void OnAccessibilityEvent(ui::AXEvent event, int event_target_id);
527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Helper function to determine if the accessibility tree in
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // GetAXTree() is about the page with the url "about:blank".
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool IsAboutBlank();
567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderFrameHostImpl* frame_host_;
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::AXEvent event_to_wait_for_;
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_refptr<MessageLoopRunner> loop_runner_;
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int event_target_id_;
617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::WeakPtrFactory<AccessibilityNotificationWaiter> weak_factory_;
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AccessibilityNotificationWaiter);
657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)};
667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}  // namespace content
687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif  // CONTENT_TEST_ACCESSIBILITY_BROWSER_TEST_UTILS_H_
70