Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / views / test / focus_manager_test.cc
blob373846c7903f203a9ab8643ff9f6130a453fd871
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 #include "ui/views/test/focus_manager_test.h"
7 #include <algorithm>
9 #include "ui/views/focus/focus_manager.h"
10 #include "ui/views/widget/widget.h"
12 namespace views {
14 ////////////////////////////////////////////////////////////////////////////////
15 // FocusManagerTest, public:
17 FocusManagerTest::FocusManagerTest()
18 : contents_view_(new View),
19 focus_change_listener_(NULL),
20 widget_focus_change_listener_(NULL) {
23 FocusManagerTest::~FocusManagerTest() {
26 FocusManager* FocusManagerTest::GetFocusManager() {
27 return GetWidget()->GetFocusManager();
30 ////////////////////////////////////////////////////////////////////////////////
31 // FocusManagerTest, ViewTestBase overrides:
33 void FocusManagerTest::SetUp() {
34 ViewsTestBase::SetUp();
36 Widget* widget = new Widget;
37 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
38 params.delegate = this;
39 params.bounds = gfx::Rect(0, 0, 1024, 768);
40 widget->Init(params);
42 InitContentView();
43 widget->Show();
46 void FocusManagerTest::TearDown() {
47 if (focus_change_listener_)
48 GetFocusManager()->RemoveFocusChangeListener(focus_change_listener_);
49 if (widget_focus_change_listener_) {
50 WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(
51 widget_focus_change_listener_);
53 GetWidget()->Close();
55 // Flush the message loop to make application verifiers happy.
56 RunPendingMessages();
57 ViewsTestBase::TearDown();
60 ////////////////////////////////////////////////////////////////////////////////
61 // FocusManagerTest, WidgetDelegate implementation:
63 View* FocusManagerTest::GetContentsView() {
64 return contents_view_;
67 Widget* FocusManagerTest::GetWidget() {
68 return contents_view_->GetWidget();
71 const Widget* FocusManagerTest::GetWidget() const {
72 return contents_view_->GetWidget();
75 void FocusManagerTest::GetAccessiblePanes(std::vector<View*>* panes) {
76 std::copy(accessible_panes_.begin(), accessible_panes_.end(),
77 std::back_inserter(*panes));
80 ////////////////////////////////////////////////////////////////////////////////
81 // FocusManagerTest, protected:
83 void FocusManagerTest::InitContentView() {
86 void FocusManagerTest::AddFocusChangeListener(FocusChangeListener* listener) {
87 ASSERT_FALSE(focus_change_listener_);
88 focus_change_listener_ = listener;
89 GetFocusManager()->AddFocusChangeListener(listener);
92 void FocusManagerTest::AddWidgetFocusChangeListener(
93 WidgetFocusChangeListener* listener) {
94 ASSERT_FALSE(widget_focus_change_listener_);
95 widget_focus_change_listener_ = listener;
96 WidgetFocusManager::GetInstance()->AddFocusChangeListener(listener);
99 void FocusManagerTest::SetAccessiblePanes(const std::vector<View*>& panes) {
100 accessible_panes_ = panes;
103 ////////////////////////////////////////////////////////////////////////////////
104 // TestFocusChangeListener
106 TestFocusChangeListener::TestFocusChangeListener() {
109 TestFocusChangeListener::~TestFocusChangeListener() {
112 void TestFocusChangeListener::OnWillChangeFocus(View* focused_before,
113 View* focused_now) {
114 focus_changes_.push_back(ViewPair(focused_before, focused_now));
116 void TestFocusChangeListener::OnDidChangeFocus(View* focused_before,
117 View* focused_now) {
120 void TestFocusChangeListener::ClearFocusChanges() {
121 focus_changes_.clear();
124 ////////////////////////////////////////////////////////////////////////////////
125 // TestWidgetFocusChangeListener
127 TestWidgetFocusChangeListener::TestWidgetFocusChangeListener() {
130 TestWidgetFocusChangeListener::~TestWidgetFocusChangeListener() {
133 void TestWidgetFocusChangeListener::ClearFocusChanges() {
134 focus_changes_.clear();
137 void TestWidgetFocusChangeListener::OnNativeFocusChanged(
138 gfx::NativeView focused_now) {
139 focus_changes_.push_back(focused_now);
142 } // namespace views