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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer_unittest.cc

Issue 14273008: Add ash-enable-sticky-edges for 'sticky' instead of 'snap' behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/ash_switches.h"
7 #include "ash/display/display_controller.h" 8 #include "ash/display/display_controller.h"
8 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
9 #include "ash/screen_ash.h" 10 #include "ash/screen_ash.h"
10 #include "ash/shelf/shelf_layout_manager.h" 11 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
13 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
14 #include "ash/wm/property_util.h" 15 #include "ash/wm/property_util.h"
15 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
16 #include "ash/wm/workspace/phantom_window_controller.h" 17 #include "ash/wm/workspace/phantom_window_controller.h"
17 #include "ash/wm/workspace/snap_sizer.h" 18 #include "ash/wm/workspace/snap_sizer.h"
18 #include "ash/wm/workspace_controller.h" 19 #include "ash/wm/workspace_controller.h"
20 #include "base/command_line.h"
19 #include "base/stringprintf.h" 21 #include "base/stringprintf.h"
20 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
21 #include "ui/aura/client/aura_constants.h" 23 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
23 #include "ui/aura/test/test_window_delegate.h" 25 #include "ui/aura/test/test_window_delegate.h"
24 #include "ui/base/hit_test.h" 26 #include "ui/base/hit_test.h"
25 #include "ui/gfx/insets.h" 27 #include "ui/gfx/insets.h"
26 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
27 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
28 30
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 TestWindowDelegate delegate4_; 157 TestWindowDelegate delegate4_;
156 scoped_ptr<aura::Window> window_; 158 scoped_ptr<aura::Window> window_;
157 scoped_ptr<aura::Window> window2_; 159 scoped_ptr<aura::Window> window2_;
158 scoped_ptr<aura::Window> window3_; 160 scoped_ptr<aura::Window> window3_;
159 scoped_ptr<aura::Window> window4_; 161 scoped_ptr<aura::Window> window4_;
160 162
161 private: 163 private:
162 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 164 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
163 }; 165 };
164 166
167 class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest {
168 public:
169 WorkspaceWindowResizerTestSticky() {}
170 virtual ~WorkspaceWindowResizerTestSticky() {}
171
172 virtual void SetUp() OVERRIDE {
173 CommandLine::ForCurrentProcess()->AppendSwitch(
174 ash::switches::kAshEnableStickyEdges);
175 WorkspaceWindowResizerTest::SetUp();
176 }
177
178 private:
179 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTestSticky);
180 };
181
165 } // namespace 182 } // namespace
166 183
167 // Assertions around attached window resize dragging from the right with 2 184 // Assertions around attached window resize dragging from the right with 2
168 // windows. 185 // windows.
169 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 186 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
170 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 187 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
171 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 188 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
172 189
173 std::vector<aura::Window*> windows; 190 std::vector<aura::Window*> windows;
174 windows.push_back(window2_.get()); 191 windows.push_back(window2_.get());
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 817
801 // Verifies snapping to edges works. 818 // Verifies snapping to edges works.
802 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { 819 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
803 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 820 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
804 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 821 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
805 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 822 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
806 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 823 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
807 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 824 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
808 ASSERT_TRUE(resizer.get()); 825 ASSERT_TRUE(resizer.get());
809 // Move to an x-coordinate of 15, which should not snap. 826 // Move to an x-coordinate of 15, which should not snap.
810 resizer->Drag(CalculateDragPoint(*resizer, -81, 0), 0); 827 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
811 // An x-coordinate of 7 should snap. 828 // An x-coordinate of 7 should snap.
812 resizer->Drag(CalculateDragPoint(*resizer, -89, 0), 0); 829 resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0);
813 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 830 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
814 // Move to -15, should still snap to 0. 831 // Move to -15, should still snap to 0.
815 resizer->Drag(CalculateDragPoint(*resizer, -111, 0), 0); 832 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
816 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 833 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
817 // At -32 should move past snap points. 834 // At -32 should move past snap points.
818 resizer->Drag(CalculateDragPoint(*resizer, -128, 0), 0); 835 resizer->Drag(CalculateDragPoint(*resizer, -32 - 96, 0), 0);
819 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString()); 836 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString());
820 resizer->Drag(CalculateDragPoint(*resizer, -129, 0), 0); 837 resizer->Drag(CalculateDragPoint(*resizer, -33 - 96, 0), 0);
821 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString()); 838 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString());
822 839
823 // Right side should similarly snap. 840 // Right side should similarly snap.
824 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0); 841 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
825 EXPECT_EQ("465,112 320x160", window_->bounds().ToString()); 842 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
826 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0); 843 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0);
827 EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); 844 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
828 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0); 845 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
829 EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); 846 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
830 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0); 847 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows())); 919 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows()));
903 ASSERT_TRUE(resizer.get()); 920 ASSERT_TRUE(resizer.get());
904 resizer->Drag( 921 resizer->Drag(
905 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0); 922 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
906 EXPECT_EQ(0, window_->bounds().x()); 923 EXPECT_EQ(0, window_->bounds().x());
907 EXPECT_EQ(200, window_->bounds().y()); 924 EXPECT_EQ(200, window_->bounds().y());
908 EXPECT_EQ(120, window_->bounds().width()); 925 EXPECT_EQ(120, window_->bounds().width());
909 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 926 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
910 } 927 }
911 928
929 // Verifies sticking to edges works.
930 TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) {
931 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
932 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
933 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
934 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
935 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
936 ASSERT_TRUE(resizer.get());
937 // Move to an x-coordinate of 15, which should not stick.
938 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
939 // Move to -15, should still stick to 0.
940 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
941 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
942 // At -100 should move past edge.
943 resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0);
944 EXPECT_EQ("-100,112 320x160", window_->bounds().ToString());
945 resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0);
946 EXPECT_EQ("-101,112 320x160", window_->bounds().ToString());
947
948 // Right side should similarly stick.
949 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
950 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
951 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
952 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
953 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 100, 0), 0);
954 EXPECT_EQ("580,112 320x160", window_->bounds().ToString());
955 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 101, 0), 0);
956 EXPECT_EQ("581,112 320x160", window_->bounds().ToString());
957
958 // And the bottom should stick too.
959 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 + 15), 0);
960 EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
961 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 100), 0);
962 EXPECT_EQ("96,538 320x160", window_->bounds().ToString());
963 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 101), 0);
964 EXPECT_EQ("96,539 320x160", window_->bounds().ToString());
965
966 // No need to test dragging < 0 as we force that to 0.
967 }
968
969 // Verifies a resize sticks when dragging TOPLEFT.
970 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) {
971 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
972 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
973 window_.get(), gfx::Point(), HTTOPLEFT, empty_windows()));
974 ASSERT_TRUE(resizer.get());
975 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0);
976 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
977 }
978
979 // Verifies a resize sticks when dragging TOPRIGHT.
980 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) {
981 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
982 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
983 window_.get()));
984 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
985 window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows()));
986 ASSERT_TRUE(resizer.get());
987 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20,
988 -200 - 15), 0);
989 EXPECT_EQ(100, window_->bounds().x());
990 EXPECT_EQ(work_area.y(), window_->bounds().y());
991 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
992 EXPECT_EQ(230, window_->bounds().height());
993 }
994
995 // Verifies a resize snap when dragging BOTTOMRIGHT.
996 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) {
997 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
998 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
999 window_.get()));
1000 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1001 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
1002 ASSERT_TRUE(resizer.get());
1003 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15,
1004 work_area.bottom() - 200 - 30 + 15), 0);
1005 EXPECT_EQ(100, window_->bounds().x());
1006 EXPECT_EQ(200, window_->bounds().y());
1007 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1008 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1009 }
1010
1011 // Verifies a resize snap when dragging BOTTOMLEFT.
1012 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) {
1013 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1014 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1015 window_.get()));
1016 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1017 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows()));
1018 ASSERT_TRUE(resizer.get());
1019 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100,
1020 work_area.bottom() - 200 - 30 + 15), 0);
1021 EXPECT_EQ(0, window_->bounds().x());
1022 EXPECT_EQ(200, window_->bounds().y());
1023 EXPECT_EQ(120, window_->bounds().width());
1024 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1025 }
1026
912 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) { 1027 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
913 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1028 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
914 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1029 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
915 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1030 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
916 ASSERT_TRUE(resizer.get()); 1031 ASSERT_TRUE(resizer.get());
917 // Resize the right bottom to add 10 in width, 12 in height. 1032 // Resize the right bottom to add 10 in width, 12 in height.
918 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN); 1033 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
919 // Both bottom and right sides to resize to exact size requested. 1034 // Both bottom and right sides to resize to exact size requested.
920 EXPECT_EQ("96,112 330x172", window_->bounds().ToString()); 1035 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
921 } 1036 }
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 ASSERT_TRUE(resizer.get()); 1600 ASSERT_TRUE(resizer.get());
1486 // Move it 50 to the left, which should contract w1 and expand w2-3. 1601 // Move it 50 to the left, which should contract w1 and expand w2-3.
1487 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); 1602 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
1488 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); 1603 EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
1489 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); 1604 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
1490 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); 1605 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1491 } 1606 }
1492 1607
1493 } // namespace internal 1608 } // namespace internal
1494 } // namespace ash 1609 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698