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

Side by Side Diff: ui/views/window/dialog_client_view_unittest.cc

Issue 2807653002: Ensure default dialog button focus remains after a dialog update. (Closed)
Patch Set: Addressing Devlin's comments. Created 3 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 unified diff | Download patch
OLDNEW
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
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.
sky 2017/04/28 20:49:52 Just to be clear, does these tests fail without yo
ackermanb 2017/05/17 17:20:54 Yep, the tests do fail out without the patch.
409 TEST_F(DialogClientViewTest, DefaultFocus) {
410 // Test with just an ok button.
411 SetDialogButtons(ui::DIALOG_BUTTON_OK);
412 EXPECT_EQ(client_view()->ok_button(), GetInitiallyFocusedView());
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(client_view()->cancel_button(), GetInitiallyFocusedView());
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(client_view()->ok_button(), GetInitiallyFocusedView());
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
OLDNEW
« ui/views/window/dialog_client_view.cc ('K') | « ui/views/window/dialog_client_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698