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

Unified Diff: chrome/browser/ui/views/toolbar/toolbar_button_interactive_uitest.cc

Issue 1864423002: ToolbarButton: Reset menu runner before deleting its menu's delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ViewEventTestBase fix Created 4 years, 8 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 | « chrome/browser/ui/views/toolbar/toolbar_button.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/toolbar/toolbar_button_interactive_uitest.cc
diff --git a/chrome/browser/ui/views/toolbar/toolbar_button_interactive_uitest.cc b/chrome/browser/ui/views/toolbar/toolbar_button_interactive_uitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ab105829e133123b2edd1678aa21373e9840fea0
--- /dev/null
+++ b/chrome/browser/ui/views/toolbar/toolbar_button_interactive_uitest.cc
@@ -0,0 +1,85 @@
+// Copyright 2016 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 "chrome/browser/ui/views/toolbar/toolbar_button.h"
+
+#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/view_event_test_base.h"
+#include "ui/base/models/simple_menu_model.h"
+#include "ui/views/controls/menu/menu_runner.h"
+
+namespace test {
+
+// Friend of ToolbarButton to access private members.
+class ToolbarButtonTestApi {
+ public:
+ explicit ToolbarButtonTestApi(ToolbarButton* button) : button_(button) {}
+
+ views::MenuRunner* menu_runner() { return button_->menu_runner_.get(); }
+ bool menu_showing() const { return button_->menu_showing_; }
+
+ private:
+ ToolbarButton* button_;
+
+ DISALLOW_COPY_AND_ASSIGN(ToolbarButtonTestApi);
+};
+
+} // namespace test
+
+class ToolbarButtonUITest : public ViewEventTestBase {
+ public:
+ ToolbarButtonUITest() {}
+
+ // ViewEventTestBase:
+ views::View* CreateContentsView() override {
+ // Usually a BackForwardMenuModel is used, but that needs a Browser*. Make
+ // something simple with at least one item so a menu gets shown. Note that
+ // ToolbarButton takes ownership of the |model|.
+ ui::SimpleMenuModel* model = new ui::SimpleMenuModel(nullptr);
+ model->AddItem(0, base::string16());
+ button_ = new ToolbarButton(&profile_, nullptr, model);
+ return button_;
+ }
+ void DoTestOnMessageLoop() override {}
+
+ protected:
+ TestingProfile profile_;
+ ToolbarButton* button_ = nullptr;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ToolbarButtonUITest);
+};
+
+// Test showing and dismissing a menu to verify menu delegate lifetime.
+TEST_F(ToolbarButtonUITest, ShowMenu) {
+ test::ToolbarButtonTestApi test_api(button_);
+
+ EXPECT_FALSE(test_api.menu_showing());
+ EXPECT_FALSE(test_api.menu_runner());
+ EXPECT_EQ(views::Button::STATE_NORMAL, button_->state());
+
+ // Show the menu. Note that it is asynchronous.
+ button_->ShowContextMenuForView(nullptr, gfx::Point(), ui::MENU_SOURCE_MOUSE);
+
+ EXPECT_TRUE(test_api.menu_showing());
+ EXPECT_TRUE(test_api.menu_runner());
+ EXPECT_TRUE(test_api.menu_runner()->IsRunning());
+
+ // Button should appear pressed when the menu is showing.
+ EXPECT_EQ(views::Button::STATE_PRESSED, button_->state());
+
+ test_api.menu_runner()->Cancel();
+
+ // Ensure the ToolbarButton's |menu_runner_| member is reset to null.
+ EXPECT_FALSE(test_api.menu_showing());
+ EXPECT_FALSE(test_api.menu_runner());
+ EXPECT_EQ(views::Button::STATE_NORMAL, button_->state());
+}
+
+// Test deleting a ToolbarButton while its menu is showing.
+TEST_F(ToolbarButtonUITest, DeleteWithMenu) {
+ button_->ShowContextMenuForView(nullptr, gfx::Point(), ui::MENU_SOURCE_MOUSE);
+ EXPECT_TRUE(test::ToolbarButtonTestApi(button_).menu_runner());
+ delete button_;
+}
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_button.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698