• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include "ui_extension_servicehost_stub_impl.h"
18 #define private public
19 #include "js_uiservice_uiext_connection.h"
20 #undef private
21 
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace OHOS::AAFwk;
25 using namespace OHOS::AbilityRuntime;
26 
27 namespace OHOS {
28 namespace AbilityRuntime {
29 class JsUiserviceUiextConnectionTest : public testing::Test {
30 public:
31     void SetUp();
32     void TearDown();
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35 };
36 
SetUpTestCase(void)37 void JsUiserviceUiextConnectionTest::SetUpTestCase(void)
38 {}
TearDownTestCase(void)39 void JsUiserviceUiextConnectionTest::TearDownTestCase(void)
40 {}
SetUp()41 void JsUiserviceUiextConnectionTest::SetUp()
42 {}
TearDown()43 void JsUiserviceUiextConnectionTest::TearDown()
44 {}
45 
46 /**
47  * @tc.number: HandleOnAbilityConnectDone_0100
48  * @tc.desc: HandleOnAbilityConnectDone
49  * @tc.type: FUNC
50  */
51 HWTEST_F(JsUiserviceUiextConnectionTest, HandleOnAbilityConnectDone_0100, TestSize.Level1)
52 {
53     napi_env env;
54     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
55     EXPECT_NE(connection, nullptr);
56 
57     AppExecFwk::ElementName element;
58     sptr<IRemoteObject> remoteObject;
59     int resultCode = 0;
60     connection->HandleOnAbilityConnectDone(element, remoteObject, resultCode);
61     EXPECT_EQ(connection->napiAsyncTask_, nullptr);
62 }
63 
64 /**
65  * @tc.number: HandleOnAbilityDisconnectDone_0100
66  * @tc.desc: HandleOnAbilityDisconnectDone
67  * @tc.type: FUNC
68  */
69 HWTEST_F(JsUiserviceUiextConnectionTest, HandleOnAbilityDisconnectDone_0100, TestSize.Level1)
70 {
71     napi_env env;
72     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
73     EXPECT_NE(connection, nullptr);
74 
75     AppExecFwk::ElementName element;
76     int resultCode = 0;
77     connection->HandleOnAbilityDisconnectDone(element, resultCode);
78     EXPECT_EQ(connection->serviceProxyObject_, nullptr);
79 }
80 
81 /**
82  * @tc.number: ResolveDuplicatedPendingTask_0100
83  * @tc.desc: ResolveDuplicatedPendingTask
84  * @tc.type: FUNC
85  */
86 HWTEST_F(JsUiserviceUiextConnectionTest, ResolveDuplicatedPendingTask_0100, TestSize.Level1)
87 {
88     napi_env env;
89     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
90     EXPECT_NE(connection, nullptr);
91 
92     napi_value proxy = nullptr;
93     connection->ResolveDuplicatedPendingTask(env, proxy);
94     EXPECT_EQ(connection->duplicatedPendingTaskList_.size(), 0);
95 }
96 
97 /**
98  * @tc.number: RejectDuplicatedPendingTask_0100
99  * @tc.desc: RejectDuplicatedPendingTask
100  * @tc.type: FUNC
101  */
102 HWTEST_F(JsUiserviceUiextConnectionTest, RejectDuplicatedPendingTask_0100, TestSize.Level1)
103 {
104     napi_env env;
105     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
106     EXPECT_NE(connection, nullptr);
107 
108     napi_value error = nullptr;
109     connection->RejectDuplicatedPendingTask(env, error);
110     EXPECT_EQ(connection->duplicatedPendingTaskList_.size(), 0);
111 }
112 
113 /**
114  * @tc.number: SetProxyObject_0100
115  * @tc.desc: SetProxyObject
116  * @tc.type: FUNC
117  */
118 HWTEST_F(JsUiserviceUiextConnectionTest, SetProxyObject_0100, TestSize.Level1)
119 {
120     napi_env env;
121     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
122     EXPECT_NE(connection, nullptr);
123 
124     napi_value proxy = nullptr;
125     connection->SetProxyObject(proxy);
126     EXPECT_EQ(connection->serviceProxyObject_, nullptr);
127 }
128 
129 /**
130  * @tc.number: GetProxyObject_0100
131  * @tc.desc: GetProxyObject
132  * @tc.type: FUNC
133  */
134 HWTEST_F(JsUiserviceUiextConnectionTest, GetProxyObject_0100, TestSize.Level1)
135 {
136     napi_env env;
137     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
138     EXPECT_NE(connection, nullptr);
139 
140     EXPECT_EQ(connection->GetProxyObject(), nullptr);
141 }
142 
143 /**
144  * @tc.number: OnSendData_0100
145  * @tc.desc: OnSendData
146  * @tc.type: FUNC
147  */
148 HWTEST_F(JsUiserviceUiextConnectionTest, OnSendData_0100, TestSize.Level1)
149 {
150     napi_env env;
151     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
152     EXPECT_NE(connection, nullptr);
153 
154     OHOS::AAFwk::WantParams data;
155     EXPECT_EQ(connection->OnSendData(data), ERR_OK);
156 }
157 
158 /**
159  * @tc.number: IsJsCallbackObjectEquals_0100
160  * @tc.desc: IsJsCallbackObjectEquals
161  * @tc.type: FUNC
162  */
163 HWTEST_F(JsUiserviceUiextConnectionTest, IsJsCallbackObjectEquals_0100, TestSize.Level1)
164 {
165     napi_env env;
166     sptr<JSUIServiceUIExtConnection> connection = sptr<JSUIServiceUIExtConnection>::MakeSptr(env);
167     EXPECT_NE(connection, nullptr);
168 
169     std::unique_ptr<NativeReference> callback;
170     napi_value value = nullptr;
171     EXPECT_TRUE(connection->IsJsCallbackObjectEquals(env, callback, value));
172 }
173 }  // namespace AAFwk
174 }  // namespace OHOS
175