• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <configuration.h>
17 #include <gtest/gtest.h>
18 #include "ability_context_impl.h"
19 #include "modifier_render_thread/rs_modifiers_draw_thread.h"
20 #include "mock_static_call.h"
21 #include "singleton_mocker.h"
22 #include "window_impl.h"
23 #include "window_scene.h"
24 
25 #include "window_scene_session_impl.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 using Mocker = SingletonMocker<StaticCall, MockStaticCall>;
33 class WindowSceneTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     virtual void SetUp() override;
38     virtual void TearDown() override;
39 
40     sptr<WindowScene> scene_ = nullptr;
41     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
42 };
SetUpTestCase()43 void WindowSceneTest::SetUpTestCase() {}
44 
TearDownTestCase()45 void WindowSceneTest::TearDownTestCase()
46 {
47 #ifdef RS_ENABLE_VK
48     RSModifiersDrawThread::Destroy();
49 #endif
50 }
51 
SetUp()52 void WindowSceneTest::SetUp()
53 {
54     DisplayId displayId = 0;
55     sptr<IWindowLifeCycle> listener = nullptr;
56     scene_ = new WindowScene();
57     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
58     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
59     sptr<WindowOption> option = new WindowOption();
60     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option)));
61     ASSERT_EQ(WMError::WM_OK, scene_->Init(displayId, abilityContext_, listener));
62 }
63 
TearDown()64 void WindowSceneTest::TearDown()
65 {
66     scene_->GoDestroy();
67     scene_ = nullptr;
68     abilityContext_ = nullptr;
69 }
70 
71 namespace {
72 /**
73  * @tc.name: Init01
74  * @tc.desc: Init Scene with null abilityContext, null listener
75  * @tc.type: FUNC
76  */
77 HWTEST_F(WindowSceneTest, Init01, TestSize.Level1)
78 {
79     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
80     sptr<WindowOption> optionTest = new WindowOption();
81     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
82     DisplayId displayId = 0;
83     sptr<IWindowLifeCycle> listener = nullptr;
84     sptr<WindowScene> scene = new WindowScene();
85     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
86     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener, optionTest));
87 }
88 
89 /**
90  * @tc.name: Init02
91  * @tc.desc: Mock window Create Static Method return nullptr, init Scene with null abilityContext, null listener
92  * @tc.type: FUNC
93  */
94 HWTEST_F(WindowSceneTest, Init02, TestSize.Level1)
95 {
96     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
97     sptr<WindowOption> optionTest = new WindowOption();
98     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
99     DisplayId displayId = 0;
100     sptr<IWindowLifeCycle> listener = nullptr;
101     sptr<WindowScene> scene = new WindowScene();
102     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
103     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener, optionTest));
104 }
105 
106 /**
107  * @tc.name: Init03
108  * @tc.desc: Init Scene with abilityContext, null listener
109  * @tc.type: FUNC
110  */
111 HWTEST_F(WindowSceneTest, Init03, TestSize.Level1)
112 {
113     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
114     sptr<WindowOption> optionTest = new WindowOption();
115     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
116     DisplayId displayId = 0;
117     sptr<IWindowLifeCycle> listener = nullptr;
118     sptr<WindowScene> scene = new WindowScene();
119     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener, optionTest));
120 }
121 
122 /**
123  * @tc.name: Init04
124  * @tc.desc: Init Scene with abilityContext, null listener
125  * @tc.type: FUNC
126  */
127 HWTEST_F(WindowSceneTest, Init04, TestSize.Level1)
128 {
129     sptr<WindowOption> optionTest = nullptr;
130     DisplayId displayId = 0;
131     sptr<IWindowLifeCycle> listener = nullptr;
132     sptr<WindowScene> scene = new WindowScene();
133     sptr<IRemoteObject> iSession = nullptr;
134     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext_, listener, optionTest, iSession));
135 }
136 
137 /**
138  * @tc.name: Init05
139  * @tc.desc: Init Scene with abilityContext, null listener
140  * @tc.type: FUNC
141  */
142 HWTEST_F(WindowSceneTest, Init05, TestSize.Level1)
143 {
144     sptr<WindowOption> optionTest = new WindowOption();
145     DisplayId displayId = 0;
146     sptr<IWindowLifeCycle> listener = nullptr;
147     sptr<WindowScene> scene = new WindowScene();
148     sptr<IRemoteObject> iSession = new IPCObjectStub();
149     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
150     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener, optionTest, iSession));
151 }
152 
153 /**
154  * @tc.name: Init06
155  * @tc.desc: Init Scene with abilityContext, null listener
156  * @tc.type: FUNC
157  */
158 HWTEST_F(WindowSceneTest, Init06, TestSize.Level1)
159 {
160     std::string identityToken = "testToken";
161     sptr<WindowScene> scene = new WindowScene();
162     sptr<WindowOption> optionTest = new WindowOption();
163     sptr<IRemoteObject> iSession = new IPCObjectStub();
164     DisplayId displayId = 1;
165     sptr<IWindowLifeCycle> listener = nullptr;
166     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
167     ASSERT_EQ(WMError::WM_ERROR_NULLPTR,
168               scene->Init(displayId, abilityContext, listener, optionTest, iSession, identityToken));
169 }
170 
171 /**
172  * @tc.name: Create01
173  * @tc.desc: CreateWindow without windowName
174  * @tc.type: FUNC
175  */
176 HWTEST_F(WindowSceneTest, Create01, TestSize.Level1)
177 {
178     sptr<WindowOption> optionTest = new WindowOption();
179     sptr<WindowScene> scene = new WindowScene();
180     ASSERT_EQ(nullptr, scene->CreateWindow("", optionTest));
181 }
182 
183 /**
184  * @tc.name: Create02
185  * @tc.desc: CreateWindow with windowName and without mainWindow
186  * @tc.type: FUNC
187  */
188 HWTEST_F(WindowSceneTest, Create02, TestSize.Level1)
189 {
190     sptr<WindowOption> optionTest = new WindowOption();
191     sptr<WindowScene> scene = new WindowScene();
192     ASSERT_EQ(nullptr, scene->CreateWindow("WindowSceneTest02", optionTest));
193 }
194 
195 /**
196  * @tc.name: Create03
197  * @tc.desc: CreateWindow with windowName and mainWindow
198  * @tc.type: FUNC
199  */
200 HWTEST_F(WindowSceneTest, Create03, TestSize.Level1)
201 {
202     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
203     sptr<WindowOption> optionTest = new WindowOption();
204     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
205     ASSERT_NE(nullptr, scene_->CreateWindow("WindowSceneTest03", optionTest));
206 }
207 
208 /**
209  * @tc.name: Create04
210  * @tc.desc: Mock window Create Static Method return nullptr, createWindow with windowName and mainWindow
211  * @tc.type: FUNC
212  */
213 HWTEST_F(WindowSceneTest, Create04, TestSize.Level1)
214 {
215     sptr<WindowOption> optionTest = new WindowOption();
216     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
217     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
218     ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest04", optionTest));
219 }
220 
221 /**
222  * @tc.name: Create05
223  * @tc.desc: createWindow with windowName and null option
224  * @tc.type: FUNC
225  */
226 HWTEST_F(WindowSceneTest, Create05, TestSize.Level1)
227 {
228     sptr<WindowOption> optionTest = nullptr;
229     ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest05", optionTest));
230 }
231 
232 /**
233  * @tc.name: GetMainWindow01
234  * @tc.desc: GetMainWindow without scene init
235  * @tc.type: FUNC
236  */
237 HWTEST_F(WindowSceneTest, GetMainWindow01, TestSize.Level1)
238 {
239     sptr<WindowScene> scene = new WindowScene();
240     ASSERT_EQ(nullptr, scene->GetMainWindow());
241 }
242 
243 /**
244  * @tc.name: GetMainWindow02
245  * @tc.desc: GetMainWindow01 with nullptr
246  * @tc.type: FUNC
247  */
248 HWTEST_F(WindowSceneTest, GetMainWindow02, TestSize.Level1)
249 {
250     ASSERT_NE(nullptr, scene_->GetMainWindow());
251 }
252 
253 /**
254  * @tc.name: GetSubWindow01
255  * @tc.desc: GetSubWindow without scene init
256  * @tc.type: FUNC
257  */
258 HWTEST_F(WindowSceneTest, GetSubWindow01, TestSize.Level1)
259 {
260     sptr<WindowScene> scene = new WindowScene();
261     std::vector<sptr<Window>> subWindows = scene->GetSubWindow();
262     ASSERT_TRUE(subWindows.empty());
263 }
264 
265 /**
266  * @tc.name: GetSubWindow02
267  * @tc.desc: GetSubWindow without scene init
268  * @tc.type: FUNC
269  */
270 HWTEST_F(WindowSceneTest, GetSubWindow02, TestSize.Level1)
271 {
272     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
273     sptr<WindowOption> optionTest = new WindowOption();
274     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
275     DisplayId displayId = 0;
276     sptr<IWindowLifeCycle> listener = nullptr;
277     sptr<WindowScene> scene = new WindowScene();
278     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
279     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
280     std::vector<sptr<Window>> subWindows = scene->GetSubWindow();
281     ASSERT_TRUE(subWindows.empty());
282 }
283 
284 /**
285  * @tc.name: OnNewWant01
286  * @tc.desc: OnNewWant nullptr
287  * @tc.type: FUNC
288  */
289 HWTEST_F(WindowSceneTest, OnNewWant01, TestSize.Level1)
290 {
291     sptr<WindowScene> scene = new WindowScene();
292     AAFwk::Want want;
293     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->OnNewWant(want));
294 }
295 
296 /**
297  * @tc.name: OnNewWant02
298  * @tc.desc: OnNewWant without scene init
299  * @tc.type: FUNC
300  */
301 HWTEST_F(WindowSceneTest, OnNewWant02, TestSize.Level1)
302 {
303     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
304     sptr<WindowOption> optionTest = new WindowOption();
305     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
306     DisplayId displayId = 0;
307     sptr<IWindowLifeCycle> listener = nullptr;
308     sptr<WindowScene> scene = new WindowScene();
309     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
310     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
311     AAFwk::Want want;
312     ASSERT_EQ(WMError::WM_OK, scene->OnNewWant(want));
313 }
314 
315 /**
316  * @tc.name: UpdateConfiguration01
317  * @tc.desc: UpdateConfiguration01 without mainWindow
318  * @tc.type: FUNC
319  * @tc.require: issueI5JQ04
320  */
321 HWTEST_F(WindowSceneTest, UpdateConfiguration01, TestSize.Level1)
322 {
323     sptr<WindowScene> scene = new WindowScene();
324     std::shared_ptr<AppExecFwk::Configuration> configuration = nullptr;
325     scene->UpdateConfiguration(configuration);
326     int32_t level = 0;
327     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(level));
328 }
329 
330 /**
331  * @tc.name: UpdateConfiguration02
332  * @tc.desc: UpdateConfiguration without scene init
333  * @tc.type: FUNC
334  */
335 HWTEST_F(WindowSceneTest, UpdateConfiguration02, TestSize.Level1)
336 {
337     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
338     sptr<WindowOption> optionTest = new WindowOption();
339     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
340     DisplayId displayId = 0;
341     sptr<IWindowLifeCycle> listener = nullptr;
342     sptr<WindowScene> scene = new WindowScene();
343     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
344     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
345     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
346     scene->UpdateConfiguration(configuration);
347 }
348 
349 /**
350  * @tc.name: UpdateConfigurationForSpecified
351  * @tc.desc: UpdateConfigurationForSpecified Test
352  * @tc.type: FUNC
353  */
354 HWTEST_F(WindowSceneTest, UpdateConfigurationForSpecified, TestSize.Level1)
355 {
356     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
357     sptr<WindowOption> optionTest = new WindowOption();
358     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
359     DisplayId displayId = 0;
360     sptr<IWindowLifeCycle> listener = nullptr;
361     sptr<WindowScene> scene = new WindowScene();
362     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
363     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
364     std::shared_ptr<AppExecFwk::Configuration> configuration;
365     std::shared_ptr<Global::Resource::ResourceManager> resourceManager;
366     scene->UpdateConfigurationForSpecified(configuration, resourceManager);
367 }
368 
369 /**
370  * @tc.name: GetContentInfo01
371  * @tc.desc: GetContentInfo nullptr
372  * @tc.type: FUNC
373  */
374 HWTEST_F(WindowSceneTest, GetContentInfo01, TestSize.Level1)
375 {
376     sptr<WindowScene> scene = new WindowScene();
377     ASSERT_EQ("", scene->GetContentInfo());
378 }
379 
380 /**
381  * @tc.name: GetContentInfo02
382  * @tc.desc: GetContentInfo without scene init
383  * @tc.type: FUNC
384  */
385 HWTEST_F(WindowSceneTest, GetContentInfo02, TestSize.Level1)
386 {
387     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
388     sptr<WindowOption> optionTest = new WindowOption();
389     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
390     DisplayId displayId = 0;
391     sptr<IWindowLifeCycle> listener = nullptr;
392     sptr<WindowScene> scene = new WindowScene();
393     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
394     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
395     ASSERT_EQ("", scene->GetContentInfo());
396 }
397 
398 /**
399  * @tc.name: SetSystemBarProperty01
400  * @tc.desc: SetSystemBarProperty nullptr
401  * @tc.type: FUNC
402  */
403 HWTEST_F(WindowSceneTest, SetSystemBarProperty01, TestSize.Level1)
404 {
405     sptr<WindowScene> scene = new WindowScene();
406     WindowType type = WindowType::WINDOW_TYPE_DIALOG;
407     SystemBarProperty property;
408     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->SetSystemBarProperty(type, property));
409 }
410 
411 /**
412  * @tc.name: SetSystemBarProperty02
413  * @tc.desc: SetSystemBarProperty without scene init
414  * @tc.type: FUNC
415  */
416 HWTEST_F(WindowSceneTest, SetSystemBarProperty02, TestSize.Level1)
417 {
418     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
419     sptr<WindowOption> optionTest = new WindowOption();
420     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
421     DisplayId displayId = 0;
422     sptr<IWindowLifeCycle> listener = nullptr;
423     sptr<WindowScene> scene = new WindowScene();
424     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
425     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
426     WindowType type = WindowType::WINDOW_TYPE_DIALOG;
427     SystemBarProperty property;
428     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->SetSystemBarProperty(type, property));
429 }
430 
431 /**
432  * @tc.name: GoForeground01
433  * @tc.desc: GoForeground01 without mainWindow
434  * @tc.type: FUNC
435  */
436 HWTEST_F(WindowSceneTest, GoForeground01, TestSize.Level1)
437 {
438     sptr<WindowScene> scene = new WindowScene();
439     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoForeground());
440 }
441 
442 /**
443  * @tc.name: GoForeground02
444  * @tc.desc: GoForeground02 without mainWindow
445  * @tc.type: FUNC
446  */
447 HWTEST_F(WindowSceneTest, GoForeground02, TestSize.Level1)
448 {
449     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
450     sptr<WindowOption> optionTest = new WindowOption();
451     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
452     DisplayId displayId = 0;
453     sptr<IWindowLifeCycle> listener = nullptr;
454     sptr<WindowScene> scene = new WindowScene();
455     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
456     uint32_t reason = 0;
457     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->GoForeground(reason));
458 }
459 
460 /**
461  * @tc.name: GoBackground01
462  * @tc.desc: GoBackground01 without mainWindow
463  * @tc.type: FUNC
464  */
465 HWTEST_F(WindowSceneTest, GoBackground01, TestSize.Level1)
466 {
467     sptr<WindowScene> scene = new WindowScene();
468     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoBackground());
469 }
470 
471 /**
472  * @tc.name: GoBackground02
473  * @tc.desc: GoBackground02 without mainWindow
474  * @tc.type: FUNC
475  */
476 HWTEST_F(WindowSceneTest, GoBackground02, TestSize.Level1)
477 {
478     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
479     sptr<WindowOption> optionTest = new WindowOption();
480     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
481     DisplayId displayId = 0;
482     sptr<IWindowLifeCycle> listener = nullptr;
483     sptr<WindowScene> scene = new WindowScene();
484     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
485     uint32_t reason = 0;
486     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->GoBackground(reason));
487 }
488 
489 /**
490  * @tc.name: GoResume01
491  * @tc.desc: GoResume01 without mainWindow
492  * @tc.type: FUNC
493  */
494 HWTEST_F(WindowSceneTest, GoResume01, TestSize.Level1)
495 {
496     sptr<WindowScene> scene = new WindowScene();
497     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoResume());
498 }
499 
500 /**
501  * @tc.name: GoResume02
502  * @tc.desc: GoResume02 with mainWindow
503  * @tc.type: FUNC
504  */
505 HWTEST_F(WindowSceneTest, GoResume02, TestSize.Level1)
506 {
507     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
508     sptr<WindowOption> optionTest = new WindowOption();
509     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
510     DisplayId displayId = 0;
511     sptr<IWindowLifeCycle> listener = nullptr;
512     sptr<WindowScene> scene = new WindowScene();
513     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
514     ASSERT_EQ(WMError::WM_OK, scene->GoResume());
515 }
516 
517 /**
518  * @tc.name: GoPause
519  * @tc.desc: GoPause with mainWindow
520  * @tc.type: FUNC
521  */
522 HWTEST_F(WindowSceneTest, GoPause, TestSize.Level1)
523 {
524     sptr<WindowScene> winScene = new WindowScene();
525     ASSERT_NE(nullptr, winScene);
526     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, winScene->GoPause());
527     std::unique_ptr<Mocker> mocker = std::make_unique<Mocker>();
528     sptr<WindowOption> optionTest = new WindowOption();
529     EXPECT_CALL(mocker->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
530     DisplayId displayId = 0;
531     sptr<IWindowLifeCycle> listener = nullptr;
532     EXPECT_EQ(WMError::WM_OK, winScene->Init(displayId, abilityContext_, listener));
533     EXPECT_EQ(WMError::WM_OK, winScene->GoPause());
534 }
535 
536 /**
537  * @tc.name: RequestFocus01
538  * @tc.desc: RequestFocus01 without mainWindow
539  * @tc.type: FUNC
540  */
541 HWTEST_F(WindowSceneTest, RequestFocus01, TestSize.Level1)
542 {
543     sptr<WindowScene> scene = new WindowScene();
544     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->RequestFocus());
545 }
546 
547 /**
548  * @tc.name: RequestFocus02
549  * @tc.desc: RequestFocus02 without mainWindow
550  * @tc.type: FUNC
551  */
552 HWTEST_F(WindowSceneTest, RequestFocus02, TestSize.Level1)
553 {
554     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
555     sptr<WindowOption> optionTest = new WindowOption();
556     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
557     DisplayId displayId = 0;
558     sptr<IWindowLifeCycle> listener = nullptr;
559     sptr<WindowScene> scene = new WindowScene();
560     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
561     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->RequestFocus());
562 }
563 
564 /**
565  * @tc.name: NotifyMemoryLevel01
566  * @tc.desc: NotifyMemoryLevel without mainWindow
567  * @tc.type: FUNC
568  * @tc.require: issueI5JQ04
569  */
570 HWTEST_F(WindowSceneTest, NotifyMemoryLevel01, TestSize.Level1)
571 {
572     sptr<WindowScene> scene = new WindowScene();
573     int32_t level = 0;
574     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(level));
575 }
576 
577 /**
578  * @tc.name: NotifyMemoryLevel02
579  * @tc.desc: NotifyMemoryLevel with level
580  * @tc.type: FUNC
581  * @tc.require: issueI5JQ04
582  */
583 HWTEST_F(WindowSceneTest, NotifyMemoryLevel02, TestSize.Level1)
584 {
585     DisplayId displayId = 0;
586     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
587     sptr<IWindowLifeCycle> listener = nullptr;
588     sptr<WindowScene> scene = new WindowScene();
589     sptr<WindowOption> option = new WindowOption();
590     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option)));
591     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
592     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(0)); // ui content is null
593 }
594 
595 /**
596  * @tc.name: NotifyMemoryLevel03
597  * @tc.desc: NotifyMemoryLevel with windowSceneSession
598  * @tc.type: FUNC
599  * @tc.require: issueI5JQ04
600  */
601 HWTEST_F(WindowSceneTest, NotifyMemoryLevel03, TestSize.Level1)
602 {
603     DisplayId displayId = 0;
604     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
605     sptr<IWindowLifeCycle> listener = nullptr;
606     sptr<WindowScene> scene = new WindowScene();
607     sptr<WindowOption> option = new WindowOption();
608     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowSceneSessionImpl(option)));
609     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
610     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(0)); // ui content is null
611 }
612 
613 /**
614  * @tc.name: GoDestroyHookWindow
615  * @tc.desc: Destroy hook window
616  * @tc.type: FUNC
617  */
618 HWTEST_F(WindowSceneTest, GoDestroyHookWindow, TestSize.Level1)
619 {
620     DisplayId displayId = 0;
621     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
622     sptr<IWindowLifeCycle> listener = nullptr;
623     sptr<WindowScene> scene = sptr<WindowScene>::MakeSptr();
624     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
625     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowSceneSessionImpl(option)));
626     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
627     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->GoDestroyHookWindow());
628 }
629 
630 /**
631  * @tc.name: SetHookedWindowElementInfo
632  * @tc.desc: SetHookedWindowElementInfo
633  * @tc.type: FUNC
634  */
635 HWTEST_F(WindowSceneTest, SetHookedWindowElementInfo, TestSize.Level1)
636 {
637     DisplayId displayId = 0;
638     AppExecFwk::ElementName elementName;
639     sptr<WindowScene> scene = sptr<WindowScene>::MakeSptr();
640     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->SetHookedWindowElementInfo(elementName));
641 
642     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
643     sptr<IWindowLifeCycle> listener = nullptr;
644     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
645     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowSceneSessionImpl(option)));
646     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
647     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->SetHookedWindowElementInfo(elementName));
648 }
649 
650 /**
651  * @tc.name: SetNavDestinationInfo01
652  * @tc.desc: SetNavDestinationInfo01
653  * @tc.type: FUNC
654  */
655 HWTEST_F(WindowSceneTest, SetNavDestinationInfo01, TestSize.Level1)
656 {
657     std::string navInfo = "testInfo";
658     auto ret = scene_->SetNavDestinationInfo(navInfo);
659     EXPECT_EQ(ret, WMError::WM_OK);
660 }
661 
662 /**
663  * @tc.name: SetNavDestinationInfo02
664  * @tc.desc: SetNavDestinationInfo02
665  * @tc.type: FUNC
666  */
667 HWTEST_F(WindowSceneTest, SetNavDestinationInfo02, TestSize.Level1)
668 {
669     sptr<WindowScene> scene = new WindowScene();
670     std::string navInfo = "testInfo";
671     auto ret = scene->SetNavDestinationInfo(navInfo);
672     EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
673 }
674 } // namespace
675 } // namespace Rosen
676 } // namespace OHOS