OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/strings/grit/ui_strings.h" |
| 6 #include "ui/touch_selection/touch_selection_menu_runner.h" |
| 7 #include "ui/views/test/views_test_base.h" |
| 8 #include "ui/views/touchui/touch_editing_menu.h" |
| 9 #include "ui/views/touchui/touch_selection_menu_runner_views.h" |
| 10 #include "ui/views/views_delegate.h" |
| 11 |
| 12 namespace views { |
| 13 |
| 14 class TouchSelectionMenuRunnerViewsTest : public ViewsTestBase, |
| 15 public ui::TouchSelectionMenuClient { |
| 16 public: |
| 17 TouchSelectionMenuRunnerViewsTest() : no_command_available_(false) {} |
| 18 ~TouchSelectionMenuRunnerViewsTest() override {} |
| 19 |
| 20 protected: |
| 21 void set_no_commmand_available(bool no_command) { |
| 22 no_command_available_ = no_command; |
| 23 } |
| 24 |
| 25 private: |
| 26 // ui::TouchSelectionMenuClient: |
| 27 bool IsCommandIdEnabled(int command_id) const override { |
| 28 return !no_command_available_; |
| 29 } |
| 30 |
| 31 void ExecuteCommand(int command_id, int event_flags) override {} |
| 32 |
| 33 void OpenContextMenu() override {} |
| 34 |
| 35 // When set to true, no command would be availble and menu should not be |
| 36 // shown. |
| 37 bool no_command_available_; |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(TouchSelectionMenuRunnerViewsTest); |
| 40 }; |
| 41 |
| 42 TEST_F(TouchSelectionMenuRunnerViewsTest, InstalledAndWorksProperly) { |
| 43 gfx::Rect menu_anchor(0, 0, 10, 10); |
| 44 gfx::Size handle_size(10, 10); |
| 45 |
| 46 // Menu runner instance should be installed, but no menu should be running. |
| 47 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()); |
| 48 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 49 |
| 50 // Run menu. Since commands are availble, this should bring up menus. |
| 51 ui::TouchSelectionMenuRunner::GetInstance()->RunMenu( |
| 52 this, menu_anchor, handle_size, GetContext()); |
| 53 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 54 |
| 55 // Close menu. |
| 56 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); |
| 57 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 58 |
| 59 // Try running menu when no commands is available. Menu should not be shown. |
| 60 set_no_commmand_available(true); |
| 61 ui::TouchSelectionMenuRunner::GetInstance()->RunMenu( |
| 62 this, menu_anchor, handle_size, GetContext()); |
| 63 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 64 } |
| 65 |
| 66 } // namespace views |
OLD | NEW |