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

Side by Side Diff: ui/views/controls/button/custom_button_unittest.cc

Issue 2017833003: Fixes ink drop being "stuck" on when losing focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removal of the nits... Created 4 years, 6 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/controls/button/custom_button.h" 5 #include "ui/views/controls/button/custom_button.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 bool pressed() { return pressed_; } 73 bool pressed() { return pressed_; }
74 bool canceled() { return canceled_; } 74 bool canceled() { return canceled_; }
75 75
76 void Reset() { 76 void Reset() {
77 pressed_ = false; 77 pressed_ = false;
78 canceled_ = false; 78 canceled_ = false;
79 } 79 }
80 80
81 private: 81 void OnFocus() override {
bruthig 2016/06/02 15:21:35 nit: a comment here would be useful. I assume it'
kylix_rd 2016/06/02 15:52:33 Done.
82 CustomButton::OnFocus();
83 }
84
85 private:
82 bool pressed_ = false; 86 bool pressed_ = false;
83 bool canceled_ = false; 87 bool canceled_ = false;
84 88
85 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); 89 DISALLOW_COPY_AND_ASSIGN(TestCustomButton);
86 }; 90 };
87 91
88 // An InkDropDelegate that keeps track of ink drop visibility. 92 // An InkDropDelegate that keeps track of ink drop visibility.
89 class TestInkDropDelegateThatTracksVisibilty : public TestInkDropDelegate { 93 class TestInkDropDelegateThatTracksVisibilty : public TestInkDropDelegate {
90 public: 94 public:
91 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) 95 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden)
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 ink_drop_delegate->SetHovered(true); 465 ink_drop_delegate->SetHovered(true);
462 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 466 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
463 467
464 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 468 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
465 469
466 EXPECT_TRUE(ink_drop_delegate->is_hovered()); 470 EXPECT_TRUE(ink_drop_delegate->is_hovered());
467 EXPECT_EQ(InkDropState::ACTION_PENDING, 471 EXPECT_EQ(InkDropState::ACTION_PENDING,
468 ink_drop_delegate->GetTargetInkDropState()); 472 ink_drop_delegate->GetTargetInkDropState());
469 } 473 }
470 474
475 TEST_F(CustomButtonTest, HideInkDropOnBlur) {
476 gfx::Point center(10, 10);
477
478 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
479 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate));
480
481 button()->OnFocus();
482
483 button()->OnMousePressed(ui::MouseEvent(
484 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
485 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
486 EXPECT_EQ(InkDropState::ACTION_PENDING,
487 ink_drop_delegate->GetTargetInkDropState());
488
489 button()->OnBlur();
490 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState());
491
492 button()->OnMouseReleased(ui::MouseEvent(
493 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
494 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
495 EXPECT_TRUE(button()->pressed());
496 }
497
471 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { 498 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) {
472 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); 499 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
473 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); 500 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate));
474 button()->set_context_menu_controller(nullptr); 501 button()->set_context_menu_controller(nullptr);
475 502
476 ink_drop_delegate->SetHovered(true); 503 ink_drop_delegate->SetHovered(true);
477 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 504 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
478 505
479 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 506 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
480 507
481 EXPECT_TRUE(ink_drop_delegate->is_hovered()); 508 EXPECT_TRUE(ink_drop_delegate->is_hovered());
482 EXPECT_EQ(InkDropState::ACTION_PENDING, 509 EXPECT_EQ(InkDropState::ACTION_PENDING,
483 ink_drop_delegate->GetTargetInkDropState()); 510 ink_drop_delegate->GetTargetInkDropState());
484 } 511 }
485 512
486 } // namespace views 513 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698