TestInputQueue.cpp (3974B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "APZCTreeManagerTester.h" 8 #include "APZTestCommon.h" 9 #include "InputUtils.h" 10 #include "mozilla/layers/ScrollableLayerGuid.h" 11 12 // Test of scenario described in bug 1269067 - that a continuing mouse drag 13 // doesn't interrupt a wheel scrolling animation 14 TEST_F(APZCTreeManagerTester, WheelInterruptedByMouseDrag) { 15 // Needed because the test uses SmoothWheel() 16 SCOPED_GFX_PREF_BOOL("general.smoothScroll", true); 17 18 // Set up a scrollable layer 19 CreateSimpleScrollingLayer(); 20 ScopedLayerTreeRegistration registration(LayersId{0}, mcc); 21 UpdateHitTestingTree(); 22 RefPtr<TestAsyncPanZoomController> apzc = ApzcOf(root); 23 24 // First start the mouse drag 25 uint64_t dragBlockId = 26 MouseDown(apzc, ScreenIntPoint(5, 5), mcc->Time()).mInputBlockId; 27 uint64_t tmpBlockId = 28 MouseMove(apzc, ScreenIntPoint(6, 6), mcc->Time()).mInputBlockId; 29 EXPECT_EQ(dragBlockId, tmpBlockId); 30 31 // Insert the wheel event, check that it has a new block id 32 uint64_t wheelBlockId = 33 SmoothWheel(apzc, ScreenIntPoint(6, 6), ScreenPoint(0, 1), mcc->Time()) 34 .mInputBlockId; 35 EXPECT_NE(dragBlockId, wheelBlockId); 36 37 // Continue the drag, check that the block id is the same as before 38 tmpBlockId = MouseMove(apzc, ScreenIntPoint(7, 5), mcc->Time()).mInputBlockId; 39 EXPECT_EQ(dragBlockId, tmpBlockId); 40 41 // Finish the wheel animation 42 apzc->AdvanceAnimationsUntilEnd(); 43 44 // Check that it scrolled 45 ParentLayerPoint scroll = apzc->GetCurrentAsyncScrollOffset( 46 AsyncPanZoomController::eForEventHandling); 47 EXPECT_EQ(scroll.x, 0); 48 EXPECT_EQ(scroll.y, 10); // We scrolled 1 "line" or 10 pixels 49 } 50 51 // Test of the scenario in bug 1894228, where the touchpad generates a 52 // mixture of wheel events with horizontal and vertical deltas, and if the 53 // content is only scrollable in the vertical direction, then an input 54 // block starting with a wheel event with a horizontal can prevent the 55 // entire input block from causing any scrolling. 56 TEST_F(APZCTreeManagerTester, HorizontalDeltaInterferesWithVerticalScrolling) { 57 using ViewID = ScrollableLayerGuid::ViewID; 58 ViewID rootScrollId = ScrollableLayerGuid::START_SCROLL_ID; 59 const char* treeShape = "x"; 60 LayerIntRect layerVisibleRect[] = { 61 LayerIntRect(0, 0, 100, 100), 62 }; 63 CreateScrollData(treeShape, layerVisibleRect); 64 // Only vertically scrollable 65 SetScrollableFrameMetrics(layers[0], rootScrollId, CSSRect(0, 0, 100, 1000)); 66 67 ScopedLayerTreeRegistration registration(LayersId{0}, mcc); 68 UpdateHitTestingTree(); 69 RefPtr<TestAsyncPanZoomController> apzc = ApzcOf(root); 70 71 // Configure the APZC to wait for main-thread confirmations before 72 // processing events. (This is needed to trigger the buggy codepath.) 73 apzc->SetWaitForMainThread(); 74 75 // Send a wheel event with a horizontal delta. 76 ScreenIntPoint cursorLocation(50, 50); 77 uint64_t wheelBlockId1 = 78 Wheel(apzc, cursorLocation, ScreenIntPoint(-10, 0), mcc->Time()) 79 .mInputBlockId; 80 81 // Send a wheel event with a vertical delta. 82 uint64_t wheelBlockId2 = 83 Wheel(apzc, cursorLocation, ScreenIntPoint(0, 10), mcc->Time()) 84 .mInputBlockId; 85 86 // Since the wheel block's target APZC has not been confirmed yet, the second 87 // event will go into the same block as the first. 88 EXPECT_EQ(wheelBlockId1, wheelBlockId2); 89 90 // Confirm the input block. 91 manager->ContentReceivedInputBlock(wheelBlockId1, false); 92 manager->SetTargetAPZC(wheelBlockId1, {apzc->GetGuid()}); 93 94 // We should have scrolled vertically. 95 EXPECT_EQ(ParentLayerPoint(0, 10), 96 apzc->GetCurrentAsyncScrollOffset( 97 AsyncPanZoomController::eForEventHandling)); 98 }