| 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/controls/button/label_button.h" | 5 #include "ui/views/controls/button/label_button.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/macros.h" | 8 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
| 12 #include "ui/base/test/material_design_controller_test_api.h" | 13 #include "ui/base/test/material_design_controller_test_api.h" |
| 14 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/events/test/event_generator.h" | 15 #include "ui/events/test/event_generator.h" |
| 14 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/font_list.h" | 17 #include "ui/gfx/font_list.h" |
| 16 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/geometry/vector2d.h" | 19 #include "ui/gfx/geometry/vector2d.h" |
| 18 #include "ui/gfx/text_utils.h" | 20 #include "ui/gfx/text_utils.h" |
| 19 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
| 20 #include "ui/views/animation/button_ink_drop_delegate.h" | 22 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 21 #include "ui/views/style/platform_style.h" | 23 #include "ui/views/style/platform_style.h" |
| 22 #include "ui/views/test/views_test_base.h" | 24 #include "ui/views/test/views_test_base.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 DISALLOW_COPY_AND_ASSIGN(InkDropLabelButton); | 445 DISALLOW_COPY_AND_ASSIGN(InkDropLabelButton); |
| 444 }; | 446 }; |
| 445 | 447 |
| 446 // Test fixture for a LabelButton that has an ink drop configured. | 448 // Test fixture for a LabelButton that has an ink drop configured. |
| 447 class InkDropLabelButtonTest : public ViewsTestBase { | 449 class InkDropLabelButtonTest : public ViewsTestBase { |
| 448 public: | 450 public: |
| 449 InkDropLabelButtonTest() {} | 451 InkDropLabelButtonTest() {} |
| 450 | 452 |
| 451 // ViewsTestBase: | 453 // ViewsTestBase: |
| 452 void SetUp() override { | 454 void SetUp() override { |
| 453 ui::test::MaterialDesignControllerTestAPI::SetMode( | 455 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 454 ui::MaterialDesignController::MATERIAL_NORMAL); | 456 switches::kTopChromeMD, switches::kTopChromeMDMaterial); |
| 455 | |
| 456 ViewsTestBase::SetUp(); | 457 ViewsTestBase::SetUp(); |
| 457 | 458 |
| 458 // Create a widget so that the CustomButton can query the hover state | 459 // Create a widget so that the CustomButton can query the hover state |
| 459 // correctly. | 460 // correctly. |
| 460 widget_.reset(new Widget); | 461 widget_.reset(new Widget); |
| 461 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 462 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 462 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 463 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 463 params.bounds = gfx::Rect(0, 0, 20, 20); | 464 params.bounds = gfx::Rect(0, 0, 20, 20); |
| 464 widget_->Init(params); | 465 widget_->Init(params); |
| 465 widget_->Show(); | 466 widget_->Show(); |
| 466 | 467 |
| 467 button_ = new InkDropLabelButton(); | 468 button_ = new InkDropLabelButton(); |
| 468 widget_->SetContentsView(button_); | 469 widget_->SetContentsView(button_); |
| 469 } | 470 } |
| 470 | 471 |
| 471 void TearDown() override { | 472 void TearDown() override { |
| 472 widget_.reset(); | 473 widget_.reset(); |
| 473 ViewsTestBase::TearDown(); | 474 ViewsTestBase::TearDown(); |
| 474 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 475 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); |
| 475 } | 476 } |
| 476 | 477 |
| 477 protected: | 478 protected: |
| 478 // Required to host the test target. | 479 // Required to host the test target. |
| 479 std::unique_ptr<Widget> widget_; | 480 std::unique_ptr<Widget> widget_; |
| 480 | 481 |
| 481 // The test target. | 482 // The test target. |
| 482 InkDropLabelButton* button_ = nullptr; | 483 InkDropLabelButton* button_ = nullptr; |
| 483 | 484 |
| 484 private: | 485 private: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 504 | 505 |
| 505 // Verifies the target event handler View is the |LabelButton| and not any of | 506 // Verifies the target event handler View is the |LabelButton| and not any of |
| 506 // the child Views. | 507 // the child Views. |
| 507 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { | 508 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { |
| 508 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( | 509 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( |
| 509 button_->bounds().CenterPoint()); | 510 button_->bounds().CenterPoint()); |
| 510 EXPECT_EQ(button_, target_view); | 511 EXPECT_EQ(button_, target_view); |
| 511 } | 512 } |
| 512 | 513 |
| 513 } // namespace views | 514 } // namespace views |
| OLD | NEW |