Index: ui/views/touchui/touch_selection_menu_runner_views_unittest.cc |
diff --git a/ui/views/touchui/touch_selection_menu_runner_views_unittest.cc b/ui/views/touchui/touch_selection_menu_runner_views_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..256a45581db747b34720d0328a1beb6ab9d513ba |
--- /dev/null |
+++ b/ui/views/touchui/touch_selection_menu_runner_views_unittest.cc |
@@ -0,0 +1,66 @@ |
+// 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/strings/grit/ui_strings.h" |
+#include "ui/touch_selection/touch_selection_menu_runner.h" |
+#include "ui/views/test/views_test_base.h" |
+#include "ui/views/touchui/touch_editing_menu.h" |
+#include "ui/views/touchui/touch_selection_menu_runner_views.h" |
+#include "ui/views/views_delegate.h" |
+ |
+namespace views { |
+ |
+class TouchSelectionMenuRunnerViewsTest : public ViewsTestBase, |
+ public ui::TouchSelectionMenuClient { |
+ public: |
+ TouchSelectionMenuRunnerViewsTest() : no_command_available_(false) {} |
+ ~TouchSelectionMenuRunnerViewsTest() override {} |
+ |
+ protected: |
+ void set_no_commmand_available(bool no_command) { |
+ no_command_available_ = no_command; |
+ } |
+ |
+ private: |
+ // ui::TouchSelectionMenuClient: |
+ bool IsCommandIdEnabled(int command_id) const override { |
+ return !no_command_available_; |
+ } |
+ |
+ void ExecuteCommand(int command_id, int event_flags) override {} |
+ |
+ void OpenContextMenu() override {} |
+ |
+ // When set to true, no command would be availble and menu should not be |
+ // shown. |
+ bool no_command_available_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TouchSelectionMenuRunnerViewsTest); |
+}; |
+ |
+TEST_F(TouchSelectionMenuRunnerViewsTest, InstalledAndWorksProperly) { |
+ gfx::Rect menu_anchor(0, 0, 10, 10); |
+ gfx::Size handle_size(10, 10); |
+ |
+ // Menu runner instance should be installed, but no menu should be running. |
+ EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()); |
+ EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
+ |
+ // Run menu. Since commands are availble, this should bring up menus. |
+ ui::TouchSelectionMenuRunner::GetInstance()->RunMenu( |
+ this, menu_anchor, handle_size, GetContext()); |
+ EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
+ |
+ // Close menu. |
+ ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); |
+ EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
+ |
+ // Try running menu when no commands is available. Menu should not be shown. |
+ set_no_commmand_available(true); |
+ ui::TouchSelectionMenuRunner::GetInstance()->RunMenu( |
+ this, menu_anchor, handle_size, GetContext()); |
+ EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
+} |
+ |
+} // namespace views |