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 // gtest
17 #include <gtest/gtest.h>
18 #include "avoid_area_controller.h"
19 #include "modifier_render_thread/rs_modifiers_draw_thread.h"
20 #include "window_manager.h"
21 #include "window_test_utils.h"
22 #include "wm_common.h"
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 using Utils = WindowTestUtils;
29
30 class WindowSplitImmersiveTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 virtual void SetUp() override;
35 virtual void TearDown() override;
36 void IsShowTopBar(const sptr<Window>& top, bool isShow);
37 void HideAndUnregister(const sptr<Window>& fullWindow, const sptr<Window>& priWindow, const sptr<Window>& top);
38
39 std::vector<sptr<Window>> activeWindows_;
40 Utils::TestWindowInfo fullInfo_;
41 Utils::TestWindowInfo splitInfo_;
42
43 private:
44 static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time
45 };
46
SetUpTestCase()47 void WindowSplitImmersiveTest::SetUpTestCase() {}
48
TearDownTestCase()49 void WindowSplitImmersiveTest::TearDownTestCase()
50 {
51 #ifdef RS_ENABLE_VK
52 RSModifiersDrawThread::Destroy();
53 #endif
54 }
55
SetUp()56 void WindowSplitImmersiveTest::SetUp()
57 {
58 fullInfo_ = {
59 .name = "fullscreen.1",
60 .rect = Utils::customAppRect_,
61 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
62 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
63 .needAvoid = true,
64 .parentLimit = false,
65 .parentId = INVALID_WINDOW_ID,
66 };
67
68 splitInfo_ = {
69 .name = "primary.1",
70 .rect = Utils::customAppRect_,
71 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
72 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
73 .needAvoid = true,
74 .parentLimit = false,
75 .parentId = INVALID_WINDOW_ID,
76 };
77
78 activeWindows_.clear();
79 }
80
TearDown()81 void WindowSplitImmersiveTest::TearDown()
82 {
83 while (!activeWindows_.empty()) {
84 ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
85 activeWindows_.pop_back();
86 }
87 }
88
89 namespace {
90 /**
91 * @tc.name: SplitImmersive01
92 * @tc.desc: one primary window and one fullscreen window, test enter and out split immersive
93 * @tc.type: FUNC
94 */
95 HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, TestSize.Level1)
96 {
97 // create fullscreen win and show
98 fullInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
99 const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
100 if (fullWindow == nullptr) {
101 return;
102 }
103
104 activeWindows_.push_back(fullWindow);
105 ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
106 sleep(SPLIT_TEST_SLEEP_S);
107
108 // enter split mode
109 splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
110 const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
111 ASSERT_NE(nullptr, priWindow);
112 activeWindows_.push_back(priWindow);
113 ASSERT_EQ(WMError::WM_OK, priWindow->Show());
114 sleep(SPLIT_TEST_SLEEP_S);
115
116 // check is enter split Immersive
117 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetWindowMode());
118 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetWindowMode());
119 Rect immersivePriRect = priWindow->GetRect();
120 ASSERT_EQ(0, immersivePriRect.posX_);
121 ASSERT_EQ(0, immersivePriRect.posY_);
122 sleep(SPLIT_TEST_SLEEP_S);
123
124 ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
125 sleep(SPLIT_TEST_SLEEP_S);
126 ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
127 sleep(SPLIT_TEST_SLEEP_S);
128 }
129 } // namespace
130 } // namespace Rosen
131 } // namespace OHOS
132