| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "ui/base/ui_base_types.h" | 8 #include "ui/base/ui_base_types.h" |
| 9 #include "ui/views/controls/button/label_button.h" | 9 #include "ui/views/controls/button/label_button.h" |
| 10 #include "ui/views/style/platform_style.h" | 10 #include "ui/views/style/platform_style.h" |
| 11 #include "ui/views/test/test_views.h" | 11 #include "ui/views/test/test_views.h" |
| 12 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
| 13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 14 #include "ui/views/window/dialog_client_view.h" | 14 #include "ui/views/window/dialog_client_view.h" |
| 15 #include "ui/views/window/dialog_delegate.h" | 15 #include "ui/views/window/dialog_delegate.h" |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 namespace test { |
| 18 | 19 |
| 19 class TestDialogClientView : public DialogClientView { | 20 class TestDialogClientView : public DialogClientView { |
| 20 public: | 21 public: |
| 21 explicit TestDialogClientView(DialogDelegateView* dialog_delegate_view) | 22 explicit TestDialogClientView(DialogDelegateView* dialog_delegate_view) |
| 22 : DialogClientView(dialog_delegate_view), | 23 : DialogClientView(nullptr, dialog_delegate_view), |
| 23 dialog_delegate_view_(dialog_delegate_view) {} | 24 dialog_delegate_view_(dialog_delegate_view) { |
| 25 // Clear button insets from the ViewsDelegate. |
| 26 button_row_insets_ = gfx::Insets(); |
| 27 } |
| 24 ~TestDialogClientView() override {} | 28 ~TestDialogClientView() override {} |
| 25 | 29 |
| 26 // DialogClientView implementation. | 30 // DialogClientView implementation. |
| 27 DialogDelegate* GetDialogDelegate() const override { | 31 DialogDelegate* GetDialogDelegate() const override { |
| 28 return dialog_delegate_view_; | 32 return dialog_delegate_view_; |
| 29 } | 33 } |
| 30 | 34 |
| 31 View* GetContentsView() { return contents_view(); } | 35 View* GetContentsView() { return contents_view(); } |
| 32 | 36 |
| 33 void CreateExtraViews() { | |
| 34 CreateExtraView(); | |
| 35 } | |
| 36 | |
| 37 private: | 37 private: |
| 38 DialogDelegateView* dialog_delegate_view_; | 38 DialogDelegateView* dialog_delegate_view_; |
| 39 | 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(TestDialogClientView); | 40 DISALLOW_COPY_AND_ASSIGN(TestDialogClientView); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 } // namespace test |
| 44 |
| 45 using test::TestDialogClientView; |
| 46 |
| 43 // Base class for tests. Also acts as the dialog delegate and contents view for | 47 // Base class for tests. Also acts as the dialog delegate and contents view for |
| 44 // TestDialogClientView. | 48 // TestDialogClientView. |
| 45 class DialogClientViewTest : public ViewsTestBase, | 49 class DialogClientViewTest : public ViewsTestBase, |
| 46 public DialogDelegateView { | 50 public DialogDelegateView { |
| 47 public: | 51 public: |
| 48 DialogClientViewTest() | 52 DialogClientViewTest() |
| 49 : dialog_buttons_(ui::DIALOG_BUTTON_NONE), | 53 : dialog_buttons_(ui::DIALOG_BUTTON_NONE), |
| 50 extra_view_(nullptr) {} | 54 extra_view_(nullptr) {} |
| 51 ~DialogClientViewTest() override {} | 55 ~DialogClientViewTest() override {} |
| 52 | 56 |
| 53 // testing::Test implementation. | 57 // testing::Test implementation. |
| 54 void SetUp() override { | 58 void SetUp() override { |
| 59 ViewsTestBase::SetUp(); |
| 55 dialog_buttons_ = ui::DIALOG_BUTTON_NONE; | 60 dialog_buttons_ = ui::DIALOG_BUTTON_NONE; |
| 56 client_view_.reset(new TestDialogClientView(this)); | 61 client_view_.reset(new TestDialogClientView(this)); |
| 57 // Add this i.e. the contents view as a child of |client_view_|. This is | 62 // Add this i.e. the contents view as a child of |client_view_|. This is |
| 58 // generally done when the client view is added to the view hierarchy. | 63 // generally done when the client view is added to the view hierarchy. |
| 59 client_view_->AddChildViewAt(this, 0); | 64 client_view_->AddChildViewAt(this, 0); |
| 60 ViewsTestBase::SetUp(); | |
| 61 } | 65 } |
| 62 | 66 |
| 63 // DialogDelegateView implementation. | 67 // DialogDelegateView implementation. |
| 64 View* CreateExtraView() override { return extra_view_; } | 68 View* CreateExtraView() override { return extra_view_; } |
| 65 bool GetExtraViewPadding(int* padding) override { | 69 bool GetExtraViewPadding(int* padding) override { |
| 66 if (extra_view_padding_) | 70 if (extra_view_padding_) |
| 67 *padding = *extra_view_padding_; | 71 *padding = *extra_view_padding_; |
| 68 return extra_view_padding_.get() != nullptr; | 72 return extra_view_padding_.get() != nullptr; |
| 69 } | 73 } |
| 70 int GetDialogButtons() const override { return dialog_buttons_; } | 74 int GetDialogButtons() const override { return dialog_buttons_; } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 90 // Sets the buttons to show in the dialog and refreshes the dialog. | 94 // Sets the buttons to show in the dialog and refreshes the dialog. |
| 91 void SetDialogButtons(int dialog_buttons) { | 95 void SetDialogButtons(int dialog_buttons) { |
| 92 dialog_buttons_ = dialog_buttons; | 96 dialog_buttons_ = dialog_buttons; |
| 93 client_view_->UpdateDialogButtons(); | 97 client_view_->UpdateDialogButtons(); |
| 94 } | 98 } |
| 95 | 99 |
| 96 // Sets the extra view. | 100 // Sets the extra view. |
| 97 void SetExtraView(View* view) { | 101 void SetExtraView(View* view) { |
| 98 DCHECK(!extra_view_); | 102 DCHECK(!extra_view_); |
| 99 extra_view_ = view; | 103 extra_view_ = view; |
| 100 client_view_->CreateExtraViews(); | |
| 101 } | 104 } |
| 102 | 105 |
| 103 // Sets the extra view padding. | 106 // Sets the extra view padding. |
| 104 void SetExtraViewPadding(int padding) { | 107 void SetExtraViewPadding(int padding) { |
| 105 DCHECK(!extra_view_padding_); | 108 DCHECK(!extra_view_padding_); |
| 106 extra_view_padding_.reset(new int(padding)); | 109 extra_view_padding_.reset(new int(padding)); |
| 107 client_view_->Layout(); | 110 client_view_->Layout(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 TestDialogClientView* client_view() { return client_view_.get(); } | 113 TestDialogClientView* client_view() { return client_view_.get(); } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Test the effect of the button strip on layout. | 226 // Test the effect of the button strip on layout. |
| 224 TEST_F(DialogClientViewTest, LayoutWithButtons) { | 227 TEST_F(DialogClientViewTest, LayoutWithButtons) { |
| 225 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | 228 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); |
| 226 CheckContentsIsSetToPreferredSize(); | 229 CheckContentsIsSetToPreferredSize(); |
| 227 EXPECT_LT(GetContentsView()->bounds().bottom(), | 230 EXPECT_LT(GetContentsView()->bounds().bottom(), |
| 228 client_view()->bounds().bottom()); | 231 client_view()->bounds().bottom()); |
| 229 gfx::Size no_extra_view_size = client_view()->bounds().size(); | 232 gfx::Size no_extra_view_size = client_view()->bounds().size(); |
| 230 | 233 |
| 231 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); | 234 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); |
| 232 SetExtraView(extra_view); | 235 SetExtraView(extra_view); |
| 236 client_view()->UpdateDialogButtons(); |
| 233 CheckContentsIsSetToPreferredSize(); | 237 CheckContentsIsSetToPreferredSize(); |
| 234 EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height()); | 238 EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height()); |
| 235 int width_of_dialog = client_view()->bounds().width(); | 239 int width_of_dialog = client_view()->bounds().width(); |
| 236 int width_of_extra_view = extra_view->bounds().width(); | 240 int width_of_extra_view = extra_view->bounds().width(); |
| 237 | 241 |
| 238 // Try with an adjusted padding for the extra view. | 242 // Try with an adjusted padding for the extra view. |
| 239 SetExtraViewPadding(250); | 243 SetExtraViewPadding(250); |
| 240 CheckContentsIsSetToPreferredSize(); | 244 CheckContentsIsSetToPreferredSize(); |
| 241 EXPECT_GT(client_view()->bounds().width(), width_of_dialog); | 245 EXPECT_GT(client_view()->bounds().width(), width_of_dialog); |
| 242 | 246 |
| 243 // Visibility of extra view is respected. | 247 // Visibility of extra view is respected. |
| 244 extra_view->SetVisible(false); | 248 extra_view->SetVisible(false); |
| 245 CheckContentsIsSetToPreferredSize(); | 249 CheckContentsIsSetToPreferredSize(); |
| 246 EXPECT_EQ(no_extra_view_size.height(), client_view()->bounds().height()); | 250 EXPECT_EQ(no_extra_view_size.height(), client_view()->bounds().height()); |
| 247 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); | 251 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); |
| 248 | 252 |
| 249 // Try with a reduced-size dialog. | 253 // Try with a reduced-size dialog. |
| 250 extra_view->SetVisible(true); | 254 extra_view->SetVisible(true); |
| 251 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); | 255 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); |
| 252 client_view()->Layout(); | 256 client_view()->Layout(); |
| 253 EXPECT_GT(width_of_extra_view, extra_view->bounds().width()); | 257 EXPECT_GT(width_of_extra_view, extra_view->bounds().width()); |
| 254 } | 258 } |
| 255 | 259 |
| 256 } // namespace views | 260 } // namespace views |
| OLD | NEW |