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 #include <thread> 17 #include <chrono> 18 #include "interfaces/inner_api/form_render/include/form_renderer.h" 19 #include "interfaces/inner_api/form_render/include/form_renderer_dispatcher_proxy.h" 20 #include "test/mock/interfaces/mock_form_renderer_dispatcher_stub.h" 21 22 using namespace testing; 23 using namespace testing::ext; 24 25 namespace OHOS::Ace { 26 namespace { 27 class FormRendererDispatcherProxyTest : public testing::Test { 28 public: SetUpTestCase()29 static void SetUpTestCase() {}; 30 TearDownTestCase()31 static void TearDownTestCase() {}; 32 }; 33 34 /** 35 * @tc.number: DispatchPointerEvent_001 36 * @tc.name: DispatchPointerEvent_001 37 * @tc.desc: Verify the DispatchPointerEvent function when remoteObject is not nullptr. 38 */ 39 HWTEST_F(FormRendererDispatcherProxyTest, DispatchPointerEvent_001, TestSize.Level1) 40 { 41 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 42 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 43 std::shared_ptr<MMI::PointerEvent> event = MMI::PointerEvent::Create(); 44 Ace::SerializedGesture serializedGesture; 45 proxy->DispatchPointerEvent(event, serializedGesture); 46 EXPECT_TRUE(mockStub->SendRequest_called); 47 } 48 49 /** 50 * @tc.number: DispatchPointerEvent_002 51 * @tc.name: DispatchPointerEvent_002 52 * @tc.desc: Verify the DispatchPointerEvent function when remoteObject is nullptr. 53 */ 54 HWTEST_F(FormRendererDispatcherProxyTest, DispatchPointerEvent_002, TestSize.Level1) 55 { 56 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 57 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 58 std::shared_ptr<MMI::PointerEvent> event = nullptr; 59 Ace::SerializedGesture serializedGesture; 60 proxy->DispatchPointerEvent(event, serializedGesture); 61 EXPECT_FALSE(mockStub->SendRequest_called); 62 } 63 64 /** 65 * @tc.number: SetAllowUpdate_001 66 * @tc.name: SetAllowUpdate_001 67 * @tc.desc: Verify the SetAllowUpdate function when it send request. 68 */ 69 HWTEST_F(FormRendererDispatcherProxyTest, SetAllowUpdate_001, TestSize.Level1) 70 { 71 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 72 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 73 bool allowUpdate = true; 74 proxy->SetAllowUpdate(allowUpdate); 75 EXPECT_TRUE(mockStub->SendRequest_called); 76 } 77 78 /** 79 * @tc.number: DispatchSurfaceChangeEvent_001 80 * @tc.name: DispatchSurfaceChangeEvent_001 81 * @tc.desc: Verify the DispatchSurfaceChangeEvent function when it send request. 82 */ 83 HWTEST_F(FormRendererDispatcherProxyTest, DispatchSurfaceChangeEvent_001, TestSize.Level1) 84 { 85 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 86 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 87 float width = 0.0; 88 float height = 0.0; 89 float borderWidth = 0.0; 90 proxy->DispatchSurfaceChangeEvent(width, height, borderWidth); 91 EXPECT_TRUE(mockStub->SendRequest_called); 92 } 93 94 /** 95 * @tc.number: SetObscured_001 96 * @tc.name: SetObscured_001 97 * @tc.desc: Verify the SetObscured function when it send request. 98 */ 99 HWTEST_F(FormRendererDispatcherProxyTest, SetObscured_001, TestSize.Level1) 100 { 101 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 102 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 103 bool isObscured = true; 104 proxy->SetObscured(isObscured); 105 EXPECT_TRUE(mockStub->SendRequest_called); 106 } 107 108 /** 109 * @tc.number: OnAccessibilityChildTreeRegister_001 110 * @tc.name: OnAccessibilityChildTreeRegister_001 111 * @tc.desc: Verify the OnAccessibilityChildTreeRegister function when it send request. 112 */ 113 HWTEST_F(FormRendererDispatcherProxyTest, OnAccessibilityChildTreeRegister_001, TestSize.Level1) 114 { 115 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 116 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 117 uint32_t windowId = 0; 118 int32_t treeId = 0; 119 int64_t accessibilityId = 0; 120 proxy->OnAccessibilityChildTreeRegister(windowId, treeId, accessibilityId); 121 EXPECT_TRUE(mockStub->SendRequest_called); 122 } 123 124 /** 125 * @tc.number: OnAccessibilityChildTreeDeregister_001 126 * @tc.name: OnAccessibilityChildTreeDeregister_001 127 * @tc.desc: Verify the OnAccessibilityChildTreeDeregister function when it send request. 128 */ 129 HWTEST_F(FormRendererDispatcherProxyTest, OnAccessibilityChildTreeDeregister_001, TestSize.Level1) 130 { 131 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 132 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 133 proxy->OnAccessibilityChildTreeDeregister(); 134 EXPECT_TRUE(mockStub->SendRequest_called); 135 } 136 137 /** 138 * @tc.number: OnAccessibilityDumpChildInfo_001 139 * @tc.name: OnAccessibilityDumpChildInfo_001 140 * @tc.desc: Verify the OnAccessibilityDumpChildInfo function when it send request. 141 */ 142 HWTEST_F(FormRendererDispatcherProxyTest, OnAccessibilityDumpChildInfo_001, TestSize.Level1) 143 { 144 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 145 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 146 std::vector<std::string> params; 147 std::vector<std::string> info; 148 proxy->OnAccessibilityDumpChildInfo(params, info); 149 EXPECT_TRUE(mockStub->SendRequest_called); 150 } 151 152 /** 153 * @tc.number: OnAccessibilityTransferHoverEvent_001 154 * @tc.name: OnAccessibilityTransferHoverEvent_001 155 * @tc.desc: Verify the OnAccessibilityTransferHoverEvent function when it send request. 156 */ 157 HWTEST_F(FormRendererDispatcherProxyTest, OnAccessibilityTransferHoverEvent_001, TestSize.Level1) 158 { 159 sptr<AppExecFwk::MockFormRendererDispatherStub> mockStub(new AppExecFwk::MockFormRendererDispatherStub()); 160 auto proxy = std::make_shared<FormRendererDispatcherProxy>(mockStub); 161 float pointX = 0.0; 162 float pointY = 0.0; 163 int32_t sourceType = 0; 164 int32_t eventType = 0; 165 int64_t timeMs = 0; 166 proxy->OnAccessibilityTransferHoverEvent(pointX, pointY, sourceType, eventType, timeMs); 167 EXPECT_TRUE(mockStub->SendRequest_called); 168 } 169 } 170 }