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 #include "ability_context_impl.h"
18 #include "display_manager_proxy.h"
19 #include "mock_window_adapter.h"
20 #include "singleton_mocker.h"
21 #include "window_impl.h"
22 #include "mock_uicontent.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
30 
31 class WindowImplTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     virtual void SetUp() override;
36     virtual void TearDown() override;
37     void CreateStretchableWindow(sptr<WindowImpl>& window, const Rect& rect);
38 
39     static inline std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
40     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
41 private:
42     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
43 };
SetUpTestCase()44 void WindowImplTest::SetUpTestCase()
45 {
46 }
47 
TearDownTestCase()48 void WindowImplTest::TearDownTestCase()
49 {
50 }
51 
SetUp()52 void WindowImplTest::SetUp()
53 {
54 }
55 
TearDown()56 void WindowImplTest::TearDown()
57 {
58     usleep(WAIT_SYNC_IN_NS);
59 }
60 
CreateStretchableWindow(sptr<WindowImpl>& window, const Rect& rect)61 void WindowImplTest::CreateStretchableWindow(sptr<WindowImpl>& window, const Rect& rect)
62 {
63     sptr<WindowOption> option = new WindowOption();
64     option->SetWindowName("StretchableWindowTest");
65     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
66     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
67     option->SetWindowRect({ 1, 1, 1, 1 });
68     if (option == nullptr) {
69         window = nullptr;
70         return;
71     }
72     window = new WindowImpl(option);
73     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
74     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
75     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
76     window->windowSystemConfig_.isStretchable_ = true;
77     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
78     ASSERT_EQ(WMError::WM_OK, window->Show());
79     window->UpdateRect(rect, true, WindowSizeChangeReason::UNDEFINED);
80     ASSERT_EQ(window->GetWindowProperty()->GetOriginRect(), rect);
81 }
82 
83 namespace {
84 /**
85  * @tc.name: CreateWindow01
86  * @tc.desc: Create window with no parentId
87  * @tc.type: FUNC
88  */
HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2)89 HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2)
90 {
91     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
92     sptr<WindowOption> option = new WindowOption();
93     option->SetWindowName("CreateWindow01");
94     sptr<WindowImpl> window = new WindowImpl(option);
95 
96     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
97     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
98     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
99 
100     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
101     ASSERT_EQ(WMError::WM_OK, window->Destroy());
102 }
103 
104 /**
105  * @tc.name: CreateWindow02
106  * @tc.desc: Create window with no parentId and no abilityContext
107  * @tc.type: FUNC
108  */
HWTEST_F(WindowImplTest, CreateWindow02, Function | SmallTest | Level2)109 HWTEST_F(WindowImplTest, CreateWindow02, Function | SmallTest | Level2)
110 {
111     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
112     sptr<WindowOption> option = new WindowOption();
113     option->SetWindowName("CreateWindow02");
114     sptr<WindowImpl> window = new WindowImpl(option);
115 
116     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
117     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
118     ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Create(INVALID_WINDOW_ID));
119     ASSERT_EQ(WMError::WM_OK, window->Destroy());
120 }
121 
122 /**
123  * @tc.name: CreateWindow03
124  * @tc.desc: Create window with illegal parentId
125  * @tc.type: FUNC
126  */
HWTEST_F(WindowImplTest, CreateWindow03, Function | SmallTest | Level2)127 HWTEST_F(WindowImplTest, CreateWindow03, Function | SmallTest | Level2)
128 {
129     sptr<WindowOption> option = new WindowOption();
130     option->SetWindowName("CreateWindow03");
131     sptr<WindowImpl> window = new WindowImpl(option);
132     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARENT, window->Create(1234));
133     ASSERT_EQ(WMError::WM_OK, window->Destroy());
134 }
135 
136 /**
137  * @tc.name: CreateWindow04
138  * @tc.desc: Create window with repeated windowName
139  * @tc.type: FUNC
140  */
HWTEST_F(WindowImplTest, CreateWindow04, Function | SmallTest | Level2)141 HWTEST_F(WindowImplTest, CreateWindow04, Function | SmallTest | Level2)
142 {
143     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
144     sptr<WindowOption> option = new WindowOption();
145     option->SetWindowName("CreateWindow04");
146     sptr<WindowImpl> window = new WindowImpl(option);
147     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
148     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
149     window->Create(INVALID_WINDOW_ID);
150 
151     sptr<WindowOption> option_other = new WindowOption();
152     option_other->SetWindowName("CreateWindow04");
153     sptr<WindowImpl> window_other = new WindowImpl(option_other);
154 
155     ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window_other->Create(INVALID_WINDOW_ID));
156     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
157     ASSERT_EQ(WMError::WM_OK, window->Destroy());
158     ASSERT_EQ(WMError::WM_OK, window_other->Destroy());
159 }
160 
161 /**
162  * @tc.name: CreateWindow05
163  * @tc.desc: Create window with exist parentId
164  * @tc.type: FUNC
165  */
HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2)166 HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2)
167 {
168     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
169     sptr<WindowOption> option = new WindowOption();
170     option->SetWindowName("CreateWindow05_parent");
171     sptr<WindowImpl> window = new WindowImpl(option);
172 
173     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
174     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
175     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
176 
177     sptr<WindowOption> option2 = new WindowOption();
178     option2->SetWindowName("CreateWindow05");
179     sptr<WindowImpl> window2 = new WindowImpl(option2);
180 
181     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
182     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
183     ASSERT_EQ(WMError::WM_OK, window2->Create(window->GetWindowId()));
184 
185     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
186     ASSERT_EQ(WMError::WM_OK, window->Destroy());
187     ASSERT_EQ(WMError::WM_OK, window2->Destroy());
188 }
189 
190 /**
191  * @tc.name: CreateWindow06
192  * @tc.desc: Create window with no default option, get and check Property
193  * @tc.type: FUNC
194  */
HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2)195 HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2)
196 {
197     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
198     sptr<WindowOption> option = new WindowOption();
199     option->SetWindowName("CreateWindow06");
200     struct Rect rect = {1, 2, 3u, 4u};
201     option->SetWindowRect(rect);
202     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
203     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
204     sptr<WindowImpl> window = new WindowImpl(option);
205 
206     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
207     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
208     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
209 
210     ASSERT_EQ(1, window->GetRequestRect().posX_);
211     ASSERT_EQ(2, window->GetRequestRect().posY_);
212     ASSERT_EQ(3u, window->GetRequestRect().width_);
213     ASSERT_EQ(4u, window->GetRequestRect().height_);
214     ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, window->GetType());
215     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
216     ASSERT_EQ("CreateWindow06", window->GetWindowName());
217 
218     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
219     ASSERT_EQ(WMError::WM_OK, window->Destroy());
220 }
221 
222 /**
223  * @tc.name: FindWindow01
224  * @tc.desc: Find one exit window
225  * @tc.type: FUNC
226  */
HWTEST_F(WindowImplTest, FindWindow01, Function | SmallTest | Level2)227 HWTEST_F(WindowImplTest, FindWindow01, Function | SmallTest | Level2)
228 {
229     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
230     sptr<WindowOption> option = new WindowOption();
231     option->SetWindowName("FindWindow01");
232     sptr<WindowImpl> window = new WindowImpl(option);
233     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
234     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
235     window->Create(INVALID_WINDOW_ID);
236     ASSERT_NE(nullptr, WindowImpl::Find("FindWindow01"));
237     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
238     ASSERT_EQ(WMError::WM_OK, window->Destroy());
239 }
240 
241 /**
242  * @tc.name: FindWindow02
243  * @tc.desc: Add another window, find both two windows
244  * @tc.type: FUNC
245  */
HWTEST_F(WindowImplTest, FindWindow02, Function | SmallTest | Level2)246 HWTEST_F(WindowImplTest, FindWindow02, Function | SmallTest | Level2)
247 {
248     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
249     sptr<WindowOption> option = new WindowOption();
250     option->SetWindowName("FindWindow02");
251     sptr<WindowImpl> window = new WindowImpl(option);
252     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
253     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
254     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
255 
256     option->SetWindowName("FindWindow02_other");
257     sptr<WindowImpl> window2 = new WindowImpl(option);
258     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
259     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
260     ASSERT_EQ(WMError::WM_OK, window2->Create(INVALID_WINDOW_ID));
261 
262     ASSERT_NE(nullptr, WindowImpl::Find("FindWindow02_other"));
263     ASSERT_NE(nullptr, WindowImpl::Find("FindWindow02"));
264 
265     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
266     ASSERT_EQ(WMError::WM_OK, window->Destroy());
267     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
268     ASSERT_EQ(WMError::WM_OK, window2->Destroy());
269 }
270 
271 /**
272  * @tc.name: FindWindow03
273  * @tc.desc: Find one no exit window
274  * @tc.type: FUNC
275  */
HWTEST_F(WindowImplTest, FindWindow03, Function | SmallTest | Level2)276 HWTEST_F(WindowImplTest, FindWindow03, Function | SmallTest | Level2)
277 {
278     ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow03"));
279 }
280 
281 /**
282  * @tc.name: FindWindow04
283  * @tc.desc: Find window with empty name
284  * @tc.type: FUNC
285  */
HWTEST_F(WindowImplTest, FindWindow04, Function | SmallTest | Level2)286 HWTEST_F(WindowImplTest, FindWindow04, Function | SmallTest | Level2)
287 {
288     ASSERT_EQ(nullptr, WindowImpl::Find(""));
289 }
290 
291 /**
292  * @tc.name: FindWindow05
293  * @tc.desc: Find one destroyed window
294  * @tc.type: FUNC
295  */
HWTEST_F(WindowImplTest, FindWindow05, Function | SmallTest | Level2)296 HWTEST_F(WindowImplTest, FindWindow05, Function | SmallTest | Level2)
297 {
298     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
299     sptr<WindowOption> option = new WindowOption();
300     option->SetWindowName("FindWindow05");
301     sptr<WindowImpl> window = new WindowImpl(option);
302     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
303     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
304     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
305 
306     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
307     ASSERT_EQ(WMError::WM_OK, window->Destroy());
308     ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow05"));
309 }
310 
311 
312 /**
313  * @tc.name: RequestVsyncSucc
314  * @tc.desc: RequestVsync Test Succ
315  * @tc.type: FUNC
316  */
HWTEST_F(WindowImplTest, RequestVsyncSucc, Function | SmallTest | Level2)317 HWTEST_F(WindowImplTest, RequestVsyncSucc, Function | SmallTest | Level2)
318 {
319     sptr<WindowOption> option = new WindowOption();
320     option->SetWindowName("RequestVsyncSucc");
321     sptr<WindowImpl> window = new WindowImpl(option);
322     ASSERT_NE(window, nullptr);
323     std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
324     window->SetWindowState(WindowState::STATE_DESTROYED);
325     ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
326     window->RequestVsync(vsyncCallback);
327     ASSERT_EQ(WMError::WM_OK, window->Destroy());
328 }
329 
330 
331 /**
332  * @tc.name: RequestVsyncErr
333  * @tc.desc: RequestVsync Test Err
334  * @tc.type: FUNC
335  */
HWTEST_F(WindowImplTest, RequestVsyncErr, Function | SmallTest | Level2)336 HWTEST_F(WindowImplTest, RequestVsyncErr, Function | SmallTest | Level2)
337 {
338     sptr<WindowOption> option = new WindowOption();
339     option->SetWindowName("RequestVsyncErr");
340     sptr<WindowImpl> window = new WindowImpl(option);
341     ASSERT_NE(window, nullptr);
342     std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
343     window->SetWindowState(WindowState::STATE_DESTROYED);
344     ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
345     window->vsyncStation_ = nullptr;
346     window->RequestVsync(vsyncCallback);
347     ASSERT_EQ(WMError::WM_OK, window->Destroy());
348 }
349 
350 /**
351  * @tc.name: ClearVsync
352  * @tc.desc: Clear vsync test
353  * @tc.type: FUNC
354  */
HWTEST_F(WindowImplTest, ClearVsync, Function | SmallTest | Level2)355 HWTEST_F(WindowImplTest, ClearVsync, Function | SmallTest | Level2)
356 {
357     sptr<WindowOption> option = new WindowOption();
358     ASSERT_NE(option, nullptr);
359     option->SetWindowName("ClearVsync");
360     sptr<WindowImpl> window = new WindowImpl(option);
361     ASSERT_NE(window, nullptr);
362     window->ClearVsyncStation();
363     ASSERT_NE(window, nullptr);
364 }
365 
366 /**
367  * @tc.name: InitWindowProperty
368  * @tc.desc: InitWindowProperty Test
369  * @tc.type: FUNC
370  */
HWTEST_F(WindowImplTest, InitWindowProperty, Function | SmallTest | Level2)371 HWTEST_F(WindowImplTest, InitWindowProperty, Function | SmallTest | Level2)
372 {
373     sptr<WindowOption> option = new WindowOption();
374     option->SetWindowName("InitWindowProperty");
375     sptr<WindowImpl> window = new WindowImpl(option);
376     ASSERT_NE(window, nullptr);
377     window->InitWindowProperty(option);
378     ASSERT_EQ(WMError::WM_OK, window->Destroy());
379 }
380 
381 /**
382  * @tc.name: FindWindowById01
383  * @tc.desc: Find one top window
384  * @tc.type: FUNC
385  */
HWTEST_F(WindowImplTest, FindWindowById01, Function | SmallTest | Level2)386 HWTEST_F(WindowImplTest, FindWindowById01, Function | SmallTest | Level2)
387 {
388     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
389     sptr<WindowOption> option = new WindowOption();
390     option->SetWindowName("FindWindowById01");
391     sptr<WindowImpl> window = new WindowImpl(option);
392     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
393     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
394     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
395 
396     ASSERT_NE(nullptr, window->FindWindowById(window->property_->GetWindowId()));
397 
398     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
399     ASSERT_EQ(WMError::WM_OK, window->Destroy());
400 }
401 
402 /**
403  * @tc.name: SetWindowType01
404  * @tc.desc: SetWindowType
405  * @tc.type: FUNC
406  */
HWTEST_F(WindowImplTest, SetWindowType01, Function | SmallTest | Level2)407 HWTEST_F(WindowImplTest, SetWindowType01, Function | SmallTest | Level2)
408 {
409     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
410     sptr<WindowOption> option = new WindowOption();
411     option->SetWindowName("SetWindowType01");
412     sptr<WindowImpl> window = new WindowImpl(option);
413     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
414     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
415     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
416     ASSERT_EQ(WMError::WM_OK, window->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
417     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
418     ASSERT_EQ(WMError::WM_OK, window->Destroy());
419 }
420 
421 /**
422  * @tc.name: SetWindowMode01
423  * @tc.desc: SetWindowMode
424  * @tc.type: FUNC
425  */
HWTEST_F(WindowImplTest, SetWindowMode01, Function | SmallTest | Level2)426 HWTEST_F(WindowImplTest, SetWindowMode01, Function | SmallTest | Level2)
427 {
428     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
429     sptr<WindowOption> option = new WindowOption();
430     option->SetWindowName("SetWindowType01");
431     sptr<WindowImpl> window = new WindowImpl(option);
432     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
433     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
434     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
435     ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
436     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
437     ASSERT_EQ(WMError::WM_OK, window->Destroy());
438 }
439 
440 /**
441  * @tc.name: SetWindowMode02
442  * @tc.desc: Set window mode to split primary
443  * @tc.type: FUNC
444  */
HWTEST_F(WindowImplTest, SetWindowMode02, Function | SmallTest | Level3)445 HWTEST_F(WindowImplTest, SetWindowMode02, Function | SmallTest | Level3)
446 {
447     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
448     sptr<WindowOption> option = new WindowOption();
449     option->SetWindowName("");
450     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
451     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
452     sptr<WindowImpl> window = new WindowImpl(option);
453     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
454     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
455     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
456     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
457     ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY));
458     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, window->GetMode());
459     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
460     ASSERT_EQ(WMError::WM_OK, window->Destroy());
461 }
462 
463 /**
464  * @tc.name: SetWindowMode03
465  * @tc.desc: Set window mode to split secondary
466  * @tc.type: FUNC
467  */
HWTEST_F(WindowImplTest, SetWindowMode03, Function | SmallTest | Level3)468 HWTEST_F(WindowImplTest, SetWindowMode03, Function | SmallTest | Level3)
469 {
470     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
471     sptr<WindowOption> option = new WindowOption();
472     option->SetWindowName("");
473     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
474     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
475     sptr<WindowImpl> window = new WindowImpl(option);
476     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
477     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
478     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
479     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
480     ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY));
481     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, window->GetMode());
482     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
483     ASSERT_EQ(WMError::WM_OK, window->Destroy());
484 }
485 
486 /**
487  * @tc.name: SetWindowMode04
488  * @tc.desc: Set window mode to floating
489  * @tc.type: FUNC
490  */
HWTEST_F(WindowImplTest, SetWindowMode04, Function | SmallTest | Level3)491 HWTEST_F(WindowImplTest, SetWindowMode04, Function | SmallTest | Level3)
492 {
493     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
494     sptr<WindowOption> option = new WindowOption();
495     option->SetWindowName("");
496     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
497     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
498     sptr<WindowImpl> window = new WindowImpl(option);
499     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
500     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
501     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
502     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
503     ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING));
504     ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode());
505     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
506     ASSERT_EQ(WMError::WM_OK, window->Destroy());
507 }
508 
509 /**
510  * @tc.name: SetWindowMode05
511  * @tc.desc: Set window mode to pip
512  * @tc.type: FUNC
513  */
HWTEST_F(WindowImplTest, SetWindowMode05, Function | SmallTest | Level3)514 HWTEST_F(WindowImplTest, SetWindowMode05, Function | SmallTest | Level3)
515 {
516     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
517     sptr<WindowOption> option = new WindowOption();
518     option->SetWindowName("");
519     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
520     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
521     sptr<WindowImpl> window = new WindowImpl(option);
522     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
523     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
524     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
525     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
526     ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_PIP));
527     ASSERT_EQ(WindowMode::WINDOW_MODE_PIP, window->GetMode());
528     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
529     ASSERT_EQ(WMError::WM_OK, window->Destroy());
530 }
531 
532 /**
533  * @tc.name: ShowHideWindow01
534  * @tc.desc: Show and hide window with add and remove window ok
535  * @tc.type: FUNC
536  */
HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2)537 HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2)
538 {
539     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
540     sptr<WindowOption> option = new WindowOption();
541     option->SetWindowName("ShowHideWindow01");
542     sptr<WindowImpl> window = new WindowImpl(option);
543     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
544     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
545     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
546     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
547     ASSERT_EQ(WMError::WM_OK, window->Show());
548     window->NotifyForeground();
549     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
550     ASSERT_EQ(WMError::WM_OK, window->Hide());
551     window->NotifyBackground();
552     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
553     ASSERT_EQ(WMError::WM_OK, window->Destroy());
554 }
555 
556 /**
557  * @tc.name: ShowHideWindow02
558  * @tc.desc: Show window with add window WM_ERROR_SAMGR
559  * @tc.type: FUNC
560  */
HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2)561 HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2)
562 {
563     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
564     sptr<WindowOption> option = new WindowOption();
565     option->SetWindowName("ShowHideWindow02");
566     sptr<WindowImpl> window = new WindowImpl(option);
567     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
568     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
569     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
570     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
571     ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Show());
572     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
573     ASSERT_EQ(WMError::WM_OK, window->Destroy());
574 }
575 
576 /**
577  * @tc.name: ShowHideWindow03
578  * @tc.desc: Show window with add window WM_ERROR_IPC_FAILED
579  * @tc.type: FUNC
580  */
HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3)581 HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3)
582 {
583     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
584     sptr<WindowOption> option = new WindowOption();
585     option->SetWindowName("ShowHideWindow03");
586     sptr<WindowImpl> window = new WindowImpl(option);
587     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
588     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
589     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
590     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED));
591     ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window->Show());
592     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
593     ASSERT_EQ(WMError::WM_OK, window->Destroy());
594 }
595 
596 /**
597  * @tc.name: ShowHideWindow04
598  * @tc.desc: Show window with add window OK & Hide window with remove window WM_ERROR_SAMGR
599  * @tc.type: FUNC
600  */
HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3)601 HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3)
602 {
603     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
604     sptr<WindowOption> option = new WindowOption();
605     option->SetWindowName("ShowHideWindow04");
606     sptr<WindowImpl> window = new WindowImpl(option);
607     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
608     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
609     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
610     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
611     ASSERT_EQ(WMError::WM_OK, window->Show());
612     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
613     ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Hide());
614     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
615     ASSERT_EQ(WMError::WM_OK, window->Destroy());
616 }
617 
618 /**
619  * @tc.name: ShowHideWindow05
620  * @tc.desc: Hide window with remove window WM_ERROR_IPC_FAILED
621  * @tc.type: FUNC
622  */
HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3)623 HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3)
624 {
625     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
626     sptr<WindowOption> option = new WindowOption();
627     option->SetWindowName("ShowHideWindow05");
628     sptr<WindowImpl> window = new WindowImpl(option);
629     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
630     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
631     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
632     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
633     ASSERT_EQ(WMError::WM_OK, window->Show());
634     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED));
635     ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window->Hide());
636     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
637     ASSERT_EQ(WMError::WM_OK, window->Destroy());
638 }
639 
640 /**
641  * @tc.name: ShowHideWindow06
642  * @tc.desc: Hide window with remove window OK
643  * @tc.type: FUNC
644  */
HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3)645 HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3)
646 {
647     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
648     sptr<WindowOption> option = new WindowOption();
649     option->SetWindowName("ShowHideWindow06");
650     sptr<WindowImpl> window = new WindowImpl(option);
651     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
652     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
653     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
654     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
655     ASSERT_EQ(WMError::WM_OK, window->Show());
656     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
657     ASSERT_EQ(WMError::WM_OK, window->Hide());
658     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
659     ASSERT_EQ(WMError::WM_OK, window->Destroy());
660 }
661 
662 /**
663  * @tc.name: SetSystemBarProperty01
664  * @tc.desc: SetSystemBarProperty with default param
665  * @tc.type: FUNC
666  */
HWTEST_F(WindowImplTest, SetSystemBarProperty01, Function | SmallTest | Level3)667 HWTEST_F(WindowImplTest, SetSystemBarProperty01, Function | SmallTest | Level3)
668 {
669     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
670     sptr<WindowOption> option = new WindowOption();
671     option->SetWindowName("SetSystemBarProperty01");
672     sptr<WindowImpl> window = new WindowImpl(option);
673     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
674     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
675     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
676 
677     WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
678     SystemBarProperty prop;
679     ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(type, prop));
680     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
681     ASSERT_EQ(WMError::WM_OK, window->Destroy());
682 }
683 
684 /**
685  * @tc.name: SetSystemBarProperty02
686  * @tc.desc: SetSystemBarProperty with adapter return WM_ERROR_SAMGR
687  * @tc.type: FUNC
688  */
HWTEST_F(WindowImplTest, SetSystemBarProperty02, Function | SmallTest | Level3)689 HWTEST_F(WindowImplTest, SetSystemBarProperty02, Function | SmallTest | Level3)
690 {
691     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
692     sptr<WindowOption> option = new WindowOption();
693     option->SetWindowName("SetSystemBarProperty02");
694     sptr<WindowImpl> window = new WindowImpl(option);
695     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
696     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
697     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
698 
699     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
700     window->Show();
701     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
702     WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
703     const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333333);
704     ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->SetSystemBarProperty(type, SYS_BAR_PROP));
705     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
706     window->Hide();
707     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
708     ASSERT_EQ(WMError::WM_OK, window->Destroy());
709 }
710 
711 /**
712  * @tc.name: SetSystemBarProperty03
713  * @tc.desc: SetSystemBarProperty to invalid window
714  * @tc.type: FUNC
715  */
HWTEST_F(WindowImplTest, SetSystemBarProperty03, Function | SmallTest | Level3)716 HWTEST_F(WindowImplTest, SetSystemBarProperty03, Function | SmallTest | Level3)
717 {
718     sptr<WindowOption> option = new WindowOption();
719     option->SetWindowName("SetSystemBarProperty03");
720     sptr<WindowImpl> window = new WindowImpl(option);
721     WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
722     SystemBarProperty prop;
723     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetSystemBarProperty(type, prop));
724 }
725 
726 /**
727  * @tc.name: GetSystemBarPropertyByType01
728  * @tc.desc: GetSystemBarPropertyByType with exist key
729  * @tc.type: FUNC
730  */
HWTEST_F(WindowImplTest, GetSystemBarPropertyByType01, Function | SmallTest | Level3)731 HWTEST_F(WindowImplTest, GetSystemBarPropertyByType01, Function | SmallTest | Level3)
732 {
733     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
734     sptr<WindowOption> option = new WindowOption();
735     option->SetWindowName("GetSystemBarPropertyByType01");
736     sptr<WindowImpl> window = new WindowImpl(option);
737     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
738     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
739     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
740 
741     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
742     ASSERT_EQ(WMError::WM_OK, window->Show());
743     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
744     WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
745     const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333344);
746     ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(type, SYS_BAR_PROP));
747     ASSERT_EQ(SYS_BAR_PROP, window->GetSystemBarPropertyByType(type));
748     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
749     window->Hide();
750     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
751     ASSERT_EQ(WMError::WM_OK, window->Destroy());
752 }
753 
754 /**
755  * @tc.name: GetSystemBarPropertyByType02
756  * @tc.desc: GetSystemBarPropertyByType with nonexist key
757  * @tc.type: FUNC
758  */
HWTEST_F(WindowImplTest, GetSystemBarPropertyByType02, Function | SmallTest | Level3)759 HWTEST_F(WindowImplTest, GetSystemBarPropertyByType02, Function | SmallTest | Level3)
760 {
761     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
762     sptr<WindowOption> option = new WindowOption();
763     option->SetWindowName("GetSystemBarPropertyByType02");
764     sptr<WindowImpl> window = new WindowImpl(option);
765     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
766     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
767     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
768 
769     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
770     window->Show();
771     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
772     const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333333);
773     const SystemBarProperty DEFAULT_PROP;
774     ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP));
775     ASSERT_EQ(DEFAULT_PROP, window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR));
776     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
777     window->Hide();
778     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
779     ASSERT_EQ(WMError::WM_OK, window->Destroy());
780 }
781 
782 /**
783  * @tc.name: GetSystemBarPropertyByType03
784  * @tc.desc: GetSystemBarPropertyByType with not systemBar type
785  * @tc.type: FUNC
786  */
HWTEST_F(WindowImplTest, GetSystemBarPropertyByType03, Function | SmallTest | Level3)787 HWTEST_F(WindowImplTest, GetSystemBarPropertyByType03, Function | SmallTest | Level3)
788 {
789     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
790     sptr<WindowOption> option = new WindowOption();
791     option->SetWindowName("GetSystemBarPropertyByType03");
792     sptr<WindowImpl> window = new WindowImpl(option);
793     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
794     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
795     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
796 
797     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
798     window->Show();
799     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
800     const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333366);
801     const SystemBarProperty DEFAULT_PROP;
802     ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP));
803     ASSERT_EQ(DEFAULT_PROP, window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
804     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
805     window->Hide();
806     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
807     ASSERT_EQ(WMError::WM_OK, window->Destroy());
808 }
809 
810 /**
811  * @tc.name: Maximize02
812  * @tc.desc: Maximize the sub window
813  * @tc.type: FUNC
814  */
HWTEST_F(WindowImplTest, Maximize02, Function | SmallTest | Level3)815 HWTEST_F(WindowImplTest, Maximize02, Function | SmallTest | Level3)
816 {
817     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
818     sptr<WindowOption> option = new WindowOption();
819     option->SetWindowName("Maximize02");
820     sptr<WindowImpl> window = new WindowImpl(option);
821     window->Maximize();
822     ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, window->GetMode());
823     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
824     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
825     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
826     window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
827     window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
828     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
829     window->Show();
830     window->Maximize();
831     ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode());
832 
833     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
834     window->Hide();
835     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
836     ASSERT_EQ(WMError::WM_OK, window->Destroy());
837 }
838 
839 /**
840  * @tc.name: Recover01
841  * @tc.desc: Recover the main window
842  * @tc.type: FUNC
843  */
HWTEST_F(WindowImplTest, Recover01, Function | SmallTest | Level3)844 HWTEST_F(WindowImplTest, Recover01, Function | SmallTest | Level3)
845 {
846     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
847     sptr<WindowOption> option = new WindowOption();
848     option->SetWindowName("Recover01");
849     sptr<WindowImpl> window = new WindowImpl(option);
850     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Recover());
851     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
852     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
853     window->Create(INVALID_WINDOW_ID);
854     window->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
855     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
856     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
857     window->Show();
858     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
859     window->Recover();
860     ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode());
861     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
862     window->Hide();
863     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
864     ASSERT_EQ(WMError::WM_OK, window->Destroy());
865 }
866 
867 /**
868  * @tc.name: Recover02
869  * @tc.desc: Recover the sub window
870  * @tc.type: FUNC
871  */
HWTEST_F(WindowImplTest, Recover02, Function | SmallTest | Level3)872 HWTEST_F(WindowImplTest, Recover02, Function | SmallTest | Level3)
873 {
874     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
875     sptr<WindowOption> option = new WindowOption();
876     option->SetWindowName("Recover02");
877     sptr<WindowImpl> window = new WindowImpl(option);
878     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
879     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
880     window->Create(INVALID_WINDOW_ID);
881     window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
882     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
883     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
884     window->Show();
885     window->Recover();
886     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
887     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
888     window->Hide();
889     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
890     ASSERT_EQ(WMError::WM_OK, window->Destroy());
891 }
892 
893 /**
894  * @tc.name: Minimize01
895  * @tc.desc: Minimize the main window
896  * @tc.type: FUNC
897  */
HWTEST_F(WindowImplTest, Minimize01, Function | SmallTest | Level3)898 HWTEST_F(WindowImplTest, Minimize01, Function | SmallTest | Level3)
899 {
900     auto option = new WindowOption();
901     option->SetWindowName("Minimize01");
902     sptr<WindowImpl> window = new WindowImpl(option);
903     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Minimize());
904     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
905     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
906     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
907     window->Create(INVALID_WINDOW_ID);
908     window->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
909     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
910     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
911     window->Show();
912     ASSERT_TRUE((window->GetWindowState() == WindowState::STATE_SHOWN));
913     EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
914     window->Minimize();
915     ASSERT_FALSE((window->GetWindowState() == WindowState::STATE_SHOWN));
916     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
917     ASSERT_EQ(WMError::WM_OK, window->Minimize());
918     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
919     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window->uiContent_.get());
920     EXPECT_CALL(*content, Destroy());
921     ASSERT_EQ(WMError::WM_OK, window->Destroy());
922 }
923 
924 /**
925  * @tc.name: Minimize02
926  * @tc.desc: Minimize the sub window
927  * @tc.type: FUNC
928  */
HWTEST_F(WindowImplTest, Minimize02, Function | SmallTest | Level3)929 HWTEST_F(WindowImplTest, Minimize02, Function | SmallTest | Level3)
930 {
931     auto option = new WindowOption();
932     option->SetWindowName("Minimize02");
933     sptr<WindowImpl> window = new WindowImpl(option);
934     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
935     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
936     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
937     window->Create(INVALID_WINDOW_ID);
938     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
939     window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
940     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
941     window->Show();
942     ASSERT_TRUE((window->GetWindowState() == WindowState::STATE_SHOWN));
943     window->Minimize();
944     ASSERT_TRUE((window->GetWindowState() == WindowState::STATE_SHOWN));
945     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
946     ASSERT_EQ(WMError::WM_OK, window->Destroy());
947 }
948 
949 /**
950  * @tc.name: IsSupportWideGamut01
951  * @tc.desc: IsSupportWideGamut
952  * @tc.type: FUNC
953  */
HWTEST_F(WindowImplTest, IsSupportWideGamut01, Function | SmallTest | Level3)954 HWTEST_F(WindowImplTest, IsSupportWideGamut01, Function | SmallTest | Level3)
955 {
956     auto option = new WindowOption();
957     option->SetWindowName("IsSupportWideGamut01");
958     sptr<WindowImpl> window = new WindowImpl(option);
959     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
960     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
961     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
962     window->Create(INVALID_WINDOW_ID);
963     window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
964     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
965     ASSERT_TRUE(window->IsSupportWideGamut());
966     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
967     ASSERT_EQ(WMError::WM_OK, window->Destroy());
968 }
969 
970 /**
971  * @tc.name: SetColorSpace01
972  * @tc.desc: SetColorSpace
973  * @tc.type: FUNC
974  */
HWTEST_F(WindowImplTest, SetColorSpace01, Function | SmallTest | Level3)975 HWTEST_F(WindowImplTest, SetColorSpace01, Function | SmallTest | Level3)
976 {
977     auto option = new WindowOption();
978     option->SetWindowName("SetColorSpace01");
979     sptr<WindowImpl> window = new WindowImpl(option);
980     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
981     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
982     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
983     window->Create(INVALID_WINDOW_ID);
984     window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
985     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
986     window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
987     ASSERT_EQ(ColorSpace::COLOR_SPACE_WIDE_GAMUT, window->GetColorSpace());
988     window->SetColorSpace(ColorSpace::COLOR_SPACE_DEFAULT);
989     ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
990     uint32_t invalidColorSpace = 1234u;
991     window->SetColorSpace(static_cast<ColorSpace>(invalidColorSpace));
992     ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
993     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
994     ASSERT_EQ(WMError::WM_OK, window->Destroy());
995 }
996 
997 /**
998  * @tc.name: GetColorSpace01
999  * @tc.desc: GetColorSpace
1000  * @tc.type: FUNC
1001  */
HWTEST_F(WindowImplTest, GetColorSpace01, Function | SmallTest | Level3)1002 HWTEST_F(WindowImplTest, GetColorSpace01, Function | SmallTest | Level3)
1003 {
1004     auto option = new WindowOption();
1005     option->SetWindowName("GetColorSpace01");
1006     sptr<WindowImpl> window = new WindowImpl(option);
1007     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1008     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1009     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1010     window->Create(INVALID_WINDOW_ID);
1011     window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1012     window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1013     window->SetColorSpace(ColorSpace::COLOR_SPACE_DEFAULT);
1014     ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
1015     window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
1016     ASSERT_EQ(ColorSpace::COLOR_SPACE_WIDE_GAMUT, window->GetColorSpace());
1017     uint32_t invalidColorSpace = 54321u;
1018     window->SetColorSpace(static_cast<ColorSpace>(invalidColorSpace));
1019     ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
1020     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1021     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1022 }
1023 
1024 /**
1025  * @tc.name: StartMove01
1026  * @tc.desc: start move main fullscreen window, test startMoveFlag
1027  * @tc.type: FUNC
1028  * @tc.require: issueI5J8IB
1029  */
HWTEST_F(WindowImplTest, StartMove01, Function | SmallTest | Level3)1030 HWTEST_F(WindowImplTest, StartMove01, Function | SmallTest | Level3)
1031 {
1032     sptr<WindowOption> option = new WindowOption();
1033     option->SetWindowName("StartMove01");
1034     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1035     sptr<WindowImpl> window = new WindowImpl(option);
1036     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1037 
1038     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1039     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1040     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1041     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1042     window->Show();
1043     window->StartMove();
1044     ASSERT_FALSE(window->moveDragProperty_->startMoveFlag_);
1045     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1046     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1047 }
1048 
1049 /**
1050  * @tc.name: StartMove02
1051  * @tc.desc: start move main fullscreen window, test startMoveFlag
1052  * @tc.type: FUNC
1053  * @tc.require: issueI5J8IB
1054  */
HWTEST_F(WindowImplTest, StartMove02, Function | SmallTest | Level3)1055 HWTEST_F(WindowImplTest, StartMove02, Function | SmallTest | Level3)
1056 {
1057     sptr<WindowOption> option = new WindowOption();
1058     option->SetWindowName("StartMove02");
1059     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1060     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1061     sptr<WindowImpl> window = new WindowImpl(option);
1062     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1063 
1064     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1065     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1066     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1067     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1068     window->Show();
1069 
1070     window->StartMove();
1071     ASSERT_FALSE(window->moveDragProperty_->startMoveFlag_);
1072     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1073     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1074 }
1075 
1076 /**
1077  * @tc.name: StartMove03
1078  * @tc.desc: start move divider, test startMoveFlag
1079  * @tc.type: FUNC
1080  * @tc.require: issueI5J8IB
1081  */
HWTEST_F(WindowImplTest, StartMove03, Function | SmallTest | Level3)1082 HWTEST_F(WindowImplTest, StartMove03, Function | SmallTest | Level3)
1083 {
1084     sptr<WindowOption> option = new WindowOption();
1085     option->SetWindowName("StartMove03");
1086     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1087     option->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE);
1088     sptr<WindowImpl> window = new WindowImpl(option);
1089     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1090 
1091     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1092     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1093     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1094     window->Show();
1095     window->StartMove();
1096     ASSERT_FALSE(window->moveDragProperty_->startMoveFlag_);
1097     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1098     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1099 }
1100 
1101 /**
1102  * @tc.name: SetBackgroundColor01
1103  * @tc.desc: test SetBackgroundColor withow uiContent
1104  * @tc.type: FUNC
1105  */
HWTEST_F(WindowImplTest, SetBackgroundColor01, Function | SmallTest | Level3)1106 HWTEST_F(WindowImplTest, SetBackgroundColor01, Function | SmallTest | Level3)
1107 {
1108     sptr<WindowOption> option = new WindowOption();
1109     option->SetWindowName("SetBackgroundColor01");
1110     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1111     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1112     sptr<WindowImpl> window = new WindowImpl(option);
1113     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1114 
1115     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1116     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1117     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1118     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1119     window->Show();
1120     ASSERT_FALSE(window->IsTransparent());
1121     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackgroundColor("#000"));
1122     ASSERT_FALSE(window->IsTransparent());
1123     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->SetBackgroundColor("#00FF00"));
1124     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->SetBackgroundColor("#FF00FF00"));
1125     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1126     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1127 }
1128 
1129 /**
1130  * @tc.name: SetTurnScreenOn01
1131  * @tc.desc: create window but not show, test SetTurnScreenOn
1132  * @tc.type: FUNC
1133  */
HWTEST_F(WindowImplTest, SetTurnScreenOn01, Function | SmallTest | Level3)1134 HWTEST_F(WindowImplTest, SetTurnScreenOn01, Function | SmallTest | Level3)
1135 {
1136     sptr<WindowOption> option = new WindowOption();
1137     option->SetWindowName("SetTurnScreenOn01");
1138     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1139     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1140     sptr<WindowImpl> window = new WindowImpl(option);
1141     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTurnScreenOn(true));
1142     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1143 
1144     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1145     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1146     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1147     ASSERT_FALSE(window->IsTurnScreenOn());
1148     ASSERT_EQ(WMError::WM_OK, window->SetTurnScreenOn(true));
1149     ASSERT_TRUE(window->IsTurnScreenOn());
1150     ASSERT_EQ(WMError::WM_OK, window->SetTurnScreenOn(false));
1151     ASSERT_FALSE(window->IsTurnScreenOn());
1152     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1153     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1154 }
1155 
1156 
1157 /**
1158  * @tc.name: SetTurnScreenOn02
1159  * @tc.desc: create window with show, test SetTurnScreenOn
1160  * @tc.type: FUNC
1161  */
HWTEST_F(WindowImplTest, SetTurnScreenOn02, Function | SmallTest | Level3)1162 HWTEST_F(WindowImplTest, SetTurnScreenOn02, Function | SmallTest | Level3)
1163 {
1164     sptr<WindowOption> option = new WindowOption();
1165     option->SetWindowName("SetTurnScreenOn02");
1166     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1167     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1168     sptr<WindowImpl> window = new WindowImpl(option);
1169     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1170 
1171     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1172     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1173     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1174     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1175     ASSERT_EQ(WMError::WM_OK, window->Show());
1176     ASSERT_FALSE(window->IsTurnScreenOn());
1177     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2).WillOnce(Return(WMError::WM_OK))
1178         .WillOnce(Return(WMError::WM_OK));
1179     ASSERT_EQ(WMError::WM_OK, window->SetTurnScreenOn(true));
1180     ASSERT_TRUE(window->IsTurnScreenOn());
1181     ASSERT_EQ(WMError::WM_OK, window->SetTurnScreenOn(false));
1182     ASSERT_FALSE(window->IsTurnScreenOn());
1183     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1184     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1185 }
1186 
1187 /**
1188  * @tc.name: SetKeepScreenOn01
1189  * @tc.desc: create window but not show, test SetKeepScreenOn
1190  * @tc.type: FUNC
1191  */
HWTEST_F(WindowImplTest, SetKeepScreenOn01, Function | SmallTest | Level3)1192 HWTEST_F(WindowImplTest, SetKeepScreenOn01, Function | SmallTest | Level3)
1193 {
1194     sptr<WindowOption> option = new WindowOption();
1195     option->SetWindowName("SetKeepScreenOn01");
1196     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1197     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1198     sptr<WindowImpl> window = new WindowImpl(option);
1199     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetKeepScreenOn(true));
1200     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1201 
1202     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1203     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1204     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1205     ASSERT_FALSE(window->IsKeepScreenOn());
1206     ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(true));
1207     ASSERT_TRUE(window->IsKeepScreenOn());
1208     ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(false));
1209     ASSERT_FALSE(window->IsKeepScreenOn());
1210     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1211     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1212 }
1213 
1214 /**
1215  * @tc.name: SetKeepScreenOn02
1216  * @tc.desc: create window with show, test SetKeepScreenOn
1217  * @tc.type: FUNC
1218  */
HWTEST_F(WindowImplTest, SetKeepScreenOn02, Function | SmallTest | Level3)1219 HWTEST_F(WindowImplTest, SetKeepScreenOn02, Function | SmallTest | Level3)
1220 {
1221     sptr<WindowOption> option = new WindowOption();
1222     option->SetWindowName("SetKeepScreenOn02");
1223     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1224     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1225     sptr<WindowImpl> window = new WindowImpl(option);
1226     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1227 
1228     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1229     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1230     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1231     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1232     ASSERT_EQ(WMError::WM_OK, window->Show());
1233     ASSERT_FALSE(window->IsKeepScreenOn());
1234     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2).WillOnce(Return(WMError::WM_OK))
1235         .WillOnce(Return(WMError::WM_OK));;
1236     ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(true));
1237     ASSERT_TRUE(window->IsKeepScreenOn());
1238     ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(false));
1239     ASSERT_FALSE(window->IsKeepScreenOn());
1240 
1241     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1242     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1243 }
1244 
1245 /**
1246  * @tc.name: SetBrightness01
1247  * @tc.desc: test SetBrightness with invalid brightness
1248  * @tc.type: FUNC
1249  */
HWTEST_F(WindowImplTest, SetBrightness01, Function | SmallTest | Level3)1250 HWTEST_F(WindowImplTest, SetBrightness01, Function | SmallTest | Level3)
1251 {
1252     sptr<WindowOption> option = new WindowOption();
1253     option->SetWindowName("SetBrightness01");
1254     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1255     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1256     sptr<WindowImpl> window = new WindowImpl(option);
1257     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetBrightness(0.f));
1258     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1259 
1260     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1261     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1262     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1263     ASSERT_EQ(WMError::WM_OK, window->SetBrightness(MAXIMUM_BRIGHTNESS));
1264 
1265     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1266     ASSERT_EQ(WMError::WM_OK, window->Show());
1267     ASSERT_EQ(MAXIMUM_BRIGHTNESS, window->GetBrightness());
1268     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBrightness(2.0f)); // 2.0f: brightness
1269     ASSERT_EQ(MAXIMUM_BRIGHTNESS, window->GetBrightness());
1270     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBrightness(-0.5f)); // -0.5f: brightness
1271     ASSERT_EQ(MAXIMUM_BRIGHTNESS, window->GetBrightness());
1272 
1273     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1274     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1275 }
1276 
1277 /**
1278  * @tc.name: SetBrightness02
1279  * @tc.desc: test SetBrightness with valid brightness
1280  * @tc.type: FUNC
1281  */
HWTEST_F(WindowImplTest, SetBrightness02, Function | SmallTest | Level3)1282 HWTEST_F(WindowImplTest, SetBrightness02, Function | SmallTest | Level3)
1283 {
1284     sptr<WindowOption> option = new WindowOption();
1285     option->SetWindowName("SetBrightness02");
1286     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1287     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1288     sptr<WindowImpl> window = new WindowImpl(option);
1289     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1290 
1291     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1292     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1293     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1294     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1295     ASSERT_EQ(WMError::WM_OK, window->Show());
1296     ASSERT_EQ(UNDEFINED_BRIGHTNESS, window->GetBrightness());
1297     EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2).WillOnce(Return(WMError::WM_OK))
1298         .WillOnce(Return(WMError::WM_OK));
1299     ASSERT_EQ(WMError::WM_OK, window->SetBrightness(MAXIMUM_BRIGHTNESS));
1300     ASSERT_EQ(MAXIMUM_BRIGHTNESS, window->GetBrightness());
1301     ASSERT_EQ(WMError::WM_OK, window->SetBrightness(MINIMUM_BRIGHTNESS));
1302     ASSERT_EQ(MINIMUM_BRIGHTNESS, window->GetBrightness());
1303 
1304     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1305     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1306 }
1307 
1308 /**
1309  * @tc.name: SetBrightness03
1310  * @tc.desc: test SetBrightness with invalid type window
1311  * @tc.type: FUNC
1312  */
HWTEST_F(WindowImplTest, SetBrightness03, Function | SmallTest | Level3)1313 HWTEST_F(WindowImplTest, SetBrightness03, Function | SmallTest | Level3)
1314 {
1315     sptr<WindowOption> option = new WindowOption();
1316     option->SetWindowName("SetBrightness03");
1317     option->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
1318     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1319     sptr<WindowImpl> window = new WindowImpl(option);
1320     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1321 
1322     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1323     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1324     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1325     ASSERT_EQ(WMError::WM_OK, window->Show());
1326     ASSERT_EQ(UNDEFINED_BRIGHTNESS, window->GetBrightness());
1327     ASSERT_EQ(WMError::WM_ERROR_INVALID_TYPE, window->SetBrightness(MAXIMUM_BRIGHTNESS));
1328     ASSERT_EQ(UNDEFINED_BRIGHTNESS, window->GetBrightness());
1329 
1330     EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1331     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1332 }
1333 
1334 /*
1335  * @tc.name: RequestVsync
1336  * @tc.desc: RequestVsync test
1337  * @tc.type: FUNC
1338  */
HWTEST_F(WindowImplTest, RequestVsync, Function | SmallTest | Level3)1339 HWTEST_F(WindowImplTest, RequestVsync, Function | SmallTest | Level3)
1340 {
1341     sptr<WindowOption> option = new WindowOption();
1342     option->SetWindowName("RequestVsync");
1343     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1344     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1345     sptr<WindowImpl> window = new WindowImpl(option);
1346     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1347     window->RestoreSplitWindowMode(0u);
1348     EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
1349     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1350     ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
1351 
1352 
1353     EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1354     ASSERT_EQ(WMError::WM_OK, window->Show());
1355     std::shared_ptr<VsyncCallback> callback = std::make_shared<VsyncCallback>();
1356     window->SetWindowState(WindowState::STATE_DESTROYED);
1357     ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
1358     window->RequestVsync(callback);
1359 
1360     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1361     window->SetWindowState(WindowState::STATE_DESTROYED);
1362     ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
1363     window->RequestVsync(callback);
1364 }
1365 
1366 /*
1367  * @tc.name: Create3
1368  * @tc.desc: Create3 WindowCreateCheck
1369  * @tc.type: FUNC
1370  */
HWTEST_F(WindowImplTest, Create3, Function | SmallTest | Level3)1371 HWTEST_F(WindowImplTest, Create3, Function | SmallTest | Level3)
1372 {
1373     sptr<WindowOption> option = new WindowOption();
1374     option->SetWindowName("WindowCreateCheck2");
1375     option->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1376     option->SetWindowType(WindowType::WINDOW_TYPE_VOLUME_OVERLAY);
1377     option->SetWindowRect({ 1, 1, 1, 1 });
1378     option->SetBundleName("OK");
1379     ASSERT_NE(option, nullptr);
1380     sptr<WindowImpl> window = new WindowImpl(option);
1381     ASSERT_NE(window, nullptr);
1382 
1383     std::shared_ptr<AbilityRuntime::AbilityContext> context =
1384         std::make_shared<AbilityRuntime::AbilityContextImpl>();
1385     WMError res = window->Create(1, context);
1386     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARENT, res);
1387     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1388 }
1389 
1390 /**
1391  * @tc.name: SetRestoredRouterStack_0100
1392  * @tc.desc: basic function test of set or get restored router stack.
1393  * @tc.type: FUNC
1394  * @tc.require: issue
1395  */
HWTEST_F(WindowImplTest, SetRestoredRouterStack_0100, Function | SmallTest | Level3)1396 HWTEST_F(WindowImplTest, SetRestoredRouterStack_0100, Function | SmallTest | Level3)
1397 {
1398     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1399     ASSERT_NE(option, nullptr);
1400     sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1401     ASSERT_NE(window, nullptr);
1402     std::string routerStack = "stackInfo:{}";
1403     EXPECT_EQ(window->SetRestoredRouterStack(routerStack), WMError::WM_OK);
1404     std::string gettedStack = window->GetRestoredRouterStack();
1405     EXPECT_EQ(gettedStack, routerStack);
1406     EXPECT_TRUE(window->GetRestoredRouterStack().empty());
1407 }
1408 }
1409 } // namespace Rosen
1410 } // namespace OHOS
1411