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

Side by Side Diff: chrome/browser/ui/panels/panel_browsertest.cc

Issue 9546001: Support detaching/attaching panels via inter-strip drags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/download/download_service.h" 8 #include "chrome/browser/download/download_service.h"
9 #include "chrome/browser/download/download_service_factory.h" 9 #include "chrome/browser/download/download_service_factory.h"
10 #include "chrome/browser/net/url_request_mock_util.h" 10 #include "chrome/browser/net/url_request_mock_util.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // expected_bounds_after_cancel != test_begin_bounds. 171 // expected_bounds_after_cancel != test_begin_bounds.
172 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds(); 172 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds();
173 173
174 NativePanel* panel_to_drag = panels[drag_index]->native_panel(); 174 NativePanel* panel_to_drag = panels[drag_index]->native_panel();
175 scoped_ptr<NativePanelTesting> panel_testing_to_drag( 175 scoped_ptr<NativePanelTesting> panel_testing_to_drag(
176 NativePanelTesting::Create(panel_to_drag)); 176 NativePanelTesting::Create(panel_to_drag));
177 177
178 if (drag_action & DRAG_ACTION_BEGIN) { 178 if (drag_action & DRAG_ACTION_BEGIN) {
179 // Trigger the mouse-pressed event. 179 // Trigger the mouse-pressed event.
180 // All panels should remain in their original positions. 180 // All panels should remain in their original positions.
181 test_dragging_mouse_location_ = panels[drag_index]->GetBounds().origin();
181 panel_testing_to_drag->PressLeftMouseButtonTitlebar( 182 panel_testing_to_drag->PressLeftMouseButtonTitlebar(
182 panels[drag_index]->GetBounds().origin()); 183 test_dragging_mouse_location_);
183 EXPECT_EQ(test_begin_bounds, GetPanelBounds(panels)); 184 EXPECT_EQ(test_begin_bounds, GetPanelBounds(panels));
184 } 185 }
185 186
186 // Trigger the drag. 187 // Trigger the drag.
187 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); 188 test_dragging_mouse_location_.Offset(delta_x, delta_y);
189 panel_testing_to_drag->DragTitlebar(test_dragging_mouse_location_);
188 190
189 // Compare against expected bounds. 191 // Compare against expected bounds.
190 EXPECT_EQ(AddXDeltaToBounds(test_begin_bounds, expected_delta_x_after_drag), 192 EXPECT_EQ(AddXDeltaToBounds(test_begin_bounds, expected_delta_x_after_drag),
191 GetPanelBounds(panels)); 193 GetPanelBounds(panels));
192 194
193 if (drag_action & DRAG_ACTION_CANCEL) { 195 if (drag_action & DRAG_ACTION_CANCEL) {
194 // Cancel the drag. 196 // Cancel the drag.
195 // All panels should return to their initial positions. 197 // All panels should return to their initial positions.
196 panel_testing_to_drag->CancelDragTitlebar(); 198 panel_testing_to_drag->CancelDragTitlebar();
197 EXPECT_EQ(expected_bounds_after_cancel, GetAllPanelBounds()); 199 EXPECT_EQ(expected_bounds_after_cancel, GetAllPanelBounds());
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 MoveMouse(minimized_bounds[index].origin()); 400 MoveMouse(minimized_bounds[index].origin());
399 } 401 }
400 402
401 // The below could be separate tests, just adding a TODO here for tracking. 403 // The below could be separate tests, just adding a TODO here for tracking.
402 // TODO(prasadt): Add test for dragging when in titlebar exposed state. 404 // TODO(prasadt): Add test for dragging when in titlebar exposed state.
403 // TODO(prasadt): Add test in presence of auto hiding task bar. 405 // TODO(prasadt): Add test in presence of auto hiding task bar.
404 406
405 for (size_t i = 0; i < panels.size(); ++i) 407 for (size_t i = 0; i < panels.size(); ++i)
406 delete native_panels_testing[i]; 408 delete native_panels_testing[i];
407 } 409 }
410
411 private:
412 gfx::Point test_dragging_mouse_location_;
408 }; 413 };
409 414
410 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { 415 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
411 PanelManager* panel_manager = PanelManager::GetInstance(); 416 PanelManager* panel_manager = PanelManager::GetInstance();
412 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. 417 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
413 418
414 Panel* panel = CreatePanel("PanelTest"); 419 Panel* panel = CreatePanel("PanelTest");
415 EXPECT_EQ(1, panel_manager->num_panels()); 420 EXPECT_EQ(1, panel_manager->num_panels());
416 421
417 gfx::Rect bounds = panel->GetBounds(); 422 gfx::Rect bounds = panel->GetBounds();
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 776
772 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, NotDraggable) { 777 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, NotDraggable) {
773 Panel* panel = CreatePanel("panel"); 778 Panel* panel = CreatePanel("panel");
774 // This is used to simulate making a docked panel not draggable. 779 // This is used to simulate making a docked panel not draggable.
775 panel->set_has_temporary_layout(true); 780 panel->set_has_temporary_layout(true);
776 Panel* panel2 = CreatePanel("panel2"); 781 Panel* panel2 = CreatePanel("panel2");
777 782
778 scoped_ptr<NativePanelTesting> panel_testing( 783 scoped_ptr<NativePanelTesting> panel_testing(
779 NativePanelTesting::Create(panel->native_panel())); 784 NativePanelTesting::Create(panel->native_panel()));
780 gfx::Rect bounds = panel->GetBounds(); 785 gfx::Rect bounds = panel->GetBounds();
781 panel_testing->PressLeftMouseButtonTitlebar(bounds.origin()); 786 gfx::Point mouse_location = bounds.origin();
787 panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
782 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); 788 EXPECT_EQ(bounds.x(), panel->GetBounds().x());
783 panel_testing->DragTitlebar(-50, 10); 789 mouse_location.Offset(-50, 10);
790 panel_testing->DragTitlebar(mouse_location);
784 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); 791 EXPECT_EQ(bounds.x(), panel->GetBounds().x());
785 panel_testing->FinishDragTitlebar(); 792 panel_testing->FinishDragTitlebar();
786 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); 793 EXPECT_EQ(bounds.x(), panel->GetBounds().x());
787 794
788 // Reset the simulation hack so that the panel can be closed correctly. 795 // Reset the simulation hack so that the panel can be closed correctly.
789 panel->set_has_temporary_layout(false); 796 panel->set_has_temporary_layout(false);
790 panel->Close(); 797 panel->Close();
791 panel2->Close(); 798 panel2->Close();
792 } 799 }
793 800
794 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { 801 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) {
795 PanelManager* panel_manager = PanelManager::GetInstance(); 802 PanelManager* panel_manager = PanelManager::GetInstance();
796 PanelDragController* drag_controller = panel_manager->drag_controller(); 803 PanelDragController* drag_controller = panel_manager->drag_controller();
797 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); 804 DockedPanelStrip* docked_strip = panel_manager->docked_strip();
798 805
799 // Create 4 detached panels. 806 // Create 4 docked panels.
800 // We have: P4 P3 P2 P1 807 // We have: P4 P3 P2 P1
801 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); 808 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100));
802 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); 809 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100));
803 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); 810 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100));
804 Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100)); 811 Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100));
805 ASSERT_EQ(4, docked_strip->num_panels()); 812 ASSERT_EQ(4, docked_strip->num_panels());
806 813
807 scoped_ptr<NativePanelTesting> panel1_testing( 814 scoped_ptr<NativePanelTesting> panel1_testing(
808 NativePanelTesting::Create(panel1->native_panel())); 815 NativePanelTesting::Create(panel1->native_panel()));
809 gfx::Point position1 = panel1->GetBounds().origin(); 816 gfx::Point position1 = panel1->GetBounds().origin();
810 gfx::Point position2 = panel2->GetBounds().origin(); 817 gfx::Point position2 = panel2->GetBounds().origin();
811 gfx::Point position3 = panel3->GetBounds().origin(); 818 gfx::Point position3 = panel3->GetBounds().origin();
812 gfx::Point position4 = panel4->GetBounds().origin(); 819 gfx::Point position4 = panel4->GetBounds().origin();
813 820
814 // Test the scenario: drag a panel, close another panel, cancel the drag. 821 // Test the scenario: drag a panel, close another panel, cancel the drag.
815 { 822 {
816 std::vector<Panel*> panels; 823 std::vector<Panel*> panels;
817 gfx::Point panel1_new_position = position1; 824 gfx::Point panel1_new_position = position1;
818 panel1_new_position.Offset(-500, 0); 825 panel1_new_position.Offset(-500, 0);
819 826
820 // Start dragging a panel. 827 // Start dragging a panel.
821 // We have: P1* P4 P3 P2 828 // We have: P1* P4 P3 P2
829 gfx::Point mouse_location = panel1->GetBounds().origin();
822 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); 830 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
823 panel1_testing->DragTitlebar(-500, -5); 831 mouse_location.Offset(-500, -5);
832 panel1_testing->DragTitlebar(mouse_location);
824 EXPECT_TRUE(drag_controller->IsDragging()); 833 EXPECT_TRUE(drag_controller->IsDragging());
825 EXPECT_EQ(panel1, drag_controller->dragging_panel()); 834 EXPECT_EQ(panel1, drag_controller->dragging_panel());
826 835
827 ASSERT_EQ(4, docked_strip->num_panels()); 836 ASSERT_EQ(4, docked_strip->num_panels());
828 panels = PanelManager::GetInstance()->panels(); 837 panels = PanelManager::GetInstance()->panels();
829 EXPECT_EQ(panel2, panels[0]); 838 EXPECT_EQ(panel2, panels[0]);
830 EXPECT_EQ(panel3, panels[1]); 839 EXPECT_EQ(panel3, panels[1]);
831 EXPECT_EQ(panel4, panels[2]); 840 EXPECT_EQ(panel4, panels[2]);
832 EXPECT_EQ(panel1, panels[3]); 841 EXPECT_EQ(panel1, panels[3]);
833 EXPECT_EQ(position1, panel2->GetBounds().origin()); 842 EXPECT_EQ(position1, panel2->GetBounds().origin());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 } 876 }
868 877
869 // Test the scenario: drag a panel, close another panel, end the drag. 878 // Test the scenario: drag a panel, close another panel, end the drag.
870 { 879 {
871 std::vector<Panel*> panels; 880 std::vector<Panel*> panels;
872 gfx::Point panel1_new_position = position1; 881 gfx::Point panel1_new_position = position1;
873 panel1_new_position.Offset(-500, 0); 882 panel1_new_position.Offset(-500, 0);
874 883
875 // Start dragging a panel. 884 // Start dragging a panel.
876 // We have: P1* P4 P3 885 // We have: P1* P4 P3
877 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); 886 gfx::Point mouse_location = panel1->GetBounds().origin();
878 panel1_testing->DragTitlebar(-500, -5); 887 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
888 mouse_location.Offset(-500, -5);
889 panel1_testing->DragTitlebar(mouse_location);
879 EXPECT_TRUE(drag_controller->IsDragging()); 890 EXPECT_TRUE(drag_controller->IsDragging());
880 EXPECT_EQ(panel1, drag_controller->dragging_panel()); 891 EXPECT_EQ(panel1, drag_controller->dragging_panel());
881 892
882 ASSERT_EQ(3, docked_strip->num_panels()); 893 ASSERT_EQ(3, docked_strip->num_panels());
883 panels = PanelManager::GetInstance()->panels(); 894 panels = PanelManager::GetInstance()->panels();
884 EXPECT_EQ(panel3, panels[0]); 895 EXPECT_EQ(panel3, panels[0]);
885 EXPECT_EQ(panel4, panels[1]); 896 EXPECT_EQ(panel4, panels[1]);
886 EXPECT_EQ(panel1, panels[2]); 897 EXPECT_EQ(panel1, panels[2]);
887 EXPECT_EQ(position1, panel3->GetBounds().origin()); 898 EXPECT_EQ(position1, panel3->GetBounds().origin());
888 EXPECT_EQ(position2, panel4->GetBounds().origin()); 899 EXPECT_EQ(position2, panel4->GetBounds().origin());
(...skipping 27 matching lines...) Expand all
916 } 927 }
917 928
918 // Test the scenario: drag a panel and close the dragging panel. 929 // Test the scenario: drag a panel and close the dragging panel.
919 { 930 {
920 std::vector<Panel*> panels; 931 std::vector<Panel*> panels;
921 gfx::Point panel1_new_position = position2; 932 gfx::Point panel1_new_position = position2;
922 panel1_new_position.Offset(-500, 0); 933 panel1_new_position.Offset(-500, 0);
923 934
924 // Start dragging a panel again. 935 // Start dragging a panel again.
925 // We have: P1* P4 936 // We have: P1* P4
926 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); 937 gfx::Point mouse_location = panel1->GetBounds().origin();
927 panel1_testing->DragTitlebar(-500, -5); 938 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
939 mouse_location.Offset(-500, -5);
940 panel1_testing->DragTitlebar(mouse_location);
928 EXPECT_TRUE(drag_controller->IsDragging()); 941 EXPECT_TRUE(drag_controller->IsDragging());
929 EXPECT_EQ(panel1, drag_controller->dragging_panel()); 942 EXPECT_EQ(panel1, drag_controller->dragging_panel());
930 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); 943 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
931 944
932 ASSERT_EQ(2, docked_strip->num_panels()); 945 ASSERT_EQ(2, docked_strip->num_panels());
933 panels = PanelManager::GetInstance()->panels(); 946 panels = PanelManager::GetInstance()->panels();
934 EXPECT_EQ(panel4, panels[0]); 947 EXPECT_EQ(panel4, panels[0]);
935 EXPECT_EQ(panel1, panels[1]); 948 EXPECT_EQ(panel1, panels[1]);
936 EXPECT_EQ(position1, panel4->GetBounds().origin()); 949 EXPECT_EQ(position1, panel4->GetBounds().origin());
937 950
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 // position when tall panel brings up its titlebar. 2169 // position when tall panel brings up its titlebar.
2157 CloseWindowAndWait(panel1->browser()); 2170 CloseWindowAndWait(panel1->browser());
2158 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, 2171 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up,
2159 GetBalloonBottomPosition(balloon)); 2172 GetBalloonBottomPosition(balloon));
2160 2173
2161 // Closing the remaining tall panel should move the notification balloon back 2174 // Closing the remaining tall panel should move the notification balloon back
2162 // to its original position. 2175 // to its original position.
2163 CloseWindowAndWait(panel2->browser()); 2176 CloseWindowAndWait(panel2->browser());
2164 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); 2177 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
2165 } 2178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698