Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / views / test / focus_manager_test.h
blobd601b3fa0898fa1d04aa5ea675952052a1d53c88
1 // Copyright 2014 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.
5 #ifndef UI_VIEWS_TEST_FOCUS_MANAGER_TEST_H_
6 #define UI_VIEWS_TEST_FOCUS_MANAGER_TEST_H_
8 #include "ui/views/focus/focus_manager.h"
9 #include "ui/views/focus/widget_focus_manager.h"
10 #include "ui/views/test/views_test_base.h"
11 #include "ui/views/widget/widget_delegate.h"
13 namespace views {
15 class FocusChangeListener;
17 class FocusManagerTest : public ViewsTestBase, public WidgetDelegate {
18 public:
19 FocusManagerTest();
20 ~FocusManagerTest() override;
22 // Convenience to obtain the focus manager for the test's hosting widget.
23 FocusManager* GetFocusManager();
25 // Overridden from ViewsTestBase:
26 void SetUp() override;
27 void TearDown() override;
29 // Overridden from WidgetDelegate:
30 View* GetContentsView() override;
31 Widget* GetWidget() override;
32 const Widget* GetWidget() const override;
33 void GetAccessiblePanes(std::vector<View*>* panes) override;
35 protected:
36 // Called after the Widget is initialized and the content view is added.
37 // Override to add controls to the layout.
38 virtual void InitContentView();
40 void AddFocusChangeListener(FocusChangeListener* listener);
41 void AddWidgetFocusChangeListener(WidgetFocusChangeListener* listener);
43 // For testing FocusManager::RotatePaneFocus().
44 void SetAccessiblePanes(const std::vector<View*>& panes);
46 private:
47 View* contents_view_;
48 FocusChangeListener* focus_change_listener_;
49 WidgetFocusChangeListener* widget_focus_change_listener_;
50 std::vector<View*> accessible_panes_;
52 DISALLOW_COPY_AND_ASSIGN(FocusManagerTest);
55 typedef std::pair<View*, View*> ViewPair;
57 // Use to record focus change notifications.
58 class TestFocusChangeListener : public FocusChangeListener {
59 public:
60 TestFocusChangeListener();
61 ~TestFocusChangeListener() override;
63 const std::vector<ViewPair>& focus_changes() const { return focus_changes_; }
64 void ClearFocusChanges();
66 // Overridden from FocusChangeListener:
67 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
68 void OnDidChangeFocus(View* focused_before, View* focused_now) override;
70 private:
71 // A vector of which views lost/gained focus.
72 std::vector<ViewPair> focus_changes_;
74 DISALLOW_COPY_AND_ASSIGN(TestFocusChangeListener);
77 // Use to record widget focus change notifications.
78 class TestWidgetFocusChangeListener : public WidgetFocusChangeListener {
79 public:
80 TestWidgetFocusChangeListener();
81 ~TestWidgetFocusChangeListener() override;
83 const std::vector<gfx::NativeView>& focus_changes() const {
84 return focus_changes_;
86 void ClearFocusChanges();
88 // Overridden from WidgetFocusChangeListener:
89 void OnNativeFocusChanged(gfx::NativeView focused_now) override;
91 private:
92 // Parameter received via OnNativeFocusChanged in oldest-to-newest-received
93 // order.
94 std::vector<gfx::NativeView> focus_changes_;
96 DISALLOW_COPY_AND_ASSIGN(TestWidgetFocusChangeListener);
99 } // namespace views
101 #endif // UI_VIEWS_TEST_FOCUS_MANAGER_TEST_H_