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

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

Issue 170863003: Removes #ash-enable-sticky-edges flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
« 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_constants.h" 7 #include "ash/ash_constants.h"
8 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/display/display_manager.h" 9 #include "ash/display/display_manager.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 scoped_ptr<aura::Window> window4_; 204 scoped_ptr<aura::Window> window4_;
205 205
206 TestWindowDelegate touch_resize_delegate_; 206 TestWindowDelegate touch_resize_delegate_;
207 scoped_ptr<aura::Window> touch_resize_window_; 207 scoped_ptr<aura::Window> touch_resize_window_;
208 WorkspaceWindowResizer* workspace_resizer_; 208 WorkspaceWindowResizer* workspace_resizer_;
209 209
210 private: 210 private:
211 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 211 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
212 }; 212 };
213 213
214 class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest {
215 public:
216 WorkspaceWindowResizerTestSticky() {}
217 virtual ~WorkspaceWindowResizerTestSticky() {}
218
219 virtual void SetUp() OVERRIDE {
220 CommandLine::ForCurrentProcess()->AppendSwitch(
221 ash::switches::kAshEnableStickyEdges);
222 WorkspaceWindowResizerTest::SetUp();
223 }
224
225 private:
226 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTestSticky);
227 };
228
229 // Assertions around attached window resize dragging from the right with 2 214 // Assertions around attached window resize dragging from the right with 2
230 // windows. 215 // windows.
231 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 216 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
232 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 217 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
233 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 218 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
234 219
235 std::vector<aura::Window*> windows; 220 std::vector<aura::Window*> windows;
236 windows.push_back(window2_.get()); 221 windows.push_back(window2_.get());
237 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest( 222 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
238 window_.get(), gfx::Point(), HTRIGHT, 223 window_.get(), gfx::Point(), HTRIGHT,
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 window_.get(), gfx::Point(), HTBOTTOMLEFT)); 1117 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1133 ASSERT_TRUE(resizer.get()); 1118 ASSERT_TRUE(resizer.get());
1134 resizer->Drag( 1119 resizer->Drag(
1135 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0); 1120 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
1136 EXPECT_EQ(0, window_->bounds().x()); 1121 EXPECT_EQ(0, window_->bounds().x());
1137 EXPECT_EQ(200, window_->bounds().y()); 1122 EXPECT_EQ(200, window_->bounds().y());
1138 EXPECT_EQ(120, window_->bounds().width()); 1123 EXPECT_EQ(120, window_->bounds().width());
1139 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1124 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1140 } 1125 }
1141 1126
1142 // Verifies sticking to edges works.
1143 TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) {
1144 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
1145 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1146 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1147 // Click 50px to the right so that the mouse pointer does not leave the
1148 // workspace ensuring sticky behavior.
1149 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1150 window_.get(),
1151 window_->bounds().origin() + gfx::Vector2d(50, 0),
1152 HTCAPTION));
1153 ASSERT_TRUE(resizer.get());
1154 // Move to an x-coordinate of 15, which should not stick.
1155 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1156 // Move to -15, should still stick to 0.
1157 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
1158 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
1159 // At -100 should move past edge.
1160 resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0);
1161 EXPECT_EQ("-100,112 320x160", window_->bounds().ToString());
1162 resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0);
1163 EXPECT_EQ("-101,112 320x160", window_->bounds().ToString());
1164
1165 // Right side should similarly stick.
1166 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
1167 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
1168 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
1169 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
1170 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 100, 0), 0);
1171 EXPECT_EQ("580,112 320x160", window_->bounds().ToString());
1172 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 101, 0), 0);
1173 EXPECT_EQ("581,112 320x160", window_->bounds().ToString());
1174
1175 // And the bottom should stick too.
1176 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 + 15), 0);
1177 EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
1178 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 100), 0);
1179 EXPECT_EQ("96,538 320x160", window_->bounds().ToString());
1180 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 101), 0);
1181 EXPECT_EQ("96,539 320x160", window_->bounds().ToString());
1182
1183 // No need to test dragging < 0 as we force that to 0.
1184 }
1185
1186 // Verifies not sticking to edges when a mouse pointer is outside of work area.
1187 TEST_F(WorkspaceWindowResizerTestSticky, NoStickToEdgeWhenOutside) {
1188 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
1189 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1190 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1191 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1192 window_.get(), gfx::Point(), HTCAPTION));
1193 ASSERT_TRUE(resizer.get());
1194 // Move to an x-coordinate of 15, which should not stick.
1195 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1196 // Move to -15, should still stick to 0.
1197 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
1198 EXPECT_EQ("-15,112 320x160", window_->bounds().ToString());
1199 }
1200
1201 // Verifies window sticks to both window and work area. 1127 // Verifies window sticks to both window and work area.
1202 TEST_F(WorkspaceWindowResizerTest, StickToBothEdgeAndWindow) { 1128 TEST_F(WorkspaceWindowResizerTest, StickToBothEdgeAndWindow) {
1203 window_->SetBounds(gfx::Rect(10, 10, 20, 50)); 1129 window_->SetBounds(gfx::Rect(10, 10, 20, 50));
1204 window_->Show(); 1130 window_->Show();
1205 window2_->SetBounds(gfx::Rect(150, 160, 25, 1000)); 1131 window2_->SetBounds(gfx::Rect(150, 160, 25, 1000));
1206 window2_->Show(); 1132 window2_->Show();
1207 1133
1208 scoped_ptr<WindowResizer> resizer(CreateResizerForTest( 1134 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1209 window_.get(), gfx::Point(10, 10), HTCAPTION)); 1135 window_.get(), gfx::Point(10, 10), HTCAPTION));
1210 ASSERT_TRUE(resizer.get()); 1136 ASSERT_TRUE(resizer.get());
(...skipping 28 matching lines...) Expand all
1239 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 1), 0); 1165 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 1), 0);
1240 expected.set_y(attach_y + initial_y); 1166 expected.set_y(attach_y + initial_y);
1241 EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); 1167 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1242 1168
1243 // Moving down further should move the window. 1169 // Moving down further should move the window.
1244 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 18), 0); 1170 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 18), 0);
1245 expected.set_y(attach_y + initial_y + 18); 1171 expected.set_y(attach_y + initial_y + 18);
1246 EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); 1172 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1247 } 1173 }
1248 1174
1249 // Verifies a resize sticks when dragging TOPLEFT.
1250 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) {
1251 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1252 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1253 window_.get(), gfx::Point(), HTTOPLEFT));
1254 ASSERT_TRUE(resizer.get());
1255 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0);
1256 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
1257 }
1258
1259 // Verifies a resize sticks when dragging TOPRIGHT.
1260 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) {
1261 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1262 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1263 window_.get()));
1264 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1265 window_.get(), gfx::Point(), HTTOPRIGHT));
1266 ASSERT_TRUE(resizer.get());
1267 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20,
1268 -200 - 15), 0);
1269 EXPECT_EQ(100, window_->bounds().x());
1270 EXPECT_EQ(work_area.y(), window_->bounds().y());
1271 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1272 EXPECT_EQ(230, window_->bounds().height());
1273 }
1274
1275 // Verifies a resize snap when dragging BOTTOMRIGHT.
1276 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) {
1277 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1278 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1279 window_.get()));
1280 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1281 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1282 ASSERT_TRUE(resizer.get());
1283 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15,
1284 work_area.bottom() - 200 - 30 + 15), 0);
1285 EXPECT_EQ(100, window_->bounds().x());
1286 EXPECT_EQ(200, window_->bounds().y());
1287 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1288 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1289 }
1290
1291 // Verifies a resize snap when dragging BOTTOMLEFT.
1292 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) {
1293 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1294 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1295 window_.get()));
1296 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1297 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1298 ASSERT_TRUE(resizer.get());
1299 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100,
1300 work_area.bottom() - 200 - 30 + 15), 0);
1301 EXPECT_EQ(0, window_->bounds().x());
1302 EXPECT_EQ(200, window_->bounds().y());
1303 EXPECT_EQ(120, window_->bounds().width());
1304 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1305 }
1306
1307 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) { 1175 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
1308 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1176 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1309 scoped_ptr<WindowResizer> resizer(CreateResizerForTest( 1177 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1310 window_.get(), gfx::Point(), HTBOTTOMRIGHT)); 1178 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1311 ASSERT_TRUE(resizer.get()); 1179 ASSERT_TRUE(resizer.get());
1312 // Resize the right bottom to add 10 in width, 12 in height. 1180 // Resize the right bottom to add 10 in width, 12 in height.
1313 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN); 1181 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
1314 // Both bottom and right sides to resize to exact size requested. 1182 // Both bottom and right sides to resize to exact size requested.
1315 EXPECT_EQ("96,112 330x172", window_->bounds().ToString()); 1183 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
1316 } 1184 }
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), 1868 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
2001 gfx::Point(400, kRootHeight - 25), 1869 gfx::Point(400, kRootHeight - 25),
2002 base::TimeDelta::FromMilliseconds(10), 1870 base::TimeDelta::FromMilliseconds(10),
2003 5); 1871 5);
2004 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), 1872 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
2005 touch_resize_window_->bounds().ToString()); 1873 touch_resize_window_->bounds().ToString());
2006 } 1874 }
2007 1875
2008 } // namespace internal 1876 } // namespace internal
2009 } // namespace ash 1877 } // 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