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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc

Issue 10909043: Cancel drag if display configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h" 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "ui/gfx/screen.h" 29 #include "ui/gfx/screen.h"
30 #include "ui/ui_controls/ui_controls.h" 30 #include "ui/ui_controls/ui_controls.h"
31 #include "ui/views/view.h" 31 #include "ui/views/view.h"
32 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
33 33
34 #if defined(USE_ASH) 34 #if defined(USE_ASH)
35 #include "ash/display/display_controller.h" 35 #include "ash/display/display_controller.h"
36 #include "ash/display/multi_display_manager.h"
36 #include "ash/shell.h" 37 #include "ash/shell.h"
37 #include "ui/aura/test/event_generator.h" 38 #include "ui/aura/test/event_generator.h"
38 #include "ui/aura/root_window.h" 39 #include "ui/aura/root_window.h"
39 #endif 40 #endif
40 41
41 namespace test { 42 namespace test {
42 43
43 namespace { 44 namespace {
44 45
45 const char kTabDragControllerInteractiveUITestUserDataKey[] = 46 const char kTabDragControllerInteractiveUITestUserDataKey[] =
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // Add another tab. 934 // Add another tab.
934 AddTabAndResetBrowser(browser()); 935 AddTabAndResetBrowser(browser());
935 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 936 TabStrip* tab_strip = GetTabStripForBrowser(browser());
936 937
937 // Create another browser. 938 // Create another browser.
938 Browser* browser2 = CreateBrowser(browser()->profile()); 939 Browser* browser2 = CreateBrowser(browser()->profile());
939 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 940 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
940 ResetIDs(browser2->tab_strip_model(), 100); 941 ResetIDs(browser2->tab_strip_model(), 100);
941 942
942 // Move the second browser to the second display. 943 // Move the second browser to the second display.
943 std::vector<aura::RootWindow*> roots( 944 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
944 ash::Shell::GetInstance()->display_controller()->GetAllRootWindows());
945 ASSERT_EQ(2u, roots.size()); 945 ASSERT_EQ(2u, roots.size());
946 aura::RootWindow* second_root = roots[1]; 946 aura::RootWindow* second_root = roots[1];
947 gfx::Rect work_area = gfx::Screen::GetDisplayNearestWindow( 947 gfx::Rect work_area = gfx::Screen::GetDisplayNearestWindow(
948 second_root).work_area(); 948 second_root).work_area();
949 browser2->window()->SetBounds(work_area); 949 browser2->window()->SetBounds(work_area);
950 EXPECT_EQ(second_root, 950 EXPECT_EQ(second_root,
951 browser2->window()->GetNativeWindow()->GetRootWindow()); 951 browser2->window()->GetNativeWindow()->GetRootWindow());
952 952
953 // Move to the first tab and drag it enough so that it detaches, but not 953 // Move to the first tab and drag it enough so that it detaches, but not
954 // enough that it attaches to browser2. 954 // enough that it attaches to browser2.
(...skipping 12 matching lines...) Expand all
967 967
968 // Release the mouse, stopping the drag session. 968 // Release the mouse, stopping the drag session.
969 ASSERT_TRUE(ReleaseInput()); 969 ASSERT_TRUE(ReleaseInput());
970 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 970 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
971 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 971 ASSERT_FALSE(tab_strip->IsDragSessionActive());
972 ASSERT_FALSE(TabDragController::IsActive()); 972 ASSERT_FALSE(TabDragController::IsActive());
973 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); 973 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
974 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 974 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
975 } 975 }
976 976
977 namespace {
978
979 // Invoked from the nested message loop.
980 void CancelDragTabToWindowInSeparateDisplayStep3(
981 DetachToBrowserTabDragControllerTest* test,
982 TabStrip* tab_strip) {
983 ASSERT_FALSE(tab_strip->IsDragSessionActive());
984 ASSERT_TRUE(TabDragController::IsActive());
985 ASSERT_EQ(2u, BrowserList::size());
986
987 // Switching display mode should cancel the drag operation.
988 ash::internal::MultiDisplayManager::CycleDisplay();
989 }
990
991 // Invoked from the nested message loop.
992 void CancelDragTabToWindowInSeparateDisplayStep2(
993 DetachToBrowserTabDragControllerTest* test,
994 TabStrip* tab_strip,
995 gfx::Point final_destination) {
996 ASSERT_FALSE(tab_strip->IsDragSessionActive());
997 ASSERT_TRUE(TabDragController::IsActive());
998 ASSERT_EQ(2u, BrowserList::size());
999
1000 Browser* new_browser = *(++BrowserList::begin());
1001 EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(),
1002 new_browser->window()->GetNativeWindow()->GetRootWindow());
1003
1004 ASSERT_TRUE(test->DragInputToNotifyWhenDone(
1005 final_destination.x(), final_destination.y(),
1006 base::Bind(&CancelDragTabToWindowInSeparateDisplayStep3,
1007 test, tab_strip)));
1008 }
1009
1010 } // namespace
1011
1012 // Drags from browser to a second display and releases input.
1013 IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
1014 CancelDragTabToWindowInSeparateDisplay) {
1015 // Add another tab.
1016 AddTabAndResetBrowser(browser());
1017 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1018
1019 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1020
1021 // Move the second browser to the second display.
1022 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
1023 ASSERT_EQ(2u, roots.size());
1024 gfx::Point final_destination =
1025 gfx::Screen::GetDisplayNearestWindow(roots[1]).work_area().CenterPoint();
1026
1027 // Move to the first tab and drag it enough so that it detaches, but not
1028 // enough to move to another display.
1029 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1030 ASSERT_TRUE(PressInput(tab_0_center));
1031 ASSERT_TRUE(DragInputToNotifyWhenDone(
1032 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
1033 base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
1034 this, tab_strip, final_destination)));
1035 QuitWhenNotDragging();
1036
1037 // Drag operation must have been cancelled.
1038 if (input_source() == INPUT_SOURCE_TOUCH) {
1039 // A window capture is reset to NULL when merging two root
1040 // windows, and that capture event completes the touch based
1041 // drag operation, instead of cancelling it.
1042 ASSERT_EQ(2u, BrowserList::size());
1043 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1044 ASSERT_FALSE(TabDragController::IsActive());
1045 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
1046 Browser* new_browser = *(++BrowserList::begin());
1047 EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
1048 } else {
1049 // Mouse operation doesn't get cancelled when the capture is
1050 // lost, and removing the display correctly cancel the operation.
1051 ASSERT_EQ(1u, BrowserList::size());
1052 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1053 ASSERT_FALSE(TabDragController::IsActive());
1054 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1055 }
1056 // Release the mouse
1057 ASSERT_TRUE(ReleaseInput());
1058 }
1059
977 #endif 1060 #endif
978 1061
979 #if defined(USE_ASH) 1062 #if defined(USE_ASH)
980 INSTANTIATE_TEST_CASE_P(TabDragging, 1063 INSTANTIATE_TEST_CASE_P(TabDragging,
981 DetachToBrowserInSeparateDisplayTabDragControllerTest, 1064 DetachToBrowserInSeparateDisplayTabDragControllerTest,
982 ::testing::Values("mouse", "touch")); 1065 ::testing::Values("mouse", "touch"));
983 INSTANTIATE_TEST_CASE_P(TabDragging, 1066 INSTANTIATE_TEST_CASE_P(TabDragging,
984 DetachToBrowserTabDragControllerTest, 1067 DetachToBrowserTabDragControllerTest,
985 ::testing::Values("mouse", "touch")); 1068 ::testing::Values("mouse", "touch"));
986 #else 1069 #else
987 INSTANTIATE_TEST_CASE_P(TabDragging, 1070 INSTANTIATE_TEST_CASE_P(TabDragging,
988 DetachToBrowserTabDragControllerTest, 1071 DetachToBrowserTabDragControllerTest,
989 ::testing::Values("mouse")); 1072 ::testing::Values("mouse"));
990 #endif 1073 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698