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 13 matching lines...) Expand all Loading... |
24 #define MAYBE(x) x | 24 #define MAYBE(x) x |
25 #endif | 25 #endif |
26 | 26 |
27 const char kTestNestedDragData[] = "test_nested_drag_data"; | 27 const char kTestNestedDragData[] = "test_nested_drag_data"; |
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 ~TestDragView() override; |
35 | 35 |
36 private: | 36 private: |
37 // views::View: | 37 // views::View: |
38 virtual int GetDragOperations(const gfx::Point& point) override; | 38 int GetDragOperations(const gfx::Point& point) override; |
39 virtual void WriteDragData(const gfx::Point& point, | 39 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 |
51 int TestDragView::GetDragOperations(const gfx::Point& point) { | 51 int TestDragView::GetDragOperations(const gfx::Point& point) { |
52 return ui::DragDropTypes::DRAG_MOVE; | 52 return ui::DragDropTypes::DRAG_MOVE; |
53 } | 53 } |
54 | 54 |
55 void TestDragView::WriteDragData(const gfx::Point& point, | 55 void TestDragView::WriteDragData(const gfx::Point& point, |
56 ui::OSExchangeData* data) { | 56 ui::OSExchangeData* data) { |
57 data->SetString(base::ASCIIToUTF16(kTestNestedDragData)); | 57 data->SetString(base::ASCIIToUTF16(kTestNestedDragData)); |
58 } | 58 } |
59 | 59 |
60 // A simple view to serve as a drop target. | 60 // A simple view to serve as a drop target. |
61 class TestTargetView : public views::View { | 61 class TestTargetView : public views::View { |
62 public: | 62 public: |
63 TestTargetView(); | 63 TestTargetView(); |
64 virtual ~TestTargetView(); | 64 ~TestTargetView() override; |
65 | 65 |
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 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 bool AreDropTypesRequired() override; |
78 virtual bool CanDrop(const OSExchangeData& data) override; | 78 bool CanDrop(const OSExchangeData& data) override; |
79 virtual void OnDragEntered(const ui::DropTargetEvent& event) override; | 79 void OnDragEntered(const ui::DropTargetEvent& event) override; |
80 virtual int OnDragUpdated(const ui::DropTargetEvent& event) override; | 80 int OnDragUpdated(const ui::DropTargetEvent& event) override; |
81 virtual int OnPerformDrop(const ui::DropTargetEvent& event) override; | 81 int OnPerformDrop(const ui::DropTargetEvent& event) override; |
82 virtual void OnDragExited() override; | 82 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 void TestTargetView::OnDragExited() { | 143 void TestTargetView::OnDragExited() { |
144 dragging_ = false; | 144 dragging_ = false; |
145 } | 145 } |
146 | 146 |
147 } // namespace | 147 } // namespace |
148 | 148 |
149 class MenuViewDragAndDropTest : public MenuTestBase { | 149 class MenuViewDragAndDropTest : public MenuTestBase { |
150 public: | 150 public: |
151 MenuViewDragAndDropTest(); | 151 MenuViewDragAndDropTest(); |
152 virtual ~MenuViewDragAndDropTest(); | 152 ~MenuViewDragAndDropTest() override; |
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 void BuildMenu(views::MenuItemView* menu) override; |
162 | 162 |
163 // views::MenuDelegate: | 163 // views::MenuDelegate: |
164 virtual bool GetDropFormats( | 164 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 bool AreDropTypesRequired(views::MenuItemView* menu) override; |
169 virtual bool CanDrop(views::MenuItemView* menu, | 169 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 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 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 bool CanDrag(views::MenuItemView* menu) override; |
178 virtual void WriteDragData(views::MenuItemView* sender, | 178 void WriteDragData(views::MenuItemView* sender, |
179 ui::OSExchangeData* data) override; | 179 ui::OSExchangeData* data) override; |
180 virtual int GetDragOperations(views::MenuItemView* sender) override; | 180 int GetDragOperations(views::MenuItemView* sender) override; |
181 virtual bool ShouldCloseOnDragComplete() override; | 181 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 | 264 |
265 bool MenuViewDragAndDropTest::ShouldCloseOnDragComplete() { | 265 bool MenuViewDragAndDropTest::ShouldCloseOnDragComplete() { |
266 asked_to_close_ = true; | 266 asked_to_close_ = true; |
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 ~MenuViewDragAndDropTestTestInMenuDrag() override {} |
274 | 274 |
275 private: | 275 private: |
276 // MenuViewDragAndDropTest: | 276 // MenuViewDragAndDropTest: |
277 virtual void DoTestWithMenuOpen() override; | 277 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // Test that an in-menu (i.e., entirely implemented in the menu code) closes the | 348 // Test that an in-menu (i.e., entirely implemented in the menu code) closes the |
349 // menu automatically once the drag is complete, and does not ask the delegate | 349 // menu automatically once the drag is complete, and does not ask the delegate |
350 // to stay open. | 350 // to stay open. |
351 #if !defined(OS_WIN) // flaky http://crbug.com/401226 | 351 #if !defined(OS_WIN) // flaky http://crbug.com/401226 |
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 ~MenuViewDragAndDropTestNestedDrag() override {} |
359 | 359 |
360 private: | 360 private: |
361 // MenuViewDragAndDropTest: | 361 // MenuViewDragAndDropTest: |
362 virtual void DoTestWithMenuOpen() override; | 362 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 // implemented in menu code) will consult the delegate before closing the view | 449 // implemented in menu code) will consult the delegate before closing the view |
450 // after the drag. | 450 // after the drag. |
451 #if !defined(OS_WIN) // http://crbug.com/401226 | 451 #if !defined(OS_WIN) // http://crbug.com/401226 |
452 VIEW_TEST(MenuViewDragAndDropTestNestedDrag, | 452 VIEW_TEST(MenuViewDragAndDropTestNestedDrag, |
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 ~MenuViewDragAndDropForDropStayOpen() override {} |
460 | 460 |
461 private: | 461 private: |
462 // MenuViewDragAndDropTest: | 462 // MenuViewDragAndDropTest: |
463 virtual int GetMenuRunnerFlags() override; | 463 int GetMenuRunnerFlags() override; |
464 virtual void DoTestWithMenuOpen() override; | 464 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(); |
475 ASSERT_TRUE(submenu); | 475 ASSERT_TRUE(submenu); |
476 ASSERT_TRUE(submenu->IsShowing()); | 476 ASSERT_TRUE(submenu->IsShowing()); |
477 | 477 |
478 views::MenuController* controller = menu()->GetMenuController(); | 478 views::MenuController* controller = menu()->GetMenuController(); |
479 ASSERT_TRUE(controller); | 479 ASSERT_TRUE(controller); |
480 EXPECT_FALSE(controller->IsCancelAllTimerRunningForTest()); | 480 EXPECT_FALSE(controller->IsCancelAllTimerRunningForTest()); |
481 | 481 |
482 Done(); | 482 Done(); |
483 } | 483 } |
484 | 484 |
485 // Test that if a menu is opened for a drop which is handled by a child view | 485 // Test that if a menu is opened for a drop which is handled by a child view |
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 ~MenuViewDragAndDropForDropCancel() override {} |
493 | 493 |
494 private: | 494 private: |
495 // MenuViewDragAndDropTest: | 495 // MenuViewDragAndDropTest: |
496 virtual int GetMenuRunnerFlags() override; | 496 int GetMenuRunnerFlags() override; |
497 virtual void DoTestWithMenuOpen() override; | 497 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 |