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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 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
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/button/image_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 9 #include "build/build_config.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/layout.h" 11 #include "ui/base/layout.h"
11 #include "ui/base/material_design/material_design_controller.h" 12 #include "ui/base/material_design/material_design_controller.h"
12 #include "ui/events/event_utils.h" 13 #include "ui/events/event_utils.h"
13 #include "ui/events/test/event_generator.h" 14 #include "ui/events/test/event_generator.h"
14 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
15 #include "ui/views/animation/ink_drop_delegate.h" 16 #include "ui/views/animation/ink_drop_delegate.h"
16 #include "ui/views/animation/ink_drop_host.h" 17 #include "ui/views/animation/ink_drop_host.h"
17 #include "ui/views/animation/test/test_ink_drop_delegate.h" 18 #include "ui/views/animation/test/test_ink_drop_delegate.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 private: 117 private:
117 bool* ink_shown_; 118 bool* ink_shown_;
118 bool* ink_hidden_; 119 bool* ink_hidden_;
119 120
120 DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegateThatTracksVisibilty); 121 DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegateThatTracksVisibilty);
121 }; 122 };
122 123
123 // A test Button class that owns a TestInkDropDelegate. 124 // A test Button class that owns a TestInkDropDelegate.
124 class TestButtonWithInkDrop : public TestCustomButton { 125 class TestButtonWithInkDrop : public TestCustomButton {
125 public: 126 public:
126 TestButtonWithInkDrop(scoped_ptr<InkDropDelegate> ink_drop_delegate) 127 TestButtonWithInkDrop(std::unique_ptr<InkDropDelegate> ink_drop_delegate)
127 : TestCustomButton(), ink_drop_delegate_(std::move(ink_drop_delegate)) { 128 : TestCustomButton(), ink_drop_delegate_(std::move(ink_drop_delegate)) {
128 set_ink_drop_delegate(ink_drop_delegate_.get()); 129 set_ink_drop_delegate(ink_drop_delegate_.get());
129 } 130 }
130 ~TestButtonWithInkDrop() override {} 131 ~TestButtonWithInkDrop() override {}
131 132
132 private: 133 private:
133 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; 134 std::unique_ptr<views::InkDropDelegate> ink_drop_delegate_;
134 135
135 DISALLOW_COPY_AND_ASSIGN(TestButtonWithInkDrop); 136 DISALLOW_COPY_AND_ASSIGN(TestButtonWithInkDrop);
136 }; 137 };
137 138
138 } // namespace 139 } // namespace
139 140
140 class CustomButtonTest : public ViewsTestBase { 141 class CustomButtonTest : public ViewsTestBase {
141 public: 142 public:
142 CustomButtonTest() {} 143 CustomButtonTest() {}
143 ~CustomButtonTest() override {} 144 ~CustomButtonTest() override {}
(...skipping 12 matching lines...) Expand all
156 157
157 button_ = new TestCustomButton(); 158 button_ = new TestCustomButton();
158 widget_->SetContentsView(button_); 159 widget_->SetContentsView(button_);
159 } 160 }
160 161
161 void TearDown() override { 162 void TearDown() override {
162 widget_.reset(); 163 widget_.reset();
163 ViewsTestBase::TearDown(); 164 ViewsTestBase::TearDown();
164 } 165 }
165 166
166 void CreateButtonWithInkDrop(scoped_ptr<InkDropDelegate> ink_drop_delegate) { 167 void CreateButtonWithInkDrop(
168 std::unique_ptr<InkDropDelegate> ink_drop_delegate) {
167 delete button_; 169 delete button_;
168 button_ = new TestButtonWithInkDrop(std::move(ink_drop_delegate)); 170 button_ = new TestButtonWithInkDrop(std::move(ink_drop_delegate));
169 widget_->SetContentsView(button_); 171 widget_->SetContentsView(button_);
170 } 172 }
171 173
172 protected: 174 protected:
173 Widget* widget() { return widget_.get(); } 175 Widget* widget() { return widget_.get(); }
174 TestCustomButton* button() { return button_; } 176 TestCustomButton* button() { return button_; }
175 void SetDraggedView(View* dragged_view) { 177 void SetDraggedView(View* dragged_view) {
176 widget_->dragged_view_ = dragged_view; 178 widget_->dragged_view_ = dragged_view;
177 } 179 }
178 180
179 private: 181 private:
180 scoped_ptr<Widget> widget_; 182 std::unique_ptr<Widget> widget_;
181 TestCustomButton* button_; 183 TestCustomButton* button_;
182 184
183 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); 185 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest);
184 }; 186 };
185 187
186 // Tests that hover state changes correctly when visiblity/enableness changes. 188 // Tests that hover state changes correctly when visiblity/enableness changes.
187 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { 189 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) {
188 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 190 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
189 191
190 generator.PressLeftButton(); 192 generator.PressLeftButton();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 388 }
387 389
388 // Tests that pressing a button shows the ink drop and releasing the button 390 // Tests that pressing a button shows the ink drop and releasing the button
389 // does not hide the ink drop. 391 // does not hide the ink drop.
390 // Note: Ink drop is not hidden upon release because CustomButton descendants 392 // Note: Ink drop is not hidden upon release because CustomButton descendants
391 // may enter a different ink drop state. 393 // may enter a different ink drop state.
392 TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) { 394 TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) {
393 gfx::Point old_cursor = gfx::Screen::GetScreen()->GetCursorScreenPoint(); 395 gfx::Point old_cursor = gfx::Screen::GetScreen()->GetCursorScreenPoint();
394 bool ink_shown = false; 396 bool ink_shown = false;
395 bool ink_hidden = false; 397 bool ink_hidden = false;
396 CreateButtonWithInkDrop(make_scoped_ptr( 398 CreateButtonWithInkDrop(base::WrapUnique(
397 new TestInkDropDelegateThatTracksVisibilty(&ink_shown, &ink_hidden))); 399 new TestInkDropDelegateThatTracksVisibilty(&ink_shown, &ink_hidden)));
398 400
399 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 401 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
400 generator.set_current_location(gfx::Point(50, 50)); 402 generator.set_current_location(gfx::Point(50, 50));
401 generator.PressLeftButton(); 403 generator.PressLeftButton();
402 EXPECT_TRUE(ink_shown); 404 EXPECT_TRUE(ink_shown);
403 EXPECT_FALSE(ink_hidden); 405 EXPECT_FALSE(ink_hidden);
404 406
405 generator.ReleaseLeftButton(); 407 generator.ReleaseLeftButton();
406 EXPECT_FALSE(ink_hidden); 408 EXPECT_FALSE(ink_hidden);
407 } 409 }
408 410
409 // Tests that pressing a button shows and releasing capture hides ink drop. 411 // Tests that pressing a button shows and releasing capture hides ink drop.
410 // Releasing capture should also reset PRESSED button state to NORMAL. 412 // Releasing capture should also reset PRESSED button state to NORMAL.
411 TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) { 413 TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) {
412 gfx::Point old_cursor = gfx::Screen::GetScreen()->GetCursorScreenPoint(); 414 gfx::Point old_cursor = gfx::Screen::GetScreen()->GetCursorScreenPoint();
413 bool ink_shown = false; 415 bool ink_shown = false;
414 bool ink_hidden = false; 416 bool ink_hidden = false;
415 CreateButtonWithInkDrop(make_scoped_ptr( 417 CreateButtonWithInkDrop(base::WrapUnique(
416 new TestInkDropDelegateThatTracksVisibilty(&ink_shown, &ink_hidden))); 418 new TestInkDropDelegateThatTracksVisibilty(&ink_shown, &ink_hidden)));
417 419
418 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 420 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
419 generator.set_current_location(gfx::Point(50, 50)); 421 generator.set_current_location(gfx::Point(50, 50));
420 generator.PressLeftButton(); 422 generator.PressLeftButton();
421 EXPECT_TRUE(ink_shown); 423 EXPECT_TRUE(ink_shown);
422 EXPECT_FALSE(ink_hidden); 424 EXPECT_FALSE(ink_hidden);
423 425
424 EXPECT_EQ(Button::ButtonState::STATE_PRESSED, button()->state()); 426 EXPECT_EQ(Button::ButtonState::STATE_PRESSED, button()->state());
425 SetDraggedView(button()); 427 SetDraggedView(button());
426 widget()->SetCapture(button()); 428 widget()->SetCapture(button());
427 widget()->ReleaseCapture(); 429 widget()->ReleaseCapture();
428 SetDraggedView(nullptr); 430 SetDraggedView(nullptr);
429 EXPECT_TRUE(ink_hidden); 431 EXPECT_TRUE(ink_hidden);
430 EXPECT_EQ(ui::MaterialDesignController::IsModeMaterial() 432 EXPECT_EQ(ui::MaterialDesignController::IsModeMaterial()
431 ? Button::ButtonState::STATE_NORMAL 433 ? Button::ButtonState::STATE_NORMAL
432 : Button::ButtonState::STATE_PRESSED, 434 : Button::ButtonState::STATE_PRESSED,
433 button()->state()); 435 button()->state());
434 } 436 }
435 437
436 TEST_F(CustomButtonTest, InkDropAfterShowingContextMenu) { 438 TEST_F(CustomButtonTest, InkDropAfterShowingContextMenu) {
437 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); 439 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
438 CreateButtonWithInkDrop(make_scoped_ptr(ink_drop_delegate)); 440 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate));
439 TestContextMenuController context_menu_controller; 441 TestContextMenuController context_menu_controller;
440 button()->set_context_menu_controller(&context_menu_controller); 442 button()->set_context_menu_controller(&context_menu_controller);
441 443
442 ink_drop_delegate->SetHovered(true); 444 ink_drop_delegate->SetHovered(true);
443 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 445 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
444 446
445 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 447 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
446 448
447 EXPECT_FALSE(ink_drop_delegate->is_hovered()); 449 EXPECT_FALSE(ink_drop_delegate->is_hovered());
448 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->state()); 450 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->state());
449 } 451 }
450 452
451 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { 453 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) {
452 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); 454 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
453 CreateButtonWithInkDrop(make_scoped_ptr(ink_drop_delegate)); 455 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate));
454 button()->set_context_menu_controller(nullptr); 456 button()->set_context_menu_controller(nullptr);
455 457
456 ink_drop_delegate->SetHovered(true); 458 ink_drop_delegate->SetHovered(true);
457 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 459 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
458 460
459 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 461 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
460 462
461 EXPECT_TRUE(ink_drop_delegate->is_hovered()); 463 EXPECT_TRUE(ink_drop_delegate->is_hovered());
462 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate->state()); 464 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate->state());
463 } 465 }
464 466
465 } // namespace views 467 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/button/image_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698