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

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

Issue 1505223004: Do not use assets for Ash window control button backgrounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ash layout constants file added Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
6 6
7 #include "ash/ash_layout_constants.h"
7 #include "ash/frame/caption_buttons/frame_caption_button.h" 8 #include "ash/frame/caption_buttons/frame_caption_button.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 11 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
11 #include "grit/ash_resources.h" 12 #include "grit/ash_resources.h"
12 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
13 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
14 #include "ui/views/widget/widget_delegate.h" 15 #include "ui/views/widget/widget_delegate.h"
15 16
16 namespace ash { 17 namespace ash {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 views::Widget::InitParams params; 63 views::Widget::InitParams params;
63 params.delegate = new TestWidgetDelegate( 64 params.delegate = new TestWidgetDelegate(
64 maximize_allowed == MAXIMIZE_ALLOWED, 65 maximize_allowed == MAXIMIZE_ALLOWED,
65 minimize_allowed == MINIMIZE_ALLOWED); 66 minimize_allowed == MINIMIZE_ALLOWED);
66 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 67 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
67 params.context = CurrentContext(); 68 params.context = CurrentContext();
68 widget->Init(params); 69 widget->Init(params);
69 return widget; 70 return widget;
70 } 71 }
71 72
72 // Sets |container| to use arbitrary images for the buttons. Setting the 73 // Sets arbitrary images for the icons and assign the default header button
73 // images causes the buttons to have non-empty sizes. 74 // size to the buttons in |container|.
74 void SetMockImages(FrameCaptionButtonContainerView* container) { 75 void InitContainer(FrameCaptionButtonContainerView* container) {
76 container->SetButtonSize(GetAshLayoutSize(DEFAULT_HEADER_BUTTON));
75 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { 77 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) {
76 container->SetButtonImages( 78 container->SetButtonImage(static_cast<CaptionButtonIcon>(icon),
77 static_cast<CaptionButtonIcon>(icon), 79 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE);
78 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE,
79 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
80 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
81 } 80 }
82 } 81 }
83 82
84 // Tests that |leftmost| and |rightmost| are at |container|'s edges. 83 // Tests that |leftmost| and |rightmost| are at |container|'s edges.
85 bool CheckButtonsAtEdges(FrameCaptionButtonContainerView* container, 84 bool CheckButtonsAtEdges(FrameCaptionButtonContainerView* container,
86 const ash::FrameCaptionButton& leftmost, 85 const ash::FrameCaptionButton& leftmost,
87 const ash::FrameCaptionButton& rightmost) { 86 const ash::FrameCaptionButton& rightmost) {
88 gfx::Rect expected(container->GetPreferredSize()); 87 gfx::Rect expected(container->GetPreferredSize());
89 88
90 gfx::Rect container_size(container->GetPreferredSize()); 89 gfx::Rect container_size(container->GetPreferredSize());
(...skipping 15 matching lines...) Expand all
106 private: 105 private:
107 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); 106 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest);
108 }; 107 };
109 108
110 // Test how the allowed actions affect which caption buttons are visible. 109 // Test how the allowed actions affect which caption buttons are visible.
111 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { 110 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) {
112 // All the buttons should be visible when minimizing and maximizing are 111 // All the buttons should be visible when minimizing and maximizing are
113 // allowed. 112 // allowed.
114 FrameCaptionButtonContainerView container1( 113 FrameCaptionButtonContainerView container1(
115 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); 114 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED));
116 SetMockImages(&container1); 115 InitContainer(&container1);
117 container1.Layout(); 116 container1.Layout();
118 FrameCaptionButtonContainerView::TestApi t1(&container1); 117 FrameCaptionButtonContainerView::TestApi t1(&container1);
119 EXPECT_TRUE(t1.minimize_button()->visible()); 118 EXPECT_TRUE(t1.minimize_button()->visible());
120 EXPECT_TRUE(t1.size_button()->visible()); 119 EXPECT_TRUE(t1.size_button()->visible());
121 EXPECT_TRUE(t1.close_button()->visible()); 120 EXPECT_TRUE(t1.close_button()->visible());
122 EXPECT_TRUE(CheckButtonsAtEdges( 121 EXPECT_TRUE(CheckButtonsAtEdges(
123 &container1, *t1.minimize_button(), *t1.close_button())); 122 &container1, *t1.minimize_button(), *t1.close_button()));
124 123
125 // The minimize button should be visible when minimizing is allowed but 124 // The minimize button should be visible when minimizing is allowed but
126 // maximizing is disallowed. 125 // maximizing is disallowed.
127 FrameCaptionButtonContainerView container2( 126 FrameCaptionButtonContainerView container2(
128 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_ALLOWED)); 127 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_ALLOWED));
129 SetMockImages(&container2); 128 InitContainer(&container2);
130 container2.Layout(); 129 container2.Layout();
131 FrameCaptionButtonContainerView::TestApi t2(&container2); 130 FrameCaptionButtonContainerView::TestApi t2(&container2);
132 EXPECT_TRUE(t2.minimize_button()->visible()); 131 EXPECT_TRUE(t2.minimize_button()->visible());
133 EXPECT_FALSE(t2.size_button()->visible()); 132 EXPECT_FALSE(t2.size_button()->visible());
134 EXPECT_TRUE(t2.close_button()->visible()); 133 EXPECT_TRUE(t2.close_button()->visible());
135 EXPECT_TRUE(CheckButtonsAtEdges( 134 EXPECT_TRUE(CheckButtonsAtEdges(
136 &container2, *t2.minimize_button(), *t2.close_button())); 135 &container2, *t2.minimize_button(), *t2.close_button()));
137 136
138 // Neither the minimize button nor the size button should be visible when 137 // Neither the minimize button nor the size button should be visible when
139 // neither minimizing nor maximizing are allowed. 138 // neither minimizing nor maximizing are allowed.
140 FrameCaptionButtonContainerView container3( 139 FrameCaptionButtonContainerView container3(
141 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_DISALLOWED)); 140 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_DISALLOWED));
142 SetMockImages(&container3); 141 InitContainer(&container3);
143 container3.Layout(); 142 container3.Layout();
144 FrameCaptionButtonContainerView::TestApi t3(&container3); 143 FrameCaptionButtonContainerView::TestApi t3(&container3);
145 EXPECT_FALSE(t3.minimize_button()->visible()); 144 EXPECT_FALSE(t3.minimize_button()->visible());
146 EXPECT_FALSE(t3.size_button()->visible()); 145 EXPECT_FALSE(t3.size_button()->visible());
147 EXPECT_TRUE(t3.close_button()->visible()); 146 EXPECT_TRUE(t3.close_button()->visible());
148 EXPECT_TRUE(CheckButtonsAtEdges( 147 EXPECT_TRUE(CheckButtonsAtEdges(
149 &container3, *t3.close_button(), *t3.close_button())); 148 &container3, *t3.close_button(), *t3.close_button()));
150 } 149 }
151 150
152 // Tests that the layout animations trigered by button visibility result in the 151 // Tests that the layout animations trigered by button visibility result in the
153 // correct placement of the buttons. 152 // correct placement of the buttons.
154 TEST_F(FrameCaptionButtonContainerViewTest, 153 TEST_F(FrameCaptionButtonContainerViewTest,
155 TestUpdateSizeButtonVisibilityAnimation) { 154 TestUpdateSizeButtonVisibilityAnimation) {
156 FrameCaptionButtonContainerView container( 155 FrameCaptionButtonContainerView container(
157 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); 156 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED));
158 SetMockImages(&container); 157 InitContainer(&container);
159 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); 158 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize()));
160 container.Layout(); 159 container.Layout();
161 160
162 FrameCaptionButtonContainerView::TestApi test(&container); 161 FrameCaptionButtonContainerView::TestApi test(&container);
163 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); 162 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds();
164 gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); 163 gfx::Rect initial_size_button_bounds = test.size_button()->bounds();
165 gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); 164 gfx::Rect initial_close_button_bounds = test.close_button()->bounds();
166 gfx::Rect initial_container_bounds = container.bounds(); 165 gfx::Rect initial_container_bounds = container.bounds();
167 166
168 ASSERT_EQ(initial_size_button_bounds.x(), 167 ASSERT_EQ(initial_size_button_bounds.x(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 EXPECT_TRUE(test.size_button()->visible()); 201 EXPECT_TRUE(test.size_button()->visible());
203 EXPECT_TRUE(test.close_button()->visible()); 202 EXPECT_TRUE(test.close_button()->visible());
204 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); 203 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds());
205 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); 204 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds());
206 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); 205 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds());
207 EXPECT_EQ(container.GetPreferredSize().width(), 206 EXPECT_EQ(container.GetPreferredSize().width(),
208 initial_container_bounds.width()); 207 initial_container_bounds.width());
209 } 208 }
210 209
211 } // namespace ash 210 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698