diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-29 10:46:47 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-02 12:02:10 +0000 |
commit | 99677208ff3b216fdfec551fbe548da5520cd6fb (patch) | |
tree | 476a4865c10320249360e859d8fdd3e01833b03a /chromium/ui/views/controls/button/label_button_unittest.cc | |
parent | c30a6232df03e1efbd9f3b226777b07e087a1122 (diff) | |
download | qtwebengine-chromium-99677208ff3b216fdfec551fbe548da5520cd6fb.tar.gz |
BASELINE: Update Chromium to 86.0.4240.124
Change-Id: Ide0ff151e94cd665ae6521a446995d34a9d1d644
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/views/controls/button/label_button_unittest.cc')
-rw-r--r-- | chromium/ui/views/controls/button/label_button_unittest.cc | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/chromium/ui/views/controls/button/label_button_unittest.cc b/chromium/ui/views/controls/button/label_button_unittest.cc index 38443891fff..88953b032f0 100644 --- a/chromium/ui/views/controls/button/label_button_unittest.cc +++ b/chromium/ui/views/controls/button/label_button_unittest.cc @@ -93,11 +93,15 @@ class LabelButtonTest : public test::WidgetTest { // used (which could be derived from the Widget's NativeTheme). test_widget_ = CreateTopLevelPlatformWidget(); + // Ensure the Widget is active, since LabelButton appearance in inactive + // Windows is platform-dependent. + test_widget_->Show(); + // The test code below is not prepared to handle dark mode. test_widget_->GetNativeTheme()->set_use_dark_colors(false); - button_ = new TestLabelButton; - test_widget_->GetContentsView()->AddChildView(button_); + button_ = test_widget_->GetContentsView()->AddChildView( + std::make_unique<TestLabelButton>()); // Establish the expected text colors for testing changes due to state. themed_normal_text_color_ = button_->GetNativeTheme()->GetSystemColor( @@ -107,7 +111,8 @@ class LabelButtonTest : public test::WidgetTest { // NativeTheme and use a hardcoded black or (on Mac) have a NativeTheme that // reliably returns black. styled_normal_text_color_ = SK_ColorBLACK; -#if defined(OS_LINUX) && BUILDFLAG(ENABLE_DESKTOP_AURA) +#if (defined(OS_LINUX) || defined(OS_CHROMEOS)) && \ + BUILDFLAG(ENABLE_DESKTOP_AURA) // The Linux theme provides a non-black highlight text color, but it's not // used for styled buttons. styled_highlight_text_color_ = styled_normal_text_color_ = @@ -154,7 +159,7 @@ TEST_F(LabelButtonTest, Init) { ax::mojom::StringAttribute::kName)); EXPECT_FALSE(button.GetIsDefault()); - EXPECT_EQ(Button::STATE_NORMAL, button.state()); + EXPECT_EQ(Button::STATE_NORMAL, button.GetState()); EXPECT_EQ(button.image()->parent(), &button); EXPECT_EQ(button.label()->parent(), &button); @@ -686,6 +691,36 @@ TEST_F(LabelButtonTest, ImageOrLabelGetClipped) { EXPECT_GE(button_->label()->height(), image_size); } +TEST_F(LabelButtonTest, UpdateImageAfterSettingImageModel) { + auto is_showing_image = [&](const gfx::ImageSkia& image) { + return button_->image()->GetImage().BackedBySameObjectAs(image); + }; + + auto normal_image = CreateTestImage(16, 16); + button_->SetImageModel(Button::STATE_NORMAL, + ui::ImageModel::FromImageSkia(normal_image)); + EXPECT_TRUE(is_showing_image(normal_image)); + + // When the button has no specific disabled image, changing the normal image + // while the button is disabled should update the currently-visible image. + normal_image = CreateTestImage(16, 16); + button_->SetState(Button::STATE_DISABLED); + button_->SetImageModel(Button::STATE_NORMAL, + ui::ImageModel::FromImageSkia(normal_image)); + EXPECT_TRUE(is_showing_image(normal_image)); + + // Any specific disabled image should take precedence over the normal image. + auto disabled_image = CreateTestImage(16, 16); + button_->SetImageModel(Button::STATE_DISABLED, + ui::ImageModel::FromImageSkia(disabled_image)); + EXPECT_TRUE(is_showing_image(disabled_image)); + + // Removing the disabled image should result in falling back to the normal + // image again. + button_->SetImageModel(Button::STATE_DISABLED, ui::ImageModel()); + EXPECT_TRUE(is_showing_image(normal_image)); +} + // Test fixture for a LabelButton that has an ink drop configured. class InkDropLabelButtonTest : public ViewsTestBase { public: |