| 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 "ash/wm/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 void DragFromCenterBy(aura::Window* window, int dx, int dy) { | 79 void DragFromCenterBy(aura::Window* window, int dx, int dy) { |
| 80 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); | 80 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); |
| 81 generator.DragMouseBy(dx, dy); | 81 generator.DragMouseBy(dx, dy); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { | 84 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { |
| 85 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); | 85 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); |
| 86 generator.PressMoveAndReleaseTouchBy(dx, dy); | 86 generator.PressMoveAndReleaseTouchBy(dx, dy); |
| 87 } | 87 } |
| 88 | 88 |
| 89 scoped_ptr<ToplevelWindowEventHandler> handler_; | 89 std::unique_ptr<ToplevelWindowEventHandler> handler_; |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest); | 92 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(ToplevelWindowEventHandlerTest, Caption) { | 97 TEST_F(ToplevelWindowEventHandlerTest, Caption) { |
| 98 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); | 98 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); |
| 99 gfx::Size size = w1->bounds().size(); | 99 gfx::Size size = w1->bounds().size(); |
| 100 DragFromCenterBy(w1.get(), 100, 100); | 100 DragFromCenterBy(w1.get(), 100, 100); |
| 101 // Position should have been offset by 100,100. | 101 // Position should have been offset by 100,100. |
| 102 EXPECT_EQ("100,100", w1->bounds().origin().ToString()); | 102 EXPECT_EQ("100,100", w1->bounds().origin().ToString()); |
| 103 // Size should not have. | 103 // Size should not have. |
| 104 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 104 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 105 | 105 |
| 106 TouchDragFromCenterBy(w1.get(), 100, 100); | 106 TouchDragFromCenterBy(w1.get(), 100, 100); |
| 107 // Position should have been offset by 100,100. | 107 // Position should have been offset by 100,100. |
| 108 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); | 108 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(CancelDragObserver); | 127 DISALLOW_COPY_AND_ASSIGN(CancelDragObserver); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 // Cancelling drag while starting window drag should not crash. | 132 // Cancelling drag while starting window drag should not crash. |
| 133 TEST_F(ToplevelWindowEventHandlerTest, CancelWhileDragStart) { | 133 TEST_F(ToplevelWindowEventHandlerTest, CancelWhileDragStart) { |
| 134 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); | 134 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); |
| 135 CancelDragObserver observer; | 135 CancelDragObserver observer; |
| 136 w1->AddObserver(&observer); | 136 w1->AddObserver(&observer); |
| 137 gfx::Point origin = w1->bounds().origin(); | 137 gfx::Point origin = w1->bounds().origin(); |
| 138 DragFromCenterBy(w1.get(), 100, 100); | 138 DragFromCenterBy(w1.get(), 100, 100); |
| 139 EXPECT_EQ(origin, w1->bounds().origin()); | 139 EXPECT_EQ(origin, w1->bounds().origin()); |
| 140 w1->RemoveObserver(&observer); | 140 w1->RemoveObserver(&observer); |
| 141 } | 141 } |
| 142 | 142 |
| 143 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { | 143 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { |
| 144 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); | 144 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); |
| 145 gfx::Point position = w1->bounds().origin(); | 145 gfx::Point position = w1->bounds().origin(); |
| 146 DragFromCenterBy(w1.get(), 100, 100); | 146 DragFromCenterBy(w1.get(), 100, 100); |
| 147 // Position should not have changed. | 147 // Position should not have changed. |
| 148 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 148 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 149 // Size should have increased by 100,100. | 149 // Size should have increased by 100,100. |
| 150 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); | 150 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST_F(ToplevelWindowEventHandlerTest, GrowBox) { | 153 TEST_F(ToplevelWindowEventHandlerTest, GrowBox) { |
| 154 scoped_ptr<aura::Window> w1(CreateWindow(HTGROWBOX)); | 154 std::unique_ptr<aura::Window> w1(CreateWindow(HTGROWBOX)); |
| 155 TestWindowDelegate* window_delegate = | 155 TestWindowDelegate* window_delegate = |
| 156 static_cast<TestWindowDelegate*>(w1->delegate()); | 156 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 157 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 157 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 158 | 158 |
| 159 gfx::Point position = w1->bounds().origin(); | 159 gfx::Point position = w1->bounds().origin(); |
| 160 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 160 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 161 generator.MoveMouseToCenterOf(w1.get()); | 161 generator.MoveMouseToCenterOf(w1.get()); |
| 162 generator.DragMouseBy(100, 100); | 162 generator.DragMouseBy(100, 100); |
| 163 // Position should not have changed. | 163 // Position should not have changed. |
| 164 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 164 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 165 // Size should have increased by 100,100. | 165 // Size should have increased by 100,100. |
| 166 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); | 166 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); |
| 167 | 167 |
| 168 // Shrink the wnidow by (-100, -100). | 168 // Shrink the wnidow by (-100, -100). |
| 169 generator.DragMouseBy(-100, -100); | 169 generator.DragMouseBy(-100, -100); |
| 170 // Position should not have changed. | 170 // Position should not have changed. |
| 171 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 171 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 172 // Size should have decreased by 100,100. | 172 // Size should have decreased by 100,100. |
| 173 EXPECT_EQ(gfx::Size(100, 100).ToString(), w1->bounds().size().ToString()); | 173 EXPECT_EQ(gfx::Size(100, 100).ToString(), w1->bounds().size().ToString()); |
| 174 | 174 |
| 175 // Enforce minimum size. | 175 // Enforce minimum size. |
| 176 generator.DragMouseBy(-60, -60); | 176 generator.DragMouseBy(-60, -60); |
| 177 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 177 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 178 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); | 178 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 TEST_F(ToplevelWindowEventHandlerTest, Right) { | 181 TEST_F(ToplevelWindowEventHandlerTest, Right) { |
| 182 scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); | 182 std::unique_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); |
| 183 gfx::Point position = w1->bounds().origin(); | 183 gfx::Point position = w1->bounds().origin(); |
| 184 DragFromCenterBy(w1.get(), 100, 100); | 184 DragFromCenterBy(w1.get(), 100, 100); |
| 185 // Position should not have changed. | 185 // Position should not have changed. |
| 186 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 186 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 187 // Size should have increased by 100,0. | 187 // Size should have increased by 100,0. |
| 188 EXPECT_EQ(gfx::Size(200, 100).ToString(), w1->bounds().size().ToString()); | 188 EXPECT_EQ(gfx::Size(200, 100).ToString(), w1->bounds().size().ToString()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 TEST_F(ToplevelWindowEventHandlerTest, Bottom) { | 191 TEST_F(ToplevelWindowEventHandlerTest, Bottom) { |
| 192 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOM)); | 192 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOM)); |
| 193 gfx::Point position = w1->bounds().origin(); | 193 gfx::Point position = w1->bounds().origin(); |
| 194 DragFromCenterBy(w1.get(), 100, 100); | 194 DragFromCenterBy(w1.get(), 100, 100); |
| 195 // Position should not have changed. | 195 // Position should not have changed. |
| 196 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 196 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 197 // Size should have increased by 0,100. | 197 // Size should have increased by 0,100. |
| 198 EXPECT_EQ(gfx::Size(100, 200).ToString(), w1->bounds().size().ToString()); | 198 EXPECT_EQ(gfx::Size(100, 200).ToString(), w1->bounds().size().ToString()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 TEST_F(ToplevelWindowEventHandlerTest, TopRight) { | 201 TEST_F(ToplevelWindowEventHandlerTest, TopRight) { |
| 202 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); | 202 std::unique_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); |
| 203 DragFromCenterBy(w1.get(), -50, 50); | 203 DragFromCenterBy(w1.get(), -50, 50); |
| 204 // Position should have been offset by 0,50. | 204 // Position should have been offset by 0,50. |
| 205 EXPECT_EQ(gfx::Point(0, 50).ToString(), w1->bounds().origin().ToString()); | 205 EXPECT_EQ(gfx::Point(0, 50).ToString(), w1->bounds().origin().ToString()); |
| 206 // Size should have decreased by 50,50. | 206 // Size should have decreased by 50,50. |
| 207 EXPECT_EQ(gfx::Size(50, 50).ToString(), w1->bounds().size().ToString()); | 207 EXPECT_EQ(gfx::Size(50, 50).ToString(), w1->bounds().size().ToString()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(ToplevelWindowEventHandlerTest, Top) { | 210 TEST_F(ToplevelWindowEventHandlerTest, Top) { |
| 211 scoped_ptr<aura::Window> w1(CreateWindow(HTTOP)); | 211 std::unique_ptr<aura::Window> w1(CreateWindow(HTTOP)); |
| 212 DragFromCenterBy(w1.get(), 50, 50); | 212 DragFromCenterBy(w1.get(), 50, 50); |
| 213 // Position should have been offset by 0,50. | 213 // Position should have been offset by 0,50. |
| 214 EXPECT_EQ(gfx::Point(0, 50).ToString(), w1->bounds().origin().ToString()); | 214 EXPECT_EQ(gfx::Point(0, 50).ToString(), w1->bounds().origin().ToString()); |
| 215 // Size should have decreased by 0,50. | 215 // Size should have decreased by 0,50. |
| 216 EXPECT_EQ(gfx::Size(100, 50).ToString(), w1->bounds().size().ToString()); | 216 EXPECT_EQ(gfx::Size(100, 50).ToString(), w1->bounds().size().ToString()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(ToplevelWindowEventHandlerTest, Left) { | 219 TEST_F(ToplevelWindowEventHandlerTest, Left) { |
| 220 scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT)); | 220 std::unique_ptr<aura::Window> w1(CreateWindow(HTLEFT)); |
| 221 DragFromCenterBy(w1.get(), 50, 50); | 221 DragFromCenterBy(w1.get(), 50, 50); |
| 222 // Position should have been offset by 50,0. | 222 // Position should have been offset by 50,0. |
| 223 EXPECT_EQ(gfx::Point(50, 0).ToString(), w1->bounds().origin().ToString()); | 223 EXPECT_EQ(gfx::Point(50, 0).ToString(), w1->bounds().origin().ToString()); |
| 224 // Size should have decreased by 50,0. | 224 // Size should have decreased by 50,0. |
| 225 EXPECT_EQ(gfx::Size(50, 100).ToString(), w1->bounds().size().ToString()); | 225 EXPECT_EQ(gfx::Size(50, 100).ToString(), w1->bounds().size().ToString()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_F(ToplevelWindowEventHandlerTest, BottomLeft) { | 228 TEST_F(ToplevelWindowEventHandlerTest, BottomLeft) { |
| 229 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); | 229 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); |
| 230 DragFromCenterBy(w1.get(), 50, -50); | 230 DragFromCenterBy(w1.get(), 50, -50); |
| 231 // Position should have been offset by 50,0. | 231 // Position should have been offset by 50,0. |
| 232 EXPECT_EQ(gfx::Point(50, 0).ToString(), w1->bounds().origin().ToString()); | 232 EXPECT_EQ(gfx::Point(50, 0).ToString(), w1->bounds().origin().ToString()); |
| 233 // Size should have decreased by 50,50. | 233 // Size should have decreased by 50,50. |
| 234 EXPECT_EQ(gfx::Size(50, 50).ToString(), w1->bounds().size().ToString()); | 234 EXPECT_EQ(gfx::Size(50, 50).ToString(), w1->bounds().size().ToString()); |
| 235 } | 235 } |
| 236 | 236 |
| 237 TEST_F(ToplevelWindowEventHandlerTest, TopLeft) { | 237 TEST_F(ToplevelWindowEventHandlerTest, TopLeft) { |
| 238 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); | 238 std::unique_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); |
| 239 DragFromCenterBy(w1.get(), 50, 50); | 239 DragFromCenterBy(w1.get(), 50, 50); |
| 240 // Position should have been offset by 50,50. | 240 // Position should have been offset by 50,50. |
| 241 EXPECT_EQ(gfx::Point(50, 50).ToString(), w1->bounds().origin().ToString()); | 241 EXPECT_EQ(gfx::Point(50, 50).ToString(), w1->bounds().origin().ToString()); |
| 242 // Size should have decreased by 50,50. | 242 // Size should have decreased by 50,50. |
| 243 EXPECT_EQ(gfx::Size(50, 50).ToString(), w1->bounds().size().ToString()); | 243 EXPECT_EQ(gfx::Size(50, 50).ToString(), w1->bounds().size().ToString()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST_F(ToplevelWindowEventHandlerTest, Client) { | 246 TEST_F(ToplevelWindowEventHandlerTest, Client) { |
| 247 scoped_ptr<aura::Window> w1(CreateWindow(HTCLIENT)); | 247 std::unique_ptr<aura::Window> w1(CreateWindow(HTCLIENT)); |
| 248 gfx::Rect bounds = w1->bounds(); | 248 gfx::Rect bounds = w1->bounds(); |
| 249 DragFromCenterBy(w1.get(), 100, 100); | 249 DragFromCenterBy(w1.get(), 100, 100); |
| 250 // Neither position nor size should have changed. | 250 // Neither position nor size should have changed. |
| 251 EXPECT_EQ(bounds.ToString(), w1->bounds().ToString()); | 251 EXPECT_EQ(bounds.ToString(), w1->bounds().ToString()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(ToplevelWindowEventHandlerTest, LeftPastMinimum) { | 254 TEST_F(ToplevelWindowEventHandlerTest, LeftPastMinimum) { |
| 255 scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT)); | 255 std::unique_ptr<aura::Window> w1(CreateWindow(HTLEFT)); |
| 256 TestWindowDelegate* window_delegate = | 256 TestWindowDelegate* window_delegate = |
| 257 static_cast<TestWindowDelegate*>(w1->delegate()); | 257 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 258 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 258 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 259 | 259 |
| 260 // Simulate a large left-to-right drag. Window width should be clamped to | 260 // Simulate a large left-to-right drag. Window width should be clamped to |
| 261 // minimum and position change should be limited as well. | 261 // minimum and position change should be limited as well. |
| 262 DragFromCenterBy(w1.get(), 333, 0); | 262 DragFromCenterBy(w1.get(), 333, 0); |
| 263 EXPECT_EQ(gfx::Point(60, 0).ToString(), w1->bounds().origin().ToString()); | 263 EXPECT_EQ(gfx::Point(60, 0).ToString(), w1->bounds().origin().ToString()); |
| 264 EXPECT_EQ(gfx::Size(40, 100).ToString(), w1->bounds().size().ToString()); | 264 EXPECT_EQ(gfx::Size(40, 100).ToString(), w1->bounds().size().ToString()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_F(ToplevelWindowEventHandlerTest, RightPastMinimum) { | 267 TEST_F(ToplevelWindowEventHandlerTest, RightPastMinimum) { |
| 268 scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); | 268 std::unique_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); |
| 269 TestWindowDelegate* window_delegate = | 269 TestWindowDelegate* window_delegate = |
| 270 static_cast<TestWindowDelegate*>(w1->delegate()); | 270 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 271 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 271 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 272 gfx::Point position = w1->bounds().origin(); | 272 gfx::Point position = w1->bounds().origin(); |
| 273 | 273 |
| 274 // Simulate a large right-to-left drag. Window width should be clamped to | 274 // Simulate a large right-to-left drag. Window width should be clamped to |
| 275 // minimum and position should not change. | 275 // minimum and position should not change. |
| 276 DragFromCenterBy(w1.get(), -333, 0); | 276 DragFromCenterBy(w1.get(), -333, 0); |
| 277 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 277 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 278 EXPECT_EQ(gfx::Size(40, 100).ToString(), w1->bounds().size().ToString()); | 278 EXPECT_EQ(gfx::Size(40, 100).ToString(), w1->bounds().size().ToString()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST_F(ToplevelWindowEventHandlerTest, TopLeftPastMinimum) { | 281 TEST_F(ToplevelWindowEventHandlerTest, TopLeftPastMinimum) { |
| 282 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); | 282 std::unique_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); |
| 283 TestWindowDelegate* window_delegate = | 283 TestWindowDelegate* window_delegate = |
| 284 static_cast<TestWindowDelegate*>(w1->delegate()); | 284 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 285 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 285 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 286 | 286 |
| 287 // Simulate a large top-left to bottom-right drag. Window width should be | 287 // Simulate a large top-left to bottom-right drag. Window width should be |
| 288 // clamped to minimum and position should be limited. | 288 // clamped to minimum and position should be limited. |
| 289 DragFromCenterBy(w1.get(), 333, 444); | 289 DragFromCenterBy(w1.get(), 333, 444); |
| 290 EXPECT_EQ(gfx::Point(60, 60).ToString(), w1->bounds().origin().ToString()); | 290 EXPECT_EQ(gfx::Point(60, 60).ToString(), w1->bounds().origin().ToString()); |
| 291 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); | 291 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 TEST_F(ToplevelWindowEventHandlerTest, TopRightPastMinimum) { | 294 TEST_F(ToplevelWindowEventHandlerTest, TopRightPastMinimum) { |
| 295 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); | 295 std::unique_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); |
| 296 TestWindowDelegate* window_delegate = | 296 TestWindowDelegate* window_delegate = |
| 297 static_cast<TestWindowDelegate*>(w1->delegate()); | 297 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 298 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 298 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 299 | 299 |
| 300 // Simulate a large top-right to bottom-left drag. Window size should be | 300 // Simulate a large top-right to bottom-left drag. Window size should be |
| 301 // clamped to minimum, x position should not change, and y position should | 301 // clamped to minimum, x position should not change, and y position should |
| 302 // be clamped. | 302 // be clamped. |
| 303 DragFromCenterBy(w1.get(), -333, 444); | 303 DragFromCenterBy(w1.get(), -333, 444); |
| 304 EXPECT_EQ(gfx::Point(0, 60).ToString(), w1->bounds().origin().ToString()); | 304 EXPECT_EQ(gfx::Point(0, 60).ToString(), w1->bounds().origin().ToString()); |
| 305 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); | 305 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftPastMinimum) { | 308 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftPastMinimum) { |
| 309 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); | 309 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); |
| 310 TestWindowDelegate* window_delegate = | 310 TestWindowDelegate* window_delegate = |
| 311 static_cast<TestWindowDelegate*>(w1->delegate()); | 311 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 312 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 312 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 313 | 313 |
| 314 // Simulate a large bottom-left to top-right drag. Window size should be | 314 // Simulate a large bottom-left to top-right drag. Window size should be |
| 315 // clamped to minimum, x position should be clamped, and y position should | 315 // clamped to minimum, x position should be clamped, and y position should |
| 316 // not change. | 316 // not change. |
| 317 DragFromCenterBy(w1.get(), 333, -444); | 317 DragFromCenterBy(w1.get(), 333, -444); |
| 318 EXPECT_EQ(gfx::Point(60, 0).ToString(), w1->bounds().origin().ToString()); | 318 EXPECT_EQ(gfx::Point(60, 0).ToString(), w1->bounds().origin().ToString()); |
| 319 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); | 319 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 TEST_F(ToplevelWindowEventHandlerTest, BottomRightPastMinimum) { | 322 TEST_F(ToplevelWindowEventHandlerTest, BottomRightPastMinimum) { |
| 323 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); | 323 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); |
| 324 TestWindowDelegate* window_delegate = | 324 TestWindowDelegate* window_delegate = |
| 325 static_cast<TestWindowDelegate*>(w1->delegate()); | 325 static_cast<TestWindowDelegate*>(w1->delegate()); |
| 326 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 326 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
| 327 gfx::Point position = w1->bounds().origin(); | 327 gfx::Point position = w1->bounds().origin(); |
| 328 | 328 |
| 329 // Simulate a large bottom-right to top-left drag. Window size should be | 329 // Simulate a large bottom-right to top-left drag. Window size should be |
| 330 // clamped to minimum and position should not change. | 330 // clamped to minimum and position should not change. |
| 331 DragFromCenterBy(w1.get(), -333, -444); | 331 DragFromCenterBy(w1.get(), -333, -444); |
| 332 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 332 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 333 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); | 333 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_F(ToplevelWindowEventHandlerTest, BottomRightWorkArea) { | 336 TEST_F(ToplevelWindowEventHandlerTest, BottomRightWorkArea) { |
| 337 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); | 337 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); |
| 338 gfx::Rect work_area = gfx::Screen::GetScreen() | 338 gfx::Rect work_area = gfx::Screen::GetScreen() |
| 339 ->GetDisplayNearestWindow(target.get()) | 339 ->GetDisplayNearestWindow(target.get()) |
| 340 .work_area(); | 340 .work_area(); |
| 341 gfx::Point position = target->bounds().origin(); | 341 gfx::Point position = target->bounds().origin(); |
| 342 // Drag further than work_area bottom. | 342 // Drag further than work_area bottom. |
| 343 DragFromCenterBy(target.get(), 100, work_area.height()); | 343 DragFromCenterBy(target.get(), 100, work_area.height()); |
| 344 // Position should not have changed. | 344 // Position should not have changed. |
| 345 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); | 345 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); |
| 346 // Size should have increased by 100, work_area.height() - target->bounds.y() | 346 // Size should have increased by 100, work_area.height() - target->bounds.y() |
| 347 EXPECT_EQ( | 347 EXPECT_EQ( |
| 348 gfx::Size(200, work_area.height() - target->bounds().y()).ToString(), | 348 gfx::Size(200, work_area.height() - target->bounds().y()).ToString(), |
| 349 target->bounds().size().ToString()); | 349 target->bounds().size().ToString()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftWorkArea) { | 352 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftWorkArea) { |
| 353 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT)); | 353 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT)); |
| 354 gfx::Rect work_area = gfx::Screen::GetScreen() | 354 gfx::Rect work_area = gfx::Screen::GetScreen() |
| 355 ->GetDisplayNearestWindow(target.get()) | 355 ->GetDisplayNearestWindow(target.get()) |
| 356 .work_area(); | 356 .work_area(); |
| 357 gfx::Point position = target->bounds().origin(); | 357 gfx::Point position = target->bounds().origin(); |
| 358 // Drag further than work_area bottom. | 358 // Drag further than work_area bottom. |
| 359 DragFromCenterBy(target.get(), -30, work_area.height()); | 359 DragFromCenterBy(target.get(), -30, work_area.height()); |
| 360 // origin is now at 70, 100. | 360 // origin is now at 70, 100. |
| 361 EXPECT_EQ(position.x() - 30, target->bounds().x()); | 361 EXPECT_EQ(position.x() - 30, target->bounds().x()); |
| 362 EXPECT_EQ(position.y(), target->bounds().y()); | 362 EXPECT_EQ(position.y(), target->bounds().y()); |
| 363 // Size should have increased by 30, work_area.height() - target->bounds.y() | 363 // Size should have increased by 30, work_area.height() - target->bounds.y() |
| 364 EXPECT_EQ( | 364 EXPECT_EQ( |
| 365 gfx::Size(130, work_area.height() - target->bounds().y()).ToString(), | 365 gfx::Size(130, work_area.height() - target->bounds().y()).ToString(), |
| 366 target->bounds().size().ToString()); | 366 target->bounds().size().ToString()); |
| 367 } | 367 } |
| 368 | 368 |
| 369 TEST_F(ToplevelWindowEventHandlerTest, BottomWorkArea) { | 369 TEST_F(ToplevelWindowEventHandlerTest, BottomWorkArea) { |
| 370 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOM)); | 370 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOM)); |
| 371 gfx::Rect work_area = gfx::Screen::GetScreen() | 371 gfx::Rect work_area = gfx::Screen::GetScreen() |
| 372 ->GetDisplayNearestWindow(target.get()) | 372 ->GetDisplayNearestWindow(target.get()) |
| 373 .work_area(); | 373 .work_area(); |
| 374 gfx::Point position = target->bounds().origin(); | 374 gfx::Point position = target->bounds().origin(); |
| 375 // Drag further than work_area bottom. | 375 // Drag further than work_area bottom. |
| 376 DragFromCenterBy(target.get(), 0, work_area.height()); | 376 DragFromCenterBy(target.get(), 0, work_area.height()); |
| 377 // Position should not have changed. | 377 // Position should not have changed. |
| 378 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); | 378 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); |
| 379 // Size should have increased by 0, work_area.height() - target->bounds.y() | 379 // Size should have increased by 0, work_area.height() - target->bounds.y() |
| 380 EXPECT_EQ( | 380 EXPECT_EQ( |
| 381 gfx::Size(100, work_area.height() - target->bounds().y()).ToString(), | 381 gfx::Size(100, work_area.height() - target->bounds().y()).ToString(), |
| 382 target->bounds().size().ToString()); | 382 target->bounds().size().ToString()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 TEST_F(ToplevelWindowEventHandlerTest, DontDragIfModalChild) { | 385 TEST_F(ToplevelWindowEventHandlerTest, DontDragIfModalChild) { |
| 386 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); | 386 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); |
| 387 scoped_ptr<aura::Window> w2(CreateWindow(HTCAPTION)); | 387 std::unique_ptr<aura::Window> w2(CreateWindow(HTCAPTION)); |
| 388 w2->SetBounds(gfx::Rect(100, 0, 100, 100)); | 388 w2->SetBounds(gfx::Rect(100, 0, 100, 100)); |
| 389 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 389 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 390 ::wm::AddTransientChild(w1.get(), w2.get()); | 390 ::wm::AddTransientChild(w1.get(), w2.get()); |
| 391 gfx::Size size = w1->bounds().size(); | 391 gfx::Size size = w1->bounds().size(); |
| 392 | 392 |
| 393 // Attempt to drag w1, position and size should not change because w1 has a | 393 // Attempt to drag w1, position and size should not change because w1 has a |
| 394 // modal child. | 394 // modal child. |
| 395 DragFromCenterBy(w1.get(), 100, 100); | 395 DragFromCenterBy(w1.get(), 100, 100); |
| 396 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); | 396 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); |
| 397 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 397 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 398 | 398 |
| 399 TouchDragFromCenterBy(w1.get(), 100, 100); | 399 TouchDragFromCenterBy(w1.get(), 100, 100); |
| 400 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); | 400 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); |
| 401 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 401 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 // Verifies we don't let windows drag to a -y location. | 404 // Verifies we don't let windows drag to a -y location. |
| 405 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) { | 405 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) { |
| 406 scoped_ptr<aura::Window> target(CreateWindow(HTTOP)); | 406 std::unique_ptr<aura::Window> target(CreateWindow(HTTOP)); |
| 407 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 407 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 408 target.get()); | 408 target.get()); |
| 409 generator.MoveMouseTo(0, 5); | 409 generator.MoveMouseTo(0, 5); |
| 410 generator.DragMouseBy(0, -5); | 410 generator.DragMouseBy(0, -5); |
| 411 // The y location and height should not have changed. | 411 // The y location and height should not have changed. |
| 412 EXPECT_EQ(0, target->bounds().y()); | 412 EXPECT_EQ(0, target->bounds().y()); |
| 413 EXPECT_EQ(100, target->bounds().height()); | 413 EXPECT_EQ(100, target->bounds().height()); |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Verifies we don't let windows go bigger than the display width. | 416 // Verifies we don't let windows go bigger than the display width. |
| 417 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) { | 417 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) { |
| 418 scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT)); | 418 std::unique_ptr<aura::Window> target(CreateWindow(HTRIGHT)); |
| 419 gfx::Rect work_area = | 419 gfx::Rect work_area = |
| 420 gfx::Screen::GetScreen()->GetDisplayNearestWindow(target.get()).bounds(); | 420 gfx::Screen::GetScreen()->GetDisplayNearestWindow(target.get()).bounds(); |
| 421 DragFromCenterBy(target.get(), work_area.width() * 2, 0); | 421 DragFromCenterBy(target.get(), work_area.width() * 2, 0); |
| 422 // The y location and height should not have changed. | 422 // The y location and height should not have changed. |
| 423 EXPECT_EQ(work_area.width(), target->bounds().width()); | 423 EXPECT_EQ(work_area.width(), target->bounds().width()); |
| 424 } | 424 } |
| 425 | 425 |
| 426 // Verifies that touch-gestures drag the window correctly. | 426 // Verifies that touch-gestures drag the window correctly. |
| 427 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { | 427 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { |
| 428 scoped_ptr<aura::Window> target( | 428 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( |
| 429 CreateTestWindowInShellWithDelegate( | 429 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); |
| 430 new TestWindowDelegate(HTCAPTION), | |
| 431 0, | |
| 432 gfx::Rect(0, 0, 100, 100))); | |
| 433 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 430 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 434 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 431 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 435 target.get()); | 432 target.get()); |
| 436 gfx::Rect old_bounds = target->bounds(); | 433 gfx::Rect old_bounds = target->bounds(); |
| 437 gfx::Point location(5, 5); | 434 gfx::Point location(5, 5); |
| 438 target->SetProperty(aura::client::kCanMaximizeKey, true); | 435 target->SetProperty(aura::client::kCanMaximizeKey, true); |
| 439 | 436 |
| 440 gfx::Point end = location; | 437 gfx::Point end = location; |
| 441 | 438 |
| 442 // Snap right; | 439 // Snap right; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); | 491 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); |
| 495 EXPECT_TRUE(window_state->IsMinimized()); | 492 EXPECT_TRUE(window_state->IsMinimized()); |
| 496 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); | 493 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); |
| 497 EXPECT_EQ(old_bounds.ToString(), | 494 EXPECT_EQ(old_bounds.ToString(), |
| 498 window_state->GetRestoreBoundsInScreen().ToString()); | 495 window_state->GetRestoreBoundsInScreen().ToString()); |
| 499 } | 496 } |
| 500 | 497 |
| 501 // Tests that a gesture cannot minimize an unminimizeable window. | 498 // Tests that a gesture cannot minimize an unminimizeable window. |
| 502 TEST_F(ToplevelWindowEventHandlerTest, | 499 TEST_F(ToplevelWindowEventHandlerTest, |
| 503 GestureAttemptMinimizeUnminimizeableWindow) { | 500 GestureAttemptMinimizeUnminimizeableWindow) { |
| 504 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 501 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 505 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 502 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 506 target.get()); | 503 target.get()); |
| 507 gfx::Rect old_bounds = target->bounds(); | 504 gfx::Rect old_bounds = target->bounds(); |
| 508 gfx::Point location(5, 5); | 505 gfx::Point location(5, 5); |
| 509 target->SetProperty(aura::client::kCanMaximizeKey, true); | 506 target->SetProperty(aura::client::kCanMaximizeKey, true); |
| 510 target->SetProperty(aura::client::kCanMinimizeKey, false); | 507 target->SetProperty(aura::client::kCanMinimizeKey, false); |
| 511 | 508 |
| 512 gfx::Point end = location; | 509 gfx::Point end = location; |
| 513 end.Offset(0, 100); | 510 end.Offset(0, 100); |
| 514 generator.GestureScrollSequence(location, end, | 511 generator.GestureScrollSequence(location, end, |
| 515 base::TimeDelta::FromMilliseconds(5), | 512 base::TimeDelta::FromMilliseconds(5), |
| 516 10); | 513 10); |
| 517 RunAllPendingInMessageLoop(); | 514 RunAllPendingInMessageLoop(); |
| 518 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); | 515 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); |
| 519 } | 516 } |
| 520 | 517 |
| 521 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { | 518 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { |
| 522 scoped_ptr<aura::Window> window( | 519 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
| 523 CreateTestWindowInShellWithDelegate( | 520 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(10, 20, 30, 40))); |
| 524 new TestWindowDelegate(HTCAPTION), | |
| 525 0, | |
| 526 gfx::Rect(10, 20, 30, 40))); | |
| 527 window->Show(); | 521 window->Show(); |
| 528 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 522 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 529 window_state->Activate(); | 523 window_state->Activate(); |
| 530 | 524 |
| 531 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 525 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 532 window.get()); | 526 window.get()); |
| 533 gfx::Rect old_bounds = window->bounds(); | 527 gfx::Rect old_bounds = window->bounds(); |
| 534 gfx::Point location, end; | 528 gfx::Point location, end; |
| 535 end = location = window->GetBoundsInRootWindow().CenterPoint(); | 529 end = location = window->GetBoundsInRootWindow().CenterPoint(); |
| 536 end.Offset(0, 100); | 530 end.Offset(0, 100); |
| 537 generator.GestureScrollSequence(location, end, | 531 generator.GestureScrollSequence(location, end, |
| 538 base::TimeDelta::FromMilliseconds(5), | 532 base::TimeDelta::FromMilliseconds(5), |
| 539 10); | 533 10); |
| 540 RunAllPendingInMessageLoop(); | 534 RunAllPendingInMessageLoop(); |
| 541 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); | 535 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); |
| 542 EXPECT_TRUE(window_state->IsMinimized()); | 536 EXPECT_TRUE(window_state->IsMinimized()); |
| 543 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); | 537 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); |
| 544 EXPECT_EQ(old_bounds.ToString(), | 538 EXPECT_EQ(old_bounds.ToString(), |
| 545 window_state->GetRestoreBoundsInScreen().ToString()); | 539 window_state->GetRestoreBoundsInScreen().ToString()); |
| 546 } | 540 } |
| 547 | 541 |
| 548 // Tests that an unresizable window cannot be dragged or snapped using gestures. | 542 // Tests that an unresizable window cannot be dragged or snapped using gestures. |
| 549 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { | 543 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { |
| 550 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 544 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 551 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 545 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 552 | 546 |
| 553 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 547 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 554 target.get()); | 548 target.get()); |
| 555 gfx::Rect old_bounds = target->bounds(); | 549 gfx::Rect old_bounds = target->bounds(); |
| 556 gfx::Point location(5, 5); | 550 gfx::Point location(5, 5); |
| 557 | 551 |
| 558 target->SetProperty(aura::client::kCanResizeKey, false); | 552 target->SetProperty(aura::client::kCanResizeKey, false); |
| 559 | 553 |
| 560 gfx::Point end = location; | 554 gfx::Point end = location; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 588 expected_bounds = old_bounds; | 582 expected_bounds = old_bounds; |
| 589 expected_bounds.Offset(gfx::Vector2d(-100, 0)); | 583 expected_bounds.Offset(gfx::Vector2d(-100, 0)); |
| 590 EXPECT_EQ(expected_bounds.ToString(), target->bounds().ToString()); | 584 EXPECT_EQ(expected_bounds.ToString(), target->bounds().ToString()); |
| 591 | 585 |
| 592 // Verify that the window did not snap left. | 586 // Verify that the window did not snap left. |
| 593 EXPECT_TRUE(window_state->IsNormalStateType()); | 587 EXPECT_TRUE(window_state->IsNormalStateType()); |
| 594 } | 588 } |
| 595 | 589 |
| 596 // Tests that dragging multiple windows at the same time is not allowed. | 590 // Tests that dragging multiple windows at the same time is not allowed. |
| 597 TEST_F(ToplevelWindowEventHandlerTest, GestureDragMultipleWindows) { | 591 TEST_F(ToplevelWindowEventHandlerTest, GestureDragMultipleWindows) { |
| 598 scoped_ptr<aura::Window> target( | 592 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( |
| 599 CreateTestWindowInShellWithDelegate( | 593 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); |
| 600 new TestWindowDelegate(HTCAPTION), | 594 std::unique_ptr<aura::Window> notmoved(CreateTestWindowInShellWithDelegate( |
| 601 0, | 595 new TestWindowDelegate(HTCAPTION), 1, gfx::Rect(100, 0, 100, 100))); |
| 602 gfx::Rect(0, 0, 100, 100))); | |
| 603 scoped_ptr<aura::Window> notmoved( | |
| 604 CreateTestWindowInShellWithDelegate( | |
| 605 new TestWindowDelegate(HTCAPTION), | |
| 606 1, gfx::Rect(100, 0, 100, 100))); | |
| 607 | 596 |
| 608 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 597 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 609 target.get()); | 598 target.get()); |
| 610 gfx::Rect old_bounds = target->bounds(); | 599 gfx::Rect old_bounds = target->bounds(); |
| 611 gfx::Point location(5, 5); | 600 gfx::Point location(5, 5); |
| 612 target->SetProperty(aura::client::kCanMaximizeKey, true); | 601 target->SetProperty(aura::client::kCanMaximizeKey, true); |
| 613 | 602 |
| 614 // Send some touch events to start dragging |target|. | 603 // Send some touch events to start dragging |target|. |
| 615 generator.MoveTouch(location); | 604 generator.MoveTouch(location); |
| 616 generator.PressTouch(); | 605 generator.PressTouch(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 631 } | 620 } |
| 632 | 621 |
| 633 // Verifies pressing escape resets the bounds to the original bounds. | 622 // Verifies pressing escape resets the bounds to the original bounds. |
| 634 // Disabled crbug.com/166219. | 623 // Disabled crbug.com/166219. |
| 635 #if defined(OS_WIN) | 624 #if defined(OS_WIN) |
| 636 #define MAYBE_EscapeReverts DISABLED_EscapeReverts | 625 #define MAYBE_EscapeReverts DISABLED_EscapeReverts |
| 637 #else | 626 #else |
| 638 #define MAYBE_EscapeReverts EscapeReverts | 627 #define MAYBE_EscapeReverts EscapeReverts |
| 639 #endif | 628 #endif |
| 640 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) { | 629 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) { |
| 641 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); | 630 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); |
| 642 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 631 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 643 target.get()); | 632 target.get()); |
| 644 generator.PressLeftButton(); | 633 generator.PressLeftButton(); |
| 645 generator.MoveMouseBy(10, 11); | 634 generator.MoveMouseBy(10, 11); |
| 646 | 635 |
| 647 // Execute any scheduled draws so that pending mouse events are processed. | 636 // Execute any scheduled draws so that pending mouse events are processed. |
| 648 RunAllPendingInMessageLoop(); | 637 RunAllPendingInMessageLoop(); |
| 649 | 638 |
| 650 EXPECT_EQ("0,0 110x111", target->bounds().ToString()); | 639 EXPECT_EQ("0,0 110x111", target->bounds().ToString()); |
| 651 generator.PressKey(ui::VKEY_ESCAPE, 0); | 640 generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 652 generator.ReleaseKey(ui::VKEY_ESCAPE, 0); | 641 generator.ReleaseKey(ui::VKEY_ESCAPE, 0); |
| 653 EXPECT_EQ("0,0 100x100", target->bounds().ToString()); | 642 EXPECT_EQ("0,0 100x100", target->bounds().ToString()); |
| 654 } | 643 } |
| 655 | 644 |
| 656 // Verifies window minimization/maximization completes drag. | 645 // Verifies window minimization/maximization completes drag. |
| 657 // Disabled crbug.com/166219. | 646 // Disabled crbug.com/166219. |
| 658 #if defined(OS_WIN) | 647 #if defined(OS_WIN) |
| 659 #define MAYBE_MinimizeMaximizeCompletes DISABLED_MinimizeMaximizeCompletes | 648 #define MAYBE_MinimizeMaximizeCompletes DISABLED_MinimizeMaximizeCompletes |
| 660 #else | 649 #else |
| 661 #define MAYBE_MinimizeMaximizeCompletes MinimizeMaximizeCompletes | 650 #define MAYBE_MinimizeMaximizeCompletes MinimizeMaximizeCompletes |
| 662 #endif | 651 #endif |
| 663 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_MinimizeMaximizeCompletes) { | 652 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_MinimizeMaximizeCompletes) { |
| 664 // Once window is minimized, window dragging completes. | 653 // Once window is minimized, window dragging completes. |
| 665 { | 654 { |
| 666 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 655 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 667 target->Focus(); | 656 target->Focus(); |
| 668 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 657 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 669 target.get()); | 658 target.get()); |
| 670 generator.PressLeftButton(); | 659 generator.PressLeftButton(); |
| 671 generator.MoveMouseBy(10, 11); | 660 generator.MoveMouseBy(10, 11); |
| 672 RunAllPendingInMessageLoop(); | 661 RunAllPendingInMessageLoop(); |
| 673 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 662 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 674 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 663 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 675 window_state->Minimize(); | 664 window_state->Minimize(); |
| 676 window_state->Restore(); | 665 window_state->Restore(); |
| 677 | 666 |
| 678 generator.PressLeftButton(); | 667 generator.PressLeftButton(); |
| 679 generator.MoveMouseBy(10, 11); | 668 generator.MoveMouseBy(10, 11); |
| 680 RunAllPendingInMessageLoop(); | 669 RunAllPendingInMessageLoop(); |
| 681 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 670 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 682 } | 671 } |
| 683 | 672 |
| 684 // Once window is maximized, window dragging completes. | 673 // Once window is maximized, window dragging completes. |
| 685 { | 674 { |
| 686 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 675 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 687 target->Focus(); | 676 target->Focus(); |
| 688 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 677 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 689 target.get()); | 678 target.get()); |
| 690 generator.PressLeftButton(); | 679 generator.PressLeftButton(); |
| 691 generator.MoveMouseBy(10, 11); | 680 generator.MoveMouseBy(10, 11); |
| 692 RunAllPendingInMessageLoop(); | 681 RunAllPendingInMessageLoop(); |
| 693 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 682 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 694 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 683 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 695 window_state->Maximize(); | 684 window_state->Maximize(); |
| 696 window_state->Restore(); | 685 window_state->Restore(); |
| 697 | 686 |
| 698 generator.PressLeftButton(); | 687 generator.PressLeftButton(); |
| 699 generator.MoveMouseBy(10, 11); | 688 generator.MoveMouseBy(10, 11); |
| 700 RunAllPendingInMessageLoop(); | 689 RunAllPendingInMessageLoop(); |
| 701 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 690 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 702 } | 691 } |
| 703 } | 692 } |
| 704 | 693 |
| 705 // Verifies that a drag cannot be started via | 694 // Verifies that a drag cannot be started via |
| 706 // aura::client::WindowMoveClient::RunMoveLoop() while another drag is already | 695 // aura::client::WindowMoveClient::RunMoveLoop() while another drag is already |
| 707 // in progress. | 696 // in progress. |
| 708 TEST_F(ToplevelWindowEventHandlerTest, RunMoveLoopFailsDuringInProgressDrag) { | 697 TEST_F(ToplevelWindowEventHandlerTest, RunMoveLoopFailsDuringInProgressDrag) { |
| 709 scoped_ptr<aura::Window> window1(CreateWindow(HTCAPTION)); | 698 std::unique_ptr<aura::Window> window1(CreateWindow(HTCAPTION)); |
| 710 EXPECT_EQ("0,0 100x100", window1->bounds().ToString()); | 699 EXPECT_EQ("0,0 100x100", window1->bounds().ToString()); |
| 711 scoped_ptr<aura::Window> window2(CreateWindow(HTCAPTION)); | 700 std::unique_ptr<aura::Window> window2(CreateWindow(HTCAPTION)); |
| 712 | 701 |
| 713 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 702 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 714 window1.get()); | 703 window1.get()); |
| 715 window1->Focus(); | 704 window1->Focus(); |
| 716 generator.PressLeftButton(); | 705 generator.PressLeftButton(); |
| 717 generator.MoveMouseBy(10, 11); | 706 generator.MoveMouseBy(10, 11); |
| 718 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); | 707 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); |
| 719 | 708 |
| 720 aura::client::WindowMoveClient* move_client = | 709 aura::client::WindowMoveClient* move_client = |
| 721 aura::client::GetWindowMoveClient(window2->GetRootWindow()); | 710 aura::client::GetWindowMoveClient(window2->GetRootWindow()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 733 aura::Window* window) { | 722 aura::Window* window) { |
| 734 generator->ReleaseLeftButton(); | 723 generator->ReleaseLeftButton(); |
| 735 window->ReleaseCapture(); | 724 window->ReleaseCapture(); |
| 736 } | 725 } |
| 737 | 726 |
| 738 } // namespace | 727 } // namespace |
| 739 | 728 |
| 740 // Test that a drag is successful even if ET_MOUSE_CAPTURE_CHANGED is sent | 729 // Test that a drag is successful even if ET_MOUSE_CAPTURE_CHANGED is sent |
| 741 // immediately after the mouse release. views::Widget has this behavior. | 730 // immediately after the mouse release. views::Widget has this behavior. |
| 742 TEST_F(ToplevelWindowEventHandlerTest, CaptureLossAfterMouseRelease) { | 731 TEST_F(ToplevelWindowEventHandlerTest, CaptureLossAfterMouseRelease) { |
| 743 scoped_ptr<aura::Window> window(CreateWindow(HTNOWHERE)); | 732 std::unique_ptr<aura::Window> window(CreateWindow(HTNOWHERE)); |
| 744 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 733 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 745 window.get()); | 734 window.get()); |
| 746 generator.PressLeftButton(); | 735 generator.PressLeftButton(); |
| 747 window->SetCapture(); | 736 window->SetCapture(); |
| 748 | 737 |
| 749 aura::client::WindowMoveClient* move_client = | 738 aura::client::WindowMoveClient* move_client = |
| 750 aura::client::GetWindowMoveClient(window->GetRootWindow()); | 739 aura::client::GetWindowMoveClient(window->GetRootWindow()); |
| 751 base::ThreadTaskRunnerHandle::Get()->PostTask( | 740 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 752 FROM_HERE, | 741 FROM_HERE, |
| 753 base::Bind(&SendMouseReleaseAndReleaseCapture, | 742 base::Bind(&SendMouseReleaseAndReleaseCapture, |
| 754 base::Unretained(&generator), base::Unretained(window.get()))); | 743 base::Unretained(&generator), base::Unretained(window.get()))); |
| 755 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 744 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 756 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 745 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
| 757 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 746 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 758 } | 747 } |
| 759 | 748 |
| 760 namespace { | 749 namespace { |
| 761 | 750 |
| 762 // Checks that |window| has capture and releases capture. | 751 // Checks that |window| has capture and releases capture. |
| 763 void CheckHasCaptureAndReleaseCapture(aura::Window* window) { | 752 void CheckHasCaptureAndReleaseCapture(aura::Window* window) { |
| 764 ASSERT_TRUE(window->HasCapture()); | 753 ASSERT_TRUE(window->HasCapture()); |
| 765 window->ReleaseCapture(); | 754 window->ReleaseCapture(); |
| 766 } | 755 } |
| 767 | 756 |
| 768 } // namespace | 757 } // namespace |
| 769 | 758 |
| 770 // Test that releasing capture completes an in-progress gesture drag. | 759 // Test that releasing capture completes an in-progress gesture drag. |
| 771 TEST_F(ToplevelWindowEventHandlerTest, GestureDragCaptureLoss) { | 760 TEST_F(ToplevelWindowEventHandlerTest, GestureDragCaptureLoss) { |
| 772 scoped_ptr<aura::Window> window(CreateWindow(HTNOWHERE)); | 761 std::unique_ptr<aura::Window> window(CreateWindow(HTNOWHERE)); |
| 773 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 762 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 774 window.get()); | 763 window.get()); |
| 775 | 764 |
| 776 aura::client::WindowMoveClient* move_client = | 765 aura::client::WindowMoveClient* move_client = |
| 777 aura::client::GetWindowMoveClient(window->GetRootWindow()); | 766 aura::client::GetWindowMoveClient(window->GetRootWindow()); |
| 778 base::ThreadTaskRunnerHandle::Get()->PostTask( | 767 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 779 FROM_HERE, base::Bind(&CheckHasCaptureAndReleaseCapture, | 768 FROM_HERE, base::Bind(&CheckHasCaptureAndReleaseCapture, |
| 780 base::Unretained(window.get()))); | 769 base::Unretained(window.get()))); |
| 781 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 770 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 782 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 771 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
| 783 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); | 772 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); |
| 784 } | 773 } |
| 785 | 774 |
| 786 // Showing the resize shadows when the mouse is over the window edges is tested | 775 // Showing the resize shadows when the mouse is over the window edges is tested |
| 787 // in resize_shadow_and_cursor_test.cc | 776 // in resize_shadow_and_cursor_test.cc |
| 788 | 777 |
| 789 } // namespace test | 778 } // namespace test |
| 790 } // namespace ash | 779 } // namespace ash |
| OLD | NEW |