Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: ui/views/view_unittest.cc

Issue 14230018: Handle dialog acclerators explicitly; nix default button switching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Limit the focused view handling to LabelButton; update tests. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/tree/tree_view.cc ('k') | ui/views/window/dialog_client_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 7e7560af9cfee9105a994187c878550563f08f8e..608a67f3e66c1181a0926033936303e432a1ec72 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -1711,7 +1711,7 @@ class DefaultButtonTest : public ViewTest {
ViewTest::TearDown();
}
- void SimulatePressingEnterAndCheckDefaultButton(ButtonID button_id) {
+ void SimulatePressingEnterAndCheckHandledButton(ButtonID button_id) {
ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false);
focus_manager_->OnKeyEvent(event);
switch (button_id) {
@@ -1749,50 +1749,50 @@ class DefaultButtonTest : public ViewTest {
};
TEST_F(DefaultButtonTest, DialogDefaultButtonTest) {
- // Window has just been shown, we expect the default button specified in the
- // DialogDelegate.
+ // The dialog should initially honor the delegate's specified default button.
EXPECT_TRUE(ok_button_->is_default());
+ EXPECT_FALSE(test_dialog_->button1_->is_default());
+ EXPECT_FALSE(test_dialog_->button2_->is_default());
// Simulate pressing enter, that should trigger the OK button.
- SimulatePressingEnterAndCheckDefaultButton(OK);
+ SimulatePressingEnterAndCheckHandledButton(OK);
- // Simulate focusing another button, it should become the default button.
- client_view_->OnWillChangeFocus(ok_button_, test_dialog_->button1_);
- EXPECT_FALSE(ok_button_->is_default());
- EXPECT_TRUE(test_dialog_->button1_->is_default());
+ // Focusing another button changes enter handling, but not the default button.
+ FocusManager* focus_manager = client_view_->GetFocusManager();
+ focus_manager->SetFocusedView(test_dialog_->button1_);
+ EXPECT_TRUE(ok_button_->is_default());
+ EXPECT_FALSE(test_dialog_->button1_->is_default());
+ EXPECT_FALSE(test_dialog_->button2_->is_default());
// Simulate pressing enter, that should trigger button1.
- SimulatePressingEnterAndCheckDefaultButton(BUTTON1);
+ SimulatePressingEnterAndCheckHandledButton(BUTTON1);
- // Now select something that is not a button, the OK should become the default
- // button again.
- client_view_->OnWillChangeFocus(test_dialog_->button1_,
- test_dialog_->checkbox_);
+ // Focusing a non-button view invokes OK.
+ focus_manager->SetFocusedView(test_dialog_->checkbox_);
EXPECT_TRUE(ok_button_->is_default());
EXPECT_FALSE(test_dialog_->button1_->is_default());
- SimulatePressingEnterAndCheckDefaultButton(OK);
+ EXPECT_FALSE(test_dialog_->button2_->is_default());
+ SimulatePressingEnterAndCheckHandledButton(OK);
- // Select yet another button.
- client_view_->OnWillChangeFocus(test_dialog_->checkbox_,
- test_dialog_->button2_);
- EXPECT_FALSE(ok_button_->is_default());
+ // Focus yet another button.
+ focus_manager->SetFocusedView(test_dialog_->button2_);
+ EXPECT_TRUE(ok_button_->is_default());
EXPECT_FALSE(test_dialog_->button1_->is_default());
- EXPECT_TRUE(test_dialog_->button2_->is_default());
- SimulatePressingEnterAndCheckDefaultButton(BUTTON2);
+ EXPECT_FALSE(test_dialog_->button2_->is_default());
+ SimulatePressingEnterAndCheckHandledButton(BUTTON2);
// Focus nothing.
- client_view_->OnWillChangeFocus(test_dialog_->button2_, NULL);
+ focus_manager->ClearFocus();
EXPECT_TRUE(ok_button_->is_default());
EXPECT_FALSE(test_dialog_->button1_->is_default());
EXPECT_FALSE(test_dialog_->button2_->is_default());
- SimulatePressingEnterAndCheckDefaultButton(OK);
+ SimulatePressingEnterAndCheckHandledButton(OK);
// Focus the cancel button.
- client_view_->OnWillChangeFocus(NULL, cancel_button_);
- EXPECT_FALSE(ok_button_->is_default());
- EXPECT_TRUE(cancel_button_->is_default());
+ focus_manager->SetFocusedView(cancel_button_);
+ EXPECT_TRUE(ok_button_->is_default());
EXPECT_FALSE(test_dialog_->button1_->is_default());
EXPECT_FALSE(test_dialog_->button2_->is_default());
- SimulatePressingEnterAndCheckDefaultButton(CANCEL);
+ SimulatePressingEnterAndCheckHandledButton(CANCEL);
}
class ButtonDropDownTest : public ViewTest {
« no previous file with comments | « ui/views/controls/tree/tree_view.cc ('k') | ui/views/window/dialog_client_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698