| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 // Set a longer than normal Cancel label so that the minimum button width is | 135 // Set a longer than normal Cancel label so that the minimum button width is |
| 136 // exceeded. The resulting width is around 160 pixels, but depends on system | 136 // exceeded. The resulting width is around 160 pixels, but depends on system |
| 137 // fonts. | 137 // fonts. |
| 138 void SetLongCancelLabel() { | 138 void SetLongCancelLabel() { |
| 139 cancel_label_ = base::ASCIIToUTF16("Cancel Cancel Cancel"); | 139 cancel_label_ = base::ASCIIToUTF16("Cancel Cancel Cancel"); |
| 140 } | 140 } |
| 141 | 141 |
| 142 DialogClientView* client_view() { return client_view_; } | 142 DialogClientView* client_view() { return client_view_; } |
| 143 | 143 |
| 144 Widget* widget() { return widget_; } |
| 145 |
| 144 private: | 146 private: |
| 145 // The dialog Widget. | 147 // The dialog Widget. |
| 146 Widget* widget_ = nullptr; | 148 Widget* widget_ = nullptr; |
| 147 | 149 |
| 148 // The DialogClientView that's being tested. Owned by |widget_|. | 150 // The DialogClientView that's being tested. Owned by |widget_|. |
| 149 DialogClientView* client_view_; | 151 DialogClientView* client_view_; |
| 150 | 152 |
| 151 // The bitmask of buttons to show in the dialog. | 153 // The bitmask of buttons to show in the dialog. |
| 152 int dialog_buttons_ = ui::DIALOG_BUTTON_NONE; | 154 int dialog_buttons_ = ui::DIALOG_BUTTON_NONE; |
| 153 | 155 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 gfx::Size(666, 666)); | 431 gfx::Size(666, 666)); |
| 430 SetDialogButtons(ui::DIALOG_BUTTON_OK); | 432 SetDialogButtons(ui::DIALOG_BUTTON_OK); |
| 431 client_view()->SizeToPreferredSize(); | 433 client_view()->SizeToPreferredSize(); |
| 432 client_view()->Layout(); | 434 client_view()->Layout(); |
| 433 EXPECT_EQ(contents_width - button_row_inset, | 435 EXPECT_EQ(contents_width - button_row_inset, |
| 434 client_view()->ok_button()->bounds().right()); | 436 client_view()->ok_button()->bounds().right()); |
| 435 EXPECT_EQ(contents_height + button_row_inset, | 437 EXPECT_EQ(contents_height + button_row_inset, |
| 436 height() + client_view()->ok_button()->y()); | 438 height() + client_view()->ok_button()->y()); |
| 437 } | 439 } |
| 438 | 440 |
| 441 // Ensures that the focus of the button remains after a dialog update. |
| 442 TEST_F(DialogClientViewTest, FocusUpdate) { |
| 443 // Test with just an ok button. |
| 444 widget()->Show(); |
| 445 SetDialogButtons(ui::DIALOG_BUTTON_OK); |
| 446 EXPECT_FALSE(client_view()->ok_button()->HasFocus()); |
| 447 client_view()->ok_button()->RequestFocus(); // Set focus. |
| 448 EXPECT_TRUE(client_view()->ok_button()->HasFocus()); |
| 449 client_view()->UpdateDialogButtons(); |
| 450 EXPECT_TRUE(client_view()->ok_button()->HasFocus()); |
| 451 } |
| 452 |
| 453 // Ensures that the focus of the button remains after a dialog update that |
| 454 // contains multiple buttons. |
| 455 TEST_F(DialogClientViewTest, FocusMultipleButtons) { |
| 456 // Test with ok and cancel buttons. |
| 457 widget()->Show(); |
| 458 SetDialogButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK); |
| 459 EXPECT_FALSE(client_view()->ok_button()->HasFocus()); |
| 460 EXPECT_FALSE(client_view()->cancel_button()->HasFocus()); |
| 461 client_view()->cancel_button()->RequestFocus(); // Set focus. |
| 462 EXPECT_FALSE(client_view()->ok_button()->HasFocus()); |
| 463 EXPECT_TRUE(client_view()->cancel_button()->HasFocus()); |
| 464 client_view()->UpdateDialogButtons(); |
| 465 EXPECT_TRUE(client_view()->cancel_button()->HasFocus()); |
| 466 } |
| 467 |
| 439 } // namespace views | 468 } // namespace views |
| OLD | NEW |