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

Side by Side Diff: content/browser/renderer_host/input/touch_action_filter_unittest.cc

Issue 2126323002: Add support for touch-action: pinch-zoom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add exception for mac Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/renderer_host/event_with_latency_info.h" 5 #include "content/browser/renderer_host/event_with_latency_info.h"
6 #include "content/browser/renderer_host/input/touch_action_filter.h" 6 #include "content/browser/renderer_host/input/touch_action_filter.h"
7 #include "content/common/input/input_event_ack_state.h" 7 #include "content/common/input/input_event_ack_state.h"
8 #include "content/common/input/synthetic_web_input_event_builders.h" 8 #include "content/common/input/synthetic_web_input_event_builders.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h" 10 #include "third_party/WebKit/public/web/WebInputEvent.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end)); 444 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
445 445
446 // Pinch state is automatically reset at the end of a scroll. 446 // Pinch state is automatically reset at the end of a scroll.
447 filter.ResetTouchAction(); 447 filter.ResetTouchAction();
448 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin)); 448 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
449 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin)); 449 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
450 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update)); 450 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
451 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end)); 451 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
452 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end)); 452 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
453 453
454 // Pinching can become disallowed during a single scroll gesture, but 454 // Pinching is only computed at GestureScrollBegin time.
455 // can't become allowed again until the scroll terminates.
456 // Note that the current TouchEventQueue design makes this scenario
457 // impossible in practice (no touch events are sent to the renderer
458 // while scrolling) and so no SetTouchAction can occur. But this
459 // could change in the future, so it's still worth verifying in this
460 // unit test.
461 filter.ResetTouchAction(); 455 filter.ResetTouchAction();
462 filter.OnSetTouchAction(TOUCH_ACTION_AUTO); 456 filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
463 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin)); 457 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
464 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin)); 458 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
465 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update)); 459 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
466 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end)); 460 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
467 filter.OnSetTouchAction(TOUCH_ACTION_NONE); 461 filter.OnSetTouchAction(TOUCH_ACTION_NONE);
468 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin)); 462 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
469 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update)); 463 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
470 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end)); 464 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
471 filter.OnSetTouchAction(TOUCH_ACTION_AUTO); 465 filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
472 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin)); 466 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
473 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update)); 467 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
474 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end)); 468 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
475 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end)); 469 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
476 470
477 // Once a pinch has started, any change in state won't affect the current 471 // Once a pinch has started, any change in state won't affect the pinch
478 // pinch gesture, but can affect a future one within the same scroll. 472 // gestures since it is computed in GestureScrollBegin.
479 filter.ResetTouchAction(); 473 filter.ResetTouchAction();
480 filter.OnSetTouchAction(TOUCH_ACTION_AUTO); 474 filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
481 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin)); 475 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
482 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin)); 476 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
483 filter.OnSetTouchAction(TOUCH_ACTION_NONE); 477 filter.OnSetTouchAction(TOUCH_ACTION_NONE);
484 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update)); 478 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
485 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end)); 479 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
486 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin)); 480 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
487 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update)); 481 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
488 EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end)); 482 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
489 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end)); 483 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
490 filter.ResetTouchAction(); 484 filter.ResetTouchAction();
485
486 scroll_begin.data.scrollBegin.pointerCount = 1;
487 // Scrolling should be disallowed for pinch zoom with only
488 // one pointer down.
489 filter.OnSetTouchAction(TOUCH_ACTION_PINCH_ZOOM);
490 EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
491 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
492 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
493 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
494 EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
495
496 scroll_begin.data.scrollBegin.pointerCount = 2;
497
498 // Scrolling is allowed when two fingers are down.
499 filter.ResetTouchAction();
500 filter.OnSetTouchAction(TOUCH_ACTION_PINCH_ZOOM);
501 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
502 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
503 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
504 EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
505 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
491 } 506 }
492 507
493 TEST(TouchActionFilterTest, DoubleTapWithTouchActionAuto) { 508 TEST(TouchActionFilterTest, DoubleTapWithTouchActionAuto) {
494 TouchActionFilter filter; 509 TouchActionFilter filter;
495 510
496 WebGestureEvent tap_down = SyntheticWebGestureEventBuilder::Build( 511 WebGestureEvent tap_down = SyntheticWebGestureEventBuilder::Build(
497 WebInputEvent::GestureTapDown, kSourceDevice); 512 WebInputEvent::GestureTapDown, kSourceDevice);
498 WebGestureEvent unconfirmed_tap = SyntheticWebGestureEventBuilder::Build( 513 WebGestureEvent unconfirmed_tap = SyntheticWebGestureEventBuilder::Build(
499 WebInputEvent::GestureTapUnconfirmed, kSourceDevice); 514 WebInputEvent::GestureTapUnconfirmed, kSourceDevice);
500 WebGestureEvent tap_cancel = SyntheticWebGestureEventBuilder::Build( 515 WebGestureEvent tap_cancel = SyntheticWebGestureEventBuilder::Build(
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 SyntheticWebGestureEventBuilder::BuildScrollBegin( 708 SyntheticWebGestureEventBuilder::BuildScrollBegin(
694 2, 3, blink::WebGestureDeviceTouchpad); 709 2, 3, blink::WebGestureDeviceTouchpad);
695 710
696 // TOUCH_ACTION_NONE filters out only touchscreen scroll events. 711 // TOUCH_ACTION_NONE filters out only touchscreen scroll events.
697 filter.ResetTouchAction(); 712 filter.ResetTouchAction();
698 filter.OnSetTouchAction(TOUCH_ACTION_NONE); 713 filter.OnSetTouchAction(TOUCH_ACTION_NONE);
699 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin)); 714 EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
700 } 715 }
701 716
702 } // namespace content 717 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_action_filter.cc ('k') | content/common/input_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698