OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/ui/views/menu_test_base.h" | 6 #include "chrome/browser/ui/views/menu_test_base.h" |
7 #include "chrome/test/base/interactive_test_utils.h" | 7 #include "chrome/test/base/interactive_test_utils.h" |
8 #include "ui/base/dragdrop/drag_drop_types.h" | 8 #include "ui/base/dragdrop/drag_drop_types.h" |
9 #include "ui/base/dragdrop/os_exchange_data.h" | 9 #include "ui/base/dragdrop/os_exchange_data.h" |
10 #include "ui/views/controls/menu/menu_controller.h" | 10 #include "ui/views/controls/menu/menu_controller.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 const char kTestTopLevelDragData[] = "test_top_level_drag_data"; | 28 const char kTestTopLevelDragData[] = "test_top_level_drag_data"; |
29 | 29 |
30 // A simple view which can be dragged. | 30 // A simple view which can be dragged. |
31 class TestDragView : public views::View { | 31 class TestDragView : public views::View { |
32 public: | 32 public: |
33 TestDragView(); | 33 TestDragView(); |
34 virtual ~TestDragView(); | 34 virtual ~TestDragView(); |
35 | 35 |
36 private: | 36 private: |
37 // views::View: | 37 // views::View: |
38 virtual int GetDragOperations(const gfx::Point& point) OVERRIDE; | 38 virtual int GetDragOperations(const gfx::Point& point) override; |
39 virtual void WriteDragData(const gfx::Point& point, | 39 virtual void WriteDragData(const gfx::Point& point, |
40 ui::OSExchangeData* data) OVERRIDE; | 40 ui::OSExchangeData* data) override; |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(TestDragView); | 42 DISALLOW_COPY_AND_ASSIGN(TestDragView); |
43 }; | 43 }; |
44 | 44 |
45 TestDragView::TestDragView() { | 45 TestDragView::TestDragView() { |
46 } | 46 } |
47 | 47 |
48 TestDragView::~TestDragView() { | 48 TestDragView::~TestDragView() { |
49 } | 49 } |
50 | 50 |
(...skipping 15 matching lines...) Expand all Loading... |
66 // Initializes this view to have the same bounds as |parent| and two draggable | 66 // Initializes this view to have the same bounds as |parent| and two draggable |
67 // child views. | 67 // child views. |
68 void Init(views::View* parent); | 68 void Init(views::View* parent); |
69 bool dragging() const { return dragging_; } | 69 bool dragging() const { return dragging_; } |
70 bool dropped() const { return dropped_; } | 70 bool dropped() const { return dropped_; } |
71 | 71 |
72 private: | 72 private: |
73 // views::View: | 73 // views::View: |
74 virtual bool GetDropFormats( | 74 virtual bool GetDropFormats( |
75 int* formats, | 75 int* formats, |
76 std::set<OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; | 76 std::set<OSExchangeData::CustomFormat>* custom_formats) override; |
77 virtual bool AreDropTypesRequired() OVERRIDE; | 77 virtual bool AreDropTypesRequired() override; |
78 virtual bool CanDrop(const OSExchangeData& data) OVERRIDE; | 78 virtual bool CanDrop(const OSExchangeData& data) override; |
79 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE; | 79 virtual void OnDragEntered(const ui::DropTargetEvent& event) override; |
80 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; | 80 virtual int OnDragUpdated(const ui::DropTargetEvent& event) override; |
81 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; | 81 virtual int OnPerformDrop(const ui::DropTargetEvent& event) override; |
82 virtual void OnDragExited() OVERRIDE; | 82 virtual void OnDragExited() override; |
83 | 83 |
84 // Whether or not we are currently dragging. | 84 // Whether or not we are currently dragging. |
85 bool dragging_; | 85 bool dragging_; |
86 | 86 |
87 // Whether or not a drop has been performed on the view. | 87 // Whether or not a drop has been performed on the view. |
88 bool dropped_; | 88 bool dropped_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(TestTargetView); | 90 DISALLOW_COPY_AND_ASSIGN(TestTargetView); |
91 }; | 91 }; |
92 | 92 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 MenuViewDragAndDropTest(); | 151 MenuViewDragAndDropTest(); |
152 virtual ~MenuViewDragAndDropTest(); | 152 virtual ~MenuViewDragAndDropTest(); |
153 | 153 |
154 protected: | 154 protected: |
155 TestTargetView* target_view() { return target_view_; } | 155 TestTargetView* target_view() { return target_view_; } |
156 bool asked_to_close() const { return asked_to_close_; } | 156 bool asked_to_close() const { return asked_to_close_; } |
157 bool performed_in_menu_drop() const { return performed_in_menu_drop_; } | 157 bool performed_in_menu_drop() const { return performed_in_menu_drop_; } |
158 | 158 |
159 private: | 159 private: |
160 // MenuTestBase: | 160 // MenuTestBase: |
161 virtual void BuildMenu(views::MenuItemView* menu) OVERRIDE; | 161 virtual void BuildMenu(views::MenuItemView* menu) override; |
162 | 162 |
163 // views::MenuDelegate: | 163 // views::MenuDelegate: |
164 virtual bool GetDropFormats( | 164 virtual bool GetDropFormats( |
165 views::MenuItemView* menu, | 165 views::MenuItemView* menu, |
166 int* formats, | 166 int* formats, |
167 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; | 167 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) override; |
168 virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE; | 168 virtual bool AreDropTypesRequired(views::MenuItemView* menu) override; |
169 virtual bool CanDrop(views::MenuItemView* menu, | 169 virtual bool CanDrop(views::MenuItemView* menu, |
170 const ui::OSExchangeData& data) OVERRIDE; | 170 const ui::OSExchangeData& data) override; |
171 virtual int GetDropOperation(views::MenuItemView* item, | 171 virtual int GetDropOperation(views::MenuItemView* item, |
172 const ui::DropTargetEvent& event, | 172 const ui::DropTargetEvent& event, |
173 DropPosition* position) OVERRIDE; | 173 DropPosition* position) override; |
174 virtual int OnPerformDrop(views::MenuItemView* menu, | 174 virtual int OnPerformDrop(views::MenuItemView* menu, |
175 DropPosition position, | 175 DropPosition position, |
176 const ui::DropTargetEvent& event) OVERRIDE; | 176 const ui::DropTargetEvent& event) override; |
177 virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE; | 177 virtual bool CanDrag(views::MenuItemView* menu) override; |
178 virtual void WriteDragData(views::MenuItemView* sender, | 178 virtual void WriteDragData(views::MenuItemView* sender, |
179 ui::OSExchangeData* data) OVERRIDE; | 179 ui::OSExchangeData* data) override; |
180 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE; | 180 virtual int GetDragOperations(views::MenuItemView* sender) override; |
181 virtual bool ShouldCloseOnDragComplete() OVERRIDE; | 181 virtual bool ShouldCloseOnDragComplete() override; |
182 | 182 |
183 // The special view in the menu, which supports its own drag and drop. | 183 // The special view in the menu, which supports its own drag and drop. |
184 TestTargetView* target_view_; | 184 TestTargetView* target_view_; |
185 | 185 |
186 // Whether or not we have been asked to close on drag complete. | 186 // Whether or not we have been asked to close on drag complete. |
187 bool asked_to_close_; | 187 bool asked_to_close_; |
188 | 188 |
189 // Whether or not a drop was performed in-menu (i.e., not including drops | 189 // Whether or not a drop was performed in-menu (i.e., not including drops |
190 // in separate child views). | 190 // in separate child views). |
191 bool performed_in_menu_drop_; | 191 bool performed_in_menu_drop_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return false; | 267 return false; |
268 } | 268 } |
269 | 269 |
270 class MenuViewDragAndDropTestTestInMenuDrag : public MenuViewDragAndDropTest { | 270 class MenuViewDragAndDropTestTestInMenuDrag : public MenuViewDragAndDropTest { |
271 public: | 271 public: |
272 MenuViewDragAndDropTestTestInMenuDrag() {} | 272 MenuViewDragAndDropTestTestInMenuDrag() {} |
273 virtual ~MenuViewDragAndDropTestTestInMenuDrag() {} | 273 virtual ~MenuViewDragAndDropTestTestInMenuDrag() {} |
274 | 274 |
275 private: | 275 private: |
276 // MenuViewDragAndDropTest: | 276 // MenuViewDragAndDropTest: |
277 virtual void DoTestWithMenuOpen() OVERRIDE; | 277 virtual void DoTestWithMenuOpen() override; |
278 | 278 |
279 void Step2(); | 279 void Step2(); |
280 void Step3(); | 280 void Step3(); |
281 void Step4(); | 281 void Step4(); |
282 }; | 282 }; |
283 | 283 |
284 void MenuViewDragAndDropTestTestInMenuDrag::DoTestWithMenuOpen() { | 284 void MenuViewDragAndDropTestTestInMenuDrag::DoTestWithMenuOpen() { |
285 // A few sanity checks to make sure the menu built correctly. | 285 // A few sanity checks to make sure the menu built correctly. |
286 views::SubmenuView* submenu = menu()->GetSubmenu(); | 286 views::SubmenuView* submenu = menu()->GetSubmenu(); |
287 ASSERT_TRUE(submenu); | 287 ASSERT_TRUE(submenu); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 VIEW_TEST(MenuViewDragAndDropTestTestInMenuDrag, MAYBE(TestInMenuDrag)) | 352 VIEW_TEST(MenuViewDragAndDropTestTestInMenuDrag, MAYBE(TestInMenuDrag)) |
353 #endif | 353 #endif |
354 | 354 |
355 class MenuViewDragAndDropTestNestedDrag : public MenuViewDragAndDropTest { | 355 class MenuViewDragAndDropTestNestedDrag : public MenuViewDragAndDropTest { |
356 public: | 356 public: |
357 MenuViewDragAndDropTestNestedDrag() {} | 357 MenuViewDragAndDropTestNestedDrag() {} |
358 virtual ~MenuViewDragAndDropTestNestedDrag() {} | 358 virtual ~MenuViewDragAndDropTestNestedDrag() {} |
359 | 359 |
360 private: | 360 private: |
361 // MenuViewDragAndDropTest: | 361 // MenuViewDragAndDropTest: |
362 virtual void DoTestWithMenuOpen() OVERRIDE; | 362 virtual void DoTestWithMenuOpen() override; |
363 | 363 |
364 void Step2(); | 364 void Step2(); |
365 void Step3(); | 365 void Step3(); |
366 void Step4(); | 366 void Step4(); |
367 }; | 367 }; |
368 | 368 |
369 void MenuViewDragAndDropTestNestedDrag::DoTestWithMenuOpen() { | 369 void MenuViewDragAndDropTestNestedDrag::DoTestWithMenuOpen() { |
370 // Sanity checks: We should be showing the menu, it should have three | 370 // Sanity checks: We should be showing the menu, it should have three |
371 // children, and the first of those children should have a nested view of the | 371 // children, and the first of those children should have a nested view of the |
372 // TestTargetView. | 372 // TestTargetView. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 MAYBE(MenuViewDragAndDropNestedDrag)) | 453 MAYBE(MenuViewDragAndDropNestedDrag)) |
454 #endif | 454 #endif |
455 | 455 |
456 class MenuViewDragAndDropForDropStayOpen : public MenuViewDragAndDropTest { | 456 class MenuViewDragAndDropForDropStayOpen : public MenuViewDragAndDropTest { |
457 public: | 457 public: |
458 MenuViewDragAndDropForDropStayOpen() {} | 458 MenuViewDragAndDropForDropStayOpen() {} |
459 virtual ~MenuViewDragAndDropForDropStayOpen() {} | 459 virtual ~MenuViewDragAndDropForDropStayOpen() {} |
460 | 460 |
461 private: | 461 private: |
462 // MenuViewDragAndDropTest: | 462 // MenuViewDragAndDropTest: |
463 virtual int GetMenuRunnerFlags() OVERRIDE; | 463 virtual int GetMenuRunnerFlags() override; |
464 virtual void DoTestWithMenuOpen() OVERRIDE; | 464 virtual void DoTestWithMenuOpen() override; |
465 }; | 465 }; |
466 | 466 |
467 int MenuViewDragAndDropForDropStayOpen::GetMenuRunnerFlags() { | 467 int MenuViewDragAndDropForDropStayOpen::GetMenuRunnerFlags() { |
468 return views::MenuRunner::HAS_MNEMONICS | | 468 return views::MenuRunner::HAS_MNEMONICS | |
469 views::MenuRunner::NESTED_DRAG | | 469 views::MenuRunner::NESTED_DRAG | |
470 views::MenuRunner::FOR_DROP; | 470 views::MenuRunner::FOR_DROP; |
471 } | 471 } |
472 | 472 |
473 void MenuViewDragAndDropForDropStayOpen::DoTestWithMenuOpen() { | 473 void MenuViewDragAndDropForDropStayOpen::DoTestWithMenuOpen() { |
474 views::SubmenuView* submenu = menu()->GetSubmenu(); | 474 views::SubmenuView* submenu = menu()->GetSubmenu(); |
(...skipping 11 matching lines...) Expand all Loading... |
486 // that the menu does not immediately try to close. | 486 // that the menu does not immediately try to close. |
487 VIEW_TEST(MenuViewDragAndDropForDropStayOpen, MenuViewStaysOpenForNestedDrag) | 487 VIEW_TEST(MenuViewDragAndDropForDropStayOpen, MenuViewStaysOpenForNestedDrag) |
488 | 488 |
489 class MenuViewDragAndDropForDropCancel : public MenuViewDragAndDropTest { | 489 class MenuViewDragAndDropForDropCancel : public MenuViewDragAndDropTest { |
490 public: | 490 public: |
491 MenuViewDragAndDropForDropCancel() {} | 491 MenuViewDragAndDropForDropCancel() {} |
492 virtual ~MenuViewDragAndDropForDropCancel() {} | 492 virtual ~MenuViewDragAndDropForDropCancel() {} |
493 | 493 |
494 private: | 494 private: |
495 // MenuViewDragAndDropTest: | 495 // MenuViewDragAndDropTest: |
496 virtual int GetMenuRunnerFlags() OVERRIDE; | 496 virtual int GetMenuRunnerFlags() override; |
497 virtual void DoTestWithMenuOpen() OVERRIDE; | 497 virtual void DoTestWithMenuOpen() override; |
498 }; | 498 }; |
499 | 499 |
500 int MenuViewDragAndDropForDropCancel::GetMenuRunnerFlags() { | 500 int MenuViewDragAndDropForDropCancel::GetMenuRunnerFlags() { |
501 return views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::FOR_DROP; | 501 return views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::FOR_DROP; |
502 } | 502 } |
503 | 503 |
504 void MenuViewDragAndDropForDropCancel::DoTestWithMenuOpen() { | 504 void MenuViewDragAndDropForDropCancel::DoTestWithMenuOpen() { |
505 views::SubmenuView* submenu = menu()->GetSubmenu(); | 505 views::SubmenuView* submenu = menu()->GetSubmenu(); |
506 ASSERT_TRUE(submenu); | 506 ASSERT_TRUE(submenu); |
507 ASSERT_TRUE(submenu->IsShowing()); | 507 ASSERT_TRUE(submenu->IsShowing()); |
508 | 508 |
509 views::MenuController* controller = menu()->GetMenuController(); | 509 views::MenuController* controller = menu()->GetMenuController(); |
510 ASSERT_TRUE(controller); | 510 ASSERT_TRUE(controller); |
511 EXPECT_TRUE(controller->IsCancelAllTimerRunningForTest()); | 511 EXPECT_TRUE(controller->IsCancelAllTimerRunningForTest()); |
512 | 512 |
513 Done(); | 513 Done(); |
514 } | 514 } |
515 | 515 |
516 // Test that if a menu is opened for a drop handled entirely by menu code, the | 516 // Test that if a menu is opened for a drop handled entirely by menu code, the |
517 // menu will try to close if it does not receive any drag updates. | 517 // menu will try to close if it does not receive any drag updates. |
518 VIEW_TEST(MenuViewDragAndDropForDropCancel, MenuViewCancelsForOwnDrag) | 518 VIEW_TEST(MenuViewDragAndDropForDropCancel, MenuViewCancelsForOwnDrag) |
OLD | NEW |