Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: views/accessible_pane_view_unittest.cc

Issue 8771006: views: Move the remaining file from views/ to ui/views/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/accessible_pane_view.cc ('k') | views/background.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include "views/accessible_pane_view.h"
6
7 #include "ui/base/accelerators/accelerator.h"
8 #include "ui/views/controls/button/text_button.h"
9 #include "ui/views/layout/fill_layout.h"
10 #include "ui/views/test/views_test_base.h"
11 #include "ui/views/widget/widget.h"
12
13 namespace views {
14
15 // TODO(alicet): bring pane rotation into views and add tests.
16 // See browser_view.cc for details.
17
18 typedef ViewsTestBase AccessiblePaneViewTest;
19
20 class TestBarView : public AccessiblePaneView,
21 public ButtonListener {
22 public:
23 TestBarView();
24 virtual ~TestBarView();
25
26 virtual void ButtonPressed(Button* sender,
27 const views::Event& event) OVERRIDE;
28 TextButton* child_button() const { return child_button_.get(); }
29 TextButton* second_child_button() const { return second_child_button_.get(); }
30 TextButton* third_child_button() const { return third_child_button_.get(); }
31 TextButton* not_child_button() const { return not_child_button_.get(); }
32
33 const ui::Accelerator& home_key() const { return home_key_; }
34 const ui::Accelerator& end_key() const { return end_key_; }
35 const ui::Accelerator& escape_key() const { return escape_key_; }
36 const ui::Accelerator& left_key() const { return left_key_; }
37 const ui::Accelerator& right_key() const { return right_key_; }
38
39 virtual View* GetDefaultFocusableChild() OVERRIDE;
40
41 private:
42 void Init();
43
44 scoped_ptr<TextButton> child_button_;
45 scoped_ptr<TextButton> second_child_button_;
46 scoped_ptr<TextButton> third_child_button_;
47 scoped_ptr<TextButton> not_child_button_;
48
49 DISALLOW_COPY_AND_ASSIGN(TestBarView);
50 };
51
52 TestBarView::TestBarView() {
53 Init();
54 }
55
56 TestBarView::~TestBarView() {}
57
58 void TestBarView::ButtonPressed(views::Button* sender,
59 const views::Event& event) {}
60
61 void TestBarView::Init() {
62 SetLayoutManager(new views::FillLayout());
63 string16 label;
64 child_button_.reset(new TextButton(this, label));
65 AddChildView(child_button_.get());
66 second_child_button_.reset(new TextButton(this, label));
67 AddChildView(second_child_button_.get());
68 third_child_button_.reset(new TextButton(this, label));
69 AddChildView(third_child_button_.get());
70 not_child_button_.reset(new TextButton(this, label));
71 }
72
73 View* TestBarView::GetDefaultFocusableChild() {
74 return child_button_.get();
75 }
76
77 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) {
78 TestBarView* test_view = new TestBarView();
79 scoped_ptr<Widget> widget(new Widget());
80 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
81 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
82 params.bounds = gfx::Rect(50, 50, 650, 650);
83 widget->Init(params);
84 View* root = widget->GetRootView();
85 root->AddChildView(test_view);
86 widget->Show();
87
88 // Set pane focus succeeds, focus on child.
89 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault());
90 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable());
91 EXPECT_EQ(test_view->child_button(),
92 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
93
94 // Set focus on non child view, focus failed, stays on pane.
95 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button()));
96 EXPECT_FALSE(test_view->not_child_button() ==
97 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
98 EXPECT_EQ(test_view->child_button(),
99 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
100 widget->CloseNow();
101 widget.reset();
102 }
103
104 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) {
105 TestBarView* test_view = new TestBarView();
106 TestBarView* test_view_2 = new TestBarView();
107 scoped_ptr<Widget> widget(new Widget());
108 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
109 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
110 params.bounds = gfx::Rect(50, 50, 650, 650);
111 widget->Init(params);
112 View* root = widget->GetRootView();
113 root->AddChildView(test_view);
114 root->AddChildView(test_view_2);
115 widget->Show();
116
117 // Set pane focus succeeds, focus on child.
118 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault());
119 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable());
120 EXPECT_EQ(test_view->child_button(),
121 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
122
123 // Set focus on another test_view, focus move to that pane.
124 EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button()));
125 EXPECT_FALSE(test_view->child_button() ==
126 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
127 EXPECT_EQ(test_view_2->second_child_button(),
128 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
129 widget->CloseNow();
130 widget.reset();
131 }
132
133 TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) {
134 TestBarView* test_view = new TestBarView();
135 TestBarView* original_test_view = new TestBarView();
136 scoped_ptr<Widget> widget(new Widget());
137 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
138 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
139 params.bounds = gfx::Rect(50, 50, 650, 650);
140 widget->Init(params);
141 View* root = widget->GetRootView();
142 root->AddChildView(original_test_view);
143 root->AddChildView(test_view);
144 widget->Show();
145
146 // Set pane focus on first view.
147 EXPECT_TRUE(original_test_view->SetPaneFocus(
148 original_test_view->third_child_button()));
149
150 // Test travesal in second view.
151 // Set pane focus on second child.
152 EXPECT_TRUE(test_view->SetPaneFocus(test_view->second_child_button()));
153 // home
154 test_view->AcceleratorPressed(test_view->home_key());
155 EXPECT_EQ(test_view->child_button(),
156 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
157 // end
158 test_view->AcceleratorPressed(test_view->end_key());
159 EXPECT_EQ(test_view->third_child_button(),
160 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
161 // left
162 test_view->AcceleratorPressed(test_view->left_key());
163 EXPECT_EQ(test_view->second_child_button(),
164 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
165 // right, right
166 test_view->AcceleratorPressed(test_view->right_key());
167 test_view->AcceleratorPressed(test_view->right_key());
168 EXPECT_EQ(test_view->child_button(),
169 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
170
171 // ESC
172 test_view->AcceleratorPressed(test_view->escape_key());
173 EXPECT_EQ(original_test_view->third_child_button(),
174 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
175 widget->CloseNow();
176 widget.reset();
177 }
178 } // namespace views
OLDNEW
« no previous file with comments | « views/accessible_pane_view.cc ('k') | views/background.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698