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

Side by Side Diff: ui/views/test/menu_test_utils.h

Issue 2778383002: MenuController Do Not SetSelection to Empty Items on Drag (Closed)
Patch Set: Make logic readible Created 3 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/menu/menu_controller_unittest.cc ('k') | ui/views/test/menu_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_VIEWS_TEST_MENU_TEST_UTILS_H_ 5 #ifndef UI_VIEWS_TEST_MENU_TEST_UTILS_H_
6 #define UI_VIEWS_TEST_MENU_TEST_UTILS_H_ 6 #define UI_VIEWS_TEST_MENU_TEST_UTILS_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "ui/views/controls/menu/menu_delegate.h" 10 #include "ui/views/controls/menu/menu_delegate.h"
11 11
12 namespace views { 12 namespace views {
13 13
14 class MenuController; 14 class MenuController;
15 15
16 namespace test { 16 namespace test {
17 17
18 // Test implementation of MenuDelegate that tracks calls to MenuDelegate, along 18 // Test implementation of MenuDelegate that tracks calls to MenuDelegate, along
19 // with the provided parameters. 19 // with the provided parameters.
20 class TestMenuDelegate : public MenuDelegate { 20 class TestMenuDelegate : public MenuDelegate {
21 public: 21 public:
22 TestMenuDelegate(); 22 TestMenuDelegate();
23 ~TestMenuDelegate() override; 23 ~TestMenuDelegate() override;
24 24
25 int show_context_menu_count() { return show_context_menu_count_; }
26 MenuItemView* show_context_menu_source() { return show_context_menu_source_; }
25 int execute_command_id() const { return execute_command_id_; } 27 int execute_command_id() const { return execute_command_id_; }
26
27 int on_menu_closed_called() const { return on_menu_closed_called_count_; } 28 int on_menu_closed_called() const { return on_menu_closed_called_count_; }
28 MenuItemView* on_menu_closed_menu() const { return on_menu_closed_menu_; } 29 MenuItemView* on_menu_closed_menu() const { return on_menu_closed_menu_; }
29 MenuRunner::RunResult on_menu_closed_run_result() const { 30 MenuRunner::RunResult on_menu_closed_run_result() const {
30 return on_menu_closed_run_result_; 31 return on_menu_closed_run_result_;
31 } 32 }
32 bool on_perform_drop_called() { return on_perform_drop_called_; } 33 bool on_perform_drop_called() { return on_perform_drop_called_; }
34 int will_hide_menu_count() { return will_hide_menu_count_; }
35 MenuItemView* will_hide_menu() { return will_hide_menu_; }
33 36
34 // MenuDelegate: 37 // MenuDelegate:
38 bool ShowContextMenu(MenuItemView* source,
39 int id,
40 const gfx::Point& p,
41 ui::MenuSourceType source_type) override;
35 void ExecuteCommand(int id) override; 42 void ExecuteCommand(int id) override;
36 void OnMenuClosed(MenuItemView* menu, MenuRunner::RunResult result) override; 43 void OnMenuClosed(MenuItemView* menu, MenuRunner::RunResult result) override;
37 int OnPerformDrop(MenuItemView* menu, 44 int OnPerformDrop(MenuItemView* menu,
38 DropPosition position, 45 DropPosition position,
39 const ui::DropTargetEvent& event) override; 46 const ui::DropTargetEvent& event) override;
40 int GetDragOperations(MenuItemView* sender) override; 47 int GetDragOperations(MenuItemView* sender) override;
41 void WriteDragData(MenuItemView* sender, OSExchangeData* data) override; 48 void WriteDragData(MenuItemView* sender, OSExchangeData* data) override;
49 void WillHideMenu(MenuItemView* menu) override;
42 50
43 private: 51 private:
52 // The number of times ShowContextMenu was called.
53 int show_context_menu_count_ = 0;
54
55 // The value of the last call to ShowContextMenu.
56 MenuItemView* show_context_menu_source_ = nullptr;
57
44 // ID of last executed command. 58 // ID of last executed command.
45 int execute_command_id_; 59 int execute_command_id_;
46 60
47 // The number of times OnMenuClosed was called. 61 // The number of times OnMenuClosed was called.
48 int on_menu_closed_called_count_; 62 int on_menu_closed_called_count_;
49 63
50 // The values of the last call to OnMenuClosed. 64 // The values of the last call to OnMenuClosed.
51 MenuItemView* on_menu_closed_menu_; 65 MenuItemView* on_menu_closed_menu_;
52 MenuRunner::RunResult on_menu_closed_run_result_; 66 MenuRunner::RunResult on_menu_closed_run_result_;
53 67
68 // The number of times WillHideMenu was called.
69 int will_hide_menu_count_ = 0;
70
71 // The value of the last call to WillHideMenu.
72 MenuItemView* will_hide_menu_ = nullptr;
73
54 bool on_perform_drop_called_; 74 bool on_perform_drop_called_;
55 75
56 DISALLOW_COPY_AND_ASSIGN(TestMenuDelegate); 76 DISALLOW_COPY_AND_ASSIGN(TestMenuDelegate);
57 }; 77 };
58 78
59 // Test api which caches the currently active MenuController. Can be used to 79 // Test api which caches the currently active MenuController. Can be used to
60 // toggle visibility, and to clear seletion states, without performing full 80 // toggle visibility, and to clear seletion states, without performing full
61 // shutdown. This is used to simulate menus with varing states, such as during 81 // shutdown. This is used to simulate menus with varing states, such as during
62 // drags, without performing the entire operation. Used to test strange shutdown 82 // drags, without performing the entire operation. Used to test strange shutdown
63 // ordering. 83 // ordering.
(...skipping 15 matching lines...) Expand all
79 private: 99 private:
80 base::WeakPtr<MenuController> controller_; 100 base::WeakPtr<MenuController> controller_;
81 101
82 DISALLOW_COPY_AND_ASSIGN(MenuControllerTestApi); 102 DISALLOW_COPY_AND_ASSIGN(MenuControllerTestApi);
83 }; 103 };
84 104
85 } // namespace test 105 } // namespace test
86 } // namespace views 106 } // namespace views
87 107
88 #endif // UI_VIEWS_TEST_MENU_TEST_UTILS_H_ 108 #endif // UI_VIEWS_TEST_MENU_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller_unittest.cc ('k') | ui/views/test/menu_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698