| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash_constants.h" | 5 #include "ash/ash_constants.h" |
| 6 #include "ash/frame/custom_frame_view_ash.h" | 6 #include "ash/frame/custom_frame_view_ash.h" |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ash/test/cursor_manager_test_api.h" | 9 #include "ash/test/cursor_manager_test_api.h" |
| 10 #include "ash/wm/resize_shadow.h" | 10 #include "ash/wm/resize_shadow.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_EQ(window_->layer()->parent(), shadow_layer->parent()); | 92 EXPECT_EQ(window_->layer()->parent(), shadow_layer->parent()); |
| 93 const auto& layers = shadow_layer->parent()->children(); | 93 const auto& layers = shadow_layer->parent()->children(); |
| 94 // Make sure the shadow layer is stacked directly beneath the window | 94 // Make sure the shadow layer is stacked directly beneath the window |
| 95 // layer. | 95 // layer. |
| 96 EXPECT_EQ(*(std::find(layers.begin(), layers.end(), shadow_layer) + 1), | 96 EXPECT_EQ(*(std::find(layers.begin(), layers.end(), shadow_layer) + 1), |
| 97 window_->layer()); | 97 window_->layer()); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Returns the current cursor type. | 101 // Returns the current cursor type. |
| 102 int GetCurrentCursorType() const { | 102 ui::CursorType GetCurrentCursorType() const { |
| 103 CursorManagerTestApi test_api(ash::Shell::Get()->cursor_manager()); | 103 CursorManagerTestApi test_api(ash::Shell::Get()->cursor_manager()); |
| 104 return test_api.GetCurrentCursor().native_type(); | 104 return test_api.GetCurrentCursor().native_type(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Called for each step of a scroll sequence initiated at the bottom right | 107 // Called for each step of a scroll sequence initiated at the bottom right |
| 108 // corner of |window_|. Tests whether the resize shadow is shown. | 108 // corner of |window_|. Tests whether the resize shadow is shown. |
| 109 void ProcessBottomRightResizeGesture(ui::EventType type, | 109 void ProcessBottomRightResizeGesture(ui::EventType type, |
| 110 const gfx::Vector2dF& delta) { | 110 const gfx::Vector2dF& delta) { |
| 111 if (type == ui::ET_GESTURE_SCROLL_END) { | 111 if (type == ui::ET_GESTURE_SCROLL_END) { |
| 112 // After gesture scroll ends, there should be no resize shadow. | 112 // After gesture scroll ends, there should be no resize shadow. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Test whether the resize shadows are visible and the cursor type based on the | 128 // Test whether the resize shadows are visible and the cursor type based on the |
| 129 // mouse's position. | 129 // mouse's position. |
| 130 TEST_F(ResizeShadowAndCursorTest, MouseHover) { | 130 TEST_F(ResizeShadowAndCursorTest, MouseHover) { |
| 131 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 131 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 132 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); | 132 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); |
| 133 | 133 |
| 134 generator.MoveMouseTo(50, 50); | 134 generator.MoveMouseTo(50, 50); |
| 135 VerifyResizeShadow(false); | 135 VerifyResizeShadow(false); |
| 136 EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType()); | 136 EXPECT_EQ(ui::CursorType::kNull, GetCurrentCursorType()); |
| 137 | 137 |
| 138 generator.MoveMouseTo(gfx::Point(50, 0)); | 138 generator.MoveMouseTo(gfx::Point(50, 0)); |
| 139 VerifyResizeShadow(true); | 139 VerifyResizeShadow(true); |
| 140 EXPECT_EQ(HTTOP, ResizeShadowHitTest()); | 140 EXPECT_EQ(HTTOP, ResizeShadowHitTest()); |
| 141 EXPECT_EQ(ui::kCursorNorthResize, GetCurrentCursorType()); | 141 EXPECT_EQ(ui::CursorType::kNorthResize, GetCurrentCursorType()); |
| 142 | 142 |
| 143 generator.MoveMouseTo(50, 50); | 143 generator.MoveMouseTo(50, 50); |
| 144 VerifyResizeShadow(false); | 144 VerifyResizeShadow(false); |
| 145 EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType()); | 145 EXPECT_EQ(ui::CursorType::kNull, GetCurrentCursorType()); |
| 146 | 146 |
| 147 generator.MoveMouseTo(200, 100); | 147 generator.MoveMouseTo(200, 100); |
| 148 VerifyResizeShadow(true); | 148 VerifyResizeShadow(true); |
| 149 EXPECT_EQ(HTBOTTOMRIGHT, ResizeShadowHitTest()); | 149 EXPECT_EQ(HTBOTTOMRIGHT, ResizeShadowHitTest()); |
| 150 EXPECT_EQ(ui::kCursorSouthEastResize, GetCurrentCursorType()); | 150 EXPECT_EQ(ui::CursorType::kSouthEastResize, GetCurrentCursorType()); |
| 151 | 151 |
| 152 generator.MoveMouseTo(50, 100); | 152 generator.MoveMouseTo(50, 100); |
| 153 VerifyResizeShadow(true); | 153 VerifyResizeShadow(true); |
| 154 EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest()); | 154 EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest()); |
| 155 EXPECT_EQ(ui::kCursorSouthResize, GetCurrentCursorType()); | 155 EXPECT_EQ(ui::CursorType::kSouthResize, GetCurrentCursorType()); |
| 156 | 156 |
| 157 generator.MoveMouseTo(50, 100 + ash::kResizeOutsideBoundsSize - 1); | 157 generator.MoveMouseTo(50, 100 + ash::kResizeOutsideBoundsSize - 1); |
| 158 VerifyResizeShadow(true); | 158 VerifyResizeShadow(true); |
| 159 EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest()); | 159 EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest()); |
| 160 EXPECT_EQ(ui::kCursorSouthResize, GetCurrentCursorType()); | 160 EXPECT_EQ(ui::CursorType::kSouthResize, GetCurrentCursorType()); |
| 161 | 161 |
| 162 generator.MoveMouseTo(50, 100 + ash::kResizeOutsideBoundsSize + 10); | 162 generator.MoveMouseTo(50, 100 + ash::kResizeOutsideBoundsSize + 10); |
| 163 VerifyResizeShadow(false); | 163 VerifyResizeShadow(false); |
| 164 EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType()); | 164 EXPECT_EQ(ui::CursorType::kNull, GetCurrentCursorType()); |
| 165 | 165 |
| 166 generator.MoveMouseTo(50, 100 - ash::kResizeInsideBoundsSize); | 166 generator.MoveMouseTo(50, 100 - ash::kResizeInsideBoundsSize); |
| 167 VerifyResizeShadow(true); | 167 VerifyResizeShadow(true); |
| 168 EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest()); | 168 EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest()); |
| 169 EXPECT_EQ(ui::kCursorSouthResize, GetCurrentCursorType()); | 169 EXPECT_EQ(ui::CursorType::kSouthResize, GetCurrentCursorType()); |
| 170 | 170 |
| 171 generator.MoveMouseTo(50, 100 - ash::kResizeInsideBoundsSize - 10); | 171 generator.MoveMouseTo(50, 100 - ash::kResizeInsideBoundsSize - 10); |
| 172 VerifyResizeShadow(false); | 172 VerifyResizeShadow(false); |
| 173 EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType()); | 173 EXPECT_EQ(ui::CursorType::kNull, GetCurrentCursorType()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Test that the resize shadows stay visible and that the cursor stays the same | 176 // Test that the resize shadows stay visible and that the cursor stays the same |
| 177 // as long as a user is resizing a window. | 177 // as long as a user is resizing a window. |
| 178 TEST_F(ResizeShadowAndCursorTest, MouseDrag) { | 178 TEST_F(ResizeShadowAndCursorTest, MouseDrag) { |
| 179 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 179 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 180 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); | 180 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); |
| 181 gfx::Size initial_size(window()->bounds().size()); | 181 gfx::Size initial_size(window()->bounds().size()); |
| 182 | 182 |
| 183 generator.MoveMouseTo(200, 50); | 183 generator.MoveMouseTo(200, 50); |
| 184 generator.PressLeftButton(); | 184 generator.PressLeftButton(); |
| 185 VerifyResizeShadow(true); | 185 VerifyResizeShadow(true); |
| 186 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 186 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 187 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 187 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 188 | 188 |
| 189 generator.MoveMouseTo(210, 50); | 189 generator.MoveMouseTo(210, 50); |
| 190 VerifyResizeShadow(true); | 190 VerifyResizeShadow(true); |
| 191 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 191 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 192 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 192 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 193 | 193 |
| 194 generator.ReleaseLeftButton(); | 194 generator.ReleaseLeftButton(); |
| 195 VerifyResizeShadow(true); | 195 VerifyResizeShadow(true); |
| 196 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 196 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 197 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 197 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 198 | 198 |
| 199 gfx::Size new_size(window()->bounds().size()); | 199 gfx::Size new_size(window()->bounds().size()); |
| 200 EXPECT_NE(new_size.ToString(), initial_size.ToString()); | 200 EXPECT_NE(new_size.ToString(), initial_size.ToString()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Test that the resize shadows stay visible while resizing a window via touch. | 203 // Test that the resize shadows stay visible while resizing a window via touch. |
| 204 TEST_F(ResizeShadowAndCursorTest, Touch) { | 204 TEST_F(ResizeShadowAndCursorTest, Touch) { |
| 205 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); | 205 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); |
| 206 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 206 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 207 | 207 |
| 208 int start_x = 200 + ash::kResizeOutsideBoundsSize - 1; | 208 int start_x = 200 + ash::kResizeOutsideBoundsSize - 1; |
| 209 int start_y = 100 + ash::kResizeOutsideBoundsSize - 1; | 209 int start_y = 100 + ash::kResizeOutsideBoundsSize - 1; |
| 210 generator.GestureScrollSequenceWithCallback( | 210 generator.GestureScrollSequenceWithCallback( |
| 211 gfx::Point(start_x, start_y), gfx::Point(start_x + 50, start_y + 50), | 211 gfx::Point(start_x, start_y), gfx::Point(start_x + 50, start_y + 50), |
| 212 base::TimeDelta::FromMilliseconds(200), 3, | 212 base::TimeDelta::FromMilliseconds(200), 3, |
| 213 base::Bind(&ResizeShadowAndCursorTest::ProcessBottomRightResizeGesture, | 213 base::Bind(&ResizeShadowAndCursorTest::ProcessBottomRightResizeGesture, |
| 214 base::Unretained(this))); | 214 base::Unretained(this))); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // Test that the resize shadows are not visible and that the default cursor is | 217 // Test that the resize shadows are not visible and that the default cursor is |
| 218 // used when the window is maximized. | 218 // used when the window is maximized. |
| 219 TEST_F(ResizeShadowAndCursorTest, MaximizeRestore) { | 219 TEST_F(ResizeShadowAndCursorTest, MaximizeRestore) { |
| 220 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 220 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 221 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); | 221 ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType()); |
| 222 | 222 |
| 223 generator.MoveMouseTo(200, 50); | 223 generator.MoveMouseTo(200, 50); |
| 224 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 224 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 225 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 225 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 226 generator.MoveMouseTo(200 - ash::kResizeInsideBoundsSize, 50); | 226 generator.MoveMouseTo(200 - ash::kResizeInsideBoundsSize, 50); |
| 227 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 227 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 228 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 228 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 229 | 229 |
| 230 ash::wm::GetWindowState(window())->Maximize(); | 230 ash::wm::GetWindowState(window())->Maximize(); |
| 231 gfx::Rect bounds(window()->GetBoundsInRootWindow()); | 231 gfx::Rect bounds(window()->GetBoundsInRootWindow()); |
| 232 gfx::Point right_center(bounds.right() - 1, | 232 gfx::Point right_center(bounds.right() - 1, |
| 233 (bounds.y() + bounds.bottom()) / 2); | 233 (bounds.y() + bounds.bottom()) / 2); |
| 234 generator.MoveMouseTo(right_center); | 234 generator.MoveMouseTo(right_center); |
| 235 VerifyResizeShadow(false); | 235 VerifyResizeShadow(false); |
| 236 EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType()); | 236 EXPECT_EQ(ui::CursorType::kNull, GetCurrentCursorType()); |
| 237 | 237 |
| 238 ash::wm::GetWindowState(window())->Restore(); | 238 ash::wm::GetWindowState(window())->Restore(); |
| 239 generator.MoveMouseTo(200, 50); | 239 generator.MoveMouseTo(200, 50); |
| 240 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 240 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 241 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 241 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 242 generator.MoveMouseTo(200 - ash::kResizeInsideBoundsSize, 50); | 242 generator.MoveMouseTo(200 - ash::kResizeInsideBoundsSize, 50); |
| 243 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); | 243 EXPECT_EQ(HTRIGHT, ResizeShadowHitTest()); |
| 244 EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType()); | 244 EXPECT_EQ(ui::CursorType::kEastResize, GetCurrentCursorType()); |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace test | 247 } // namespace test |
| 248 } // namespace ash | 248 } // namespace ash |
| OLD | NEW |