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 <gtest/gtest.h>
17 #include "iremote_object_mocker.h"
18 #include "mock/mock_session.h"
19 #include "mock/mock_session_stage.h"
20 #include "mock/mock_window_event_channel.h"
21 #include "session_manager/include/scene_session_manager.h"
22 #include "session_manager/include/zidl/scene_session_manager_interface.h"
23 #include "session_manager/include/zidl/scene_session_manager_proxy.h"
24 #include "window_manager_agent.h"
25 #include "zidl/window_manager_agent_interface.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 namespace OHOS {
30 namespace Rosen {
31 class sceneSessionManagerProxyLifecycleTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37     sptr<IRemoteObject> iRemoteObjectMocker;
38     sptr<SceneSessionManagerProxy> sceneSessionManagerProxy_;
39 };
40 
SetUpTestCase()41 void sceneSessionManagerProxyLifecycleTest::SetUpTestCase()
42 {
43 }
44 
TearDownTestCase()45 void sceneSessionManagerProxyLifecycleTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void sceneSessionManagerProxyLifecycleTest::SetUp()
50 {
51 }
52 
TearDown()53 void sceneSessionManagerProxyLifecycleTest::TearDown()
54 {
55 }
56 
57 namespace {
58 /**
59  * @tc.name: UpdateSessionWindowVisibilityListener001
60  * @tc.desc: normal function
61  * @tc.type: FUNC
62  */
63 HWTEST_F(sceneSessionManagerProxyLifecycleTest, UpdateSessionWindowVisibilityListener001, Function | SmallTest | Level2)
64 {
65     int32_t persistentId = 0;
66     bool haveListener = true;
67     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
68     sptr<SceneSessionManagerProxy> sceneSessionManagerProxy_ =
69         new (std::nothrow) SceneSessionManagerProxy(iRemoteObjectMocker);
70     EXPECT_NE(sceneSessionManagerProxy_, nullptr);
71 
72     ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->UpdateSessionWindowVisibilityListener(persistentId,
73         haveListener));
74     sceneSessionManagerProxy_ = nullptr;
75 }
76 
77 /**
78  * @tc.name: PendingSessionToForeground
79  * @tc.desc: normal function
80  * @tc.type: FUNC
81  */
82 HWTEST_F(sceneSessionManagerProxyLifecycleTest, PendingSessionToForeground, Function | SmallTest | Level2)
83 {
84     sptr<IRemoteObject> token = nullptr;
85     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
86     sptr<SceneSessionManagerProxy> sceneSessionManagerProxy_ =
87         new (std::nothrow) SceneSessionManagerProxy(iRemoteObjectMocker);
88     EXPECT_NE(sceneSessionManagerProxy_, nullptr);
89 
90     ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, sceneSessionManagerProxy_->PendingSessionToForeground(token));
91     sceneSessionManagerProxy_ = nullptr;
92 }
93 
94 /**
95  * @tc.name: PendingSessionToBackgroundForDelegator
96  * @tc.desc: normal function
97  * @tc.type: FUNC
98  */
99 HWTEST_F(sceneSessionManagerProxyLifecycleTest, PendingSessionToBackgroundForDelegator, Function | SmallTest | Level2)
100 {
101     sptr<IRemoteObject> token = nullptr;
102     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
103     sptr<SceneSessionManagerProxy> sceneSessionManagerProxy_ =
104         new (std::nothrow) SceneSessionManagerProxy(iRemoteObjectMocker);
105     EXPECT_NE(sceneSessionManagerProxy_, nullptr);
106 
107     ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED,
108         sceneSessionManagerProxy_->PendingSessionToBackgroundForDelegator(token, true));
109     sceneSessionManagerProxy_ = nullptr;
110 }
111 
112 /**
113  * @tc.name: GetVisibilityWindowInfo
114  * @tc.desc: normal function
115  * @tc.type: FUNC
116  */
117 HWTEST_F(sceneSessionManagerProxyLifecycleTest, GetVisibilityWindowInfo, Function | SmallTest | Level2)
118 {
119     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
120     sptr<SceneSessionManagerProxy> sceneSessionManagerProxy_ =
121         new (std::nothrow) SceneSessionManagerProxy(iRemoteObjectMocker);
122     EXPECT_NE(sceneSessionManagerProxy_, nullptr);
123 
124     std::vector<sptr<WindowVisibilityInfo>> infos;
125     ASSERT_EQ(WMError::WM_OK, sceneSessionManagerProxy_->GetVisibilityWindowInfo(infos));
126     sceneSessionManagerProxy_ = nullptr;
127 }
128 }  // namespace
129 }
130 }
131