• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 "widget_context.h"
17 
18 #include <future>
19 
20 #include "mock_context.h"
21 
22 #include "schedule_node_impl.h"
23 #include "widget_context_callback_impl.h"
24 #include "relative_timer.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace UserIam {
30 namespace UserAuth {
31 namespace {
32 auto &timer = RelativeTimer::GetInstance();
33 }
34 class WidgetContextTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37 
38     static void TearDownTestCase();
39 
40     void SetUp() override;
41 
42     void TearDown() override;
43 };
44 
SetUpTestCase()45 void WidgetContextTest::SetUpTestCase()
46 {
47 }
48 
TearDownTestCase()49 void WidgetContextTest::TearDownTestCase()
50 {
51 }
52 
SetUp()53 void WidgetContextTest::SetUp()
54 {
55 }
56 
TearDown()57 void WidgetContextTest::TearDown()
58 {
59 }
60 
CreateWidgetContext(uint64_t contextId,ContextFactory::AuthWidgetContextPara para)61 std::shared_ptr<WidgetContext> CreateWidgetContext(uint64_t contextId, ContextFactory::AuthWidgetContextPara para)
62 {
63     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
64     return Common::MakeShared<WidgetContext>(contextId, para, contextCallback, nullptr);
65 }
66 
67 HWTEST_F(WidgetContextTest, WidgetContextTestStart, TestSize.Level0)
68 {
69     uint64_t contextId = 1;
70     ContextFactory::AuthWidgetContextPara para;
71     auto widgetContext = CreateWidgetContext(contextId, para);
72     EXPECT_TRUE(widgetContext->Start());
73     EXPECT_FALSE(widgetContext->Start());
74     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460202() 75     handler->EnsureTask([]() {});
76 }
77 
78 HWTEST_F(WidgetContextTest, WidgetContextTestStop, TestSize.Level0)
79 {
80     uint64_t contextId = 1;
81     ContextFactory::AuthWidgetContextPara para;
82     auto widgetContext = CreateWidgetContext(contextId, para);
83     EXPECT_TRUE(widgetContext->Stop());
84     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460302() 85     handler->EnsureTask([]() {});
86 }
87 
88 HWTEST_F(WidgetContextTest, WidgetContextTestGetScheduleNode, TestSize.Level0)
89 {
90     uint64_t contextId = 1;
91     ContextFactory::AuthWidgetContextPara para;
92     auto widgetContext = CreateWidgetContext(contextId, para);
93     EXPECT_EQ(widgetContext->GetScheduleNode(contextId), nullptr);
94     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460402() 95     handler->EnsureTask([]() {});
96 }
97 
98 HWTEST_F(WidgetContextTest, WidgetContextTestGetLatestError, TestSize.Level0)
99 {
100     uint64_t contextId = 1;
101     ContextFactory::AuthWidgetContextPara para;
102     auto widgetContext = CreateWidgetContext(contextId, para);
103     EXPECT_EQ(widgetContext->GetLatestError(), ResultCode::GENERAL_ERROR);
104     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460502() 105     handler->EnsureTask([]() {});
106 }
107 
108 HWTEST_F(WidgetContextTest, WidgetContextTestGetContextType, TestSize.Level0)
109 {
110     uint64_t contextId = 1;
111     ContextFactory::AuthWidgetContextPara para;
112     auto widgetContext = CreateWidgetContext(contextId, para);
113     EXPECT_EQ(widgetContext->GetContextType(), WIDGET_AUTH_CONTEXT);
114     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460602() 115     handler->EnsureTask([]() {});
116 }
117 
118 HWTEST_F(WidgetContextTest, WidgetContextTestGetTokenId, TestSize.Level0)
119 {
120     uint64_t contextId = 1;
121     ContextFactory::AuthWidgetContextPara para;
122     auto widgetContext = CreateWidgetContext(contextId, para);
123     EXPECT_EQ(widgetContext->GetTokenId(), (uint32_t)0);
124     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460702() 125     handler->EnsureTask([]() {});
126 }
127 
128 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0001, TestSize.Level0)
129 {
130     uint64_t contextId = 1;
131     ContextFactory::AuthWidgetContextPara para;
132     auto widgetContext = CreateWidgetContext(contextId, para);
133     EXPECT_NE(widgetContext, nullptr);
134     Attributes finalResult;
135     widgetContext->AuthResult(ResultCode::SUCCESS, 1, finalResult);
136     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460802() 137     handler->EnsureTask([]() {});
138 }
139 
140 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0002, TestSize.Level0)
141 {
142     uint64_t contextId = 1;
143     ContextFactory::AuthWidgetContextPara para;
144     auto widgetContext = CreateWidgetContext(contextId, para);
145     EXPECT_NE(widgetContext, nullptr);
146     Attributes finalResult;
147     finalResult.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 1);
148     widgetContext->AuthResult(ResultCode::SUCCESS, 1, finalResult);
149     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460902() 150     handler->EnsureTask([]() {});
151 }
152 
153 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0003, TestSize.Level0)
154 {
155     uint64_t contextId = 1;
156     ContextFactory::AuthWidgetContextPara para;
157     auto widgetContext = CreateWidgetContext(contextId, para);
158     EXPECT_NE(widgetContext, nullptr);
159     Attributes finalResult;
160     finalResult.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 1);
161     finalResult.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 1);
162     widgetContext->AuthResult(ResultCode::SUCCESS, 1, finalResult);
163     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460a02() 164     handler->EnsureTask([]() {});
165 }
166 
167 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0004, TestSize.Level0)
168 {
169     uint64_t contextId = 1;
170     ContextFactory::AuthWidgetContextPara para;
171     auto widgetContext = CreateWidgetContext(contextId, para);
172     EXPECT_NE(widgetContext, nullptr);
173     EXPECT_TRUE(widgetContext->Start());
174     Attributes finalResult;
175     finalResult.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 1);
176     finalResult.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 1);
177     widgetContext->AuthResult(ResultCode::SUCCESS, 1, finalResult);
178     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460b02() 179     handler->EnsureTask([]() {});
180 }
181 
182 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0005, TestSize.Level0)
183 {
184     uint64_t contextId = 1;
185     ContextFactory::AuthWidgetContextPara para;
186     auto widgetContext = CreateWidgetContext(contextId, para);
187     EXPECT_NE(widgetContext, nullptr);
188     EXPECT_TRUE(widgetContext->Start());
189     Attributes finalResult;
190     finalResult.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 1);
191     finalResult.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 1);
192     widgetContext->AuthResult(ResultCode::GENERAL_ERROR, 1, finalResult);
193     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460c02() 194     handler->EnsureTask([]() {});
195 }
196 
197 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0006, TestSize.Level0)
198 {
199     uint64_t contextId = 1;
200     ContextFactory::AuthWidgetContextPara para;
201     auto widgetContext = CreateWidgetContext(contextId, para);
202     EXPECT_NE(widgetContext, nullptr);
203     EXPECT_TRUE(widgetContext->Start());
204     Attributes finalResult;
205     finalResult.SetInt32Value(Attributes::ATTR_AUTH_TYPE, PIN);
206     widgetContext->AuthResult(ResultCode::COMPLEXITY_CHECK_FAILED, 1, finalResult);
207     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460d02() 208     handler->EnsureTask([]() {});
209 }
210 
211 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0007, TestSize.Level0)
212 {
213     uint64_t contextId = 1;
214     ContextFactory::AuthWidgetContextPara para;
215     auto widgetContext = CreateWidgetContext(contextId, para);
216     EXPECT_NE(widgetContext, nullptr);
217     EXPECT_TRUE(widgetContext->Start());
218     Attributes finalResult;
219     std::vector<uint8_t> token = {1, 1};
220     finalResult.SetInt32Value(Attributes::ATTR_AUTH_TYPE, PIN);
221     finalResult.SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, token);
222     widgetContext->AuthResult(ResultCode::COMPLEXITY_CHECK_FAILED, 1, finalResult);
223     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460e02() 224     handler->EnsureTask([]() {});
225 }
226 
227 HWTEST_F(WidgetContextTest, WidgetContextTestAuthResult_0008, TestSize.Level0)
228 {
229     uint64_t contextId = 1;
230     ContextFactory::AuthWidgetContextPara para;
231     auto widgetContext = CreateWidgetContext(contextId, para);
232     EXPECT_NE(widgetContext, nullptr);
233     EXPECT_TRUE(widgetContext->Start());
234     Attributes finalResult;
235     std::vector<uint8_t> token = {1, 1};
236     finalResult.SetInt32Value(Attributes::ATTR_AUTH_TYPE, PIN);
237     finalResult.SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, token);
238     finalResult.SetUint64Value(Attributes::ATTR_CREDENTIAL_DIGEST, 1);
239     widgetContext->AuthResult(ResultCode::COMPLEXITY_CHECK_FAILED, 1, finalResult);
240     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8460f02() 241     handler->EnsureTask([]() {});
242 }
243 
244 HWTEST_F(WidgetContextTest, WidgetContextTestLaunchWidget_001, TestSize.Level0)
245 {
246     uint64_t contextId = 1;
247     ContextFactory::AuthWidgetContextPara para;
248     auto widgetContext = CreateWidgetContext(contextId, para);
249     widgetContext->LaunchWidget();
250     EXPECT_NE(widgetContext, nullptr);
251     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461002() 252     handler->EnsureTask([]() {});
253 }
254 
255 HWTEST_F(WidgetContextTest, WidgetContextTestLaunchWidget_002, TestSize.Level0)
256 {
257     uint64_t contextId = 1;
258     ContextFactory::AuthWidgetContextPara para;
259     ContextFactory::AuthProfile contextPara;
260     para.authProfileMap[PIN] = contextPara;
261     auto widgetContext = CreateWidgetContext(contextId, para);
262     widgetContext->LaunchWidget();
263     EXPECT_NE(widgetContext, nullptr);
264     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461102() 265     handler->EnsureTask([]() {});
266 }
267 
268 HWTEST_F(WidgetContextTest, WidgetContextTestLaunchWidget_003, TestSize.Level0)
269 {
270     uint64_t contextId = 1;
271     ContextFactory::AuthWidgetContextPara para;
272     ContextFactory::AuthProfile authProfile;
273     authProfile.sensorInfo = "1";
274     para.authProfileMap[AuthType::FINGERPRINT] = authProfile;
275     auto widgetContext = CreateWidgetContext(contextId, para);
276     widgetContext->LaunchWidget();
277     EXPECT_NE(widgetContext, nullptr);
278     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461202() 279     handler->EnsureTask([]() {});
280 }
281 
282 HWTEST_F(WidgetContextTest, WidgetContextTestEndAuthAsCancel_001, TestSize.Level0)
283 {
284     uint64_t contextId = 1;
285     ContextFactory::AuthWidgetContextPara para;
286     auto widgetContext = CreateWidgetContext(contextId, para);
287     widgetContext->EndAuthAsCancel();
288     EXPECT_NE(widgetContext, nullptr);
289     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461302() 290     handler->EnsureTask([]() {});
291 }
292 
293 HWTEST_F(WidgetContextTest, WidgetContextTestEndAuthAsCancel_002, TestSize.Level0)
294 {
295     uint64_t contextId = 1;
296     ContextFactory::AuthWidgetContextPara para;
297     auto widgetContext = CreateWidgetContext(contextId, para);
298     widgetContext->SetLatestError(COMPLEXITY_CHECK_FAILED);
299     widgetContext->EndAuthAsCancel();
300     EXPECT_NE(widgetContext, nullptr);
301     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461402() 302     handler->EnsureTask([]() {});
303 }
304 
305 HWTEST_F(WidgetContextTest, WidgetContextTestEndAuthAsNaviPin, TestSize.Level0)
306 {
307     uint64_t contextId = 1;
308     ContextFactory::AuthWidgetContextPara para;
309     auto widgetContext = CreateWidgetContext(contextId, para);
310     widgetContext->EndAuthAsNaviPin();
311     EXPECT_NE(widgetContext, nullptr);
312     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461502() 313     handler->EnsureTask([]() {});
314 }
315 
316 HWTEST_F(WidgetContextTest, WidgetContextTestEndAuthAsWidgetParaInvalid, TestSize.Level0)
317 {
318     uint64_t contextId = 1;
319     ContextFactory::AuthWidgetContextPara para;
320     auto widgetContext = CreateWidgetContext(contextId, para);
321     widgetContext->EndAuthAsWidgetParaInvalid();
322     EXPECT_NE(widgetContext, nullptr);
323     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461602() 324     handler->EnsureTask([]() {});
325 }
326 
327 HWTEST_F(WidgetContextTest, WidgetContextTestStopAuthList_001, TestSize.Level0)
328 {
329     uint64_t contextId = 1;
330     ContextFactory::AuthWidgetContextPara para;
331     auto widgetContext = CreateWidgetContext(contextId, para);
332     std::vector<AuthType> authTypeList;
333     widgetContext->StopAuthList(authTypeList);
334     EXPECT_NE(widgetContext, nullptr);
335     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461702() 336     handler->EnsureTask([]() {});
337 }
338 
339 HWTEST_F(WidgetContextTest, WidgetContextTestStopAuthList_002, TestSize.Level0)
340 {
341     uint64_t contextId = 1;
342     ContextFactory::AuthWidgetContextPara para;
343     auto widgetContext = CreateWidgetContext(contextId, para);
344     std::vector<AuthType> authTypeList = {ALL, PIN, FACE};
345     widgetContext->StopAuthList(authTypeList);
346     EXPECT_NE(widgetContext, nullptr);
347     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461802() 348     handler->EnsureTask([]() {});
349 }
350 
351 HWTEST_F(WidgetContextTest, WidgetContextTestStopAuthList_003, TestSize.Level0)
352 {
353     uint64_t contextId = 1;
354     ContextFactory::AuthWidgetContextPara para;
355     para.challenge = {0, 1};
356     para.atl = ATL2;
357     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
358     auto widgetContext = CreateWidgetContext(contextId, para);
359     std::set<AuthType> authTypeList;
360     authTypeList.insert(FACE);
361     authTypeList.insert(ALL);
362     widgetContext->ExecuteAuthList(authTypeList, false, AuthIntent::DEFAULT);
363 
364     std::vector<AuthType> testTypeList = {ALL, PIN, FACE};
365     widgetContext->StopAuthList(testTypeList);
366     EXPECT_NE(widgetContext, nullptr);
367     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461902() 368     handler->EnsureTask([]() {});
369 }
370 
371 HWTEST_F(WidgetContextTest, WidgetContextTestSuccessAuth_001, TestSize.Level0)
372 {
373     uint64_t contextId = 1;
374     ContextFactory::AuthWidgetContextPara para;
375     auto widgetContext = CreateWidgetContext(contextId, para);
376     AuthType authType = ALL;
377     widgetContext->SuccessAuth(authType);
378     EXPECT_NE(widgetContext, nullptr);
379     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461a02() 380     handler->EnsureTask([]() {});
381 }
382 
383 HWTEST_F(WidgetContextTest, WidgetContextTestSuccessAuth_002, TestSize.Level0)
384 {
385     uint64_t contextId = 1;
386     ContextFactory::AuthWidgetContextPara para;
387     auto widgetContext = CreateWidgetContext(contextId, para);
388     AuthType authType = ALL;
389     widgetContext->LaunchWidget();
390     widgetContext->SuccessAuth(authType);
391     EXPECT_NE(widgetContext, nullptr);
392     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461b02() 393     handler->EnsureTask([]() {});
394 }
395 
396 HWTEST_F(WidgetContextTest, WidgetContextTestSuccessAuth_003, TestSize.Level0)
397 {
398     uint64_t contextId = 1;
399     ContextFactory::AuthWidgetContextPara para;
400     para.challenge = {0, 1};
401     para.atl = ATL2;
402     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
403     auto widgetContext = CreateWidgetContext(contextId, para);
404     std::set<AuthType> authTypeList;
405     authTypeList.insert(FACE);
406     widgetContext->ExecuteAuthList(authTypeList, true, AuthIntent::DEFAULT);
407     AuthType authType = ALL;
408     widgetContext->SuccessAuth(authType);
409     EXPECT_NE(widgetContext, nullptr);
410     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461c02() 411     handler->EnsureTask([]() {});
412 }
413 
414 HWTEST_F(WidgetContextTest, WidgetContextTestSuccessAuth_004, TestSize.Level0)
415 {
416     uint64_t contextId = 1;
417     ContextFactory::AuthWidgetContextPara para;
418     auto widgetContext = CreateWidgetContext(contextId, para);
419     AuthType authType = ALL;
420     widgetContext->SetLatestError(ResultCode::COMPLEXITY_CHECK_FAILED);
421     widgetContext->SuccessAuth(authType);
422     EXPECT_NE(widgetContext, nullptr);
423     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461d02() 424     handler->EnsureTask([]() {});
425 }
426 
427 HWTEST_F(WidgetContextTest, WidgetContextTestExecuteAuthList_0001, TestSize.Level0)
428 {
429     uint64_t contextId = 1;
430     ContextFactory::AuthWidgetContextPara para;
431     auto widgetContext = Common::MakeShared<WidgetContext>(contextId, para, nullptr, nullptr);
432     std::set<AuthType> authTypeList;
433     widgetContext->ExecuteAuthList(authTypeList, false, AuthIntent::DEFAULT);
434     EXPECT_NE(widgetContext, nullptr);
435     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461e02() 436     handler->EnsureTask([]() {});
437 }
438 
439 HWTEST_F(WidgetContextTest, WidgetContextTestExecuteAuthList_0002, TestSize.Level0)
440 {
441     uint64_t contextId = 1;
442     ContextFactory::AuthWidgetContextPara para;
443     auto widgetContext = Common::MakeShared<WidgetContext>(contextId, para, nullptr, nullptr);
444     std::set<AuthType> authTypeList;
445     authTypeList.insert(AuthType::PIN);
446     widgetContext->ExecuteAuthList(authTypeList, true, AuthIntent::DEFAULT);
447     EXPECT_NE(widgetContext, nullptr);
448     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8461f02() 449     handler->EnsureTask([]() {});
450 }
451 
452 HWTEST_F(WidgetContextTest, WidgetContextTestExecuteAuthList_0003, TestSize.Level0)
453 {
454     uint64_t contextId = 1;
455     ContextFactory::AuthWidgetContextPara para;
456     para.challenge = {0, 1};
457     para.atl = AuthTrustLevel::ATL1;
458     auto contextCallback = Common::MakeShared<MockContextCallback>();
459     auto widgetContext = Common::MakeShared<WidgetContext>(contextId, para, contextCallback, nullptr);
460     std::set<AuthType> authTypeList;
461     authTypeList.insert(AuthType::PIN);
462     widgetContext->ExecuteAuthList(authTypeList, false, AuthIntent::DEFAULT);
463     EXPECT_NE(widgetContext, nullptr);
464     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462002() 465     handler->EnsureTask([]() {});
466 }
467 
468 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReloadInit, TestSize.Level0)
469 {
470     uint64_t contextId = 1;
471     ContextFactory::AuthWidgetContextPara para;
472     auto widgetContext = CreateWidgetContext(contextId, para);
473     widgetContext->AuthWidgetReloadInit();
474     EXPECT_NE(widgetContext, nullptr);
475     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462102() 476     handler->EnsureTask([]() {});
477 }
478 
479 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0001, TestSize.Level0)
480 {
481     uint64_t contextId = 1;
482     ContextFactory::AuthWidgetContextPara para;
483     auto widgetContext = CreateWidgetContext(contextId, para);
484     uint32_t orientation = 1;
485     uint32_t needRotate = 1;
486     uint32_t alreadyLoad = 1;
487     AuthType rotateAuthType = PIN;
488     widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
489     EXPECT_NE(widgetContext, nullptr);
490     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462202() 491     handler->EnsureTask([]() {});
492 }
493 
494 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0002, TestSize.Level0)
495 {
496     uint64_t contextId = 1;
497     ContextFactory::AuthWidgetContextPara para;
498     auto widgetContext = CreateWidgetContext(contextId, para);
499     uint32_t orientation = 2;
500     uint32_t needRotate = 1;
501     uint32_t alreadyLoad = 1;
502     AuthType rotateAuthType = FINGERPRINT;
503     widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
504     EXPECT_NE(widgetContext, nullptr);
505     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462302() 506     handler->EnsureTask([]() {});
507 }
508 
509 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0003, TestSize.Level0)
510 {
511     uint64_t contextId = 1;
512     ContextFactory::AuthWidgetContextPara para;
513     auto widgetContext = CreateWidgetContext(contextId, para);
514     uint32_t orientation = 3;
515     uint32_t needRotate = 1;
516     uint32_t alreadyLoad = 1;
517     AuthType rotateAuthType = FACE;
518     widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
519     EXPECT_NE(widgetContext, nullptr);
520     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462402() 521     handler->EnsureTask([]() {});
522 }
523 
524 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0004, TestSize.Level0)
525 {
526     uint64_t contextId = 1;
527     ContextFactory::AuthWidgetContextPara para;
528     auto widgetContext = CreateWidgetContext(contextId, para);
529     uint32_t orientation = 2;
530     uint32_t needRotate = 1;
531     uint32_t alreadyLoad = 0;
532     AuthType rotateAuthType = FACE;
533     widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
534     EXPECT_NE(widgetContext, nullptr);
535     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462502() 536     handler->EnsureTask([]() {});
537 }
538 
539 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0005, TestSize.Level0)
540 {
541     uint64_t contextId = 1;
542     ContextFactory::AuthWidgetContextPara para;
543     auto widgetContext = CreateWidgetContext(contextId, para);
544     uint32_t orientation = 3;
545     uint32_t needRotate = 1;
546     uint32_t alreadyLoad = 0;
547     AuthType rotateAuthType = FACE;
548     widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
549     EXPECT_NE(widgetContext, nullptr);
550     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462602() 551     handler->EnsureTask([]() {});
552 }
553 
554 HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0006, TestSize.Level0)
555 {
556     uint64_t contextId = 1;
557     ContextFactory::AuthWidgetContextPara para;
558     auto widgetContext = CreateWidgetContext(contextId, para);
559     uint32_t orientation = 1;
560     uint32_t needRotate = 1;
561     uint32_t alreadyLoad = 0;
562     AuthType rotateAuthType = FACE;
563     WidgetCmdParameters widgetCmdParameters;
564     WidgetContext::WidgetRotatePara widgetRotatePara;
565     widgetRotatePara.orientation = 3;
566     widgetRotatePara.isReload = 0;
567     widgetRotatePara.needRotate = 0;
568     widgetContext->ProcessRotatePara(widgetCmdParameters, widgetRotatePara);
569     widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
570     EXPECT_NE(widgetContext, nullptr);
571     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462702() 572     handler->EnsureTask([]() {});
573 }
574 
575 HWTEST_F(WidgetContextTest, WidgetContextTestProcessRotatePara, TestSize.Level0)
576 {
577     uint64_t contextId = 1;
578     ContextFactory::AuthWidgetContextPara para;
579     auto widgetContext = CreateWidgetContext(contextId, para);
580     WidgetCmdParameters widgetCmdParameters;
581     WidgetContext::WidgetRotatePara widgetRotatePara;
582     widgetRotatePara.orientation = 2;
583     widgetRotatePara.isReload = 0;
584     widgetRotatePara.needRotate = 1;
585     widgetContext->ProcessRotatePara(widgetCmdParameters, widgetRotatePara);
586     EXPECT_NE(widgetContext, nullptr);
587     auto handler = ThreadHandler::GetSingleThreadInstance();
__anon5a97f8462802() 588     handler->EnsureTask([]() {});
589 }
590 
591 HWTEST_F(WidgetContextTest, WidgetContextTestGetUserId, TestSize.Level0)
592 {
593     uint64_t contextId = 1;
594     ContextFactory::AuthWidgetContextPara para;
595     auto widgetContext = CreateWidgetContext(contextId, para);
596     EXPECT_NE(widgetContext, nullptr);
597     widgetContext->GetUserId();
598 }
599 
600 HWTEST_F(WidgetContextTest, WidgetContextTestOnResult, TestSize.Level0)
601 {
602     uint64_t contextId = 1;
603     ContextFactory::AuthWidgetContextPara para;
604     auto widgetContext = CreateWidgetContext(contextId, para);
605     EXPECT_NE(widgetContext, nullptr);
606     std::shared_ptr<Attributes> scheduleResultAttr = Common::MakeShared<Attributes>();
607     EXPECT_NE(scheduleResultAttr, nullptr);
608     int32_t resultCode = 2;
609     widgetContext->OnResult(resultCode, scheduleResultAttr);
610 }
611 
612 HWTEST_F(WidgetContextTest, WidgetContextTestIsSingleFaceOrFingerPrintAuth_001, TestSize.Level0)
613 {
614     uint64_t contextId = 1;
615     ContextFactory::AuthWidgetContextPara para;
616     para.authTypeList.push_back(FACE);
617     auto widgetContext = CreateWidgetContext(contextId, para);
618     EXPECT_NE(widgetContext, nullptr);
619     EXPECT_TRUE(widgetContext->IsSingleFaceOrFingerPrintAuth());
620 }
621 
622 HWTEST_F(WidgetContextTest, WidgetContextTestIsSingleFaceOrFingerPrintAuth_002, TestSize.Level0)
623 {
624     uint64_t contextId = 1;
625     ContextFactory::AuthWidgetContextPara para;
626     para.authTypeList.push_back(FINGERPRINT);
627     auto widgetContext = CreateWidgetContext(contextId, para);
628     EXPECT_NE(widgetContext, nullptr);
629     EXPECT_TRUE(widgetContext->IsSingleFaceOrFingerPrintAuth());
630 }
631 
632 HWTEST_F(WidgetContextTest, WidgetContextTestIsSingleFaceOrFingerPrintAuth_003, TestSize.Level0)
633 {
634     uint64_t contextId = 1;
635     ContextFactory::AuthWidgetContextPara para;
636     para.authTypeList.push_back(FACE);
637     para.widgetParam.navigationButtonText = "111";
638     auto widgetContext = CreateWidgetContext(contextId, para);
639     EXPECT_NE(widgetContext, nullptr);
640     EXPECT_TRUE(!widgetContext->IsSingleFaceOrFingerPrintAuth());
641 }
642 
643 HWTEST_F(WidgetContextTest, WidgetContextTestIsSingleFaceOrFingerPrintAuth_004, TestSize.Level0)
644 {
645     uint64_t contextId = 1;
646     ContextFactory::AuthWidgetContextPara para;
647     para.authTypeList.push_back(FACE);
648     para.authTypeList.push_back(FINGERPRINT);
649     auto widgetContext = CreateWidgetContext(contextId, para);
650     EXPECT_NE(widgetContext, nullptr);
651     EXPECT_TRUE(!widgetContext->IsSingleFaceOrFingerPrintAuth());
652 }
653 
654 HWTEST_F(WidgetContextTest, WidgetContextTestIsNavigationAuth_001, TestSize.Level0)
655 {
656     uint64_t contextId = 1;
657     ContextFactory::AuthWidgetContextPara para;
658     para.authTypeList.push_back(FACE);
659     para.widgetParam.navigationButtonText = "111";
660     auto widgetContext = CreateWidgetContext(contextId, para);
661     EXPECT_NE(widgetContext, nullptr);
662     EXPECT_TRUE(widgetContext->IsNavigationAuth());
663 }
664 
665 HWTEST_F(WidgetContextTest, WidgetContextTestIsNavigationAuth_002, TestSize.Level0)
666 {
667     uint64_t contextId = 1;
668     ContextFactory::AuthWidgetContextPara para;
669     para.authTypeList.push_back(FACE);
670     auto widgetContext = CreateWidgetContext(contextId, para);
671     EXPECT_NE(widgetContext, nullptr);
672     EXPECT_TRUE(!widgetContext->IsNavigationAuth());
673 }
674 
675 HWTEST_F(WidgetContextTest, WidgetContextTestSendAuthTipInfo, TestSize.Level0)
676 {
677     uint64_t contextId = 1;
678     ContextFactory::AuthWidgetContextPara para;
679     auto widgetContext = CreateWidgetContext(contextId, para);
680     EXPECT_NE(widgetContext, nullptr);
681     int32_t authType = FACE;
682     int32_t tipCode = TIP_CODE_FAIL;
683     EXPECT_NO_THROW(widgetContext->SendAuthTipInfo(authType, tipCode));
684 }
685 
686 HWTEST_F(WidgetContextTest, WidgetContextTestGetAuthTipCode, TestSize.Level0)
687 {
688     uint64_t contextId = 1;
689     ContextFactory::AuthWidgetContextPara para;
690     auto widgetContext = CreateWidgetContext(contextId, para);
691     EXPECT_NE(widgetContext, nullptr);
692     EXPECT_EQ(widgetContext->GetAuthTipCode(ResultCode::TIMEOUT, 0), TIP_CODE_TIMEOUT);
693     EXPECT_EQ(widgetContext->GetAuthTipCode(ResultCode::FAIL, 1), TIP_CODE_COMPARE_FAIL_WITH_FROZEN);
694     EXPECT_EQ(widgetContext->GetAuthTipCode(ResultCode::FAIL, INT32_MAX), TIP_CODE_COMPARE_FAIL_WITH_FROZEN);
695     EXPECT_EQ(widgetContext->GetAuthTipCode(ResultCode::FAIL, -1), TIP_CODE_FAIL);
696     EXPECT_EQ(widgetContext->GetAuthTipCode(ResultCode::LOCKED, 1), TIP_CODE_TEMPORARILY_LOCKED);
697     EXPECT_EQ(widgetContext->GetAuthTipCode(ResultCode::LOCKED, INT32_MAX), TIP_CODE_PERMANENTLY_LOCKED);
698 }
699 
700 HWTEST_F(WidgetContextTest, WidgetContextTestProcAuthResult, TestSize.Level0)
701 {
702     uint64_t contextId = 1;
703     ContextFactory::AuthWidgetContextPara para;
704     auto widgetContext = CreateWidgetContext(contextId, para);
705     EXPECT_NE(widgetContext, nullptr);
706     const Attributes attribute;
707     EXPECT_NO_THROW(widgetContext->ProcAuthResult(ResultCode::SUCCESS, PIN, 0, attribute));
708     EXPECT_NO_THROW(widgetContext->ProcAuthResult(ResultCode::COMPLEXITY_CHECK_FAILED, PIN, 0, attribute));
709     EXPECT_NO_THROW(widgetContext->ProcAuthResult(ResultCode::FAIL, PIN, 0, attribute));
710 }
711 
712 HWTEST_F(WidgetContextTest, WidgetContextTestProcAuthTipInfo, TestSize.Level0)
713 {
714     uint64_t contextId = 1;
715     ContextFactory::AuthWidgetContextPara para;
716     auto widgetContext = CreateWidgetContext(contextId, para);
717     EXPECT_NE(widgetContext, nullptr);
718     std::vector<uint8_t> extraInfo;
719     EXPECT_NO_THROW(widgetContext->ProcAuthTipInfo(USER_AUTH_TIP_SINGLE_AUTH_RESULT, PIN, extraInfo));
720     EXPECT_NO_THROW(widgetContext->ProcAuthTipInfo(0, PIN, extraInfo));
721 }
722 
723 HWTEST_F(WidgetContextTest, WidgetContextTestSetSysDialogZOrder, TestSize.Level0)
724 {
725     uint64_t contextId = 1;
726     ContextFactory::AuthWidgetContextPara para;
727     auto widgetContext = CreateWidgetContext(contextId, para);
728     EXPECT_NE(widgetContext, nullptr);
729     WidgetCmdParameters widgetCmdParameters = {};
730     EXPECT_NO_THROW(widgetContext->SetSysDialogZOrder(widgetCmdParameters));
731     widgetContext->para_.callerName = "findnetwork";
732     widgetContext->para_.callerType = Security::AccessToken::TOKEN_NATIVE;
733     EXPECT_NO_THROW(widgetContext->SetSysDialogZOrder(widgetCmdParameters));
734 }
735 
736 HWTEST_F(WidgetContextTest, WidgetContextTestConnectExtension, TestSize.Level0)
737 {
738     uint64_t contextId = 1;
739     ContextFactory::AuthWidgetContextPara para;
740     auto widgetContext = CreateWidgetContext(contextId, para);
741     EXPECT_NE(widgetContext, nullptr);
742     WidgetContext::WidgetRotatePara widgetRotatePara = {};
743     widgetRotatePara.isReload = true;
744     AuthType authType = AuthType::FACE;
745     widgetContext->para_.authTypeList.emplace_back(authType);
746     EXPECT_EQ(widgetContext->ConnectExtension(widgetRotatePara), false);
747 }
748 } // namespace UserAuth
749 } // namespace UserIam
750 } // namespace OHOS