1 /* 2 * Copyright (c) 2025 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 TEST_UNITTEST_CORE_EVENT_FOCUS_API_TEST_H 17 #define TEST_UNITTEST_CORE_EVENT_FOCUS_API_TEST_H 18 #include <cstddef> 19 #include <cstdint> 20 21 #include "gtest/gtest.h" 22 #include "test/mock/core/common/mock_theme_manager.h" 23 #include "test/mock/core/pipeline/mock_pipeline_context.h" 24 #include "test/unittest/core/event/focus_core/focus_test_base.h" 25 #include "test/unittest/core/event/frame_node_on_tree.h" 26 27 #include "base/geometry/ng/offset_t.h" 28 #include "base/geometry/ng/size_t.h" 29 #include "base/memory/ace_type.h" 30 #include "base/memory/referenced.h" 31 #include "core/components/theme/app_theme.h" 32 #include "core/components_ng/base/frame_node.h" 33 #include "core/components_ng/event/focus_hub.h" 34 #include "core/components_ng/event/touch_event.h" 35 #include "core/components_ng/manager/focus/focus_view.h" 36 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" 37 #include "core/components_ng/pattern/pattern.h" 38 #include "core/components_v2/inspector/inspector_constants.h" 39 #include "core/event/key_event.h" 40 #include "core/pipeline_ng/pipeline_context.h" 41 42 namespace OHOS::Ace::NG { 43 44 struct FocusRequestFocusAble { 45 bool isAFocusable; 46 bool isBFocusable; 47 }; 48 struct FocusRequestTestCase { 49 FocusRequestFocusAble isFocusable; 50 bool isADependenceSelf; 51 bool isAOnMainTree; 52 bool isWindowSwiping; 53 std::string inspectorId; 54 std::vector<bool> expectResults; FocusRequestTestCaseFocusRequestTestCase55 FocusRequestTestCase(FocusRequestFocusAble isFocusable, bool isADependenceSelf, bool isAOnMainTree, 56 bool isWindowSwiping, std::string inspectorId, const std::vector<bool>& expectResults) 57 : isFocusable { isFocusable.isAFocusable, isFocusable.isBFocusable }, isADependenceSelf(isADependenceSelf), 58 isAOnMainTree(isAOnMainTree), isWindowSwiping(isWindowSwiping), inspectorId(inspectorId), 59 expectResults(expectResults) 60 {} 61 }; 62 class FocusRequestTestNG : public FocusTestBaseNg, public testing::Test { 63 public: 64 static void SetUpTestSuite(); 65 static void TearDownTestSuite(); 66 testing::AssertionResult IsRequestFocusStateEqual( 67 int32_t caseNum, const std::vector<bool>& actualState, const std::vector<bool>& expectState); 68 RefPtr<FrameNode> CreatNode(bool isFocusable); 69 void SetFcousCurrents(const RefPtr<FocusHub>& focusHub, const RefPtr<FrameNode>& node); 70 void InitFocusRequest(); 71 void SetDependence(bool isDependenceSelf, const RefPtr<FocusHub>& focusHub); 72 void SetWindowSwiping(bool isWindowSwiping); 73 }; 74 75 } // namespace OHOS::Ace::NG 76 77 #endif // TEST_UNITTEST_CORE_EVENT_FOCUS_HUB_TEST_NG_H