| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 EXPECT_EQ(NULL, client_view()->ok_button()); | 169 EXPECT_EQ(NULL, client_view()->ok_button()); |
| 170 delete client_view()->cancel_button(); | 170 delete client_view()->cancel_button(); |
| 171 EXPECT_EQ(NULL, client_view()->cancel_button()); | 171 EXPECT_EQ(NULL, client_view()->cancel_button()); |
| 172 | 172 |
| 173 // Updating should restore the requested buttons properly. | 173 // Updating should restore the requested buttons properly. |
| 174 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | 174 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); |
| 175 EXPECT_TRUE(client_view()->ok_button()->is_default()); | 175 EXPECT_TRUE(client_view()->ok_button()->is_default()); |
| 176 EXPECT_FALSE(client_view()->cancel_button()->is_default()); | 176 EXPECT_FALSE(client_view()->cancel_button()->is_default()); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Test that views inside the dialog client view have the correct focus order. |
| 180 TEST_F(DialogClientViewTest, SetupFocusChain) { |
| 181 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
| 182 const bool kIsOkButtonOnLeftSide = true; |
| 183 #else |
| 184 const bool kIsOkButtonOnLeftSide = false; |
| 185 #endif |
| 186 |
| 187 // Initially the dialog client view only contains the content view. |
| 188 EXPECT_EQ(nullptr, client_view()->GetContentsView()->GetNextFocusableView()); |
| 189 |
| 190 // Add OK and cancel buttons. |
| 191 SetDialogButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); |
| 192 |
| 193 if (kIsOkButtonOnLeftSide) { |
| 194 EXPECT_EQ(client_view()->ok_button(), |
| 195 client_view()->GetContentsView()->GetNextFocusableView()); |
| 196 EXPECT_EQ(client_view()->cancel_button(), |
| 197 client_view()->ok_button()->GetNextFocusableView()); |
| 198 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); |
| 199 } else { |
| 200 EXPECT_EQ(client_view()->cancel_button(), |
| 201 client_view()->GetContentsView()->GetNextFocusableView()); |
| 202 EXPECT_EQ(client_view()->ok_button(), |
| 203 client_view()->cancel_button()->GetNextFocusableView()); |
| 204 EXPECT_EQ(nullptr, client_view()->ok_button()->GetNextFocusableView()); |
| 205 } |
| 206 |
| 207 // Add extra view and remove OK button. |
| 208 View* extra_view = new StaticSizedView(gfx::Size(200, 200)); |
| 209 SetExtraView(extra_view); |
| 210 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); |
| 211 |
| 212 EXPECT_EQ(extra_view, |
| 213 client_view()->GetContentsView()->GetNextFocusableView()); |
| 214 EXPECT_EQ(client_view()->cancel_button(), extra_view->GetNextFocusableView()); |
| 215 EXPECT_EQ(nullptr, client_view()->cancel_button()->GetNextFocusableView()); |
| 216 } |
| 217 |
| 179 // Test that the contents view gets its preferred size in the basic dialog | 218 // Test that the contents view gets its preferred size in the basic dialog |
| 180 // configuration. | 219 // configuration. |
| 181 TEST_F(DialogClientViewTest, ContentsSize) { | 220 TEST_F(DialogClientViewTest, ContentsSize) { |
| 182 CheckContentsIsSetToPreferredSize(); | 221 CheckContentsIsSetToPreferredSize(); |
| 183 EXPECT_EQ(GetContentsView()->bounds().bottom(), | 222 EXPECT_EQ(GetContentsView()->bounds().bottom(), |
| 184 client_view()->bounds().bottom()); | 223 client_view()->bounds().bottom()); |
| 185 } | 224 } |
| 186 | 225 |
| 187 // Test the effect of the button strip on layout. | 226 // Test the effect of the button strip on layout. |
| 188 TEST_F(DialogClientViewTest, LayoutWithButtons) { | 227 TEST_F(DialogClientViewTest, LayoutWithButtons) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 289 |
| 251 View* footnote_view = new ProportionallySizedView(3); | 290 View* footnote_view = new ProportionallySizedView(3); |
| 252 SetFootnoteView(footnote_view); | 291 SetFootnoteView(footnote_view); |
| 253 CheckContentsIsSetToPreferredSize(); | 292 CheckContentsIsSetToPreferredSize(); |
| 254 EXPECT_GT(client_view()->bounds().height(), no_footnote_size.height()); | 293 EXPECT_GT(client_view()->bounds().height(), no_footnote_size.height()); |
| 255 EXPECT_EQ(footnote_view->bounds().width() * 3, | 294 EXPECT_EQ(footnote_view->bounds().width() * 3, |
| 256 footnote_view->bounds().height()); | 295 footnote_view->bounds().height()); |
| 257 } | 296 } |
| 258 | 297 |
| 259 } // namespace views | 298 } // namespace views |
| OLD | NEW |