| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "ui/base/ui_base_types.h" | 7 #include "ui/base/ui_base_types.h" |
| 8 #include "ui/views/controls/button/label_button.h" | 8 #include "ui/views/controls/button/label_button.h" |
| 9 #include "ui/views/test/test_views.h" | 9 #include "ui/views/test/test_views.h" |
| 10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 dialog_buttons_ = ui::DIALOG_BUTTON_NONE; | 52 dialog_buttons_ = ui::DIALOG_BUTTON_NONE; |
| 53 contents_.reset(new StaticSizedView(gfx::Size(100, 200))); | 53 contents_.reset(new StaticSizedView(gfx::Size(100, 200))); |
| 54 client_view_.reset(new TestDialogClientView(contents_.get(), this)); | 54 client_view_.reset(new TestDialogClientView(contents_.get(), this)); |
| 55 | 55 |
| 56 ViewsTestBase::SetUp(); | 56 ViewsTestBase::SetUp(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // DialogDelegateView implementation. | 59 // DialogDelegateView implementation. |
| 60 View* GetContentsView() override { return contents_.get(); } | 60 View* GetContentsView() override { return contents_.get(); } |
| 61 View* CreateExtraView() override { return extra_view_; } | 61 View* CreateExtraView() override { return extra_view_; } |
| 62 bool GetExtraViewPadding(int* padding) override { |
| 63 if (extra_view_padding_) |
| 64 *padding = *extra_view_padding_; |
| 65 return extra_view_padding_.get() != nullptr; |
| 66 } |
| 62 View* CreateFootnoteView() override { return footnote_view_; } | 67 View* CreateFootnoteView() override { return footnote_view_; } |
| 63 int GetDialogButtons() const override { return dialog_buttons_; } | 68 int GetDialogButtons() const override { return dialog_buttons_; } |
| 64 | 69 |
| 65 protected: | 70 protected: |
| 66 gfx::Rect GetUpdatedClientBounds() { | 71 gfx::Rect GetUpdatedClientBounds() { |
| 67 client_view_->SizeToPreferredSize(); | 72 client_view_->SizeToPreferredSize(); |
| 68 client_view_->Layout(); | 73 client_view_->Layout(); |
| 69 return client_view_->bounds(); | 74 return client_view_->bounds(); |
| 70 } | 75 } |
| 71 | 76 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 86 client_view_->UpdateDialogButtons(); | 91 client_view_->UpdateDialogButtons(); |
| 87 } | 92 } |
| 88 | 93 |
| 89 // Sets the extra view. | 94 // Sets the extra view. |
| 90 void SetExtraView(View* view) { | 95 void SetExtraView(View* view) { |
| 91 DCHECK(!extra_view_); | 96 DCHECK(!extra_view_); |
| 92 extra_view_ = view; | 97 extra_view_ = view; |
| 93 client_view_->CreateExtraViews(); | 98 client_view_->CreateExtraViews(); |
| 94 } | 99 } |
| 95 | 100 |
| 101 // Sets the extra view padding. |
| 102 void SetExtraViewPadding(int padding) { |
| 103 DCHECK(!extra_view_padding_); |
| 104 extra_view_padding_.reset(new int(padding)); |
| 105 client_view_->Layout(); |
| 106 } |
| 107 |
| 96 // Sets the footnote view. | 108 // Sets the footnote view. |
| 97 void SetFootnoteView(View* view) { | 109 void SetFootnoteView(View* view) { |
| 98 DCHECK(!footnote_view_); | 110 DCHECK(!footnote_view_); |
| 99 footnote_view_ = view; | 111 footnote_view_ = view; |
| 100 client_view_->CreateExtraViews(); | 112 client_view_->CreateExtraViews(); |
| 101 } | 113 } |
| 102 | 114 |
| 103 TestDialogClientView* client_view() { return client_view_.get(); } | 115 TestDialogClientView* client_view() { return client_view_.get(); } |
| 104 | 116 |
| 105 private: | 117 private: |
| 106 // The contents of the dialog. | 118 // The contents of the dialog. |
| 107 scoped_ptr<View> contents_; | 119 scoped_ptr<View> contents_; |
| 108 // The DialogClientView that's being tested. | 120 // The DialogClientView that's being tested. |
| 109 scoped_ptr<TestDialogClientView> client_view_; | 121 scoped_ptr<TestDialogClientView> client_view_; |
| 110 // The bitmask of buttons to show in the dialog. | 122 // The bitmask of buttons to show in the dialog. |
| 111 int dialog_buttons_; | 123 int dialog_buttons_; |
| 112 View* extra_view_; // weak | 124 View* extra_view_; // weak |
| 125 scoped_ptr<int> extra_view_padding_; // Null by default. |
| 113 View* footnote_view_; // weak | 126 View* footnote_view_; // weak |
| 114 | 127 |
| 115 DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); | 128 DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); |
| 116 }; | 129 }; |
| 117 | 130 |
| 118 TEST_F(DialogClientViewTest, UpdateButtons) { | 131 TEST_F(DialogClientViewTest, UpdateButtons) { |
| 119 // This dialog should start with no buttons. | 132 // This dialog should start with no buttons. |
| 120 EXPECT_EQ(GetDialogButtons(), ui::DIALOG_BUTTON_NONE); | 133 EXPECT_EQ(GetDialogButtons(), ui::DIALOG_BUTTON_NONE); |
| 121 EXPECT_EQ(NULL, client_view()->ok_button()); | 134 EXPECT_EQ(NULL, client_view()->ok_button()); |
| 122 EXPECT_EQ(NULL, client_view()->cancel_button()); | 135 EXPECT_EQ(NULL, client_view()->cancel_button()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | 188 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); |
| 176 CheckContentsIsSetToPreferredSize(); | 189 CheckContentsIsSetToPreferredSize(); |
| 177 EXPECT_LT(GetContentsView()->bounds().bottom(), | 190 EXPECT_LT(GetContentsView()->bounds().bottom(), |
| 178 client_view()->bounds().bottom()); | 191 client_view()->bounds().bottom()); |
| 179 gfx::Size no_extra_view_size = client_view()->bounds().size(); | 192 gfx::Size no_extra_view_size = client_view()->bounds().size(); |
| 180 | 193 |
| 181 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); | 194 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); |
| 182 SetExtraView(extra_view); | 195 SetExtraView(extra_view); |
| 183 CheckContentsIsSetToPreferredSize(); | 196 CheckContentsIsSetToPreferredSize(); |
| 184 EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height()); | 197 EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height()); |
| 198 int width_of_dialog = client_view()->bounds().width(); |
| 185 int width_of_extra_view = extra_view->bounds().width(); | 199 int width_of_extra_view = extra_view->bounds().width(); |
| 186 | 200 |
| 201 // Try with an adjusted padding for the extra view. |
| 202 SetExtraViewPadding(250); |
| 203 CheckContentsIsSetToPreferredSize(); |
| 204 EXPECT_GT(client_view()->bounds().width(), width_of_dialog); |
| 205 |
| 187 // Visibility of extra view is respected. | 206 // Visibility of extra view is respected. |
| 188 extra_view->SetVisible(false); | 207 extra_view->SetVisible(false); |
| 189 CheckContentsIsSetToPreferredSize(); | 208 CheckContentsIsSetToPreferredSize(); |
| 190 EXPECT_EQ(no_extra_view_size.height(), client_view()->bounds().height()); | 209 EXPECT_EQ(no_extra_view_size.height(), client_view()->bounds().height()); |
| 191 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); | 210 EXPECT_EQ(no_extra_view_size.width(), client_view()->bounds().width()); |
| 192 | 211 |
| 193 // Try with a reduced-size dialog. | 212 // Try with a reduced-size dialog. |
| 194 extra_view->SetVisible(true); | 213 extra_view->SetVisible(true); |
| 195 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); | 214 client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size)); |
| 196 client_view()->Layout(); | 215 client_view()->Layout(); |
| 197 DCHECK_GT(width_of_extra_view, extra_view->bounds().width()); | 216 EXPECT_GT(width_of_extra_view, extra_view->bounds().width()); |
| 198 } | 217 } |
| 199 | 218 |
| 200 // Test the effect of the footnote view on layout. | 219 // Test the effect of the footnote view on layout. |
| 201 TEST_F(DialogClientViewTest, LayoutWithFootnote) { | 220 TEST_F(DialogClientViewTest, LayoutWithFootnote) { |
| 202 CheckContentsIsSetToPreferredSize(); | 221 CheckContentsIsSetToPreferredSize(); |
| 203 gfx::Size no_footnote_size = client_view()->bounds().size(); | 222 gfx::Size no_footnote_size = client_view()->bounds().size(); |
| 204 | 223 |
| 205 View* footnote_view = new StaticSizedView(gfx::Size(200, 200)); | 224 View* footnote_view = new StaticSizedView(gfx::Size(200, 200)); |
| 206 SetFootnoteView(footnote_view); | 225 SetFootnoteView(footnote_view); |
| 207 CheckContentsIsSetToPreferredSize(); | 226 CheckContentsIsSetToPreferredSize(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // Test that the FocusManager is properly cleared when the DialogClientView is | 302 // Test that the FocusManager is properly cleared when the DialogClientView is |
| 284 // removed from |dialog| during the widget's destruction. | 303 // removed from |dialog| during the widget's destruction. |
| 285 client_view->set_owned_by_client(); | 304 client_view->set_owned_by_client(); |
| 286 scoped_ptr<DialogClientView> owned_client_view(client_view); | 305 scoped_ptr<DialogClientView> owned_client_view(client_view); |
| 287 toplevel1->CloseNow(); | 306 toplevel1->CloseNow(); |
| 288 toplevel2->CloseNow(); | 307 toplevel2->CloseNow(); |
| 289 EXPECT_EQ(NULL, owned_client_view->focus_manager_); | 308 EXPECT_EQ(NULL, owned_client_view->focus_manager_); |
| 290 } | 309 } |
| 291 | 310 |
| 292 } // namespace views | 311 } // namespace views |
| OLD | NEW |