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

Unified Diff: ui/views/animation/ink_drop_delegate_unittest.cc

Issue 1494433003: Fixes a crash when InkDropDelegate gets destroyed after its InkDropHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes a crash when InkDropDelegate gets destroyed after its InkDropHost (corrections and test) Created 5 years 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 | « chrome/browser/ui/views/toolbar/toolbar_action_view.cc ('k') | ui/views/controls/button/custom_button.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/animation/ink_drop_delegate_unittest.cc
diff --git a/ui/views/animation/ink_drop_delegate_unittest.cc b/ui/views/animation/ink_drop_delegate_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d8a1b5f0e2d44c96e10e5cf41d2ed240ef0d0a55
--- /dev/null
+++ b/ui/views/animation/ink_drop_delegate_unittest.cc
@@ -0,0 +1,109 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/animation/ink_drop_delegate.h"
+
+#include "ui/views/animation/ink_drop_host.h"
+#include "ui/views/controls/button/custom_button.h"
+#include "ui/views/test/views_test_base.h"
+
+namespace views {
+
+namespace {
+
+// An InkDropDelegate that handles animations for toolbar buttons.
bruthig 2015/12/03 04:11:35 Incorrect documentation. i.e. copy/pasted
varkha 2015/12/03 19:20:43 Done.
+class TestInkDropDelegate : public InkDropDelegate {
+ public:
+ TestInkDropDelegate(InkDropHost* ink_drop_host,
+ bool* button_deleted,
+ bool* delegate_deleted)
+ : ink_drop_host_(ink_drop_host),
+ button_deleted_(button_deleted),
+ delegate_deleted_(delegate_deleted) {
+ ink_drop_host_->AddInkDropLayer(nullptr);
+ }
+ ~TestInkDropDelegate() override {
+ EXPECT_FALSE(*button_deleted_);
bruthig 2015/12/03 04:11:35 This should probably be an ASSERT_FALSE instead of
varkha 2015/12/03 19:20:43 Not sure, I wanted to allow the test to continue s
+ ink_drop_host_->RemoveInkDropLayer(nullptr);
+ *delegate_deleted_ = true;
+ }
+
+ // InkDropDelegate:
+ void SetInkDropSize(int large_size,
+ int large_corner_radius,
+ int small_size,
+ int small_corner_radius) override {}
+ void OnLayout() override {}
+ void OnAction(InkDropState state) override {}
+
+ private:
+ InkDropHost* ink_drop_host_;
+ bool* button_deleted_;
+ bool* delegate_deleted_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegate);
+};
+
+// Test Button class that owns a TestInkDropDelegate.
+class TestButton : public views::CustomButton, public views::InkDropHost {
+ public:
+ TestButton(bool* layer_added,
+ bool* layer_removed,
+ bool* button_deleted,
+ bool* delegate_deleted)
+ : CustomButton(nullptr),
+ layer_added_(layer_added),
+ layer_removed_(layer_removed),
+ button_deleted_(button_deleted) {
+ scoped_ptr<views::InkDropDelegate> new_ink_drop_delegate(
+ new views::TestInkDropDelegate(this, button_deleted, delegate_deleted));
+ SetInkDropDelegate(new_ink_drop_delegate.Pass());
+ EXPECT_TRUE(*layer_added_);
bruthig 2015/12/03 04:11:35 ASSERT instead of EXPECT
varkha 2015/12/03 19:20:43 Acknowledged.
+ }
+ ~TestButton() override {
+ SetInkDropDelegate(scoped_ptr<views::InkDropDelegate>());
+ EXPECT_TRUE(*layer_removed_);
bruthig 2015/12/03 04:11:35 ASSERT instead of EXPECT
varkha 2015/12/03 19:20:43 Acknowledged.
+ *button_deleted_ = true;
+ }
+
+ // views::InkDropHost:
+ void AddInkDropLayer(ui::Layer* ink_drop_layer) override {
+ *layer_added_ = true;
+ }
+ void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override {
+ *layer_removed_ = true;
+ }
+ gfx::Point CalculateInkDropCenter() const override { return gfx::Point(); }
+
+ private:
+ bool* layer_added_;
+ bool* layer_removed_;
+ bool* button_deleted_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestButton);
+};
+
+} // namespace
+
+TEST(InkDropDelegateTest, CanBeDeleted) {
+ bool layer_added = false;
+ bool layer_removed = false;
+ bool button_deleted = false;
+ bool delegate_deleted = false;
+
+ TestButton* button = new TestButton(&layer_added, &layer_removed,
+ &button_deleted, &delegate_deleted);
+ EXPECT_TRUE(layer_added);
+ EXPECT_FALSE(layer_removed);
+ EXPECT_FALSE(button_deleted);
+ EXPECT_FALSE(delegate_deleted);
+
+ delete button;
+ EXPECT_TRUE(layer_added);
+ EXPECT_TRUE(layer_removed);
+ EXPECT_TRUE(button_deleted);
+ EXPECT_TRUE(delegate_deleted);
+}
+
+} // namespace views
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view.cc ('k') | ui/views/controls/button/custom_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698