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

Side by Side Diff: ash/common/frame/caption_buttons/frame_caption_button_container_view_unittest.cc

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (Closed)
Patch Set: Created 3 years, 9 months 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
OLDNEW
(Empty)
1 // Copyright 2013 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 "ash/common/frame/caption_buttons/frame_caption_button_container_view.h "
6
7 #include "ash/common/ash_layout_constants.h"
8 #include "ash/common/frame/caption_buttons/frame_caption_button.h"
9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/resources/grit/ash_resources.h"
12 #include "ash/resources/vector_icons/vector_icons.h"
13 #include "ash/test/ash_test_base.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/views/widget/widget.h"
16 #include "ui/views/widget/widget_delegate.h"
17
18 namespace ash {
19
20 namespace {
21
22 class TestWidgetDelegate : public views::WidgetDelegateView {
23 public:
24 TestWidgetDelegate(bool can_maximize, bool can_minimize)
25 : can_maximize_(can_maximize), can_minimize_(can_minimize) {}
26 ~TestWidgetDelegate() override {}
27
28 bool CanMaximize() const override { return can_maximize_; }
29
30 bool CanMinimize() const override { return can_minimize_; }
31
32 private:
33 bool can_maximize_;
34 bool can_minimize_;
35
36 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
37 };
38
39 } // namespace
40
41 class FrameCaptionButtonContainerViewTest : public ash::test::AshTestBase {
42 public:
43 enum MaximizeAllowed { MAXIMIZE_ALLOWED, MAXIMIZE_DISALLOWED };
44
45 enum MinimizeAllowed { MINIMIZE_ALLOWED, MINIMIZE_DISALLOWED };
46
47 FrameCaptionButtonContainerViewTest() {}
48
49 ~FrameCaptionButtonContainerViewTest() override {}
50
51 // Creates a widget which allows maximizing based on |maximize_allowed|.
52 // The caller takes ownership of the returned widget.
53 views::Widget* CreateTestWidget(MaximizeAllowed maximize_allowed,
54 MinimizeAllowed minimize_allowed)
55 WARN_UNUSED_RESULT {
56 views::Widget* widget = new views::Widget;
57 views::Widget::InitParams params;
58 params.delegate =
59 new TestWidgetDelegate(maximize_allowed == MAXIMIZE_ALLOWED,
60 minimize_allowed == MINIMIZE_ALLOWED);
61 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
62 params.context = CurrentContext();
63 widget->Init(params);
64 return widget;
65 }
66
67 // Sets arbitrary images for the icons and assign the default caption button
68 // size to the buttons in |container|.
69 void InitContainer(FrameCaptionButtonContainerView* container) {
70 container->SetButtonSize(
71 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON));
72 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) {
73 container->SetButtonImage(static_cast<CaptionButtonIcon>(icon),
74 ash::kWindowControlCloseIcon);
75 }
76 }
77
78 // Tests that |leftmost| and |rightmost| are at |container|'s edges.
79 bool CheckButtonsAtEdges(FrameCaptionButtonContainerView* container,
80 const ash::FrameCaptionButton& leftmost,
81 const ash::FrameCaptionButton& rightmost) {
82 gfx::Rect expected(container->GetPreferredSize());
83
84 gfx::Rect container_size(container->GetPreferredSize());
85 if (leftmost.y() == rightmost.y() &&
86 leftmost.height() == rightmost.height() &&
87 leftmost.x() == expected.x() && leftmost.y() == expected.y() &&
88 leftmost.height() == expected.height() &&
89 rightmost.bounds().right() == expected.right()) {
90 return true;
91 }
92
93 LOG(ERROR) << "Buttons " << leftmost.bounds().ToString() << " "
94 << rightmost.bounds().ToString() << " not at edges of "
95 << expected.ToString();
96 return false;
97 }
98
99 private:
100 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest);
101 };
102
103 // Test how the allowed actions affect which caption buttons are visible.
104 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) {
105 // All the buttons should be visible when minimizing and maximizing are
106 // allowed.
107 FrameCaptionButtonContainerView container1(
108 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED));
109 InitContainer(&container1);
110 container1.Layout();
111 FrameCaptionButtonContainerView::TestApi t1(&container1);
112 EXPECT_TRUE(t1.minimize_button()->visible());
113 EXPECT_TRUE(t1.size_button()->visible());
114 EXPECT_TRUE(t1.close_button()->visible());
115 EXPECT_TRUE(CheckButtonsAtEdges(&container1, *t1.minimize_button(),
116 *t1.close_button()));
117
118 // The minimize button should be visible when minimizing is allowed but
119 // maximizing is disallowed.
120 FrameCaptionButtonContainerView container2(
121 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_ALLOWED));
122 InitContainer(&container2);
123 container2.Layout();
124 FrameCaptionButtonContainerView::TestApi t2(&container2);
125 EXPECT_TRUE(t2.minimize_button()->visible());
126 EXPECT_FALSE(t2.size_button()->visible());
127 EXPECT_TRUE(t2.close_button()->visible());
128 EXPECT_TRUE(CheckButtonsAtEdges(&container2, *t2.minimize_button(),
129 *t2.close_button()));
130
131 // Neither the minimize button nor the size button should be visible when
132 // neither minimizing nor maximizing are allowed.
133 FrameCaptionButtonContainerView container3(
134 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_DISALLOWED));
135 InitContainer(&container3);
136 container3.Layout();
137 FrameCaptionButtonContainerView::TestApi t3(&container3);
138 EXPECT_FALSE(t3.minimize_button()->visible());
139 EXPECT_FALSE(t3.size_button()->visible());
140 EXPECT_TRUE(t3.close_button()->visible());
141 EXPECT_TRUE(
142 CheckButtonsAtEdges(&container3, *t3.close_button(), *t3.close_button()));
143 }
144
145 // Tests that the layout animations trigered by button visibility result in the
146 // correct placement of the buttons.
147 TEST_F(FrameCaptionButtonContainerViewTest,
148 TestUpdateSizeButtonVisibilityAnimation) {
149 FrameCaptionButtonContainerView container(
150 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED));
151 InitContainer(&container);
152 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize()));
153 container.Layout();
154
155 FrameCaptionButtonContainerView::TestApi test(&container);
156 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds();
157 gfx::Rect initial_size_button_bounds = test.size_button()->bounds();
158 gfx::Rect initial_close_button_bounds = test.close_button()->bounds();
159 gfx::Rect initial_container_bounds = container.bounds();
160
161 ASSERT_EQ(initial_size_button_bounds.x(),
162 initial_minimize_button_bounds.right());
163 ASSERT_EQ(initial_close_button_bounds.x(),
164 initial_size_button_bounds.right());
165
166 // Hidden size button should result in minimize button animating to the
167 // right. The size button should not be visible, but should not have moved.
168 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
169 true);
170 container.UpdateSizeButtonVisibility();
171 test.EndAnimations();
172 // Parent needs to layout in response to size change.
173 container.Layout();
174
175 EXPECT_TRUE(test.minimize_button()->visible());
176 EXPECT_FALSE(test.size_button()->visible());
177 EXPECT_TRUE(test.close_button()->visible());
178 gfx::Rect minimize_button_bounds = test.minimize_button()->bounds();
179 gfx::Rect close_button_bounds = test.close_button()->bounds();
180 EXPECT_EQ(close_button_bounds.x(), minimize_button_bounds.right());
181 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds());
182 EXPECT_EQ(initial_close_button_bounds.size(), close_button_bounds.size());
183 EXPECT_LT(container.GetPreferredSize().width(),
184 initial_container_bounds.width());
185
186 // Revealing the size button should cause the minimize button to return to its
187 // original position.
188 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
189 false);
190 container.UpdateSizeButtonVisibility();
191 // Calling code needs to layout in response to size change.
192 container.Layout();
193 test.EndAnimations();
194 EXPECT_TRUE(test.minimize_button()->visible());
195 EXPECT_TRUE(test.size_button()->visible());
196 EXPECT_TRUE(test.close_button()->visible());
197 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds());
198 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds());
199 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds());
200 EXPECT_EQ(container.GetPreferredSize().width(),
201 initial_container_bounds.width());
202 }
203
204 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698