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

Unified Diff: ui/views/controls/button/custom_button_unittest.cc

Issue 2431493002: MD Buttons: Don't add layers for hidden -> hidden transitions. (Closed)
Patch Set: Additional test Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/animation/test/test_ink_drop_host.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/custom_button_unittest.cc
diff --git a/ui/views/controls/button/custom_button_unittest.cc b/ui/views/controls/button/custom_button_unittest.cc
index 418ff6e1c6b28cafad81a4e267f4adb97d239460..6532653b15dbc0c2e816168c5489d3c868d37f20 100644
--- a/ui/views/controls/button/custom_button_unittest.cc
+++ b/ui/views/controls/button/custom_button_unittest.cc
@@ -6,6 +6,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
+#include "base/run_loop.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/layout.h"
@@ -13,6 +14,7 @@
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/animation/ink_drop_host.h"
+#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/test/ink_drop_host_view_test_api.h"
#include "ui/views/animation/test/test_ink_drop.h"
#include "ui/views/animation/test/test_ink_drop_host.h"
@@ -72,8 +74,20 @@ class TestCustomButton : public CustomButton, public ButtonListener {
canceled_ = true;
}
+ // InkDropHostView:
+ void AddInkDropLayer(ui::Layer* ink_drop_layer) override {
+ ++ink_drop_layer_add_count_;
+ CustomButton::AddInkDropLayer(ink_drop_layer);
+ }
+ void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override {
+ ++ink_drop_layer_remove_count_;
+ CustomButton::RemoveInkDropLayer(ink_drop_layer);
+ }
+
bool pressed() { return pressed_; }
bool canceled() { return canceled_; }
+ int ink_drop_layer_add_count() { return ink_drop_layer_add_count_; }
+ int ink_drop_layer_remove_count() { return ink_drop_layer_remove_count_; }
void Reset() {
pressed_ = false;
@@ -87,6 +101,9 @@ class TestCustomButton : public CustomButton, public ButtonListener {
bool pressed_ = false;
bool canceled_ = false;
+ int ink_drop_layer_add_count_ = 0;
+ int ink_drop_layer_remove_count_ = 0;
+
DISALLOW_COPY_AND_ASSIGN(TestCustomButton);
};
@@ -126,6 +143,14 @@ class CustomButtonTest : public ViewsTestBase {
widget_->SetContentsView(button_);
}
+ void CreateButtonWithRealInkDrop() {
+ delete button_;
+ button_ = new TestCustomButton(false);
+ InkDropHostViewTestApi(button_).SetInkDrop(
+ base::MakeUnique<InkDropImpl>(button_));
+ widget_->SetContentsView(button_);
+ }
+
protected:
Widget* widget() { return widget_.get(); }
TestCustomButton* button() { return button_; }
@@ -571,6 +596,39 @@ TEST_F(CustomButtonTest, InkDropStaysHiddenWhileDragging) {
SetDraggedView(nullptr);
}
+// Test that hiding or closing a Widget doesn't attempt to add a layer due to
+// changed visibility states.
+TEST_F(CustomButtonTest, NoLayerAddedForWidgetVisibilityChanges) {
+ CreateButtonWithRealInkDrop();
+
+ EXPECT_TRUE(button()->visible());
+ EXPECT_FALSE(button()->layer());
+
+ widget()->Hide();
+ EXPECT_FALSE(button()->layer());
+ EXPECT_EQ(0, button()->ink_drop_layer_add_count());
+ EXPECT_EQ(0, button()->ink_drop_layer_remove_count());
+
+ widget()->Show();
+ EXPECT_FALSE(button()->layer());
+ EXPECT_EQ(0, button()->ink_drop_layer_add_count());
+ EXPECT_EQ(0, button()->ink_drop_layer_remove_count());
+
+ // Allow the button to be interrogated after the view hierarchy is torn down.
+ button()->set_owned_by_client();
+ widget()->Close(); // Start an asynchronous close.
+ EXPECT_FALSE(button()->layer());
+ EXPECT_EQ(0, button()->ink_drop_layer_add_count());
+ EXPECT_EQ(0, button()->ink_drop_layer_remove_count());
+
+ base::RunLoop().RunUntilIdle(); // Complete the Close().
+ EXPECT_FALSE(button()->layer());
+ EXPECT_EQ(0, button()->ink_drop_layer_add_count());
+ EXPECT_EQ(0, button()->ink_drop_layer_remove_count());
+
+ delete button();
+}
+
// Todo(karandeepb): On Mac, a button should get clicked on a Space key press
// (and not release). Modify this test after fixing crbug.com/607429.
// Test that Space Key behaves correctly on a focused button.
« no previous file with comments | « ui/views/animation/test/test_ink_drop_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698