1 /*
2 * Copyright (c) 2021-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 "core/common/flutter/flutter_task_executor.h"
19 #define private public
20 #define protected public
21 #include "bridge/plugin_frontend/plugin_frontend.h"
22 #undef private
23 #undef protected
24 #include "base/test/mock/mock_asset_manager.h"
25 #include "core/common/test/mock/mock_resource_register.h"
26
27 using namespace testing;
28 using namespace testing::ext;
29
30 namespace OHOS::Ace {
31 namespace {
32 const std::string LABEL = "task executor";
33 const std::string THREADFIRST = "thread_1";
34 const std::string THREADSECOND = "thread_2";
35 const std::string THREADTHIRD = "thread_3";
36 const std::string THREADFOURTH = "thread_4";
37 const uint8_t ERROR = -1;
38 const uint8_t DEFAULT = 0;
39 const uint8_t PUSH = 1;
40 const uint8_t REPLACE = 2;
41 const uint8_t BACK = 3;
42 } // namespace
43 class PluginFrontendTest : public testing::Test {
44 public:
SetUpTestCase()45 static void SetUpTestCase() {}
TearDownTestCase()46 static void TearDownTestCase() {}
SetUp()47 void SetUp() {}
TearDown()48 void TearDown() {}
49 static RefPtr<PipelineContext> GetPipelineContext(const RefPtr<PluginFrontend>& frontend);
50 };
51
GetPipelineContext(const RefPtr<PluginFrontend> & frontend)52 RefPtr<PipelineContext> PluginFrontendTest::GetPipelineContext(const RefPtr<PluginFrontend>& frontend)
53 {
54 auto platformWindow = PlatformWindow::Create(nullptr);
55 auto window = std::make_unique<Window>(std::move(platformWindow));
56
57 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
58
59 auto assetManager = Referenced::MakeRefPtr<MockAssetManager>();
60 auto resRegister = Referenced::MakeRefPtr<MockResourceRegister>();
61 return AceType::MakeRefPtr<PipelineContext>(
62 std::move(window), taskExecutor, assetManager, resRegister, frontend, 0);
63 }
64
65 /**
66 * @tc.name: OnBackPressedTest001
67 * @tc.desc: Verify the OnBackPressed Interface of PluginFrontend work correctly.
68 * @tc.type: FUNC
69 */
70 HWTEST_F(PluginFrontendTest, OnBackPressedTest001, TestSize.Level1)
71 {
72 /**
73 * @tc.steps: step1. Build a PluginFrontend.
74 */
75 PluginFrontend pluginFrontend;
76
77 /**
78 * @tc.steps: step2. On Back Pressed.
79 * @tc.expected: step2. On Back Pressed return false.
80 */
81 EXPECT_EQ(pluginFrontend.OnBackPressed(), false);
82 }
83
84 /**
85 * @tc.name: OnShowTest001
86 * @tc.desc: Verify the OnShow Interface of PluginFrontend work success.
87 * @tc.type: FUNC
88 */
89 HWTEST_F(PluginFrontendTest, OnShowTest001, TestSize.Level1)
90 {
91 /**
92 * @tc.steps: step1. Build a PluginFrontend.
93 */
94 PluginFrontend pluginFrontend;
95
96 /**
97 * @tc.steps: step2. On Show.
98 * @tc.expected: step2. On Show success.
99 */
100 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
101 std::string label = LABEL;
102 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
103 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
104 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
105 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
106 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
107 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
108 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
109 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
110 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
111 taskExecutor->InitJsThread(true);
112 taskExecutor->InitOtherThreads(taskRunner);
113 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
114 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
115 pluginFrontend.OnShow();
116 }
117
118 /**
119 * @tc.name: OnShowTest002
120 * @tc.desc: Verify the OnShow Interface of PluginFrontend work fail because delegate is nullptr.
121 * @tc.type: FUNC
122 */
123 HWTEST_F(PluginFrontendTest, OnShowTest002, TestSize.Level1)
124 {
125 /**
126 * @tc.steps: step1. Build a PluginFrontend.
127 */
128 PluginFrontend pluginFrontend;
129
130 /**
131 * @tc.steps: step2. On Show.
132 * @tc.expected: step2. On Show fail.
133 */
134 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
135 pluginFrontend.OnShow();
136 }
137
138 /**
139 * @tc.name: OnHideTest001
140 * @tc.desc: Verify the OnHide Interface of PluginFrontend work success.
141 * @tc.type: FUNC
142 */
143 HWTEST_F(PluginFrontendTest, OnHideTest001, TestSize.Level1)
144 {
145 /**
146 * @tc.steps: step1. Build a PluginFrontend.
147 */
148 PluginFrontend pluginFrontend;
149
150 /**
151 * @tc.steps: step2. On Hide.
152 * @tc.expected: step2. On Hide success.
153 */
154 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
155 std::string label = LABEL;
156 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
157 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
158 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
159 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
160 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
161 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
162 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
163 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
164 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
165 taskExecutor->InitJsThread(true);
166 taskExecutor->InitOtherThreads(taskRunner);
167 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
168 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
169 pluginFrontend.OnHide();
170 }
171
172 /**
173 * @tc.name: OnHideTest002
174 * @tc.desc: Verify the OnHide Interface of PluginFrontend work fail because delegate is nullptr.
175 * @tc.type: FUNC
176 */
177 HWTEST_F(PluginFrontendTest, OnHideTest002, TestSize.Level1)
178 {
179 /**
180 * @tc.steps: step1. Build a PluginFrontend.
181 */
182 PluginFrontend pluginFrontend;
183
184 /**
185 * @tc.steps: step2. On Hide.
186 * @tc.expected: step2. On Hide fail.
187 */
188 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
189 pluginFrontend.OnHide();
190 }
191
192 /**
193 * @tc.name: OnConfigurationUpdatedTest001
194 * @tc.desc: Verify the OnConfigurationUpdated Interface of PluginFrontend work success.
195 * @tc.type: FUNC
196 */
197 HWTEST_F(PluginFrontendTest, OnConfigurationUpdatedTest001, TestSize.Level1)
198 {
199 /**
200 * @tc.steps: step1. Build a PluginFrontend.
201 */
202 PluginFrontend pluginFrontend;
203
204 /**
205 * @tc.steps: step2. On Configuration Updated.
206 * @tc.expected: step2. On Configuration Updated success.
207 */
208 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
209 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
210 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
211 pluginFrontend.OnConfigurationUpdated("data");
212 }
213
214 /**
215 * @tc.name: OnConfigurationUpdatedTest002
216 * @tc.desc: Verify the OnHide Interface of PluginFrontend work fail because delegate is nullptr.
217 * @tc.type: FUNC
218 */
219 HWTEST_F(PluginFrontendTest, OnConfigurationUpdatedTest002, TestSize.Level1)
220 {
221 /**
222 * @tc.steps: step1. Build a PluginFrontend.
223 */
224 PluginFrontend pluginFrontend;
225
226 /**
227 * @tc.steps: step2. On Configuration Updated.
228 * @tc.expected: step2. On Configuration Updated fail.
229 */
230 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
231 pluginFrontend.OnConfigurationUpdated("data");
232 }
233
234 /**
235 * @tc.name: OnActiveTest001
236 * @tc.desc: Verify the On Active Interface of PluginFrontend work success.
237 * @tc.type: FUNC
238 */
239 HWTEST_F(PluginFrontendTest, OnActiveTest001, TestSize.Level1)
240 {
241 /**
242 * @tc.steps: step1. Build a PluginFrontend.
243 */
244 PluginFrontend pluginFrontend;
245
246 /**
247 * @tc.steps: step2. On Active.
248 * @tc.expected: step2. On Configuration Updated success.
249 */
250 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
251 std::string label = LABEL;
252 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
253 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
254 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
255 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
256 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
257 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
258 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
259 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
260 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
261 taskExecutor->InitJsThread(true);
262 taskExecutor->InitOtherThreads(taskRunner);
263 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
264 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
265 pluginFrontend.OnActive();
266 EXPECT_EQ(pluginFrontend.foregroundFrontend_, true);
267 }
268
269 /**
270 * @tc.name: OnActiveTest002
271 * @tc.desc: Verify the OnActive Interface of PluginFrontend work fail because delegate is nullptr.
272 * @tc.type: FUNC
273 */
274 HWTEST_F(PluginFrontendTest, OnActiveTest002, TestSize.Level1)
275 {
276 /**
277 * @tc.steps: step1. Build a PluginFrontend.
278 */
279 PluginFrontend pluginFrontend;
280
281 /**
282 * @tc.steps: step2. On Active.
283 * @tc.expected: step2. On Active fail.
284 */
285 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
286 pluginFrontend.OnActive();
287 EXPECT_EQ(pluginFrontend.foregroundFrontend_, false);
288 }
289
290 /**
291 * @tc.name: OnInactiveTest001
292 * @tc.desc: Verify the On OnInactive Interface of PluginFrontend work success.
293 * @tc.type: FUNC
294 */
295 HWTEST_F(PluginFrontendTest, OnInactiveTest001, TestSize.Level1)
296 {
297 /**
298 * @tc.steps: step1. Build a PluginFrontend.
299 */
300 PluginFrontend pluginFrontend;
301
302 /**
303 * @tc.steps: step2. On Inactive.
304 * @tc.expected: step2. On Inactive success.
305 */
306 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
307 std::string label = LABEL;
308 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
309 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
310 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
311 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
312 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
313 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
314 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
315 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
316 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
317 taskExecutor->InitJsThread(true);
318 taskExecutor->InitOtherThreads(taskRunner);
319 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
320 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
321 pluginFrontend.OnInactive();
322 }
323
324 /**
325 * @tc.name: OnInactiveTest002
326 * @tc.desc: Verify the OnInactive Interface of PluginFrontend work fail because delegate is nullptr.
327 * @tc.type: FUNC
328 */
329 HWTEST_F(PluginFrontendTest, OnInactiveTest002, TestSize.Level1)
330 {
331 /**
332 * @tc.steps: step1. Build a PluginFrontend.
333 */
334 PluginFrontend pluginFrontend;
335
336 /**
337 * @tc.steps: step2. On Active.
338 * @tc.expected: step2. On Active fail.
339 */
340 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
341 pluginFrontend.OnInactive();
342 }
343
344 /**
345 * @tc.name: OnStartContinuationTest001
346 * @tc.desc: Verify the On OnStartContinuation Interface of PluginFrontend work fail because delegate is nullptr.
347 * @tc.type: FUNC
348 */
349 HWTEST_F(PluginFrontendTest, OnStartContinuationTest001, TestSize.Level1)
350 {
351 /**
352 * @tc.steps: step1. Build a PluginFrontend.
353 */
354 PluginFrontend pluginFrontend;
355
356 /**
357 * @tc.steps: step2. On Start Continuation.
358 * @tc.expected: step2. On Start Continuation fail.
359 */
360 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
361 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
362 EXPECT_EQ(pluginFrontend.OnStartContinuation(), false);
363 }
364
365 /**
366 * @tc.name: OnCompleteContinuationTest001
367 * @tc.desc: Verify the OnCompleteContinuation Interface of PluginFrontend work success.
368 * @tc.type: FUNC
369 */
370 HWTEST_F(PluginFrontendTest, OnCompleteContinuationTest001, TestSize.Level1)
371 {
372 /**
373 * @tc.steps: step1. Build a PluginFrontend.
374 */
375 PluginFrontend pluginFrontend;
376
377 /**
378 * @tc.steps: step2.On Complete Continuation.
379 * @tc.expected: step2. On Complete Continuation success.
380 */
381 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
382 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
383 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
384 pluginFrontend.OnCompleteContinuation(0);
385 }
386
387 /**
388 * @tc.name: OnCompleteContinuationTest002
389 * @tc.desc: Verify the OnCompleteContinuation Interface of PluginFrontend work fail because delegate is nullptr.
390 * @tc.type: FUNC
391 */
392 HWTEST_F(PluginFrontendTest, OnCompleteContinuationTest002, TestSize.Level1)
393 {
394 /**
395 * @tc.steps: step1. Build a PluginFrontend.
396 */
397 PluginFrontend pluginFrontend;
398
399 /**
400 * @tc.steps: step2. On Complete Continuation.
401 * @tc.expected: step2. On Complete Continuation fail.
402 */
403 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
404 pluginFrontend.OnCompleteContinuation(0);
405 }
406
407 /**
408 * @tc.name: OnMemoryLevelTest001
409 * @tc.desc: Verify the OnMemoryLevel Interface of PluginFrontend work success.
410 * @tc.type: FUNC
411 */
412 HWTEST_F(PluginFrontendTest, OnMemoryLevelTest001, TestSize.Level1)
413 {
414 /**
415 * @tc.steps: step1. Build a PluginFrontend.
416 */
417 PluginFrontend pluginFrontend;
418
419 /**
420 * @tc.steps: step2. On Memory Level.
421 * @tc.expected: step2. On Memory Level success.
422 */
423 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
424 std::string label = LABEL;
425 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
426 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
427 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
428 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
429 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
430 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
431 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
432 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
433 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
434 taskExecutor->InitJsThread(true);
435 taskExecutor->InitOtherThreads(taskRunner);
436 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
437 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
438 pluginFrontend.OnMemoryLevel(0);
439 }
440
441 /**
442 * @tc.name: OnMemoryLevelTest002
443 * @tc.desc: Verify the OnMemoryLevel Interface of PluginFrontend work fail because delegate is nullptr.
444 * @tc.type: FUNC
445 */
446 HWTEST_F(PluginFrontendTest, OnMemoryLevelTest002, TestSize.Level1)
447 {
448 /**
449 * @tc.steps: step1. Build a PluginFrontend.
450 */
451 PluginFrontend pluginFrontend;
452
453 /**
454 * @tc.steps: step2. On Memory Level.
455 * @tc.expected: step2. On Memory Level fail.
456 */
457 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
458 pluginFrontend.OnMemoryLevel(0);
459 }
460
461 /**
462 * @tc.name: OnSaveDataTest001
463 * @tc.desc: Verify the OnSaveData Interface of PluginFrontend work success.
464 * @tc.type: FUNC
465 */
466 HWTEST_F(PluginFrontendTest, OnSaveDataTest001, TestSize.Level1)
467 {
468 /**
469 * @tc.steps: step1. Build a PluginFrontend.
470 */
471 PluginFrontend pluginFrontend;
472
473 /**
474 * @tc.steps: step2. On Save Data.
475 * @tc.expected: step2. On Save Data success.
476 */
477 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
478 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
479 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
480 std::string data = "data";
481 pluginFrontend.OnSaveData(data);
482 }
483
484 /**
485 * @tc.name: OnMemoryLevelTest002
486 * @tc.desc: Verify the OnMemoryLevel Interface of PluginFrontend work fail because delegate is nullptr.
487 * @tc.type: FUNC
488 */
489 HWTEST_F(PluginFrontendTest, OnSaveDataTest002, TestSize.Level1)
490 {
491 /**
492 * @tc.steps: step1. Build a PluginFrontend.
493 */
494 PluginFrontend pluginFrontend;
495
496 /**
497 * @tc.steps: step2. On Memory Level.
498 * @tc.expected: step2. On Memory Level fail.
499 */
500 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
501 std::string data = "data";
502 pluginFrontend.OnSaveData(data);
503 }
504
505 /**
506 * @tc.name: GetPluginsUsedTest001
507 * @tc.desc: Verify the GetPluginsUsed Interface of PluginFrontend work success.
508 * @tc.type: FUNC
509 */
510 HWTEST_F(PluginFrontendTest, GetPluginsUsedTest001, TestSize.Level1)
511 {
512 /**
513 * @tc.steps: step1. Build a PluginFrontend.
514 */
515 PluginFrontend pluginFrontend;
516
517 /**
518 * @tc.steps: step2. Get Plugins Used.
519 * @tc.expected: step2. Get Plugins Used success.
520 */
521 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
522 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
523 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
524 std::string data = "data";
525 pluginFrontend.GetPluginsUsed(data);
526 }
527
528 /**
529 * @tc.name: GetPluginsUsedTest002
530 * @tc.desc: Verify the GetPluginsUsed Interface of PluginFrontend work fail because delegate is nullptr.
531 * @tc.type: FUNC
532 */
533 HWTEST_F(PluginFrontendTest, GetPluginsUsedTest002, TestSize.Level1)
534 {
535 /**
536 * @tc.steps: step1. Build a PluginFrontend.
537 */
538 PluginFrontend pluginFrontend;
539
540 /**
541 * @tc.steps: step2. Get Plugins Used.
542 * @tc.expected: step2. Get Plugins Used fail.
543 */
544 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
545 std::string data = "data";
546 pluginFrontend.GetPluginsUsed(data);
547 }
548
549 /**
550 * @tc.name: OnRestoreDataTest001
551 * @tc.desc: Verify the OnRestoreDataTest001 Interface of PluginFrontend work fail because delegate is nullptr.
552 * @tc.type: FUNC
553 */
554 HWTEST_F(PluginFrontendTest, OnRestoreDataTest001, TestSize.Level1)
555 {
556 /**
557 * @tc.steps: step1. Build a PluginFrontend.
558 */
559 PluginFrontend pluginFrontend;
560
561 /**
562 * @tc.steps: step2. Get Plugins Used.
563 * @tc.expected: step2. Get Plugins Used fail.
564 */
565 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
566 std::string data = "data";
567 EXPECT_EQ(pluginFrontend.OnRestoreData(data), false);
568 }
569
570 /**
571 * @tc.name: OnRemoteTerminatedTest001
572 * @tc.desc: Verify the OnRemoteTerminated Interface of PluginFrontend work success.
573 * @tc.type: FUNC
574 */
575 HWTEST_F(PluginFrontendTest, OnRemoteTerminatedTest001, TestSize.Level1)
576 {
577 /**
578 * @tc.steps: step1. Build a PluginFrontend.
579 */
580 PluginFrontend pluginFrontend;
581
582 /**
583 * @tc.steps: step2. On Remote Terminated.
584 * @tc.expected: step2. On Remote Terminated success.
585 */
586 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
587 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
588 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
589 pluginFrontend.OnRemoteTerminated();
590 }
591
592 /**
593 * @tc.name: OnRemoteTerminatedTest002
594 * @tc.desc: Verify the GetPluginsUsed Interface of PluginFrontend work fail because delegate is nullptr.
595 * @tc.type: FUNC
596 */
597 HWTEST_F(PluginFrontendTest, OnRemoteTerminatedTest002, TestSize.Level1)
598 {
599 /**
600 * @tc.steps: step1. Build a PluginFrontend.
601 */
602 PluginFrontend pluginFrontend;
603
604 /**
605 * @tc.steps: step2. On Remote Terminated.
606 * @tc.expected: step2. On Remote Terminated fail.
607 */
608 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
609 pluginFrontend.OnRemoteTerminated();
610 }
611
612 /**
613 * @tc.name: OnNewRequestTest001
614 * @tc.desc: Verify the OnNewRequest Interface of PluginFrontend work success.
615 * @tc.type: FUNC
616 */
617 HWTEST_F(PluginFrontendTest, OnNewRequestTest001, TestSize.Level1)
618 {
619 /**
620 * @tc.steps: step1. Build a PluginFrontend.
621 */
622 PluginFrontend pluginFrontend;
623
624 /**
625 * @tc.steps: step2. On Remote Terminated.
626 * @tc.expected: step2. On Remote Terminated success.
627 */
628 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
629 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
630 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
631 std::string data = "data";
632 pluginFrontend.OnNewRequest(data);
633 }
634
635 /**
636 * @tc.name: OnNewRequestTest002
637 * @tc.desc: Verify the OnNewRequest Interface of PluginFrontend work fail because delegate is nullptr.
638 * @tc.type: FUNC
639 */
640 HWTEST_F(PluginFrontendTest, OnNewRequestTest002, TestSize.Level1)
641 {
642 /**
643 * @tc.steps: step1. Build a PluginFrontend.
644 */
645 PluginFrontend pluginFrontend;
646
647 /**
648 * @tc.steps: step2. On New Request.
649 * @tc.expected: step2. On New Request fail.
650 */
651 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
652 std::string data = "data";
653 pluginFrontend.OnNewRequest(data);
654 }
655
656 /**
657 * @tc.name: CallRouterBackTest001
658 * @tc.desc: Verify the CallRouterBack Interface of PluginFrontend work success.
659 * @tc.type: FUNC
660 */
661 HWTEST_F(PluginFrontendTest, CallRouterBackTest001, TestSize.Level1)
662 {
663 /**
664 * @tc.steps: step1. Build a PluginFrontend.
665 */
666 PluginFrontend pluginFrontend;
667
668 /**
669 * @tc.steps: step2. Call Router Back.
670 * @tc.expected: step2. Call Router Back success.
671 */
672 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
673 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
674 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
675 pluginFrontend.CallRouterBack();
676 }
677
678 /**
679 * @tc.name: CallRouterBackTest002
680 * @tc.desc: Verify the CallRouterBack Interface of PluginFrontend work fail because delegate is nullptr.
681 * @tc.type: FUNC
682 */
683 HWTEST_F(PluginFrontendTest, CallRouterBackTest002, TestSize.Level1)
684 {
685 /**
686 * @tc.steps: step1. Build a PluginFrontend.
687 */
688 PluginFrontend pluginFrontend;
689
690 /**
691 * @tc.steps: step2. Call Router Back.
692 * @tc.expected: step2. Call Router Back fail.
693 */
694 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
695 pluginFrontend.CallRouterBack();
696 }
697
698 /**
699 * @tc.name: CallRouterBackTest003
700 * @tc.desc: Verify the CallRouterBack Interface of PluginFrontend work fail because this is the last page of sub
701 * window.
702 * @tc.type: FUNC
703 */
704 HWTEST_F(PluginFrontendTest, CallRouterBackTest003, TestSize.Level1)
705 {
706 /**
707 * @tc.steps: step1. Build a PluginFrontend.
708 */
709 PluginFrontend pluginFrontend;
710
711 /**
712 * @tc.steps: step2. Call Router Back.
713 * @tc.expected: step2. Call Router Back fail.
714 */
715 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
716 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
717 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
718 pluginFrontend.isSubWindow_ = true;
719 pluginFrontend.CallRouterBack();
720 }
721
722 /**
723 * @tc.name: OnSurfaceChangedTest001
724 * @tc.desc: Verify the OnSurfaceChanged Interface of PluginFrontend work success.
725 * @tc.type: FUNC
726 */
727 HWTEST_F(PluginFrontendTest, OnSurfaceChangedTest001, TestSize.Level1)
728 {
729 /**
730 * @tc.steps: step1. Build a PluginFrontend.
731 */
732 PluginFrontend pluginFrontend;
733
734 /**
735 * @tc.steps: step2. On Surface Changed.
736 * @tc.expected: step2. On Surface Changed success.
737 */
738 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
739 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
740 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
741 pluginFrontend.OnSurfaceChanged(0, 0);
742 }
743
744 /**
745 * @tc.name: OnSurfaceChangedTest002
746 * @tc.desc: Verify the OnSurfaceChanged Interface of PluginFrontend work fail because delegate is nullptr.
747 * @tc.type: FUNC
748 */
749 HWTEST_F(PluginFrontendTest, OnSurfaceChangedTest002, TestSize.Level1)
750 {
751 /**
752 * @tc.steps: step1. Build a PluginFrontend.
753 */
754 PluginFrontend pluginFrontend;
755
756 /**
757 * @tc.steps: step2. On Surface Changed.
758 * @tc.expected: step2. On Surface Changed fail.
759 */
760 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
761 pluginFrontend.OnSurfaceChanged(0, 0);
762 }
763
764 /**
765 * @tc.name: DumpFrontendTest001
766 * @tc.desc: Verify the DumpFrontend Interface of PluginFrontend work success.
767 * @tc.type: FUNC
768 */
769 HWTEST_F(PluginFrontendTest, DumpFrontendTest001, TestSize.Level1)
770 {
771 /**
772 * @tc.steps: step1. Build a PluginFrontend.
773 */
774 PluginFrontend pluginFrontend;
775
776 /**
777 * @tc.steps: step2. Dump Frontend.
778 * @tc.expected: step2. Dump Frontend success.
779 */
780 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
781 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
782 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
783 pluginFrontend.DumpFrontend();
784 }
785
786 /**
787 * @tc.name: DumpFrontendTest002
788 * @tc.desc: Verify the DumpFrontend Interface of PluginFrontend work fail because delegate is nullptr.
789 * @tc.type: FUNC
790 */
791 HWTEST_F(PluginFrontendTest, DumpFrontendTest002, TestSize.Level1)
792 {
793 /**
794 * @tc.steps: step1. Build a PluginFrontend.
795 */
796 PluginFrontend pluginFrontend;
797
798 /**
799 * @tc.steps: step2. Dump Frontend.
800 * @tc.expected: step2. Dump Frontend fail.
801 */
802 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
803 pluginFrontend.DumpFrontend();
804 }
805
806 /**
807 * @tc.name: SetColorModeTest002
808 * @tc.desc: Verify the DumpFrontend Interface of PluginFrontend work fail because delegate is nullptr.
809 * @tc.type: FUNC
810 */
811 HWTEST_F(PluginFrontendTest, SetColorModeTest002, TestSize.Level1)
812 {
813 /**
814 * @tc.steps: step1. Build a PluginFrontend.
815 */
816 PluginFrontend pluginFrontend;
817
818 /**
819 * @tc.steps: step2. Set Color Mode.
820 * @tc.expected: step2. Set Color Mode fail.
821 */
822 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
823 pluginFrontend.SetColorMode(ColorMode::LIGHT);
824 }
825
826 /**
827 * @tc.name: RebuildAllPagesTest001
828 * @tc.desc: Verify the RebuildAllPages Interface of PluginFrontend work success.
829 * @tc.type: FUNC
830 */
831 HWTEST_F(PluginFrontendTest, RebuildAllPagesTest001, TestSize.Level1)
832 {
833 /**
834 * @tc.steps: step1. Build a PluginFrontend.
835 */
836 PluginFrontend pluginFrontend;
837
838 /**
839 * @tc.steps: step2. Rebuild AllPagese.
840 * @tc.expected: step2. Rebuild AllPages success.
841 */
842 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
843 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
844 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
845 pluginFrontend.RebuildAllPages();
846 }
847
848 /**
849 * @tc.name: RebuildAllPagesTest002
850 * @tc.desc: Verify the RebuildAllPages Interface of PluginFrontend work fail because delegate is nullptr.
851 * @tc.type: FUNC
852 */
853 HWTEST_F(PluginFrontendTest, RebuildAllPagesTest002, TestSize.Level1)
854 {
855 /**
856 * @tc.steps: step1. Build a PluginFrontend.
857 */
858 PluginFrontend pluginFrontend;
859
860 /**
861 * @tc.steps: step2. Rebuild All Pages.
862 * @tc.expected: step2. Rebuild All Pages fail.
863 */
864 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
865 pluginFrontend.RebuildAllPages();
866 }
867
868 /**
869 * @tc.name: NotifyAppStorageTest001
870 * @tc.desc: Verify the NotifyAppStorage Interface of PluginFrontend work success.
871 * @tc.type: FUNC
872 */
873 HWTEST_F(PluginFrontendTest, NotifyAppStorageTest001, TestSize.Level1)
874 {
875 /**
876 * @tc.steps: step1. Build a PluginFrontend.
877 */
878 PluginFrontend pluginFrontend;
879
880 /**
881 * @tc.steps: step2. Notify App Storage.
882 * @tc.expected: step2. Notify App Storage success.
883 */
884 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
885 std::string label = LABEL;
886 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
887 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
888 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
889 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
890 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
891 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
892 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
893 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
894 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
895 taskExecutor->InitJsThread(true);
896 taskExecutor->InitOtherThreads(taskRunner);
897 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
898 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
899 pluginFrontend.NotifyAppStorage("key", "value");
900 }
901
902 /**
903 * @tc.name: NotifyAppStorageTest002
904 * @tc.desc: Verify the NotifyAppStorage Interface of PluginFrontend work fail because delegate is nullptr.
905 * @tc.type: FUNC
906 */
907 HWTEST_F(PluginFrontendTest, NotifyAppStorageTest002, TestSize.Level1)
908 {
909 /**
910 * @tc.steps: step1. Build a PluginFrontend.
911 */
912 PluginFrontend pluginFrontend;
913
914 /**
915 * @tc.steps: step2. Notify App Storage.
916 * @tc.expected: step2. Notify App Storage fail.
917 */
918 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
919 pluginFrontend.NotifyAppStorage("key", "value");
920 }
921
922 /**
923 * @tc.name: RunPageTest001
924 * @tc.desc: Verify the RunPage Interface of PluginFrontend work success.
925 * @tc.type: FUNC
926 */
927 HWTEST_F(PluginFrontendTest, RunPageTest001, TestSize.Level1)
928 {
929 /**
930 * @tc.steps: step1. Build a PluginFrontend.
931 */
932 PluginFrontend pluginFrontend;
933
934 /**
935 * @tc.steps: step2. Run Page.
936 * @tc.expected: step2. Run Page success.
937 */
938 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
939 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
940 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
941 pluginFrontend.RunPage(0, "url", "params");
942 }
943
944 /**
945 * @tc.name: RunPageTest002
946 * @tc.desc: Verify the RunPage Interface of PluginFrontend work fail because delegate is nullptr.
947 * @tc.type: FUNC
948 */
949 HWTEST_F(PluginFrontendTest, RunPageTest002, TestSize.Level1)
950 {
951 /**
952 * @tc.steps: step1. Build a PluginFrontend.
953 */
954 PluginFrontend pluginFrontend;
955
956 /**
957 * @tc.steps: step2. Run Page.
958 * @tc.expected: step2. Run Page fail.
959 */
960 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
961 pluginFrontend.RunPage(0, "url", "params");
962 }
963
964 /**
965 * @tc.name: ReplacePageTest001
966 * @tc.desc: Verify the ReplacePage Interface of PluginFrontend work success.
967 * @tc.type: FUNC
968 */
969 HWTEST_F(PluginFrontendTest, ReplacePageTest001, TestSize.Level1)
970 {
971 /**
972 * @tc.steps: step1. Build a PluginFrontend.
973 */
974 PluginFrontend pluginFrontend;
975
976 /**
977 * @tc.steps: step2. Replace Page.
978 * @tc.expected: step2. Replace Page success.
979 */
980 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
981 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
982 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
983 pluginFrontend.ReplacePage("url", "params");
984 }
985
986 /**
987 * @tc.name: ReplacePageTest002
988 * @tc.desc: Verify the Replace Page Interface of PluginFrontend work fail because delegate is nullptr.
989 * @tc.type: FUNC
990 */
991 HWTEST_F(PluginFrontendTest, ReplacePageTest002, TestSize.Level1)
992 {
993 /**
994 * @tc.steps: step1. Build a PluginFrontend.
995 */
996 PluginFrontend pluginFrontend;
997
998 /**
999 * @tc.steps: step2. Replace Page.
1000 * @tc.expected: step2. Replace Page fail.
1001 */
1002 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1003 pluginFrontend.ReplacePage("url", "params");
1004 }
1005
1006 /**
1007 * @tc.name: PushPageTest001
1008 * @tc.desc: Verify the PushPage Interface of PluginFrontend work success.
1009 * @tc.type: FUNC
1010 */
1011 HWTEST_F(PluginFrontendTest, PushPageTest001, TestSize.Level1)
1012 {
1013 /**
1014 * @tc.steps: step1. Build a PluginFrontend.
1015 */
1016 PluginFrontend pluginFrontend;
1017
1018 /**
1019 * @tc.steps: step2. Push Page.
1020 * @tc.expected: step2. Push Page success.
1021 */
1022 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1023 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1024 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1025 pluginFrontend.ReplacePage("url", "params");
1026 }
1027
1028 /**
1029 * @tc.name: PushPageTest002
1030 * @tc.desc: Verify the Push Page Interface of PluginFrontend work fail because delegate is nullptr.
1031 * @tc.type: FUNC
1032 */
1033 HWTEST_F(PluginFrontendTest, PushPageTest002, TestSize.Level1)
1034 {
1035 /**
1036 * @tc.steps: step1. Build a PluginFrontend.
1037 */
1038 PluginFrontend pluginFrontend;
1039
1040 /**
1041 * @tc.steps: step2. Push Page.
1042 * @tc.expected: step2. Push Page fail.
1043 */
1044 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1045 pluginFrontend.PushPage("url", "params");
1046 }
1047
1048 /**
1049 * @tc.name: NavigatePageTest001
1050 * @tc.desc: Verify the NavigatePage Interface of PluginFrontend work success type is PUSH.
1051 * @tc.type: FUNC
1052 */
1053 HWTEST_F(PluginFrontendTest, NavigatePageTest001, TestSize.Level1)
1054 {
1055 /**
1056 * @tc.steps: step1. Build a PluginFrontend.
1057 */
1058 PluginFrontend pluginFrontend;
1059
1060 /**
1061 * @tc.steps: step2. Navigate Page.
1062 * @tc.expected: step2. Navigate Page success.
1063 */
1064 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1065 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1066 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1067 pluginFrontend.NavigatePage(PUSH, PageTarget("uri"), "params");
1068 }
1069
1070 /**
1071 * @tc.name: NavigatePageTest002
1072 * @tc.desc: Verify the NavigatePage Interface of PluginFrontend work success type is REPLACE.
1073 * @tc.type: FUNC
1074 */
1075 HWTEST_F(PluginFrontendTest, NavigatePageTest002, TestSize.Level1)
1076 {
1077 /**
1078 * @tc.steps: step1. Build a PluginFrontend.
1079 */
1080 PluginFrontend pluginFrontend;
1081
1082 /**
1083 * @tc.steps: step2. Navigate Page.
1084 * @tc.expected: step2. Navigate Page success.
1085 */
1086 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1087 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1088 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1089 pluginFrontend.NavigatePage(REPLACE, PageTarget("uri"), "params");
1090 }
1091
1092 /**
1093 * @tc.name: NavigatePageTest003
1094 * @tc.desc: Verify the NavigatePage Interface of PluginFrontend work success type is BACK.
1095 * @tc.type: FUNC
1096 */
1097 HWTEST_F(PluginFrontendTest, NavigatePageTest003, TestSize.Level1)
1098 {
1099 /**
1100 * @tc.steps: step1. Build a PluginFrontend.
1101 */
1102 PluginFrontend pluginFrontend;
1103
1104 /**
1105 * @tc.steps: step2. Navigate Page.
1106 * @tc.expected: step2. Navigate Page success.
1107 */
1108 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1109 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1110 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1111 pluginFrontend.NavigatePage(BACK, PageTarget("uri"), "params");
1112 }
1113
1114 /**
1115 * @tc.name: NavigatePageTest004
1116 * @tc.desc: Verify the NavigatePage Interface of PluginFrontend work success type is DEFAULT.
1117 * @tc.type: FUNC
1118 */
1119 HWTEST_F(PluginFrontendTest, NavigatePageTest004, TestSize.Level1)
1120 {
1121 /**
1122 * @tc.steps: step1. Build a PluginFrontend.
1123 */
1124 PluginFrontend pluginFrontend;
1125
1126 /**
1127 * @tc.steps: step2. Navigate Page.
1128 * @tc.expected: step2. Navigate Page success.
1129 */
1130 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1131 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1132 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1133 pluginFrontend.NavigatePage(DEFAULT, PageTarget("uri"), "params");
1134 }
1135
1136 /**
1137 * @tc.name: NavigatePageTest005
1138 * @tc.desc: Verify the NavigatePage Interface of PluginFrontend work fail because delegate is nullptr.
1139 * @tc.type: FUNC
1140 */
1141 HWTEST_F(PluginFrontendTest, NavigatePageTest005, TestSize.Level1)
1142 {
1143 /**
1144 * @tc.steps: step1. Build a PluginFrontend.
1145 */
1146 PluginFrontend pluginFrontend;
1147
1148 /**
1149 * @tc.steps: step2. Send Callback Message.
1150 * @tc.expected: step2. Send Callback Message fail.
1151 */
1152 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1153 pluginFrontend.NavigatePage(DEFAULT, PageTarget("uri"), "params");
1154 }
1155
1156 /**
1157 * @tc.name: SendCallbackMessageTest001
1158 * @tc.desc: Verify the SendCallbackMessage Interface of PluginFrontend work success.
1159 * @tc.type: FUNC
1160 */
1161 HWTEST_F(PluginFrontendTest, SendCallbackMessageTest001, TestSize.Level1)
1162 {
1163 /**
1164 * @tc.steps: step1. Build a PluginFrontend.
1165 */
1166 PluginFrontend pluginFrontend;
1167
1168 /**
1169 * @tc.steps: step2. Send Callback Message.
1170 * @tc.expected: step2. Send Callback Message success.
1171 */
1172 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1173 std::string label = LABEL;
1174 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1175 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1176 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1177 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1178 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1179 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1180 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1181 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1182 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1183 taskExecutor->InitJsThread(true);
1184 taskExecutor->InitOtherThreads(taskRunner);
1185 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1186 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1187 pluginFrontend.SendCallbackMessage("callbackId", "data");
1188 }
1189
1190 /**
1191 * @tc.name: SendCallbackMessageTest002
1192 * @tc.desc: Verify the SendCallbackMessage Interface of PluginFrontend work fail because delegate is nullptr.
1193 * @tc.type: FUNC
1194 */
1195 HWTEST_F(PluginFrontendTest, SendCallbackMessageTest002, TestSize.Level1)
1196 {
1197 /**
1198 * @tc.steps: step1. Build a PluginFrontend.
1199 */
1200 PluginFrontend pluginFrontend;
1201
1202 /**
1203 * @tc.steps: step2. Send Callback Message.
1204 * @tc.expected: step2. Send Callback Message fail.
1205 */
1206 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1207 pluginFrontend.SendCallbackMessage("callbackId", "data");
1208 }
1209
1210 /**
1211 * @tc.name: TransferComponentResponseDataTest001
1212 * @tc.desc: Verify the TransferComponentResponseData Interface of PluginFrontend work success.
1213 * @tc.type: FUNC
1214 */
1215 HWTEST_F(PluginFrontendTest, TransferComponentResponseDataTest001, TestSize.Level1)
1216 {
1217 /**
1218 * @tc.steps: step1. Build a PluginFrontend.
1219 */
1220 RefPtr<PluginFrontend> pluginFrontend = Referenced::MakeRefPtr<PluginFrontend>();
1221
1222 /**
1223 * @tc.steps: step2. Transfer Component Response Data.
1224 * @tc.expected: step2. Transfer Component Response Data success.
1225 */
1226 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1227 std::string label = LABEL;
1228 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1229 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1230 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1231 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1232 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1233 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1234 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1235 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1236 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1237 taskExecutor->InitJsThread(true);
1238 taskExecutor->InitOtherThreads(taskRunner);
1239 pluginFrontend->Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1240 EXPECT_TRUE(pluginFrontend->delegate_ != nullptr);
1241 std::vector<uint8_t> vec = { 0, 0 };
1242 pluginFrontend->delegate_->AttachPipelineContext(PluginFrontendTest::GetPipelineContext(pluginFrontend));
1243 pluginFrontend->TransferComponentResponseData(0, 0, std::move(vec));
1244 }
1245
1246 /**
1247 * @tc.name: TransferComponentResponseDataTest002
1248 * @tc.desc: Verify the TransferComponentResponseData Interface of PluginFrontend work fail because delegate is nullptr.
1249 * @tc.type: FUNC
1250 */
1251 HWTEST_F(PluginFrontendTest, TransferComponentResponseDataTest002, TestSize.Level1)
1252 {
1253 /**
1254 * @tc.steps: step1. Build a PluginFrontend.
1255 */
1256 PluginFrontend pluginFrontend;
1257
1258 /**
1259 * @tc.steps: step2. Transfer Component Response Data.
1260 * @tc.expected: step2. Transfer Component Response Data fail.
1261 */
1262 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1263 std::vector<uint8_t> vec { 0, 0 };
1264 pluginFrontend.TransferComponentResponseData(0, 0, std::move(vec));
1265 }
1266
1267 /**
1268 * @tc.name: TransferJsResponseDataTest001
1269 * @tc.desc: Verify the TransferJsResponseData Interface of PluginFrontend work success.
1270 * @tc.type: FUNC
1271 */
1272 HWTEST_F(PluginFrontendTest, TransferJsResponseDataTest001, TestSize.Level1)
1273 {
1274 /**
1275 * @tc.steps: step1. Build a PluginFrontend.
1276 */
1277 PluginFrontend pluginFrontend;
1278
1279 /**
1280 * @tc.steps: step2. Transfer Js Response Data.
1281 * @tc.expected: step2. Transfer Js ResponseData success.
1282 */
1283 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1284 std::string label = LABEL;
1285 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1286 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1287 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1288 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1289 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1290 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1291 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1292 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1293 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1294 taskExecutor->InitJsThread(true);
1295 taskExecutor->InitOtherThreads(taskRunner);
1296 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1297 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1298 std::vector<uint8_t> vec = { 0, 0 };
1299 pluginFrontend.TransferJsResponseData(0, 0, std::move(vec));
1300 }
1301
1302 /**
1303 * @tc.name: TransferJsResponseDataTest002
1304 * @tc.desc: Verify the TransferJsResponseData Interface of PluginFrontend work fail because delegate is nullptr.
1305 * @tc.type: FUNC
1306 */
1307 HWTEST_F(PluginFrontendTest, TransferJsResponseDataTest002, TestSize.Level1)
1308 {
1309 /**
1310 * @tc.steps: step1. Build a PluginFrontend.
1311 */
1312 PluginFrontend pluginFrontend;
1313
1314 /**
1315 * @tc.steps: step2. Transfer Js Response Data.
1316 * @tc.expected: step2. Transfer Js Response Data fail.
1317 */
1318 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1319 std::vector<uint8_t> vec { 0, 0 };
1320 pluginFrontend.TransferJsResponseData(0, 0, std::move(vec));
1321 }
1322
1323 /**
1324 * @tc.name: TransferJsPluginGetErrorTest001
1325 * @tc.desc: Verify the TransferJsPluginGetError Interface of PluginFrontend work success.
1326 * @tc.type: FUNC
1327 */
1328 HWTEST_F(PluginFrontendTest, TransferJsPluginGetErrorTest001, TestSize.Level1)
1329 {
1330 /**
1331 * @tc.steps: step1. Build a PluginFrontend.
1332 */
1333 PluginFrontend pluginFrontend;
1334
1335 /**
1336 * @tc.steps: step2. Transfer Js Response Data.
1337 * @tc.expected: step2. Transfer Js ResponseData success.
1338 */
1339 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1340 std::string label = LABEL;
1341 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1342 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1343 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1344 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1345 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1346 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1347 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1348 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1349 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1350 taskExecutor->InitJsThread(true);
1351 taskExecutor->InitOtherThreads(taskRunner);
1352 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1353 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1354 std::string errorMessage { "errorMessage" };
1355 pluginFrontend.TransferJsPluginGetError(0, 0, std::move(errorMessage));
1356 }
1357
1358 /**
1359 * @tc.name: TransferJsPluginGetErrorTest002
1360 * @tc.desc: Verify the TransferJsPluginGetError Interface of PluginFrontend work fail because delegate is nullptr.
1361 * @tc.type: FUNC
1362 */
1363 HWTEST_F(PluginFrontendTest, TransferJsPluginGetErrorTest002, TestSize.Level1)
1364 {
1365 /**
1366 * @tc.steps: step1. Build a PluginFrontend.
1367 */
1368 PluginFrontend pluginFrontend;
1369
1370 /**
1371 * @tc.steps: step2. Transfer Js Response Data.
1372 * @tc.expected: step2. Transfer Js Response Data fail.
1373 */
1374 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1375 std::string errorMessage { "errorMessage" };
1376 pluginFrontend.TransferJsPluginGetError(0, 0, std::move(errorMessage));
1377 }
1378
1379 /**
1380 * @tc.name: TransferJsEventDataTest001
1381 * @tc.desc: Verify the TransferJsEventData Interface of PluginFrontend work success.
1382 * @tc.type: FUNC
1383 */
1384 HWTEST_F(PluginFrontendTest, TransferJsEventDataTest001, TestSize.Level1)
1385 {
1386 /**
1387 * @tc.steps: step1. Build a PluginFrontend.
1388 */
1389 PluginFrontend pluginFrontend;
1390
1391 /**
1392 * @tc.steps: step2. Transfer Js Event Data.
1393 * @tc.expected: step2. Transfer Js EventData success.
1394 */
1395 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1396 std::string label = LABEL;
1397 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1398 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1399 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1400 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1401 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1402 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1403 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1404 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1405 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1406 taskExecutor->InitJsThread(true);
1407 taskExecutor->InitOtherThreads(taskRunner);
1408 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1409 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1410 std::vector<uint8_t> vec { 0, 0 };
1411 pluginFrontend.TransferJsEventData(0, 0, std::move(vec));
1412 }
1413
1414 /**
1415 * @tc.name: TransferJsEventDataTest002
1416 * @tc.desc: Verify the TransferJsEventData Interface of PluginFrontend work fail because delegate is nullptr.
1417 * @tc.type: FUNC
1418 */
1419 HWTEST_F(PluginFrontendTest, TransferJsEventDataTest002, TestSize.Level1)
1420 {
1421 /**
1422 * @tc.steps: step1. Build a PluginFrontend.
1423 */
1424 PluginFrontend pluginFrontend;
1425
1426 /**
1427 * @tc.steps: step2. Transfer Js Event Data.
1428 * @tc.expected: step2. Transfer Js Event Data fail.
1429 */
1430 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1431 std::vector<uint8_t> vec { 0, 0 };
1432 pluginFrontend.TransferJsEventData(0, 0, std::move(vec));
1433 }
1434
1435 /**
1436 * @tc.name: LoadPluginJsCodeTest001
1437 * @tc.desc: Verify the LoadPluginJsCode Interface of PluginFrontend work success.
1438 * @tc.type: FUNC
1439 */
1440 HWTEST_F(PluginFrontendTest, LoadPluginJsCodeTest001, TestSize.Level1)
1441 {
1442 /**
1443 * @tc.steps: step1. Build a PluginFrontend.
1444 */
1445 PluginFrontend pluginFrontend;
1446
1447 /**
1448 * @tc.steps: step2. Transfer Js Event Data.
1449 * @tc.expected: step2. Transfer Js EventData success.
1450 */
1451 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1452 std::string label = LABEL;
1453 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1454 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1455 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1456 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1457 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1458 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1459 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1460 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1461 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1462 taskExecutor->InitJsThread(true);
1463 taskExecutor->InitOtherThreads(taskRunner);
1464 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1465 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1466 std::string vecJsCode { "JsCode" };
1467 pluginFrontend.LoadPluginJsCode(std::move(vecJsCode));
1468 }
1469
1470 /**
1471 * @tc.name: LoadPluginJsCodeTest002
1472 * @tc.desc: Verify the LoadPluginJsCode Interface of PluginFrontend work fail because delegate is nullptr.
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(PluginFrontendTest, LoadPluginJsCodeTest002, TestSize.Level1)
1476 {
1477 /**
1478 * @tc.steps: step1. Build a PluginFrontend.
1479 */
1480 PluginFrontend pluginFrontend;
1481
1482 /**
1483 * @tc.steps: step2. Load Plugin Js Code.
1484 * @tc.expected: step2. Load Plugin Js Code fail.
1485 */
1486 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1487 std::string vecJsCode { "JsCode" };
1488 pluginFrontend.LoadPluginJsCode(std::move(vecJsCode));
1489 }
1490
1491 /**
1492 * @tc.name: UpdateStateTest001
1493 * @tc.desc: Verify the UpdateState Interface of PluginFrontend work success type is ON_CREATE.
1494 * @tc.type: FUNC
1495 */
1496 HWTEST_F(PluginFrontendTest, UpdateStateTest001, TestSize.Level1)
1497 {
1498 /**
1499 * @tc.steps: step1. Build a PluginFrontend.
1500 */
1501 PluginFrontend pluginFrontend;
1502
1503 /**
1504 * @tc.steps: step2. Transfer Js Event Data.
1505 * @tc.expected: step2. Transfer Js EventData success.
1506 */
1507 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1508 std::string label = LABEL;
1509 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1510 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1511 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1512 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1513 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1514 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1515 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1516 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1517 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1518 taskExecutor->InitJsThread(true);
1519 taskExecutor->InitOtherThreads(taskRunner);
1520 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1521 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1522 pluginFrontend.UpdateState(Frontend::State::ON_CREATE);
1523 }
1524
1525 /**
1526 * @tc.name: UpdateStateTest002
1527 * @tc.desc: Verify the UpdateState Interface of PluginFrontend work success type is ON_SHOW.
1528 * @tc.type: FUNC
1529 */
1530 HWTEST_F(PluginFrontendTest, UpdateStateTest002, TestSize.Level1)
1531 {
1532 /**
1533 * @tc.steps: step1. Build a PluginFrontend.
1534 */
1535 PluginFrontend pluginFrontend;
1536
1537 /**
1538 * @tc.steps: step2. Transfer Js Event Data.
1539 * @tc.expected: step2. Transfer Js EventData success.
1540 */
1541 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1542 std::string label = LABEL;
1543 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1544 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1545 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1546 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1547 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1548 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1549 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1550 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1551 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1552 taskExecutor->InitJsThread(true);
1553 taskExecutor->InitOtherThreads(taskRunner);
1554 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1555 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1556 pluginFrontend.UpdateState(Frontend::State::ON_SHOW);
1557 }
1558
1559 /**
1560 * @tc.name: UpdateStateTest003
1561 * @tc.desc: Verify the UpdateState Interface of PluginFrontend work success type is ON_HIDE.
1562 * @tc.type: FUNC
1563 */
1564 HWTEST_F(PluginFrontendTest, LoadPluginJsCodeTest003, TestSize.Level1)
1565 {
1566 /**
1567 * @tc.steps: step1. Build a PluginFrontend.
1568 */
1569 PluginFrontend pluginFrontend;
1570
1571 /**
1572 * @tc.steps: step2. Transfer Js Event Data.
1573 * @tc.expected: step2. Transfer Js EventData success.
1574 */
1575 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1576 std::string label = LABEL;
1577 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1578 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1579 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1580 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1581 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1582 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1583 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1584 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1585 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1586 taskExecutor->InitJsThread(true);
1587 taskExecutor->InitOtherThreads(taskRunner);
1588 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1589 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1590 pluginFrontend.UpdateState(Frontend::State::ON_HIDE);
1591 }
1592
1593 /**
1594 * @tc.name: UpdateStateTest004
1595 * @tc.desc: Verify the UpdateState Interface of PluginFrontend work success type is ON_DESTROY.
1596 * @tc.type: FUNC
1597 */
1598 HWTEST_F(PluginFrontendTest, UpdateStateTest004, TestSize.Level1)
1599 {
1600 /**
1601 * @tc.steps: step1. Build a PluginFrontend.
1602 */
1603 PluginFrontend pluginFrontend;
1604
1605 /**
1606 * @tc.steps: step2. Transfer Js Event Data.
1607 * @tc.expected: step2. Transfer Js EventData success.
1608 */
1609 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1610 std::string label = LABEL;
1611 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1612 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1613 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1614 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1615 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1616 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1617 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1618 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1619 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1620 taskExecutor->InitJsThread(true);
1621 taskExecutor->InitOtherThreads(taskRunner);
1622 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1623 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1624 pluginFrontend.UpdateState(Frontend::State::ON_DESTROY);
1625 }
1626
1627 /**
1628 * @tc.name: UpdateStateTest005
1629 * @tc.desc: Verify the UpdateState Interface of PluginFrontend work success type is ERROR.
1630 * @tc.type: FUNC
1631 */
1632 HWTEST_F(PluginFrontendTest, UpdateStateTest005, TestSize.Level1)
1633 {
1634 /**
1635 * @tc.steps: step1. Build a PluginFrontend.
1636 */
1637 PluginFrontend pluginFrontend;
1638
1639 /**
1640 * @tc.steps: step2. Transfer Js Event Data.
1641 * @tc.expected: step2. Transfer Js EventData success.
1642 */
1643 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1644 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1645 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1646 pluginFrontend.UpdateState(static_cast<Frontend::State>(ERROR));
1647 }
1648
1649 /**
1650 * @tc.name: UpdateStateTest006
1651 * @tc.desc: Verify the UpdateState Interface of PluginFrontend work fail because delegate is nullptr.
1652 * @tc.type: FUNC
1653 */
1654 HWTEST_F(PluginFrontendTest, UpdateStateTest006, TestSize.Level1)
1655 {
1656 /**
1657 * @tc.steps: step1. Build a PluginFrontend.
1658 */
1659 PluginFrontend pluginFrontend;
1660
1661 /**
1662 * @tc.steps: step2. Load Plugin Js Code.
1663 * @tc.expected: step2. Load Plugin Js Code fail.
1664 */
1665 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1666 pluginFrontend.UpdateState(Frontend::State::ON_HIDE);
1667 }
1668
1669 /**
1670 * @tc.name: LoadPluginJsByteCodeTest001
1671 * @tc.desc: Verify the LoadPluginJsByteCode Interface of PluginFrontend work success.
1672 * @tc.type: FUNC
1673 */
1674 HWTEST_F(PluginFrontendTest, LoadPluginJsByteCodeTest001, TestSize.Level1)
1675 {
1676 /**
1677 * @tc.steps: step1. Build a PluginFrontend.
1678 */
1679 PluginFrontend pluginFrontend;
1680
1681 /**
1682 * @tc.steps: step2. Load Plugin Js Byte Code.
1683 * @tc.expected: step2. Load Plugin Js Byte Code success.
1684 */
1685 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1686 std::string label = LABEL;
1687 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1688 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1689 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1690 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1691 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1692 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1693 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1694 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1695 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1696 taskExecutor->InitJsThread(true);
1697 taskExecutor->InitOtherThreads(taskRunner);
1698 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1699 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1700 std::vector<uint8_t> vecJsCode { 0, 0 };
1701 std::vector<int32_t> vecJsCodeLen { 0, 0 };
1702 pluginFrontend.LoadPluginJsByteCode(std::move(vecJsCode), std::move(vecJsCodeLen));
1703 }
1704
1705 /**
1706 * @tc.name: LoadPluginJsByteCodeTest002
1707 * @tc.desc: Verify the LoadPluginJsByteCode Interface of PluginFrontend work fail because delegate is nullptr.
1708 * @tc.type: FUNC
1709 */
1710 HWTEST_F(PluginFrontendTest, LoadPluginJsByteCodeTest002, TestSize.Level1)
1711 {
1712 /**
1713 * @tc.steps: step1. Build a PluginFrontend.
1714 */
1715 PluginFrontend pluginFrontend;
1716
1717 /**
1718 * @tc.steps: step2. Load Plugin Js Code.
1719 * @tc.expected: step2. Load Plugin Js Code fail.
1720 */
1721 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1722 std::vector<uint8_t> vecJsCode { 0, 0 };
1723 std::vector<int32_t> vecJsCodeLen { 0, 0 };
1724 pluginFrontend.LoadPluginJsByteCode(std::move(vecJsCode), std::move(vecJsCodeLen));
1725 }
1726
1727 /**
1728 * @tc.name: OnWindowDisplayModeChangedTest001
1729 * @tc.desc: Verify the OnWindowDisplayModeChanged Interface of PluginFrontend work success.
1730 * @tc.type: FUNC
1731 */
1732 HWTEST_F(PluginFrontendTest, OnWindowDisplayModeChangedTest001, TestSize.Level1)
1733 {
1734 /**
1735 * @tc.steps: step1. Build a PluginFrontend.
1736 */
1737 PluginFrontend pluginFrontend;
1738
1739 /**
1740 * @tc.steps: step2. On Window Display ModeChanged.
1741 * @tc.expected: step2. On Window Display Mode Changed success.
1742 */
1743 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1744 std::string label = LABEL;
1745 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1746 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1747 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1748 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1749 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1750 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1751 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1752 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1753 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1754 taskExecutor->InitJsThread(true);
1755 taskExecutor->InitOtherThreads(taskRunner);
1756 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1757 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1758 pluginFrontend.OnWindowDisplayModeChanged(true, "data");
1759 }
1760
1761 /**
1762 * @tc.name: OnWindowDisplayModeChangedTest002
1763 * @tc.desc: Verify the OnWindowDisplayModeChanged Interface of PluginFrontend work fail because delegate is nullptr.
1764 * @tc.type: FUNC
1765 */
1766 HWTEST_F(PluginFrontendTest, OnWindowDisplayModeChangedTest002, TestSize.Level1)
1767 {
1768 /**
1769 * @tc.steps: step1. Build a PluginFrontend.
1770 */
1771 PluginFrontend pluginFrontend;
1772
1773 /**
1774 * @tc.steps: step2. On Window Display ModeChanged.
1775 * @tc.expected: step2. On Window Display ModeChanged fail.
1776 */
1777 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1778 pluginFrontend.OnWindowDisplayModeChanged(true, "data");
1779 }
1780
1781 /**
1782 * @tc.name: OnSaveAbilityStateTest001
1783 * @tc.desc: Verify the OnSaveAbilityState Interface of PluginFrontend work success.
1784 * @tc.type: FUNC
1785 */
1786 HWTEST_F(PluginFrontendTest, OnSaveAbilityStateTest001, TestSize.Level1)
1787 {
1788 /**
1789 * @tc.steps: step1. Build a PluginFrontend.
1790 */
1791 PluginFrontend pluginFrontend;
1792
1793 /**
1794 * @tc.steps: step2. On Save Ability State.
1795 * @tc.expected: step2.On Save Ability State success.
1796 */
1797 RefPtr<TaskExecutor> taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1798 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1799 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1800 std::string data = "data";
1801 pluginFrontend.OnSaveAbilityState(data);
1802 }
1803
1804 /**
1805 * @tc.name: OnSaveAbilityStateTest002
1806 * @tc.desc: Verify the Send OnSaveAbilityState Interface of PluginFrontend work fail because delegate is nullptr.
1807 * @tc.type: FUNC
1808 */
1809 HWTEST_F(PluginFrontendTest, OnSaveAbilityStateTest002, TestSize.Level1)
1810 {
1811 /**
1812 * @tc.steps: step1. Build a PluginFrontend.
1813 */
1814 PluginFrontend pluginFrontend;
1815
1816 /**
1817 * @tc.steps: step2. On Save Ability State.
1818 * @tc.expected: step2. On Save Ability State fail.
1819 */
1820 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1821 std::string data = "data";
1822 pluginFrontend.OnSaveAbilityState(data);
1823 }
1824
1825 /**
1826 * @tc.name: OnRestoreAbilityStateTest001
1827 * @tc.desc: Verify the OnRestoreAbilityState Interface of PluginFrontend work success.
1828 * @tc.type: FUNC
1829 */
1830 HWTEST_F(PluginFrontendTest, OnRestoreAbilityStateTest001, TestSize.Level1)
1831 {
1832 /**
1833 * @tc.steps: step1. Build a PluginFrontend.
1834 */
1835 PluginFrontend pluginFrontend;
1836
1837 /**
1838 * @tc.steps: step2. On Restore Ability State.
1839 * @tc.expected: step2. On Restore Ability State success.
1840 */
1841 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1842 std::string label = LABEL;
1843 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1844 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1845 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1846 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1847 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1848 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1849 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1850 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1851 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1852 taskExecutor->InitJsThread(true);
1853 taskExecutor->InitOtherThreads(taskRunner);
1854 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1855 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1856 pluginFrontend.OnRestoreAbilityState("data");
1857 }
1858
1859 /**
1860 * @tc.name: OnRestoreAbilityStateTest002
1861 * @tc.desc: Verify the Send OnRestoreAbilityState Interface of PluginFrontend work fail because delegate is nullptr.
1862 * @tc.type: FUNC
1863 */
1864 HWTEST_F(PluginFrontendTest, OnRestoreAbilityStateTest002, TestSize.Level1)
1865 {
1866 /**
1867 * @tc.steps: step1. Build a PluginFrontend.
1868 */
1869 PluginFrontend pluginFrontend;
1870
1871 /**
1872 * @tc.steps: step2. On Restore Ability State.
1873 * @tc.expected: step2. On Restore Ability State fail.
1874 */
1875 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1876 pluginFrontend.OnRestoreAbilityState("data");
1877 }
1878
1879 /**
1880 * @tc.name: OnNewWantTest001
1881 * @tc.desc: Verify the OnNewWant Interface of PluginFrontend work success.
1882 * @tc.type: FUNC
1883 */
1884 HWTEST_F(PluginFrontendTest, OnNewWantTest001, TestSize.Level1)
1885 {
1886 /**
1887 * @tc.steps: step1. Build a PluginFrontend.
1888 */
1889 PluginFrontend pluginFrontend;
1890
1891 /**
1892 * @tc.steps: step2. On New Want Message.
1893 * @tc.expected: step2. On New Want success.
1894 */
1895 auto taskExecutor = Referenced::MakeRefPtr<FlutterTaskExecutor>();
1896 std::string label = LABEL;
1897 std::unique_ptr<fml::Thread> ThreadFirst = std::make_unique<fml::Thread>(THREADFIRST);
1898 std::unique_ptr<fml::Thread> ThreadSecond = std::make_unique<fml::Thread>(THREADSECOND);
1899 std::unique_ptr<fml::Thread> ThreadThird = std::make_unique<fml::Thread>(THREADTHIRD);
1900 std::unique_ptr<fml::Thread> ThreadFourth = std::make_unique<fml::Thread>(THREADFOURTH);
1901 fml::RefPtr<fml::TaskRunner> platform = ThreadFirst->GetTaskRunner();
1902 fml::RefPtr<fml::TaskRunner> gpu = ThreadSecond->GetTaskRunner();
1903 fml::RefPtr<fml::TaskRunner> ui = ThreadThird->GetTaskRunner();
1904 fml::RefPtr<fml::TaskRunner> io = ThreadFourth->GetTaskRunner();
1905 flutter::TaskRunners taskRunner(label, platform, gpu, ui, io);
1906 taskExecutor->InitJsThread(true);
1907 taskExecutor->InitOtherThreads(taskRunner);
1908 pluginFrontend.Initialize(FrontendType::JS_PLUGIN, taskExecutor);
1909 EXPECT_TRUE(pluginFrontend.delegate_ != nullptr);
1910 pluginFrontend.OnNewWant("data");
1911 }
1912
1913 /**
1914 * @tc.name: OnNewWantTest002
1915 * @tc.desc: Verify the Send Callback Message Interface of PluginFrontend work fail because delegate is nullptr.
1916 * @tc.type: FUNC
1917 */
1918 HWTEST_F(PluginFrontendTest, OnNewWantTest002, TestSize.Level1)
1919 {
1920 /**
1921 * @tc.steps: step1. Build a PluginFrontend.
1922 */
1923 PluginFrontend pluginFrontend;
1924
1925 /**
1926 * @tc.steps: step2. On New Want.
1927 * @tc.expected: step2. On New Want fail.
1928 */
1929 EXPECT_TRUE(pluginFrontend.delegate_ == nullptr);
1930 pluginFrontend.OnNewWant("data");
1931 }
1932 } // namespace OHOS::Ace