Chromium Code Reviews| 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/test/test_views.h" | 10 #include "ui/views/test/test_views.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 public DialogDelegateView { | 42 public DialogDelegateView { |
| 43 public: | 43 public: |
| 44 DialogClientViewTest() | 44 DialogClientViewTest() |
| 45 : dialog_buttons_(ui::DIALOG_BUTTON_NONE), | 45 : dialog_buttons_(ui::DIALOG_BUTTON_NONE), |
| 46 extra_view_(nullptr) {} | 46 extra_view_(nullptr) {} |
| 47 ~DialogClientViewTest() override {} | 47 ~DialogClientViewTest() override {} |
| 48 | 48 |
| 49 // testing::Test implementation. | 49 // testing::Test implementation. |
| 50 void SetUp() override { | 50 void SetUp() override { |
| 51 dialog_buttons_ = ui::DIALOG_BUTTON_NONE; | 51 dialog_buttons_ = ui::DIALOG_BUTTON_NONE; |
| 52 contents_.reset(new StaticSizedView(gfx::Size(100, 200))); | 52 contents_ = new StaticSizedView(gfx::Size(100, 200)); |
| 53 client_view_.reset(new TestDialogClientView(contents_.get(), this)); | 53 client_view_.reset(new TestDialogClientView(contents_, this)); |
| 54 | 54 // Add |contents_| as a child of |client_view|. This is generally done when |
| 55 // the client view is added to the view hierarchy. | |
| 56 client_view_->AddChildViewAt(contents_, 0); | |
| 55 ViewsTestBase::SetUp(); | 57 ViewsTestBase::SetUp(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 // DialogDelegateView implementation. | 60 // DialogDelegateView implementation. |
| 59 View* GetContentsView() override { return contents_.get(); } | 61 View* GetContentsView() override { return contents_; } |
| 60 View* CreateExtraView() override { return extra_view_; } | 62 View* CreateExtraView() override { return extra_view_; } |
| 61 bool GetExtraViewPadding(int* padding) override { | 63 bool GetExtraViewPadding(int* padding) override { |
| 62 if (extra_view_padding_) | 64 if (extra_view_padding_) |
| 63 *padding = *extra_view_padding_; | 65 *padding = *extra_view_padding_; |
| 64 return extra_view_padding_.get() != nullptr; | 66 return extra_view_padding_.get() != nullptr; |
| 65 } | 67 } |
| 66 int GetDialogButtons() const override { return dialog_buttons_; } | 68 int GetDialogButtons() const override { return dialog_buttons_; } |
| 67 | 69 |
| 68 protected: | 70 protected: |
| 69 gfx::Rect GetUpdatedClientBounds() { | 71 gfx::Rect GetUpdatedClientBounds() { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 100 void SetExtraViewPadding(int padding) { | 102 void SetExtraViewPadding(int padding) { |
| 101 DCHECK(!extra_view_padding_); | 103 DCHECK(!extra_view_padding_); |
| 102 extra_view_padding_.reset(new int(padding)); | 104 extra_view_padding_.reset(new int(padding)); |
| 103 client_view_->Layout(); | 105 client_view_->Layout(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 TestDialogClientView* client_view() { return client_view_.get(); } | 108 TestDialogClientView* client_view() { return client_view_.get(); } |
| 107 | 109 |
| 108 private: | 110 private: |
| 109 // The contents of the dialog. | 111 // The contents of the dialog. |
| 110 scoped_ptr<View> contents_; | 112 View* contents_; |
|
sky
2016/04/07 19:09:38
Why do you need contents_? This is a DialogDelegat
karandeepb
2016/04/08 01:40:43
Yeah I also thought this was weird. Have refactore
| |
| 111 // The DialogClientView that's being tested. | 113 // The DialogClientView that's being tested. |
| 112 scoped_ptr<TestDialogClientView> client_view_; | 114 scoped_ptr<TestDialogClientView> client_view_; |
| 113 // The bitmask of buttons to show in the dialog. | 115 // The bitmask of buttons to show in the dialog. |
| 114 int dialog_buttons_; | 116 int dialog_buttons_; |
| 115 View* extra_view_; // weak | 117 View* extra_view_; // weak |
| 116 scoped_ptr<int> extra_view_padding_; // Null by default. | 118 scoped_ptr<int> extra_view_padding_; // Null by default. |
| 117 | 119 |
| 118 DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); | 120 DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); |
| 119 }; | 121 }; |
| 120 | 122 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 197 |
| 196 // Add extra view and remove OK button. | 198 // Add extra view and remove OK button. |
| 197 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); | 199 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); |
| 198 SetExtraView(extra_view); | 200 SetExtraView(extra_view); |
| 199 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); | 201 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); |
| 200 | 202 |
| 201 EXPECT_EQ(extra_view, | 203 EXPECT_EQ(extra_view, |
| 202 client_view()->GetContentsView()->GetNextFocusableView()); | 204 client_view()->GetContentsView()->GetNextFocusableView()); |
| 203 EXPECT_EQ(client_view()->cancel_button(), extra_view->GetNextFocusableView()); | 205 EXPECT_EQ(client_view()->cancel_button(), extra_view->GetNextFocusableView()); |
| 204 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); | 206 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); |
| 207 | |
| 208 // Add a dummy view to the client view. | |
| 209 View* dummy_view = new StaticSizedView(gfx::Size(200, 200)); | |
| 210 client_view()->AddChildView(dummy_view); | |
| 211 EXPECT_EQ(dummy_view, client_view()->cancel_button()->GetNextFocusableView()); | |
| 205 } | 212 } |
| 206 | 213 |
| 207 // Test that the contents view gets its preferred size in the basic dialog | 214 // Test that the contents view gets its preferred size in the basic dialog |
| 208 // configuration. | 215 // configuration. |
| 209 TEST_F(DialogClientViewTest, ContentsSize) { | 216 TEST_F(DialogClientViewTest, ContentsSize) { |
| 210 CheckContentsIsSetToPreferredSize(); | 217 CheckContentsIsSetToPreferredSize(); |
| 211 EXPECT_EQ(GetContentsView()->bounds().bottom(), | 218 EXPECT_EQ(GetContentsView()->bounds().bottom(), |
| 212 client_view()->bounds().bottom()); | 219 client_view()->bounds().bottom()); |
| 213 } | 220 } |
| 214 | 221 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 239 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); | 246 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); |
| 240 | 247 |
| 241 // Try with a reduced-size dialog. | 248 // Try with a reduced-size dialog. |
| 242 extra_view->SetVisible(true); | 249 extra_view->SetVisible(true); |
| 243 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); | 250 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); |
| 244 client_view()->Layout(); | 251 client_view()->Layout(); |
| 245 EXPECT_GT(width_of_extra_view, extra_view->bounds().width()); | 252 EXPECT_GT(width_of_extra_view, extra_view->bounds().width()); |
| 246 } | 253 } |
| 247 | 254 |
| 248 } // namespace views | 255 } // namespace views |
| OLD | NEW |