summaryrefslogtreecommitdiffstats
path: root/components/test_runner/accessibility_controller.h
blob: 8617b1077ec2ab8199b688cf985b6245c5a8ce7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_TEST_RUNNER_ACCESSIBILITY_CONTROLLER_H_
#define COMPONENTS_TEST_RUNNER_ACCESSIBILITY_CONTROLLER_H_

#include <vector>

#include "base/memory/weak_ptr.h"
#include "components/test_runner/web_ax_object_proxy.h"
#include "third_party/WebKit/public/web/WebAXObject.h"
#include "v8/include/v8.h"

namespace blink {
class WebFrame;
class WebString;
class WebView;
}

namespace test_runner {

class WebTestDelegate;

class AccessibilityController :
      public base::SupportsWeakPtr<AccessibilityController> {
 public:
  AccessibilityController();
  ~AccessibilityController();

  void Reset();
  void Install(blink::WebFrame* frame);
  void SetFocusedElement(const blink::WebAXObject&);
  bool ShouldLogAccessibilityEvents();
  void NotificationReceived(const blink::WebAXObject& target,
                            const std::string& notification_name);

  void SetDelegate(WebTestDelegate* delegate);
  void SetWebView(blink::WebView* web_view);

 private:
  friend class AccessibilityControllerBindings;

  // Bound methods and properties
  void LogAccessibilityEvents();
  void SetNotificationListener(v8::Local<v8::Function> callback);
  void UnsetNotificationListener();
  v8::Local<v8::Object> FocusedElement();
  v8::Local<v8::Object> RootElement();
  v8::Local<v8::Object> AccessibleElementById(const std::string& id);

  v8::Local<v8::Object> FindAccessibleElementByIdRecursive(
      const blink::WebAXObject&, const blink::WebString& id);

  // If true, will log all accessibility notifications.
  bool log_accessibility_events_;

  blink::WebAXObject focused_element_;
  blink::WebAXObject root_element_;

  WebAXObjectProxyList elements_;

  v8::Persistent<v8::Function> notification_callback_;

  WebTestDelegate* delegate_;
  blink::WebView* web_view_;

  base::WeakPtrFactory<AccessibilityController> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(AccessibilityController);
};

}  // namespace test_runner

#endif  // COMPONENTS_TEST_RUNNER_ACCESSIBILITY_CONTROLLER_H_