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 "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/test/material_design_controller_test_api.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 // Remove |extra_button| from the View hierarchy so that it can be replaced. | 398 // Remove |extra_button| from the View hierarchy so that it can be replaced. |
| 399 delete extra_button; | 399 delete extra_button; |
| 400 | 400 |
| 401 // Non-buttons should always be sized to their preferred size. | 401 // Non-buttons should always be sized to their preferred size. |
| 402 View* boring_view = new StaticSizedView(gfx::Size(20, 20)); | 402 View* boring_view = new StaticSizedView(gfx::Size(20, 20)); |
| 403 SetExtraView(boring_view); | 403 SetExtraView(boring_view); |
| 404 CheckContentsIsSetToPreferredSize(); | 404 CheckContentsIsSetToPreferredSize(); |
| 405 EXPECT_EQ(20, boring_view->width()); | 405 EXPECT_EQ(20, boring_view->width()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 // Tests that the default focus of the button reamins after a dialog update. | |
| 409 TEST_F(DialogClientViewTest, DefaultFocus) { | |
| 410 // Test with just an ok button. | |
| 411 SetDialogButtons(ui::DIALOG_BUTTON_OK); | |
| 412 EXPECT_EQ(GetInitiallyFocusedView(), client_view()->ok_button()); | |
|
Devlin
2017/04/12 19:36:31
nitty nit: EXPECT_EQ(expected, actual)
Ackerman
2017/04/28 18:22:59
Done.
| |
| 413 GetInitiallyFocusedView()->RequestFocus(); // Focus is not given by default. | |
| 414 EXPECT_TRUE(client_view()->ok_button()->HasFocus()); | |
| 415 client_view()->UpdateDialogButtons(); | |
| 416 EXPECT_TRUE(client_view()->ok_button()->HasFocus()); | |
| 417 | |
| 418 // Test with just a cancel button. | |
| 419 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); | |
| 420 EXPECT_EQ(GetInitiallyFocusedView(), client_view()->cancel_button()); | |
| 421 GetInitiallyFocusedView()->RequestFocus(); // Focus is not given by default. | |
| 422 EXPECT_TRUE(client_view()->cancel_button()->HasFocus()); | |
| 423 client_view()->UpdateDialogButtons(); | |
| 424 EXPECT_TRUE(client_view()->cancel_button()->HasFocus()); | |
| 425 | |
| 426 // Test with both buttons, the ok button is default. | |
| 427 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK); | |
| 428 EXPECT_EQ(GetInitiallyFocusedView(), client_view()->ok_button()); | |
| 429 GetInitiallyFocusedView()->RequestFocus(); // Focus is not given by default. | |
| 430 EXPECT_TRUE(client_view()->ok_button()->HasFocus()); | |
| 431 EXPECT_FALSE(client_view()->cancel_button()->HasFocus()); | |
| 432 client_view()->UpdateDialogButtons(); | |
| 433 EXPECT_TRUE(client_view()->ok_button()->HasFocus()); | |
| 434 EXPECT_FALSE(client_view()->cancel_button()->HasFocus()); | |
| 435 } | |
| 436 | |
| 408 } // namespace views | 437 } // namespace views |
| OLD | NEW |