OLD | NEW |
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 Loading... |
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 Loading... |
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 // TODO(jianli): This is a temporary workaround to make TestDragging work |
| 413 // with mouse location parameter changes. Fix this when we move drag related |
| 414 // tests to new testing class. |
| 415 gfx::Point test_dragging_mouse_location_; |
408 }; | 416 }; |
409 | 417 |
410 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 418 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
411 PanelManager* panel_manager = PanelManager::GetInstance(); | 419 PanelManager* panel_manager = PanelManager::GetInstance(); |
412 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 420 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
413 | 421 |
414 Panel* panel = CreatePanel("PanelTest"); | 422 Panel* panel = CreatePanel("PanelTest"); |
415 EXPECT_EQ(1, panel_manager->num_panels()); | 423 EXPECT_EQ(1, panel_manager->num_panels()); |
416 | 424 |
417 gfx::Rect bounds = panel->GetBounds(); | 425 gfx::Rect bounds = panel->GetBounds(); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 780 |
773 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, NotDraggable) { | 781 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, NotDraggable) { |
774 Panel* panel = CreatePanel("panel"); | 782 Panel* panel = CreatePanel("panel"); |
775 // This is used to simulate making a docked panel not draggable. | 783 // This is used to simulate making a docked panel not draggable. |
776 panel->set_has_temporary_layout(true); | 784 panel->set_has_temporary_layout(true); |
777 Panel* panel2 = CreatePanel("panel2"); | 785 Panel* panel2 = CreatePanel("panel2"); |
778 | 786 |
779 scoped_ptr<NativePanelTesting> panel_testing( | 787 scoped_ptr<NativePanelTesting> panel_testing( |
780 NativePanelTesting::Create(panel->native_panel())); | 788 NativePanelTesting::Create(panel->native_panel())); |
781 gfx::Rect bounds = panel->GetBounds(); | 789 gfx::Rect bounds = panel->GetBounds(); |
782 panel_testing->PressLeftMouseButtonTitlebar(bounds.origin()); | 790 gfx::Point mouse_location = bounds.origin(); |
| 791 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
783 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); | 792 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); |
784 panel_testing->DragTitlebar(-50, 10); | 793 mouse_location.Offset(-50, 10); |
| 794 panel_testing->DragTitlebar(mouse_location); |
785 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); | 795 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); |
786 panel_testing->FinishDragTitlebar(); | 796 panel_testing->FinishDragTitlebar(); |
787 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); | 797 EXPECT_EQ(bounds.x(), panel->GetBounds().x()); |
788 | 798 |
789 // Reset the simulation hack so that the panel can be closed correctly. | 799 // Reset the simulation hack so that the panel can be closed correctly. |
790 panel->set_has_temporary_layout(false); | 800 panel->set_has_temporary_layout(false); |
791 panel->Close(); | 801 panel->Close(); |
792 panel2->Close(); | 802 panel2->Close(); |
793 } | 803 } |
794 | 804 |
795 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { | 805 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { |
796 PanelManager* panel_manager = PanelManager::GetInstance(); | 806 PanelManager* panel_manager = PanelManager::GetInstance(); |
797 PanelDragController* drag_controller = panel_manager->drag_controller(); | 807 PanelDragController* drag_controller = panel_manager->drag_controller(); |
798 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); | 808 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
799 | 809 |
800 // Create 4 detached panels. | 810 // Create 4 docked panels. |
801 // We have: P4 P3 P2 P1 | 811 // We have: P4 P3 P2 P1 |
802 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); | 812 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); |
803 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); | 813 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); |
804 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); | 814 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); |
805 Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100)); | 815 Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100)); |
806 ASSERT_EQ(4, docked_strip->num_panels()); | 816 ASSERT_EQ(4, docked_strip->num_panels()); |
807 | 817 |
808 scoped_ptr<NativePanelTesting> panel1_testing( | 818 scoped_ptr<NativePanelTesting> panel1_testing( |
809 NativePanelTesting::Create(panel1->native_panel())); | 819 NativePanelTesting::Create(panel1->native_panel())); |
810 gfx::Point position1 = panel1->GetBounds().origin(); | 820 gfx::Point position1 = panel1->GetBounds().origin(); |
811 gfx::Point position2 = panel2->GetBounds().origin(); | 821 gfx::Point position2 = panel2->GetBounds().origin(); |
812 gfx::Point position3 = panel3->GetBounds().origin(); | 822 gfx::Point position3 = panel3->GetBounds().origin(); |
813 gfx::Point position4 = panel4->GetBounds().origin(); | 823 gfx::Point position4 = panel4->GetBounds().origin(); |
814 | 824 |
815 // Test the scenario: drag a panel, close another panel, cancel the drag. | 825 // Test the scenario: drag a panel, close another panel, cancel the drag. |
816 { | 826 { |
817 std::vector<Panel*> panels; | 827 std::vector<Panel*> panels; |
818 gfx::Point panel1_new_position = position1; | 828 gfx::Point panel1_new_position = position1; |
819 panel1_new_position.Offset(-500, 0); | 829 panel1_new_position.Offset(-500, 0); |
820 | 830 |
821 // Start dragging a panel. | 831 // Start dragging a panel. |
822 // We have: P1* P4 P3 P2 | 832 // We have: P1* P4 P3 P2 |
823 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | 833 gfx::Point mouse_location = panel1->GetBounds().origin(); |
824 panel1_testing->DragTitlebar(-500, -5); | 834 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 835 mouse_location.Offset(-500, -5); |
| 836 panel1_testing->DragTitlebar(mouse_location); |
825 EXPECT_TRUE(drag_controller->IsDragging()); | 837 EXPECT_TRUE(drag_controller->IsDragging()); |
826 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | 838 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
827 | 839 |
828 ASSERT_EQ(4, docked_strip->num_panels()); | 840 ASSERT_EQ(4, docked_strip->num_panels()); |
829 panels = PanelManager::GetInstance()->panels(); | 841 panels = PanelManager::GetInstance()->panels(); |
830 EXPECT_EQ(panel2, panels[0]); | 842 EXPECT_EQ(panel2, panels[0]); |
831 EXPECT_EQ(panel3, panels[1]); | 843 EXPECT_EQ(panel3, panels[1]); |
832 EXPECT_EQ(panel4, panels[2]); | 844 EXPECT_EQ(panel4, panels[2]); |
833 EXPECT_EQ(panel1, panels[3]); | 845 EXPECT_EQ(panel1, panels[3]); |
834 EXPECT_EQ(position1, panel2->GetBounds().origin()); | 846 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 } | 880 } |
869 | 881 |
870 // Test the scenario: drag a panel, close another panel, end the drag. | 882 // Test the scenario: drag a panel, close another panel, end the drag. |
871 { | 883 { |
872 std::vector<Panel*> panels; | 884 std::vector<Panel*> panels; |
873 gfx::Point panel1_new_position = position1; | 885 gfx::Point panel1_new_position = position1; |
874 panel1_new_position.Offset(-500, 0); | 886 panel1_new_position.Offset(-500, 0); |
875 | 887 |
876 // Start dragging a panel. | 888 // Start dragging a panel. |
877 // We have: P1* P4 P3 | 889 // We have: P1* P4 P3 |
878 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | 890 gfx::Point mouse_location = panel1->GetBounds().origin(); |
879 panel1_testing->DragTitlebar(-500, -5); | 891 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 892 mouse_location.Offset(-500, -5); |
| 893 panel1_testing->DragTitlebar(mouse_location); |
880 EXPECT_TRUE(drag_controller->IsDragging()); | 894 EXPECT_TRUE(drag_controller->IsDragging()); |
881 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | 895 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
882 | 896 |
883 ASSERT_EQ(3, docked_strip->num_panels()); | 897 ASSERT_EQ(3, docked_strip->num_panels()); |
884 panels = PanelManager::GetInstance()->panels(); | 898 panels = PanelManager::GetInstance()->panels(); |
885 EXPECT_EQ(panel3, panels[0]); | 899 EXPECT_EQ(panel3, panels[0]); |
886 EXPECT_EQ(panel4, panels[1]); | 900 EXPECT_EQ(panel4, panels[1]); |
887 EXPECT_EQ(panel1, panels[2]); | 901 EXPECT_EQ(panel1, panels[2]); |
888 EXPECT_EQ(position1, panel3->GetBounds().origin()); | 902 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
889 EXPECT_EQ(position2, panel4->GetBounds().origin()); | 903 EXPECT_EQ(position2, panel4->GetBounds().origin()); |
(...skipping 27 matching lines...) Expand all Loading... |
917 } | 931 } |
918 | 932 |
919 // Test the scenario: drag a panel and close the dragging panel. | 933 // Test the scenario: drag a panel and close the dragging panel. |
920 { | 934 { |
921 std::vector<Panel*> panels; | 935 std::vector<Panel*> panels; |
922 gfx::Point panel1_new_position = position2; | 936 gfx::Point panel1_new_position = position2; |
923 panel1_new_position.Offset(-500, 0); | 937 panel1_new_position.Offset(-500, 0); |
924 | 938 |
925 // Start dragging a panel again. | 939 // Start dragging a panel again. |
926 // We have: P1* P4 | 940 // We have: P1* P4 |
927 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | 941 gfx::Point mouse_location = panel1->GetBounds().origin(); |
928 panel1_testing->DragTitlebar(-500, -5); | 942 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 943 mouse_location.Offset(-500, -5); |
| 944 panel1_testing->DragTitlebar(mouse_location); |
929 EXPECT_TRUE(drag_controller->IsDragging()); | 945 EXPECT_TRUE(drag_controller->IsDragging()); |
930 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | 946 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
931 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | 947 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
932 | 948 |
933 ASSERT_EQ(2, docked_strip->num_panels()); | 949 ASSERT_EQ(2, docked_strip->num_panels()); |
934 panels = PanelManager::GetInstance()->panels(); | 950 panels = PanelManager::GetInstance()->panels(); |
935 EXPECT_EQ(panel4, panels[0]); | 951 EXPECT_EQ(panel4, panels[0]); |
936 EXPECT_EQ(panel1, panels[1]); | 952 EXPECT_EQ(panel1, panels[1]); |
937 EXPECT_EQ(position1, panel4->GetBounds().origin()); | 953 EXPECT_EQ(position1, panel4->GetBounds().origin()); |
938 | 954 |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2175 // position when tall panel brings up its titlebar. | 2191 // position when tall panel brings up its titlebar. |
2176 CloseWindowAndWait(panel1->browser()); | 2192 CloseWindowAndWait(panel1->browser()); |
2177 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, | 2193 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
2178 GetBalloonBottomPosition(balloon)); | 2194 GetBalloonBottomPosition(balloon)); |
2179 | 2195 |
2180 // Closing the remaining tall panel should move the notification balloon back | 2196 // Closing the remaining tall panel should move the notification balloon back |
2181 // to its original position. | 2197 // to its original position. |
2182 CloseWindowAndWait(panel2->browser()); | 2198 CloseWindowAndWait(panel2->browser()); |
2183 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); | 2199 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
2184 } | 2200 } |
OLD | NEW |