1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_SCROLL_TEST_NG_H 17 #define FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_SCROLL_TEST_NG_H 18 19 #include "test/unittest/core/pattern/test_ng.h" 20 21 #define private public 22 #define protected public 23 #include "core/components_ng/pattern/scroll/scroll_model_ng.h" 24 #include "core/components_ng/pattern/scroll/scroll_pattern.h" 25 26 namespace OHOS::Ace::NG { 27 using namespace testing; 28 using namespace testing::ext; 29 constexpr float SCROLL_WIDTH = 480.f; 30 constexpr float SCROLL_HEIGHT = 800.f; 31 constexpr int32_t TOTAL_ITEM_NUMBER = 10; 32 constexpr int32_t VIEW_ITEM_NUMBER = 8; 33 constexpr int32_t SNAP_ITEM_NUMBER = 30; 34 constexpr float DEFAULT_ACTIVE_WIDTH = 8.0f; 35 constexpr float DEFAULT_INACTIVE_WIDTH = 4.0f; 36 constexpr float DEFAULT_NORMAL_WIDTH = 4.0f; 37 constexpr float DEFAULT_TOUCH_WIDTH = 32.0f; 38 constexpr float ITEM_WIDTH = 60.f; 39 constexpr float ITEM_HEIGHT = 100.f; 40 constexpr float VERTICAL_SCROLLABLE_DISTANCE = (TOTAL_ITEM_NUMBER - VIEW_ITEM_NUMBER) * ITEM_HEIGHT; 41 constexpr float SNAP_SCROLLABLE_DISTANCE = (SNAP_ITEM_NUMBER - VIEW_ITEM_NUMBER) * ITEM_HEIGHT; 42 constexpr float NORMAL_WIDTH = 4.f; 43 constexpr float SCROLL_PAGING_SPEED_THRESHOLD = 1200.0f; 44 45 class ScrollTestNg : public TestNG { 46 public: 47 static void SetUpTestSuite(); 48 static void TearDownTestSuite(); 49 void SetUp() override; 50 void TearDown() override; 51 void GetScroll(); 52 53 ScrollModelNG CreateScroll(); 54 void CreateSnapScroll(ScrollSnapAlign scrollSnapAlign, const Dimension& intervalSize, 55 const std::vector<Dimension>& snapPaginations, const std::pair<bool, bool>& enableSnapToSide); 56 57 void CreateContent(int32_t childNumber = TOTAL_ITEM_NUMBER); 58 RefPtr<FrameNode> GetContentChild(int32_t index); 59 void Touch(TouchType touchType, Offset offset, SourceType sourceType); 60 void Mouse(Offset location, MouseButton mouseButton = MouseButton::NONE_BUTTON, 61 MouseAction mouseAction = MouseAction::NONE); 62 void Hover(bool isHover); 63 bool OnScrollCallback(float offset, int32_t source); 64 void ScrollToEdge(ScrollEdgeType scrollEdgeType); 65 void ScrollTo(float offset); 66 Axis GetAxis(); 67 float GetOffset(float childNumber); 68 AssertionResult UpdateAndVerifyPosition(float delta, int32_t source, float expectOffset); 69 AssertionResult ScrollToNode(int32_t childIndex, float expectOffset); 70 AssertionResult IsEqualCurrentPosition(float expectOffset); 71 72 RefPtr<FrameNode> frameNode_; 73 RefPtr<ScrollPattern> pattern_; 74 RefPtr<ScrollEventHub> eventHub_; 75 RefPtr<ScrollLayoutProperty> layoutProperty_; 76 RefPtr<ScrollablePaintProperty> paintProperty_; 77 RefPtr<ScrollAccessibilityProperty> accessibilityProperty_; 78 RefPtr<ScrollBar> scrollBar_; 79 }; 80 } // namespace OHOS::Ace::NG 81 82 #endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_SCROLL_TEST_NG_H