1 /*
2 * Copyright (c) 2023 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 <cstdint>
17 #include <gtest/gtest.h>
18 #include "display_manager.h"
19 #include "window_agent.h"
20 #include "window_group_mgr.h"
21 #include "window_impl.h"
22 #include "window_property.h"
23 #include "window_root.h"
24 #include "wm_common.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowGroupMgrTest"};
33 }
34
35 class WindowGroupMgrTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 static sptr<WindowGroupMgr> windowGroupMgr_;
42 static sptr<WindowRoot> windowRoot_;
43 static DisplayId defalutDisplayId_;
44 static int missionCount_;
45 };
46
47
48 sptr<WindowGroupMgr> WindowGroupMgrTest::windowGroupMgr_ = nullptr;
49 sptr<WindowRoot> WindowGroupMgrTest::windowRoot_;
50 DisplayId WindowGroupMgrTest::defalutDisplayId_ = -1;
51 int WindowGroupMgrTest::missionCount_ = 3;
52
SetUpTestCase()53 void WindowGroupMgrTest::SetUpTestCase()
54 {
55 WLOGI("SetUpTestCase");
56 windowRoot_ = new WindowRoot(nullptr);
57 windowGroupMgr_ = new WindowGroupMgr(windowRoot_);
58
59 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
60 ASSERT_TRUE((display != nullptr));
61 sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
62 ASSERT_TRUE((displayInfo != nullptr));
63 auto container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
64 defalutDisplayId_ = display->GetId();
65
66 for (int i = 0; i < missionCount_; i++) {
67 int32_t missindId = i + 1;
68 sptr<WindowProperty> property = new WindowProperty();
69 AbilityInfo abilityInfo({"bundle_test" + std::to_string(missindId), "ability_test" + std::to_string(missindId),
70 missindId});
71 property->SetAbilityInfo(abilityInfo);
72 property->SetWindowId(static_cast<uint32_t>(missindId));
73 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
74 property->SetDisplayId(defalutDisplayId_);
75 sptr<WindowNode> node = new WindowNode(property);
76 node->abilityInfo_ = abilityInfo;
77 sptr<WindowOption> windowOption = new WindowOption();
78 sptr<WindowImpl> windowImpl = new WindowImpl(windowOption);
79 windowImpl->SetWindowState(WindowState::STATE_SHOWN);
80 sptr<IWindow> window = new WindowAgent(windowImpl);
81 node->SetWindowToken(window);
82 WLOGFI("windowId: %{public}u, missionId: %{public}d", node->GetWindowId(), node->abilityInfo_.missionId_);
83 windowRoot_->SaveWindow(node);
84 }
85 }
86
TearDownTestCase()87 void WindowGroupMgrTest::TearDownTestCase()
88 {
89 windowGroupMgr_ = nullptr;
90 windowRoot_ = nullptr;
91 defalutDisplayId_ = -1;
92 }
93
SetUp()94 void WindowGroupMgrTest::SetUp()
95 {
96 }
97
TearDown()98 void WindowGroupMgrTest::TearDown()
99 {
100 }
101
102 namespace {
103 /**
104 * @tc.name: MoveMissionsToForeground01
105 * @tc.desc: move missions to foreground
106 * @tc.type: FUNC
107 */
108 HWTEST_F(WindowGroupMgrTest, MoveMissionsToForeground01, Function | SmallTest | Level2)
109 {
110 WLOGI("MoveMissionsToForeground01");
111 auto rs = windowGroupMgr_->MoveMissionsToForeground({1, 2, 3}, 2);
112 ASSERT_EQ(WMError::WM_OK, rs);
113 rs = windowGroupMgr_->MoveMissionsToForeground({1, 2, 3}, -1);
114 ASSERT_EQ(WMError::WM_OK, rs);
115 }
116
117 /**
118 * @tc.name: MoveMissionsToBackground01
119 * @tc.desc: move missions to background
120 * @tc.type: FUNC
121 */
122 HWTEST_F(WindowGroupMgrTest, MoveMissionsToBackground01, Function | SmallTest | Level2)
123 {
124 std::vector<int32_t> moveRs;
125 auto rs = windowGroupMgr_->MoveMissionsToBackground({1, 2, 3}, moveRs);
126 ASSERT_EQ(WMError::WM_OK, rs);
127 ASSERT_EQ(3, moveRs.size());
128 }
129
130 /**
131 * @tc.name: OnWindowDestroyed01
132 * @tc.desc: OnWindowDestroyed test
133 * @tc.type: FUNC
134 */
135 HWTEST_F(WindowGroupMgrTest, OnWindowDestroyed01, Function | SmallTest | Level2)
136 {
137 windowGroupMgr_->OnWindowDestroyed(1);
138 ASSERT_EQ(0, windowGroupMgr_->backupWindowModes_.count(1));
139 }
140 /**
141 * @tc.name: OnDisplayStateChange01
142 * @tc.desc: OnDisplayStateChange test
143 * @tc.type: FUNC
144 */
145 HWTEST_F(WindowGroupMgrTest, OnDisplayStateChange01, Function | SmallTest | Level2)
146 {
147 windowGroupMgr_->OnDisplayStateChange(defalutDisplayId_, nullptr, {}, DisplayStateChangeType::DESTROY);
148 ASSERT_EQ(0, windowGroupMgr_->backupDividerWindowRect_.count(defalutDisplayId_));
149 }
150
151 }
152 }
153 }