• 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 "mock_static_call.h"
20 #include "singleton_mocker.h"
21 #include "window_impl.h"
22 #include "window_scene.h"
23 
24 #include "window_scene_session_impl.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 using Mocker = SingletonMocker<StaticCall, MockStaticCall>;
32 class WindowSceneTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     virtual void SetUp() override;
37     virtual void TearDown() override;
38 
39     sptr<WindowScene> scene_ = nullptr;
40     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
41 };
SetUpTestCase()42 void WindowSceneTest::SetUpTestCase() {}
43 
TearDownTestCase()44 void WindowSceneTest::TearDownTestCase() {}
45 
SetUp()46 void WindowSceneTest::SetUp()
47 {
48     DisplayId displayId = 0;
49     sptr<IWindowLifeCycle> listener = nullptr;
50     scene_ = new WindowScene();
51     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
52     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
53     sptr<WindowOption> option = new WindowOption();
54     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option)));
55     ASSERT_EQ(WMError::WM_OK, scene_->Init(displayId, abilityContext_, listener));
56 }
57 
TearDown()58 void WindowSceneTest::TearDown()
59 {
60     scene_->GoDestroy();
61     scene_ = nullptr;
62     abilityContext_ = nullptr;
63 }
64 
65 namespace {
66 /**
67  * @tc.name: Init01
68  * @tc.desc: Init Scene with null abilityContext, null listener
69  * @tc.type: FUNC
70  */
71 HWTEST_F(WindowSceneTest, Init01, Function | SmallTest | Level2)
72 {
73     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
74     sptr<WindowOption> optionTest = new WindowOption();
75     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
76     DisplayId displayId = 0;
77     sptr<IWindowLifeCycle> listener = nullptr;
78     sptr<WindowScene> scene = new WindowScene();
79     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
80     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener, optionTest));
81 }
82 
83 /**
84  * @tc.name: Init02
85  * @tc.desc: Mock window Create Static Method return nullptr, init Scene with null abilityContext, null listener
86  * @tc.type: FUNC
87  */
88 HWTEST_F(WindowSceneTest, Init02, Function | SmallTest | Level2)
89 {
90     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
91     sptr<WindowOption> optionTest = new WindowOption();
92     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
93     DisplayId displayId = 0;
94     sptr<IWindowLifeCycle> listener = nullptr;
95     sptr<WindowScene> scene = new WindowScene();
96     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
97     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener, optionTest));
98 }
99 
100 /**
101  * @tc.name: Init03
102  * @tc.desc: Init Scene with abilityContext, null listener
103  * @tc.type: FUNC
104  */
105 HWTEST_F(WindowSceneTest, Init03, Function | SmallTest | Level2)
106 {
107     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
108     sptr<WindowOption> optionTest = new WindowOption();
109     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
110     DisplayId displayId = 0;
111     sptr<IWindowLifeCycle> listener = nullptr;
112     sptr<WindowScene> scene = new WindowScene();
113     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener, optionTest));
114 }
115 
116 /**
117  * @tc.name: Init04
118  * @tc.desc: Init Scene with abilityContext, null listener
119  * @tc.type: FUNC
120  */
121 HWTEST_F(WindowSceneTest, Init04, Function | SmallTest | Level2)
122 {
123     sptr<WindowOption> optionTest = nullptr;
124     DisplayId displayId = 0;
125     sptr<IWindowLifeCycle> listener = nullptr;
126     sptr<WindowScene> scene = new WindowScene();
127     sptr<IRemoteObject> iSession = nullptr;
128     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext_, listener, optionTest, iSession));
129 }
130 
131 /**
132  * @tc.name: Init05
133  * @tc.desc: Init Scene with abilityContext, null listener
134  * @tc.type: FUNC
135  */
136 HWTEST_F(WindowSceneTest, Init05, Function | SmallTest | Level2)
137 {
138     sptr<WindowOption> optionTest = new WindowOption();
139     DisplayId displayId = 0;
140     sptr<IWindowLifeCycle> listener = nullptr;
141     sptr<WindowScene> scene = new WindowScene();
142     sptr<IRemoteObject> iSession = new IPCObjectStub();
143     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
144     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener, optionTest, iSession));
145 }
146 
147 /**
148  * @tc.name: Init06
149  * @tc.desc: Init Scene with abilityContext, null listener
150  * @tc.type: FUNC
151  */
152 HWTEST_F(WindowSceneTest, Init06, Function | SmallTest | Level2)
153 {
154     std::string identityToken = "testToken";
155     sptr<WindowScene> scene = new WindowScene();
156     sptr<WindowOption> optionTest = new WindowOption();
157     sptr<IRemoteObject> iSession = new IPCObjectStub();
158     DisplayId displayId = 1;
159     sptr<IWindowLifeCycle> listener = nullptr;
160     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
161     ASSERT_EQ(WMError::WM_ERROR_NULLPTR,
162               scene->Init(displayId, abilityContext, listener, optionTest, iSession, identityToken));
163 }
164 
165 /**
166  * @tc.name: Create01
167  * @tc.desc: CreateWindow without windowName
168  * @tc.type: FUNC
169  */
170 HWTEST_F(WindowSceneTest, Create01, Function | SmallTest | Level2)
171 {
172     sptr<WindowOption> optionTest = new WindowOption();
173     sptr<WindowScene> scene = new WindowScene();
174     ASSERT_EQ(nullptr, scene->CreateWindow("", optionTest));
175 }
176 
177 /**
178  * @tc.name: Create02
179  * @tc.desc: CreateWindow with windowName and without mainWindow
180  * @tc.type: FUNC
181  */
182 HWTEST_F(WindowSceneTest, Create02, Function | SmallTest | Level2)
183 {
184     sptr<WindowOption> optionTest = new WindowOption();
185     sptr<WindowScene> scene = new WindowScene();
186     ASSERT_EQ(nullptr, scene->CreateWindow("WindowSceneTest02", optionTest));
187 }
188 
189 /**
190  * @tc.name: Create03
191  * @tc.desc: CreateWindow with windowName and mainWindow
192  * @tc.type: FUNC
193  */
194 HWTEST_F(WindowSceneTest, Create03, Function | SmallTest | Level2)
195 {
196     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
197     sptr<WindowOption> optionTest = new WindowOption();
198     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
199     ASSERT_NE(nullptr, scene_->CreateWindow("WindowSceneTest03", optionTest));
200 }
201 
202 /**
203  * @tc.name: Create04
204  * @tc.desc: Mock window Create Static Method return nullptr, createWindow with windowName and mainWindow
205  * @tc.type: FUNC
206  */
207 HWTEST_F(WindowSceneTest, Create04, Function | SmallTest | Level2)
208 {
209     sptr<WindowOption> optionTest = new WindowOption();
210     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
211     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
212     ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest04", optionTest));
213 }
214 
215 /**
216  * @tc.name: Create05
217  * @tc.desc: createWindow with windowName and null option
218  * @tc.type: FUNC
219  */
220 HWTEST_F(WindowSceneTest, Create05, Function | SmallTest | Level2)
221 {
222     sptr<WindowOption> optionTest = nullptr;
223     ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest05", optionTest));
224 }
225 
226 /**
227  * @tc.name: GetMainWindow01
228  * @tc.desc: GetMainWindow without scene init
229  * @tc.type: FUNC
230  */
231 HWTEST_F(WindowSceneTest, GetMainWindow01, Function | SmallTest | Level2)
232 {
233     sptr<WindowScene> scene = new WindowScene();
234     ASSERT_EQ(nullptr, scene->GetMainWindow());
235 }
236 
237 /**
238  * @tc.name: GetMainWindow02
239  * @tc.desc: GetMainWindow01 with nullptr
240  * @tc.type: FUNC
241  */
242 HWTEST_F(WindowSceneTest, GetMainWindow02, Function | SmallTest | Level2)
243 {
244     ASSERT_NE(nullptr, scene_->GetMainWindow());
245 }
246 
247 /**
248  * @tc.name: GetSubWindow01
249  * @tc.desc: GetSubWindow without scene init
250  * @tc.type: FUNC
251  */
252 HWTEST_F(WindowSceneTest, GetSubWindow01, Function | SmallTest | Level2)
253 {
254     sptr<WindowScene> scene = new WindowScene();
255     std::vector<sptr<Window>> subWindows = scene->GetSubWindow();
256     ASSERT_TRUE(subWindows.empty());
257 }
258 
259 /**
260  * @tc.name: GetSubWindow02
261  * @tc.desc: GetSubWindow without scene init
262  * @tc.type: FUNC
263  */
264 HWTEST_F(WindowSceneTest, GetSubWindow02, Function | SmallTest | Level2)
265 {
266     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
267     sptr<WindowOption> optionTest = new WindowOption();
268     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
269     DisplayId displayId = 0;
270     sptr<IWindowLifeCycle> listener = nullptr;
271     sptr<WindowScene> scene = new WindowScene();
272     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
273     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
274     std::vector<sptr<Window>> subWindows = scene->GetSubWindow();
275     ASSERT_TRUE(subWindows.empty());
276 }
277 
278 /**
279  * @tc.name: OnNewWant01
280  * @tc.desc: OnNewWant nullptr
281  * @tc.type: FUNC
282  */
283 HWTEST_F(WindowSceneTest, OnNewWant01, Function | SmallTest | Level2)
284 {
285     sptr<WindowScene> scene = new WindowScene();
286     AAFwk::Want want;
287     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->OnNewWant(want));
288 }
289 
290 /**
291  * @tc.name: OnNewWant02
292  * @tc.desc: OnNewWant without scene init
293  * @tc.type: FUNC
294  */
295 HWTEST_F(WindowSceneTest, OnNewWant02, Function | SmallTest | Level2)
296 {
297     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
298     sptr<WindowOption> optionTest = new WindowOption();
299     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
300     DisplayId displayId = 0;
301     sptr<IWindowLifeCycle> listener = nullptr;
302     sptr<WindowScene> scene = new WindowScene();
303     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
304     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
305     AAFwk::Want want;
306     ASSERT_EQ(WMError::WM_OK, scene->OnNewWant(want));
307 }
308 
309 /**
310  * @tc.name: UpdateConfiguration01
311  * @tc.desc: UpdateConfiguration01 without mainWindow
312  * @tc.type: FUNC
313  * @tc.require: issueI5JQ04
314  */
315 HWTEST_F(WindowSceneTest, UpdateConfiguration01, Function | SmallTest | Level2)
316 {
317     sptr<WindowScene> scene = new WindowScene();
318     std::shared_ptr<AppExecFwk::Configuration> configuration = nullptr;
319     scene->UpdateConfiguration(configuration);
320     int32_t level = 0;
321     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(level));
322 }
323 
324 /**
325  * @tc.name: UpdateConfiguration02
326  * @tc.desc: UpdateConfiguration without scene init
327  * @tc.type: FUNC
328  */
329 HWTEST_F(WindowSceneTest, UpdateConfiguration02, Function | SmallTest | Level2)
330 {
331     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
332     sptr<WindowOption> optionTest = new WindowOption();
333     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
334     DisplayId displayId = 0;
335     sptr<IWindowLifeCycle> listener = nullptr;
336     sptr<WindowScene> scene = new WindowScene();
337     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
338     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
339     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
340     scene->UpdateConfiguration(configuration);
341 }
342 
343 /**
344  * @tc.name: UpdateConfigurationForSpecified
345  * @tc.desc: UpdateConfigurationForSpecified Test
346  * @tc.type: FUNC
347  */
348 HWTEST_F(WindowSceneTest, UpdateConfigurationForSpecified, Function | SmallTest | Level2)
349 {
350     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
351     sptr<WindowOption> optionTest = new WindowOption();
352     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
353     DisplayId displayId = 0;
354     sptr<IWindowLifeCycle> listener = nullptr;
355     sptr<WindowScene> scene = new WindowScene();
356     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
357     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
358     std::shared_ptr<AppExecFwk::Configuration> configuration;
359     std::shared_ptr<Global::Resource::ResourceManager> resourceManager;
360     scene->UpdateConfigurationForSpecified(configuration, resourceManager);
361 }
362 
363 /**
364  * @tc.name: GetContentInfo01
365  * @tc.desc: GetContentInfo nullptr
366  * @tc.type: FUNC
367  */
368 HWTEST_F(WindowSceneTest, GetContentInfo01, Function | SmallTest | Level2)
369 {
370     sptr<WindowScene> scene = new WindowScene();
371     ASSERT_EQ("", scene->GetContentInfo());
372 }
373 
374 /**
375  * @tc.name: GetContentInfo02
376  * @tc.desc: GetContentInfo without scene init
377  * @tc.type: FUNC
378  */
379 HWTEST_F(WindowSceneTest, GetContentInfo02, Function | SmallTest | Level2)
380 {
381     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
382     sptr<WindowOption> optionTest = new WindowOption();
383     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
384     DisplayId displayId = 0;
385     sptr<IWindowLifeCycle> listener = nullptr;
386     sptr<WindowScene> scene = new WindowScene();
387     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
388     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
389     ASSERT_EQ("", scene->GetContentInfo());
390 }
391 
392 /**
393  * @tc.name: SetSystemBarProperty01
394  * @tc.desc: SetSystemBarProperty nullptr
395  * @tc.type: FUNC
396  */
397 HWTEST_F(WindowSceneTest, SetSystemBarProperty01, Function | SmallTest | Level2)
398 {
399     sptr<WindowScene> scene = new WindowScene();
400     WindowType type = WindowType::WINDOW_TYPE_DIALOG;
401     SystemBarProperty property;
402     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->SetSystemBarProperty(type, property));
403 }
404 
405 /**
406  * @tc.name: SetSystemBarProperty02
407  * @tc.desc: SetSystemBarProperty without scene init
408  * @tc.type: FUNC
409  */
410 HWTEST_F(WindowSceneTest, SetSystemBarProperty02, Function | SmallTest | Level2)
411 {
412     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
413     sptr<WindowOption> optionTest = new WindowOption();
414     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
415     DisplayId displayId = 0;
416     sptr<IWindowLifeCycle> listener = nullptr;
417     sptr<WindowScene> scene = new WindowScene();
418     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
419     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener));
420     WindowType type = WindowType::WINDOW_TYPE_DIALOG;
421     SystemBarProperty property;
422     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->SetSystemBarProperty(type, property));
423 }
424 
425 /**
426  * @tc.name: GoForeground01
427  * @tc.desc: GoForeground01 without mainWindow
428  * @tc.type: FUNC
429  */
430 HWTEST_F(WindowSceneTest, GoForeground01, Function | SmallTest | Level2)
431 {
432     sptr<WindowScene> scene = new WindowScene();
433     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoForeground());
434 }
435 
436 /**
437  * @tc.name: GoForeground02
438  * @tc.desc: GoForeground02 without mainWindow
439  * @tc.type: FUNC
440  */
441 HWTEST_F(WindowSceneTest, GoForeground02, Function | SmallTest | Level2)
442 {
443     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
444     sptr<WindowOption> optionTest = new WindowOption();
445     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
446     DisplayId displayId = 0;
447     sptr<IWindowLifeCycle> listener = nullptr;
448     sptr<WindowScene> scene = new WindowScene();
449     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
450     uint32_t reason = 0;
451     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->GoForeground(reason));
452 }
453 
454 /**
455  * @tc.name: GoBackground01
456  * @tc.desc: GoBackground01 without mainWindow
457  * @tc.type: FUNC
458  */
459 HWTEST_F(WindowSceneTest, GoBackground01, Function | SmallTest | Level2)
460 {
461     sptr<WindowScene> scene = new WindowScene();
462     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoBackground());
463 }
464 
465 /**
466  * @tc.name: GoBackground02
467  * @tc.desc: GoBackground02 without mainWindow
468  * @tc.type: FUNC
469  */
470 HWTEST_F(WindowSceneTest, GoBackground02, Function | SmallTest | Level2)
471 {
472     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
473     sptr<WindowOption> optionTest = new WindowOption();
474     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
475     DisplayId displayId = 0;
476     sptr<IWindowLifeCycle> listener = nullptr;
477     sptr<WindowScene> scene = new WindowScene();
478     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
479     uint32_t reason = 0;
480     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->GoBackground(reason));
481 }
482 
483 /**
484  * @tc.name: GoResume01
485  * @tc.desc: GoResume01 without mainWindow
486  * @tc.type: FUNC
487  */
488 HWTEST_F(WindowSceneTest, GoResume01, Function | SmallTest | Level2)
489 {
490     sptr<WindowScene> scene = new WindowScene();
491     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoResume());
492 }
493 
494 /**
495  * @tc.name: GoResume02
496  * @tc.desc: GoResume02 with mainWindow
497  * @tc.type: FUNC
498  */
499 HWTEST_F(WindowSceneTest, GoResume02, Function | SmallTest | Level2)
500 {
501     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
502     sptr<WindowOption> optionTest = new WindowOption();
503     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
504     DisplayId displayId = 0;
505     sptr<IWindowLifeCycle> listener = nullptr;
506     sptr<WindowScene> scene = new WindowScene();
507     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
508     ASSERT_EQ(WMError::WM_OK, scene->GoResume());
509 }
510 
511 /**
512  * @tc.name: RequestFocus01
513  * @tc.desc: RequestFocus01 without mainWindow
514  * @tc.type: FUNC
515  */
516 HWTEST_F(WindowSceneTest, RequestFocus01, Function | SmallTest | Level2)
517 {
518     sptr<WindowScene> scene = new WindowScene();
519     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->RequestFocus());
520 }
521 
522 /**
523  * @tc.name: RequestFocus02
524  * @tc.desc: RequestFocus02 without mainWindow
525  * @tc.type: FUNC
526  */
527 HWTEST_F(WindowSceneTest, RequestFocus02, Function | SmallTest | Level2)
528 {
529     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
530     sptr<WindowOption> optionTest = new WindowOption();
531     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
532     DisplayId displayId = 0;
533     sptr<IWindowLifeCycle> listener = nullptr;
534     sptr<WindowScene> scene = new WindowScene();
535     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
536     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, scene->RequestFocus());
537 }
538 
539 /**
540  * @tc.name: NotifyMemoryLevel01
541  * @tc.desc: NotifyMemoryLevel without mainWindow
542  * @tc.type: FUNC
543  * @tc.require: issueI5JQ04
544  */
545 HWTEST_F(WindowSceneTest, NotifyMemoryLevel01, Function | SmallTest | Level2)
546 {
547     sptr<WindowScene> scene = new WindowScene();
548     int32_t level = 0;
549     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(level));
550 }
551 
552 /**
553  * @tc.name: NotifyMemoryLevel02
554  * @tc.desc: NotifyMemoryLevel with level
555  * @tc.type: FUNC
556  * @tc.require: issueI5JQ04
557  */
558 HWTEST_F(WindowSceneTest, NotifyMemoryLevel02, Function | SmallTest | Level2)
559 {
560     DisplayId displayId = 0;
561     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
562     sptr<IWindowLifeCycle> listener = nullptr;
563     sptr<WindowScene> scene = new WindowScene();
564     sptr<WindowOption> option = new WindowOption();
565     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option)));
566     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
567     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(0)); // ui content is null
568 }
569 
570 /**
571  * @tc.name: NotifyMemoryLevel03
572  * @tc.desc: NotifyMemoryLevel with windowSceneSession
573  * @tc.type: FUNC
574  * @tc.require: issueI5JQ04
575  */
576 HWTEST_F(WindowSceneTest, NotifyMemoryLevel03, Function | SmallTest | Level2)
577 {
578     DisplayId displayId = 0;
579     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
580     sptr<IWindowLifeCycle> listener = nullptr;
581     sptr<WindowScene> scene = new WindowScene();
582     sptr<WindowOption> option = new WindowOption();
583     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowSceneSessionImpl(option)));
584     ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener));
585     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->NotifyMemoryLevel(0)); // ui content is null
586 }
587 
588 } // namespace
589 } // namespace Rosen
590 } // namespace OHOS