• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
18 #include "app_mgr_stub.h"
19 #include "hilog_wrapper.h"
20 #include "mock_app_mgr_service.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace {
28 const int32_t USER_ID = 100;
29 }  // namespace
30 
31 class AppMgrStubTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 
38     sptr<MockAppMgrService> mockAppMgrService_;
39 
40     void WriteInterfaceToken(MessageParcel &data);
41 };
42 
SetUpTestCase(void)43 void AppMgrStubTest::SetUpTestCase(void)
44 {}
45 
TearDownTestCase(void)46 void AppMgrStubTest::TearDownTestCase(void)
47 {}
48 
SetUp()49 void AppMgrStubTest::SetUp()
50 {
51     GTEST_LOG_(INFO) << "AppMgrStubTest::SetUp()";
52 
53     mockAppMgrService_ = new MockAppMgrService();
54 }
55 
TearDown()56 void AppMgrStubTest::TearDown()
57 {}
58 
WriteInterfaceToken(MessageParcel & data)59 void AppMgrStubTest::WriteInterfaceToken(MessageParcel &data)
60 {
61     GTEST_LOG_(INFO) << "AppMgrStubTest::WriteInterfaceToken()";
62 
63     data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
64 }
65 
66 /**
67  * @tc.name: AppMgrStub_GetProcessRunningInfosByUserId_0100
68  * @tc.desc: GetProcessRunningInfosByUserId
69  * @tc.type: FUNC
70  * @tc.require: SR000GH1GO
71  */
72 HWTEST_F(AppMgrStubTest, AppMgrStub_GetProcessRunningInfosByUserId_0100, TestSize.Level0)
73 {
74     GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 start";
75 
76     MessageParcel data;
77     MessageParcel reply;
78     MessageOption option;
79 
80     WriteInterfaceToken(data);
81     data.WriteInt32(USER_ID);
82 
83     EXPECT_CALL(*mockAppMgrService_, GetProcessRunningInfosByUserId(_, _)).Times(1);
84 
85     auto result = mockAppMgrService_->OnRemoteRequest(
86         static_cast<uint32_t>(IAppMgr::Message::APP_GET_RUNNING_PROCESSES_BY_USER_ID), data, reply, option);
87     EXPECT_EQ(result, NO_ERROR);
88 
89     GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 end";
90 }
91 
92 /**
93  * @tc.name: HandleGetAppRunningStateByBundleName_0100
94  * @tc.desc: Handle get app running state by bundle name.
95  * @tc.type: FUNC
96  * @tc.require: issueI581VW
97  */
98 HWTEST_F(AppMgrStubTest, HandleGetAppRunningStateByBundleName_0100, TestSize.Level0)
99 {
100     HILOG_INFO("%{public}s start.", __func__);
101 
102     MessageParcel data;
103     MessageParcel reply;
104     MessageOption option;
105 
106     WriteInterfaceToken(data);
107     std::string bundleName = "testBundleName";
108     data.WriteString(bundleName);
109 
110     EXPECT_CALL(*mockAppMgrService_, GetAppRunningStateByBundleName(_)).Times(1);
111 
112     auto result = mockAppMgrService_->OnRemoteRequest(
113         static_cast<uint32_t>(IAppMgr::Message::GET_APP_RUNNING_STATE), data, reply, option);
114     EXPECT_EQ(result, NO_ERROR);
115 
116     HILOG_INFO("%{public}s end.", __func__);
117 }
118 
119 /**
120  * @tc.name: HandleNotifyLoadRepairPatch_0100
121  * @tc.desc: Handle notify load repair patch.
122  * @tc.type: FUNC
123  * @tc.require: issueI581VW
124  */
125 HWTEST_F(AppMgrStubTest, HandleNotifyLoadRepairPatch_0100, TestSize.Level0)
126 {
127     HILOG_INFO("%{public}s start.", __func__);
128 
129     MessageParcel data;
130     MessageParcel reply;
131     MessageOption option;
132 
133     WriteInterfaceToken(data);
134     std::string bundleName = "testBundleName";
135     data.WriteString(bundleName);
136 
137     EXPECT_CALL(*mockAppMgrService_, NotifyLoadRepairPatch(_, _)).Times(1);
138 
139     auto result = mockAppMgrService_->OnRemoteRequest(
140         static_cast<uint32_t>(IAppMgr::Message::NOTIFY_LOAD_REPAIR_PATCH), data, reply, option);
141     EXPECT_EQ(result, NO_ERROR);
142 
143     HILOG_INFO("%{public}s end.", __func__);
144 }
145 
146 /**
147  * @tc.name: HandleNotifyHotReloadPage_0100
148  * @tc.desc: Handle notify ace hot reload page.
149  * @tc.type: FUNC
150  * @tc.require: issueI581VW
151  */
152 HWTEST_F(AppMgrStubTest, HandleNotifyHotReloadPage_0100, TestSize.Level0)
153 {
154     HILOG_INFO("%{public}s start.", __func__);
155 
156     MessageParcel data;
157     MessageParcel reply;
158     MessageOption option;
159 
160     WriteInterfaceToken(data);
161     std::string bundleName = "testBundleName";
162     data.WriteString(bundleName);
163 
164     EXPECT_CALL(*mockAppMgrService_, NotifyHotReloadPage(_, _)).Times(1);
165 
166     auto result = mockAppMgrService_->OnRemoteRequest(
167         static_cast<uint32_t>(IAppMgr::Message::NOTIFY_HOT_RELOAD_PAGE), data, reply, option);
168     EXPECT_EQ(result, NO_ERROR);
169 
170     HILOG_INFO("%{public}s end.", __func__);
171 }
172 
173 /**
174  * @tc.name: HandleNotifyUnLoadRepairPatch_0100
175  * @tc.desc: Handle notify unload repair patch.
176  * @tc.type: FUNC
177  * @tc.require: issueI581VW
178  */
179 HWTEST_F(AppMgrStubTest, HandleNotifyUnLoadRepairPatch_0100, TestSize.Level0)
180 {
181     HILOG_INFO("%{public}s start.", __func__);
182 
183     MessageParcel data;
184     MessageParcel reply;
185     MessageOption option;
186 
187     WriteInterfaceToken(data);
188     std::string bundleName = "testBundleName";
189     data.WriteString(bundleName);
190 
191     EXPECT_CALL(*mockAppMgrService_, NotifyUnLoadRepairPatch(_, _)).Times(1);
192 
193     auto result = mockAppMgrService_->OnRemoteRequest(
194         static_cast<uint32_t>(IAppMgr::Message::NOTIFY_UNLOAD_REPAIR_PATCH), data, reply, option);
195     EXPECT_EQ(result, NO_ERROR);
196 
197     HILOG_INFO("%{public}s end.", __func__);
198 }
199 
200 /**
201  * @tc.name: PreStartNWebSpawnProcess_001
202  * @tc.desc: prestart nwebspawn process.
203  * @tc.type: FUNC
204  * @tc.require: issueI5W4S7
205  */
206 HWTEST_F(AppMgrStubTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
207 {
208     HILOG_INFO("%{public}s start.", __func__);
209     MessageParcel data;
210     MessageParcel reply;
211     MessageOption option;
212     WriteInterfaceToken(data);
213     EXPECT_CALL(*mockAppMgrService_, PreStartNWebSpawnProcess()).Times(1);
214 
215     auto result = mockAppMgrService_->OnRemoteRequest(
216         static_cast<uint32_t>(IAppMgr::Message::PRE_START_NWEBSPAWN_PROCESS), data, reply, option);
217     EXPECT_EQ(result, NO_ERROR);
218 
219     HILOG_INFO("%{public}s end.", __func__);
220 }
221 }  // namespace AppExecFwk
222 }  // namespace OHOS
223