| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/renderer_host/input/touch_selection_controller.h" | 5 #include "content/browser/renderer_host/input/touch_selection_controller.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/events/test/mock_motion_event.h" | 8 #include "ui/events/test/mock_motion_event.h" |
| 9 | 9 |
| 10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 scoped_ptr<TouchSelectionController> controller_; | 180 scoped_ptr<TouchSelectionController> controller_; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 TEST_F(TouchSelectionControllerTest, InsertionBasic) { | 183 TEST_F(TouchSelectionControllerTest, InsertionBasic) { |
| 184 gfx::RectF insertion_rect(5, 5, 0, 10); | 184 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 185 bool visible = true; | 185 bool visible = true; |
| 186 | 186 |
| 187 // Insertion events are ignored until automatic showing is enabled. | 187 // Insertion events are ignored until automatic showing is enabled. |
| 188 ChangeInsertion(insertion_rect, visible); | 188 ChangeInsertion(insertion_rect, visible); |
| 189 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 189 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 190 controller().ShowInsertionHandleAutomatically(); | 190 controller().OnTapEvent(); |
| 191 | 191 |
| 192 // Insertion events are ignored until the selection region is marked editable. | 192 // Insertion events are ignored until the selection region is marked editable. |
| 193 ChangeInsertion(insertion_rect, visible); | 193 ChangeInsertion(insertion_rect, visible); |
| 194 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 194 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 195 |
| 196 controller().OnTapEvent(); |
| 195 controller().OnSelectionEditable(true); | 197 controller().OnSelectionEditable(true); |
| 196 | |
| 197 ChangeInsertion(insertion_rect, visible); | 198 ChangeInsertion(insertion_rect, visible); |
| 198 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 199 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 199 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 200 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 200 | 201 |
| 201 insertion_rect.Offset(1, 0); | 202 insertion_rect.Offset(1, 0); |
| 202 ChangeInsertion(insertion_rect, visible); | 203 ChangeInsertion(insertion_rect, visible); |
| 203 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 204 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); |
| 204 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 205 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 205 | 206 |
| 206 insertion_rect.Offset(0, 1); | 207 insertion_rect.Offset(0, 1); |
| 207 ChangeInsertion(insertion_rect, visible); | 208 ChangeInsertion(insertion_rect, visible); |
| 208 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 209 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); |
| 209 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 210 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 210 | 211 |
| 211 ClearInsertion(); | 212 ClearInsertion(); |
| 212 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 213 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); |
| 213 } | 214 } |
| 214 | 215 |
| 215 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { | 216 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { |
| 216 gfx::RectF insertion_rect(5, 5, 0, 10); | 217 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 217 bool visible = true; | 218 bool visible = true; |
| 218 controller().ShowInsertionHandleAutomatically(); | 219 controller().OnTapEvent(); |
| 219 controller().OnSelectionEditable(true); | 220 controller().OnSelectionEditable(true); |
| 220 | 221 |
| 221 ChangeInsertion(insertion_rect, visible); | 222 ChangeInsertion(insertion_rect, visible); |
| 222 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 223 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 223 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 224 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 224 | 225 |
| 225 controller().OnSelectionEditable(false); | 226 controller().OnSelectionEditable(false); |
| 226 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 227 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); |
| 227 } | 228 } |
| 228 | 229 |
| 230 TEST_F(TouchSelectionControllerTest, InsertionStaysHiddenIfEmptyRegionTapped) { |
| 231 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 232 bool visible = true; |
| 233 controller().OnSelectionEditable(true); |
| 234 |
| 235 // Taps should be ignored if they're in an empty editable region. |
| 236 controller().OnTapEvent(); |
| 237 controller().OnSelectionEmpty(true); |
| 238 ChangeInsertion(insertion_rect, visible); |
| 239 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 240 |
| 241 // Once the region becomes editable, taps should show the insertion handle. |
| 242 controller().OnTapEvent(); |
| 243 controller().OnSelectionEmpty(false); |
| 244 ChangeInsertion(insertion_rect, visible); |
| 245 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 246 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 247 |
| 248 // Reset the selection. |
| 249 controller().HideAndDisallowShowingAutomatically(); |
| 250 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); |
| 251 |
| 252 // Long-pressing should show the handle even if the editable region is empty. |
| 253 insertion_rect.Offset(2, -2); |
| 254 controller().OnLongPressEvent(); |
| 255 controller().OnSelectionEmpty(true); |
| 256 ChangeInsertion(insertion_rect, visible); |
| 257 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 258 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 259 } |
| 260 |
| 261 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { |
| 262 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 263 bool visible = true; |
| 264 |
| 265 // Simulate the user tapping an empty text field. |
| 266 controller().OnTapEvent(); |
| 267 controller().OnSelectionEditable(true); |
| 268 controller().OnSelectionEmpty(true); |
| 269 ChangeInsertion(insertion_rect, visible); |
| 270 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 271 |
| 272 // Simulate the cursor moving while a user is typing. |
| 273 insertion_rect.Offset(10, 0); |
| 274 controller().OnSelectionEmpty(false); |
| 275 ChangeInsertion(insertion_rect, visible); |
| 276 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 277 |
| 278 // If the user taps the *same* position as the cursor at the end of the text |
| 279 // entry, the handle should appear. |
| 280 controller().OnTapEvent(); |
| 281 ChangeInsertion(insertion_rect, visible); |
| 282 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 283 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 284 } |
| 285 |
| 229 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { | 286 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { |
| 230 controller().ShowSelectionHandlesAutomatically(); | 287 controller().OnLongPressEvent(); |
| 231 controller().ShowInsertionHandleAutomatically(); | |
| 232 controller().OnSelectionEditable(true); | 288 controller().OnSelectionEditable(true); |
| 233 | 289 |
| 234 gfx::RectF anchor_rect(5, 5, 0, 10); | 290 gfx::RectF anchor_rect(5, 5, 0, 10); |
| 235 gfx::RectF focus_rect(50, 5, 0, 10); | 291 gfx::RectF focus_rect(50, 5, 0, 10); |
| 236 bool visible = true; | 292 bool visible = true; |
| 237 | 293 |
| 238 ChangeInsertion(anchor_rect, visible); | 294 ChangeInsertion(anchor_rect, visible); |
| 239 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 295 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 240 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 296 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 241 | 297 |
| 242 ChangeSelection(anchor_rect, visible, focus_rect, visible); | 298 ChangeSelection(anchor_rect, visible, focus_rect, visible); |
| 243 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 299 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); |
| 244 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 300 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 245 | 301 |
| 246 ChangeInsertion(focus_rect, visible); | 302 ChangeInsertion(focus_rect, visible); |
| 247 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 303 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 248 EXPECT_EQ(focus_rect.bottom_left(), GetLastEventAnchor()); | 304 EXPECT_EQ(focus_rect.bottom_left(), GetLastEventAnchor()); |
| 249 | 305 |
| 250 controller().HideAndDisallowAutomaticShowing(); | 306 controller().HideAndDisallowShowingAutomatically(); |
| 251 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 307 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); |
| 252 | 308 |
| 253 controller().ShowInsertionHandleAutomatically(); | 309 controller().OnTapEvent(); |
| 254 ChangeInsertion(focus_rect, visible); | 310 ChangeInsertion(focus_rect, visible); |
| 255 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 311 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 256 EXPECT_EQ(focus_rect.bottom_left(), GetLastEventAnchor()); | 312 EXPECT_EQ(focus_rect.bottom_left(), GetLastEventAnchor()); |
| 257 } | 313 } |
| 258 | 314 |
| 259 TEST_F(TouchSelectionControllerTest, InsertionDragged) { | 315 TEST_F(TouchSelectionControllerTest, InsertionDragged) { |
| 260 base::TimeTicks event_time = base::TimeTicks::Now(); | 316 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 261 controller().ShowInsertionHandleAutomatically(); | 317 controller().OnTapEvent(); |
| 262 controller().OnSelectionEditable(true); | 318 controller().OnSelectionEditable(true); |
| 263 | 319 |
| 264 // The touch sequence should not be handled if insertion is not active. | 320 // The touch sequence should not be handled if insertion is not active. |
| 265 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 321 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 266 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 322 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 267 | 323 |
| 268 float line_height = 10.f; | 324 float line_height = 10.f; |
| 269 gfx::RectF anchor_rect(10, 0, 0, line_height); | 325 gfx::RectF anchor_rect(10, 0, 0, line_height); |
| 270 bool visible = true; | 326 bool visible = true; |
| 271 ChangeInsertion(anchor_rect, visible); | 327 ChangeInsertion(anchor_rect, visible); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 300 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 356 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 301 EXPECT_FALSE(GetAndResetCaretMoved()); | 357 EXPECT_FALSE(GetAndResetCaretMoved()); |
| 302 | 358 |
| 303 // Once the drag is complete, no more touch events should be consumed until | 359 // Once the drag is complete, no more touch events should be consumed until |
| 304 // the next ACTION_DOWN. | 360 // the next ACTION_DOWN. |
| 305 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 361 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 306 } | 362 } |
| 307 | 363 |
| 308 TEST_F(TouchSelectionControllerTest, InsertionTapped) { | 364 TEST_F(TouchSelectionControllerTest, InsertionTapped) { |
| 309 base::TimeTicks event_time = base::TimeTicks::Now(); | 365 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 310 controller().ShowInsertionHandleAutomatically(); | 366 controller().OnTapEvent(); |
| 311 controller().OnSelectionEditable(true); | 367 controller().OnSelectionEditable(true); |
| 312 SetDraggingEnabled(true); | 368 SetDraggingEnabled(true); |
| 313 | 369 |
| 314 gfx::RectF anchor_rect(10, 0, 0, 10); | 370 gfx::RectF anchor_rect(10, 0, 0, 10); |
| 315 bool visible = true; | 371 bool visible = true; |
| 316 ChangeInsertion(anchor_rect, visible); | 372 ChangeInsertion(anchor_rect, visible); |
| 317 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 373 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 318 | 374 |
| 319 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 375 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 320 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 376 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 321 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 377 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 322 | 378 |
| 323 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 379 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 324 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 380 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 325 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 381 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
| 326 | 382 |
| 327 // Reset the insertion. | 383 // Reset the insertion. |
| 328 ClearInsertion(); | 384 ClearInsertion(); |
| 329 controller().ShowInsertionHandleAutomatically(); | 385 controller().OnTapEvent(); |
| 330 ChangeInsertion(anchor_rect, visible); | 386 ChangeInsertion(anchor_rect, visible); |
| 331 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 387 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 332 | 388 |
| 333 // No tap should be signalled if the time between DOWN and UP was too long. | 389 // No tap should be signalled if the time between DOWN and UP was too long. |
| 334 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 390 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 335 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 391 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 336 event = MockMotionEvent(MockMotionEvent::ACTION_UP, | 392 event = MockMotionEvent(MockMotionEvent::ACTION_UP, |
| 337 event_time + base::TimeDelta::FromSeconds(1), | 393 event_time + base::TimeDelta::FromSeconds(1), |
| 338 0, | 394 0, |
| 339 0); | 395 0); |
| 340 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 396 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 341 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 397 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 342 | 398 |
| 343 // Reset the insertion. | 399 // Reset the insertion. |
| 344 ClearInsertion(); | 400 ClearInsertion(); |
| 345 controller().ShowInsertionHandleAutomatically(); | 401 controller().OnTapEvent(); |
| 346 ChangeInsertion(anchor_rect, visible); | 402 ChangeInsertion(anchor_rect, visible); |
| 347 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 348 | 404 |
| 349 // No tap should be signalled if the touch sequence is cancelled. | 405 // No tap should be signalled if the touch sequence is cancelled. |
| 350 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 351 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 407 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 352 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
| 353 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 409 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 354 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 355 } | 411 } |
| 356 | 412 |
| 357 TEST_F(TouchSelectionControllerTest, SelectionBasic) { | 413 TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
| 358 gfx::RectF anchor_rect(5, 5, 0, 10); | 414 gfx::RectF anchor_rect(5, 5, 0, 10); |
| 359 gfx::RectF focus_rect(50, 5, 0, 10); | 415 gfx::RectF focus_rect(50, 5, 0, 10); |
| 360 bool visible = true; | 416 bool visible = true; |
| 361 | 417 |
| 362 // Selection events are ignored until automatic showing is enabled. | 418 // Selection events are ignored until automatic showing is enabled. |
| 363 ChangeSelection(anchor_rect, visible, focus_rect, visible); | 419 ChangeSelection(anchor_rect, visible, focus_rect, visible); |
| 364 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 420 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 365 | 421 |
| 366 controller().ShowSelectionHandlesAutomatically(); | 422 controller().OnLongPressEvent(); |
| 367 ChangeSelection(anchor_rect, visible, focus_rect, visible); | 423 ChangeSelection(anchor_rect, visible, focus_rect, visible); |
| 368 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 424 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); |
| 369 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 425 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 370 | 426 |
| 371 anchor_rect.Offset(1, 0); | 427 anchor_rect.Offset(1, 0); |
| 372 ChangeSelection(anchor_rect, visible, focus_rect, visible); | 428 ChangeSelection(anchor_rect, visible, focus_rect, visible); |
| 373 // Selection movement does not currently trigger a separate event. | 429 // Selection movement does not currently trigger a separate event. |
| 374 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 430 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); |
| 375 | 431 |
| 376 ClearSelection(); | 432 ClearSelection(); |
| 377 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | 433 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); |
| 378 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 434 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 379 } | 435 } |
| 380 | 436 |
| 381 TEST_F(TouchSelectionControllerTest, SelectionDragged) { | 437 TEST_F(TouchSelectionControllerTest, SelectionDragged) { |
| 382 base::TimeTicks event_time = base::TimeTicks::Now(); | 438 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 383 controller().ShowSelectionHandlesAutomatically(); | 439 controller().OnLongPressEvent(); |
| 384 | 440 |
| 385 // The touch sequence should not be handled if selection is not active. | 441 // The touch sequence should not be handled if selection is not active. |
| 386 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 442 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 387 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 443 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 388 | 444 |
| 389 float line_height = 10.f; | 445 float line_height = 10.f; |
| 390 gfx::RectF anchor_rect(0, 0, 0, line_height); | 446 gfx::RectF anchor_rect(0, 0, 0, line_height); |
| 391 gfx::RectF focus_rect(50, 0, 0, line_height); | 447 gfx::RectF focus_rect(50, 0, 0, line_height); |
| 392 bool visible = true; | 448 bool visible = true; |
| 393 ChangeSelection(anchor_rect, visible, focus_rect, visible); | 449 ChangeSelection(anchor_rect, visible, focus_rect, visible); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 484 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 429 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 485 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 430 EXPECT_FALSE(GetAndResetSelectionMoved()); | 486 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 431 | 487 |
| 432 // Once the drag is complete, no more touch events should be consumed until | 488 // Once the drag is complete, no more touch events should be consumed until |
| 433 // the next ACTION_DOWN. | 489 // the next ACTION_DOWN. |
| 434 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 490 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 435 } | 491 } |
| 436 | 492 |
| 437 TEST_F(TouchSelectionControllerTest, Animation) { | 493 TEST_F(TouchSelectionControllerTest, Animation) { |
| 438 controller().ShowInsertionHandleAutomatically(); | 494 controller().OnTapEvent(); |
| 439 controller().OnSelectionEditable(true); | 495 controller().OnSelectionEditable(true); |
| 440 | 496 |
| 441 gfx::RectF insertion_rect(5, 5, 0, 10); | 497 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 442 | 498 |
| 443 bool visible = true; | 499 bool visible = true; |
| 444 ChangeInsertion(insertion_rect, visible); | 500 ChangeInsertion(insertion_rect, visible); |
| 445 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 501 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 446 | 502 |
| 447 visible = false; | 503 visible = false; |
| 448 ChangeInsertion(insertion_rect, visible); | 504 ChangeInsertion(insertion_rect, visible); |
| 449 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 505 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 450 | 506 |
| 451 visible = true; | 507 visible = true; |
| 452 ChangeInsertion(insertion_rect, visible); | 508 ChangeInsertion(insertion_rect, visible); |
| 453 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 509 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 454 | 510 |
| 455 // If the handles are explicity hidden, no animation should be triggered. | 511 // If the handles are explicity hidden, no animation should be triggered. |
| 456 controller().HideAndDisallowAutomaticShowing(); | 512 controller().HideAndDisallowShowingAutomatically(); |
| 457 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 513 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 458 | 514 |
| 459 // If the client doesn't support animation, no animation should be triggered. | 515 // If the client doesn't support animation, no animation should be triggered. |
| 460 SetAnimationEnabled(false); | 516 SetAnimationEnabled(false); |
| 461 controller().ShowInsertionHandleAutomatically(); | 517 controller().OnTapEvent(); |
| 462 visible = true; | 518 visible = true; |
| 463 ChangeInsertion(insertion_rect, visible); | 519 ChangeInsertion(insertion_rect, visible); |
| 464 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 520 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 465 } | 521 } |
| 466 | 522 |
| 467 TEST_F(TouchSelectionControllerTest, TemporarilyHidden) { | 523 TEST_F(TouchSelectionControllerTest, TemporarilyHidden) { |
| 468 controller().ShowInsertionHandleAutomatically(); | 524 controller().OnTapEvent(); |
| 469 controller().OnSelectionEditable(true); | 525 controller().OnSelectionEditable(true); |
| 470 | 526 |
| 471 gfx::RectF insertion_rect(5, 5, 0, 10); | 527 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 472 | 528 |
| 473 bool visible = true; | 529 bool visible = true; |
| 474 ChangeInsertion(insertion_rect, visible); | 530 ChangeInsertion(insertion_rect, visible); |
| 475 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 531 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 476 | 532 |
| 477 controller().SetTemporarilyHidden(true); | 533 controller().SetTemporarilyHidden(true); |
| 478 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 534 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 479 | 535 |
| 480 visible = false; | 536 visible = false; |
| 481 ChangeInsertion(insertion_rect, visible); | 537 ChangeInsertion(insertion_rect, visible); |
| 482 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 538 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 483 | 539 |
| 484 visible = true; | 540 visible = true; |
| 485 ChangeInsertion(insertion_rect, visible); | 541 ChangeInsertion(insertion_rect, visible); |
| 486 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 542 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 487 | 543 |
| 488 controller().SetTemporarilyHidden(false); | 544 controller().SetTemporarilyHidden(false); |
| 489 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 545 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 490 } | 546 } |
| 491 | 547 |
| 492 } // namespace content | 548 } // namespace content |
| OLD | NEW |