| 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/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
| 13 #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" | 14 #include "ui/base/ui_base_switches.h" |
| 15 #include "ui/events/test/event_generator.h" | 15 #include "ui/events/test/event_generator.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/color_utils.h" |
| 17 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 19 #include "ui/gfx/geometry/vector2d.h" | 20 #include "ui/gfx/geometry/vector2d.h" |
| 20 #include "ui/gfx/text_utils.h" | 21 #include "ui/gfx/text_utils.h" |
| 21 #include "ui/native_theme/native_theme.h" | 22 #include "ui/native_theme/native_theme.h" |
| 22 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" | 23 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" |
| 23 #include "ui/views/animation/test/test_ink_drop.h" | 24 #include "ui/views/animation/test/test_ink_drop.h" |
| 24 #include "ui/views/style/platform_style.h" | 25 #include "ui/views/style/platform_style.h" |
| 25 #include "ui/views/test/views_test_base.h" | 26 #include "ui/views/test/views_test_base.h" |
| 26 #include "ui/views/test/widget_test.h" | 27 #include "ui/views/test/widget_test.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 default_after->SetIsDefault(true); | 399 default_after->SetIsDefault(true); |
| 399 EXPECT_EQ(styled_highlight_text_color_, | 400 EXPECT_EQ(styled_highlight_text_color_, |
| 400 default_after->label()->enabled_color()); | 401 default_after->label()->enabled_color()); |
| 401 | 402 |
| 402 // Test becoming default before adding to the Widget. | 403 // Test becoming default before adding to the Widget. |
| 403 TestLabelButton* default_before = AddStyledButton("OK", true); | 404 TestLabelButton* default_before = AddStyledButton("OK", true); |
| 404 EXPECT_EQ(styled_highlight_text_color_, | 405 EXPECT_EQ(styled_highlight_text_color_, |
| 405 default_before->label()->enabled_color()); | 406 default_before->label()->enabled_color()); |
| 406 } | 407 } |
| 407 | 408 |
| 409 // Ensure the label gets the correct enabled color after |
| 410 // LabelButton::ResetColorsFromNativeTheme() is invoked. |
| 411 TEST_F(LabelButtonTest, ResetColorsFromNativeTheme) { |
| 412 ASSERT_FALSE(color_utils::IsInvertedColorScheme()); |
| 413 ASSERT_NE(button_->label()->background_color(), SK_ColorBLACK); |
| 414 EXPECT_EQ(themed_normal_text_color_, button_->label()->enabled_color()); |
| 415 |
| 416 button_->label()->SetBackgroundColor(SK_ColorBLACK); |
| 417 button_->label()->SetAutoColorReadabilityEnabled(true); |
| 418 EXPECT_NE(themed_normal_text_color_, button_->label()->enabled_color()); |
| 419 |
| 420 button_->ResetColorsFromNativeTheme(); |
| 421 EXPECT_EQ(themed_normal_text_color_, button_->label()->enabled_color()); |
| 422 } |
| 423 |
| 408 // Test fixture for a LabelButton that has an ink drop configured. | 424 // Test fixture for a LabelButton that has an ink drop configured. |
| 409 class InkDropLabelButtonTest : public ViewsTestBase { | 425 class InkDropLabelButtonTest : public ViewsTestBase { |
| 410 public: | 426 public: |
| 411 InkDropLabelButtonTest() {} | 427 InkDropLabelButtonTest() {} |
| 412 | 428 |
| 413 // ViewsTestBase: | 429 // ViewsTestBase: |
| 414 void SetUp() override { | 430 void SetUp() override { |
| 415 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 431 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 416 switches::kTopChromeMD, switches::kTopChromeMDMaterial); | 432 switches::kTopChromeMD, switches::kTopChromeMDMaterial); |
| 417 ViewsTestBase::SetUp(); | 433 ViewsTestBase::SetUp(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 488 |
| 473 // Verifies the target event handler View is the |LabelButton| and not any of | 489 // Verifies the target event handler View is the |LabelButton| and not any of |
| 474 // the child Views. | 490 // the child Views. |
| 475 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { | 491 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { |
| 476 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( | 492 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( |
| 477 button_->bounds().CenterPoint()); | 493 button_->bounds().CenterPoint()); |
| 478 EXPECT_EQ(button_, target_view); | 494 EXPECT_EQ(button_, target_view); |
| 479 } | 495 } |
| 480 | 496 |
| 481 } // namespace views | 497 } // namespace views |
| OLD | NEW |