OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/window/dialog_client_view.h" | 5 #include "ui/views/window/dialog_client_view.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "ui/base/test/material_design_controller_test_api.h" | |
10 #include "ui/base/ui_base_types.h" | 11 #include "ui/base/ui_base_types.h" |
11 #include "ui/views/controls/button/label_button.h" | 12 #include "ui/views/controls/button/label_button.h" |
12 #include "ui/views/style/platform_style.h" | 13 #include "ui/views/style/platform_style.h" |
13 #include "ui/views/test/test_views.h" | 14 #include "ui/views/test/test_views.h" |
14 #include "ui/views/test/widget_test.h" | 15 #include "ui/views/test/widget_test.h" |
15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
16 #include "ui/views/window/dialog_delegate.h" | 17 #include "ui/views/window/dialog_delegate.h" |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 | 20 |
(...skipping 16 matching lines...) Expand all Loading... | |
36 widget_->Init(params); | 37 widget_->Init(params); |
37 EXPECT_EQ(this, GetContentsView()); | 38 EXPECT_EQ(this, GetContentsView()); |
38 } | 39 } |
39 | 40 |
40 void TearDown() override { | 41 void TearDown() override { |
41 widget_->CloseNow(); | 42 widget_->CloseNow(); |
42 WidgetTest::TearDown(); | 43 WidgetTest::TearDown(); |
43 } | 44 } |
44 | 45 |
45 // DialogDelegateView: | 46 // DialogDelegateView: |
47 gfx::Size GetPreferredSize() const override { return preferred_size_; } | |
48 gfx::Size GetMinimumSize() const override { return min_size_; } | |
49 gfx::Size GetMaximumSize() const override { return max_size_; } | |
46 ClientView* CreateClientView(Widget* widget) override { | 50 ClientView* CreateClientView(Widget* widget) override { |
47 client_view_ = new DialogClientView(widget, this); | 51 client_view_ = new DialogClientView(widget, this); |
48 return client_view_; | 52 return client_view_; |
49 } | 53 } |
50 | 54 |
51 bool ShouldUseCustomFrame() const override { return false; } | 55 bool ShouldUseCustomFrame() const override { return false; } |
52 | 56 |
53 void DeleteDelegate() override { | 57 void DeleteDelegate() override { |
54 // DialogDelegateView would delete this, but |this| is owned by the test. | 58 // DialogDelegateView would delete this, but |this| is owned by the test. |
55 } | 59 } |
56 | 60 |
57 View* CreateExtraView() override { return next_extra_view_.release(); } | 61 View* CreateExtraView() override { return next_extra_view_.release(); } |
58 | 62 |
59 bool GetExtraViewPadding(int* padding) override { | 63 bool GetExtraViewPadding(int* padding) override { |
60 if (extra_view_padding_) | 64 if (extra_view_padding_) |
61 *padding = *extra_view_padding_; | 65 *padding = *extra_view_padding_; |
62 return extra_view_padding_.get() != nullptr; | 66 return extra_view_padding_.get() != nullptr; |
63 } | 67 } |
64 | 68 |
65 int GetDialogButtons() const override { return dialog_buttons_; } | 69 int GetDialogButtons() const override { return dialog_buttons_; } |
70 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override { | |
71 if (button == ui::DIALOG_BUTTON_CANCEL && !cancel_label_.empty()) | |
72 return cancel_label_; | |
73 return DialogDelegate::GetDialogButtonLabel(button); | |
Peter Kasting
2017/03/02 23:09:34
Nit: Optional fractionally-less-verbose form:
tapted
2017/03/06 03:51:48
Done.
| |
74 } | |
66 | 75 |
67 protected: | 76 protected: |
68 gfx::Rect GetUpdatedClientBounds() { | 77 gfx::Rect GetUpdatedClientBounds() { |
69 client_view_->SizeToPreferredSize(); | 78 client_view_->SizeToPreferredSize(); |
70 client_view_->Layout(); | 79 client_view_->Layout(); |
71 return client_view_->bounds(); | 80 return client_view_->bounds(); |
72 } | 81 } |
73 | 82 |
74 // Makes sure that the content view is sized correctly. Width must be at least | 83 // Makes sure that the content view is sized correctly. Width must be at least |
75 // the requested amount, but height should always match exactly. | 84 // the requested amount, but height should always match exactly. |
(...skipping 19 matching lines...) Expand all Loading... | |
95 EXPECT_FALSE(next_extra_view_); | 104 EXPECT_FALSE(next_extra_view_); |
96 next_extra_view_ = base::WrapUnique(view); | 105 next_extra_view_ = base::WrapUnique(view); |
97 client_view_->UpdateDialogButtons(); | 106 client_view_->UpdateDialogButtons(); |
98 EXPECT_FALSE(next_extra_view_); | 107 EXPECT_FALSE(next_extra_view_); |
99 } | 108 } |
100 | 109 |
101 // Sets the extra view padding. | 110 // Sets the extra view padding. |
102 void SetExtraViewPadding(int padding) { | 111 void SetExtraViewPadding(int padding) { |
103 DCHECK(!extra_view_padding_); | 112 DCHECK(!extra_view_padding_); |
104 extra_view_padding_.reset(new int(padding)); | 113 extra_view_padding_.reset(new int(padding)); |
105 client_view_->Layout(); | 114 client_view_->UpdateDialogButtons(); |
115 } | |
116 | |
117 void SetSizeConstraints(const gfx::Size& min_size, | |
118 const gfx::Size& preferred_size, | |
119 const gfx::Size& max_size) { | |
120 min_size_ = min_size; | |
121 preferred_size_ = preferred_size; | |
122 max_size_ = max_size; | |
106 } | 123 } |
107 | 124 |
108 View* FocusableViewAfter(View* view) { | 125 View* FocusableViewAfter(View* view) { |
109 const bool dont_loop = false; | 126 const bool dont_loop = false; |
110 const bool reverse = false; | 127 const bool reverse = false; |
111 return GetFocusManager()->GetNextFocusableView(view, GetWidget(), reverse, | 128 return GetFocusManager()->GetNextFocusableView(view, GetWidget(), reverse, |
112 dont_loop); | 129 dont_loop); |
113 } | 130 } |
114 | 131 |
132 // Set a longer than normal Cancel label so that the minimum button width is | |
133 // exceeded. | |
134 void SetLongCancelLabel() { | |
135 cancel_label_ = base::ASCIIToUTF16("Cancel Cancel"); | |
Peter Kasting
2017/03/02 23:09:35
Nit: Maybe make this string even longer to reduce
tapted
2017/03/06 03:51:49
Done.
| |
136 } | |
137 | |
115 DialogClientView* client_view() { return client_view_; } | 138 DialogClientView* client_view() { return client_view_; } |
116 | 139 |
117 private: | 140 private: |
118 // The dialog Widget. | 141 // The dialog Widget. |
119 Widget* widget_ = nullptr; | 142 Widget* widget_ = nullptr; |
120 | 143 |
121 // The DialogClientView that's being tested. Owned by |widget_|. | 144 // The DialogClientView that's being tested. Owned by |widget_|. |
122 DialogClientView* client_view_; | 145 DialogClientView* client_view_; |
123 | 146 |
124 // The bitmask of buttons to show in the dialog. | 147 // The bitmask of buttons to show in the dialog. |
125 int dialog_buttons_ = ui::DIALOG_BUTTON_NONE; | 148 int dialog_buttons_ = ui::DIALOG_BUTTON_NONE; |
126 | 149 |
127 // Set and cleared in SetExtraView(). | 150 // Set and cleared in SetExtraView(). |
128 std::unique_ptr<View> next_extra_view_; | 151 std::unique_ptr<View> next_extra_view_; |
129 | 152 |
130 std::unique_ptr<int> extra_view_padding_; | 153 std::unique_ptr<int> extra_view_padding_; |
131 | 154 |
155 gfx::Size preferred_size_; | |
156 gfx::Size min_size_; | |
157 gfx::Size max_size_; | |
158 | |
159 base::string16 cancel_label_; // If set, the label for the Cancel button. | |
160 | |
132 DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); | 161 DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); |
133 }; | 162 }; |
134 | 163 |
135 TEST_F(DialogClientViewTest, UpdateButtons) { | 164 TEST_F(DialogClientViewTest, UpdateButtons) { |
136 // This dialog should start with no buttons. | 165 // This dialog should start with no buttons. |
137 EXPECT_EQ(GetDialogButtons(), ui::DIALOG_BUTTON_NONE); | 166 EXPECT_EQ(GetDialogButtons(), ui::DIALOG_BUTTON_NONE); |
138 EXPECT_EQ(NULL, client_view()->ok_button()); | 167 EXPECT_EQ(NULL, client_view()->ok_button()); |
139 EXPECT_EQ(NULL, client_view()->cancel_button()); | 168 EXPECT_EQ(NULL, client_view()->cancel_button()); |
140 const int height_without_buttons = GetUpdatedClientBounds().height(); | 169 const int height_without_buttons = GetUpdatedClientBounds().height(); |
141 | 170 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 } | 210 } |
182 | 211 |
183 // Test that views inside the dialog client view have the correct focus order. | 212 // Test that views inside the dialog client view have the correct focus order. |
184 TEST_F(DialogClientViewTest, SetupFocusChain) { | 213 TEST_F(DialogClientViewTest, SetupFocusChain) { |
185 #if defined(OS_WIN) || defined(OS_CHROMEOS) | 214 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
186 const bool kIsOkButtonOnLeftSide = true; | 215 const bool kIsOkButtonOnLeftSide = true; |
187 #else | 216 #else |
188 const bool kIsOkButtonOnLeftSide = false; | 217 const bool kIsOkButtonOnLeftSide = false; |
189 #endif | 218 #endif |
190 | 219 |
220 GetContentsView()->SetFocusBehavior(View::FocusBehavior::ALWAYS); | |
191 // Initially the dialog client view only contains the content view. | 221 // Initially the dialog client view only contains the content view. |
192 EXPECT_EQ(nullptr, GetContentsView()->GetNextFocusableView()); | 222 EXPECT_EQ(GetContentsView(), FocusableViewAfter(GetContentsView())); |
193 | 223 |
194 // Add OK and cancel buttons. | 224 // Add OK and cancel buttons. |
195 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | 225 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); |
196 | 226 |
197 if (kIsOkButtonOnLeftSide) { | 227 if (kIsOkButtonOnLeftSide) { |
198 EXPECT_EQ(client_view()->ok_button(), | 228 EXPECT_EQ(client_view()->ok_button(), |
199 GetContentsView()->GetNextFocusableView()); | 229 FocusableViewAfter(GetContentsView())); |
200 EXPECT_EQ(client_view()->cancel_button(), | 230 EXPECT_EQ(client_view()->cancel_button(), |
201 client_view()->ok_button()->GetNextFocusableView()); | 231 FocusableViewAfter(client_view()->ok_button())); |
202 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); | 232 EXPECT_EQ(GetContentsView(), |
233 FocusableViewAfter(client_view()->cancel_button())); | |
203 } else { | 234 } else { |
204 EXPECT_EQ(client_view()->cancel_button(), | 235 EXPECT_EQ(client_view()->cancel_button(), |
205 GetContentsView()->GetNextFocusableView()); | 236 FocusableViewAfter(GetContentsView())); |
206 EXPECT_EQ(client_view()->ok_button(), | 237 EXPECT_EQ(client_view()->ok_button(), |
207 client_view()->cancel_button()->GetNextFocusableView()); | 238 FocusableViewAfter(client_view()->cancel_button())); |
208 EXPECT_EQ(nullptr, client_view()->ok_button()->GetNextFocusableView()); | 239 EXPECT_EQ(GetContentsView(), |
240 FocusableViewAfter(client_view()->ok_button())); | |
209 } | 241 } |
210 | 242 |
211 // Add extra view and remove OK button. | 243 // Add extra view and remove OK button. |
212 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); | 244 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); |
213 extra_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 245 extra_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
214 SetExtraView(extra_view); | 246 SetExtraView(extra_view); |
215 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); | 247 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); |
216 | 248 |
217 EXPECT_EQ(extra_view, GetContentsView()->GetNextFocusableView()); | 249 EXPECT_EQ(extra_view, FocusableViewAfter(GetContentsView())); |
218 EXPECT_EQ(client_view()->cancel_button(), extra_view->GetNextFocusableView()); | 250 EXPECT_EQ(client_view()->cancel_button(), FocusableViewAfter(extra_view)); |
219 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); | 251 EXPECT_EQ(GetContentsView(), FocusableViewAfter(client_view())); |
220 | 252 |
221 // Add a dummy view to the contents view. Consult the FocusManager for the | 253 // Add a dummy view to the contents view. Consult the FocusManager for the |
222 // traversal order since it now spans different levels of the view hierarchy. | 254 // traversal order since it now spans different levels of the view hierarchy. |
223 View* dummy_view = new StaticSizedView(gfx::Size(200, 200)); | 255 View* dummy_view = new StaticSizedView(gfx::Size(200, 200)); |
224 dummy_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 256 dummy_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
257 GetContentsView()->SetFocusBehavior(View::FocusBehavior::NEVER); | |
225 GetContentsView()->AddChildView(dummy_view); | 258 GetContentsView()->AddChildView(dummy_view); |
226 EXPECT_EQ(dummy_view, FocusableViewAfter(client_view()->cancel_button())); | 259 EXPECT_EQ(dummy_view, FocusableViewAfter(client_view()->cancel_button())); |
227 EXPECT_EQ(extra_view, FocusableViewAfter(dummy_view)); | 260 EXPECT_EQ(extra_view, FocusableViewAfter(dummy_view)); |
228 EXPECT_EQ(client_view()->cancel_button(), FocusableViewAfter(extra_view)); | 261 EXPECT_EQ(client_view()->cancel_button(), FocusableViewAfter(extra_view)); |
229 | 262 |
230 // Views are added to the contents view, not the client view, so the focus | 263 // Views are added to the contents view, not the client view, so the focus |
231 // chain within the client view is not affected. | 264 // chain within the client view is not affected. |
232 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); | 265 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); |
233 } | 266 } |
234 | 267 |
235 // Test that the contents view gets its preferred size in the basic dialog | 268 // Test that the contents view gets its preferred size in the basic dialog |
236 // configuration. | 269 // configuration. |
237 TEST_F(DialogClientViewTest, ContentsSize) { | 270 TEST_F(DialogClientViewTest, ContentsSize) { |
238 CheckContentsIsSetToPreferredSize(); | 271 CheckContentsIsSetToPreferredSize(); |
239 EXPECT_EQ(GetContentsView()->size(), client_view()->size()); | 272 EXPECT_EQ(GetContentsView()->size(), client_view()->size()); |
240 // There's nothing in the contents view (i.e. |this|), so it should be 0x0. | 273 // There's nothing in the contents view (i.e. |this|), so it should be 0x0. |
241 EXPECT_EQ(gfx::Size(), client_view()->size()); | 274 EXPECT_EQ(gfx::Size(), client_view()->size()); |
242 } | 275 } |
243 | 276 |
244 // Test the effect of the button strip on layout. | 277 // Test the effect of the button strip on layout. |
245 TEST_F(DialogClientViewTest, LayoutWithButtons) { | 278 TEST_F(DialogClientViewTest, LayoutWithButtons) { |
246 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | 279 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); |
247 CheckContentsIsSetToPreferredSize(); | 280 CheckContentsIsSetToPreferredSize(); |
248 | 281 |
249 EXPECT_LT(GetContentsView()->bounds().bottom(), | 282 EXPECT_LT(GetContentsView()->bounds().bottom(), |
250 client_view()->bounds().bottom()); | 283 client_view()->bounds().bottom()); |
251 gfx::Size no_extra_view_size = client_view()->bounds().size(); | 284 const gfx::Size no_extra_view_size = client_view()->bounds().size(); |
252 | 285 |
253 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); | 286 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); |
254 SetExtraView(extra_view); | 287 SetExtraView(extra_view); |
255 CheckContentsIsSetToPreferredSize(); | 288 CheckContentsIsSetToPreferredSize(); |
256 EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height()); | 289 EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height()); |
257 int width_of_dialog = client_view()->bounds().width(); | 290 const int width_of_dialog_small_padding = client_view()->width(); |
258 int width_of_extra_view = extra_view->bounds().width(); | |
259 | 291 |
260 // Try with an adjusted padding for the extra view. | 292 // Try with an adjusted padding for the extra view. |
261 SetExtraViewPadding(250); | 293 SetExtraViewPadding(250); |
262 CheckContentsIsSetToPreferredSize(); | 294 CheckContentsIsSetToPreferredSize(); |
263 EXPECT_GT(client_view()->bounds().width(), width_of_dialog); | 295 EXPECT_GT(client_view()->bounds().width(), width_of_dialog_small_padding); |
264 | 296 |
265 // Visibility of extra view is respected. | 297 const gfx::Size with_extra_view_size = client_view()->size(); |
298 EXPECT_NE(no_extra_view_size, with_extra_view_size); | |
299 | |
300 // Hiding the extra view removes it as well as the extra padding. | |
266 extra_view->SetVisible(false); | 301 extra_view->SetVisible(false); |
267 CheckContentsIsSetToPreferredSize(); | 302 CheckContentsIsSetToPreferredSize(); |
268 EXPECT_EQ(no_extra_view_size.height(), client_view()->bounds().height()); | 303 EXPECT_EQ(no_extra_view_size, client_view()->size()); |
269 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); | |
270 | 304 |
271 // Try with a reduced-size dialog. | 305 // Making it visible again adds it all back. |
272 extra_view->SetVisible(true); | 306 extra_view->SetVisible(true); |
273 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); | 307 CheckContentsIsSetToPreferredSize(); |
274 client_view()->Layout(); | 308 EXPECT_EQ(with_extra_view_size, client_view()->size()); |
275 EXPECT_GT(width_of_extra_view, extra_view->bounds().width()); | 309 |
310 // Leave |extra_view| hidden. It should still have a parent, to ensure it is | |
311 // owned by a View hierarchy and gets deleted. | |
312 extra_view->SetVisible(false); | |
313 EXPECT_TRUE(extra_view->parent()); | |
314 } | |
315 | |
316 // Ensure the minimum, maximum and preferred sizes of the contents view are | |
317 // respected by the client view, and that the client view includes the button | |
318 // row in its minimum and preferred size calculations. | |
319 TEST_F(DialogClientViewTest, MinMaxPreferredSize) { | |
320 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | |
321 const gfx::Size buttons_size = client_view()->GetPreferredSize(); | |
322 EXPECT_FALSE(buttons_size.IsEmpty()); | |
323 | |
324 // When the contents view has no preference, just fit the buttons. The | |
325 // maximum size should be unconstrained in both directions. | |
326 EXPECT_EQ(buttons_size, client_view()->GetMinimumSize()); | |
327 EXPECT_EQ(gfx::Size(), client_view()->GetMaximumSize()); | |
328 | |
329 // Ensure buttons are between these widths, for the constants below. | |
330 EXPECT_LT(20, buttons_size.width()); | |
331 EXPECT_GT(300, buttons_size.width()); | |
332 | |
333 // With no buttons, client view should match the contents view. | |
334 SetDialogButtons(ui::DIALOG_BUTTON_NONE); | |
335 SetSizeConstraints(gfx::Size(10, 15), gfx::Size(20, 25), gfx::Size(300, 350)); | |
336 EXPECT_EQ(gfx::Size(10, 15), client_view()->GetMinimumSize()); | |
337 EXPECT_EQ(gfx::Size(20, 25), client_view()->GetPreferredSize()); | |
338 EXPECT_EQ(gfx::Size(300, 350), client_view()->GetMaximumSize()); | |
339 | |
340 // With buttons, size should increase vertically only. | |
341 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | |
342 EXPECT_EQ(gfx::Size(buttons_size.width(), 15 + buttons_size.height()), | |
343 client_view()->GetMinimumSize()); | |
344 EXPECT_EQ(gfx::Size(buttons_size.width(), 25 + buttons_size.height()), | |
345 client_view()->GetPreferredSize()); | |
346 EXPECT_EQ(gfx::Size(300, 350 + buttons_size.height()), | |
347 client_view()->GetMaximumSize()); | |
348 | |
349 // If the contents view gets bigger, it should take over the width. | |
350 SetSizeConstraints(gfx::Size(400, 450), gfx::Size(500, 550), | |
351 gfx::Size(600, 650)); | |
352 EXPECT_EQ(gfx::Size(400, 450 + buttons_size.height()), | |
353 client_view()->GetMinimumSize()); | |
354 EXPECT_EQ(gfx::Size(500, 550 + buttons_size.height()), | |
355 client_view()->GetPreferredSize()); | |
356 EXPECT_EQ(gfx::Size(600, 650 + buttons_size.height()), | |
357 client_view()->GetMaximumSize()); | |
358 } | |
359 | |
360 // Ensure button widths are linked under MD. | |
361 TEST_F(DialogClientViewTest, LinkedWidths) { | |
362 ui::test::MaterialDesignControllerTestAPI md_test_api( | |
363 ui::MaterialDesignController::MATERIAL_NORMAL); | |
364 md_test_api.SetSecondaryUiMaterial(true); | |
365 SetLongCancelLabel(); | |
366 | |
367 SetDialogButtons(ui::DIALOG_BUTTON_OK); | |
368 CheckContentsIsSetToPreferredSize(); | |
369 const int ok_button_only_width = client_view()->ok_button()->width(); | |
370 | |
371 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); | |
372 CheckContentsIsSetToPreferredSize(); | |
373 const int cancel_button_width = client_view()->cancel_button()->width(); | |
374 | |
375 // Ensure the single buttons have different preferred widths when alone. | |
376 EXPECT_GT(cancel_button_width, ok_button_only_width); | |
Peter Kasting
2017/03/02 23:09:34
Nit: If you're just checking that they're differen
tapted
2017/03/06 03:51:49
Updated the comment - the cancel button needs to b
| |
377 | |
378 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK); | |
379 CheckContentsIsSetToPreferredSize(); | |
380 | |
381 // OK button should now match the bigger, cancel button. | |
382 EXPECT_EQ(cancel_button_width, client_view()->ok_button()->width()); | |
383 | |
384 // But not under non-MD. | |
385 md_test_api.SetSecondaryUiMaterial(false); | |
386 client_view()->UpdateDialogButtons(); | |
387 CheckContentsIsSetToPreferredSize(); | |
388 EXPECT_EQ(ok_button_only_width, client_view()->ok_button()->width()); | |
389 md_test_api.SetSecondaryUiMaterial(true); | |
390 | |
391 // The extra view should also match, if it's a button. | |
392 LabelButton* extra_button = new LabelButton(nullptr, base::string16()); | |
393 SetExtraView(extra_button); | |
394 CheckContentsIsSetToPreferredSize(); | |
395 EXPECT_EQ(cancel_button_width, extra_button->width()); | |
396 | |
397 delete extra_button; | |
Peter Kasting
2017/03/02 23:09:34
You delete |extra_button| here but not |boring_vie
tapted
2017/03/06 03:51:48
yes. views::View's destructor always ensures it ge
Peter Kasting
2017/03/06 07:36:27
FWIW, I find the pattern that views code takes own
| |
398 | |
399 // Non-buttons should always be sized to their preferred size. | |
400 View* boring_view = new StaticSizedView(gfx::Size(20, 20)); | |
401 SetExtraView(boring_view); | |
402 CheckContentsIsSetToPreferredSize(); | |
403 EXPECT_EQ(20, boring_view->width()); | |
276 } | 404 } |
277 | 405 |
278 } // namespace views | 406 } // namespace views |
OLD | NEW |