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 };
39
SetUpTestCase()40 void sceneSessionManagerProxyLifecycleTest::SetUpTestCase() {}
41
TearDownTestCase()42 void sceneSessionManagerProxyLifecycleTest::TearDownTestCase() {}
43
SetUp()44 void sceneSessionManagerProxyLifecycleTest::SetUp() {}
45
TearDown()46 void sceneSessionManagerProxyLifecycleTest::TearDown() {}
47
48 namespace {
49 /**
50 * @tc.name: UpdateSessionWindowVisibilityListener001
51 * @tc.desc: normal function
52 * @tc.type: FUNC
53 */
54 HWTEST_F(sceneSessionManagerProxyLifecycleTest, UpdateSessionWindowVisibilityListener001, TestSize.Level1)
55 {
56 int32_t persistentId = 0;
57 bool haveListener = true;
58 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
59 sptr<SceneSessionManagerProxy> sceneSessionManagerProxy =
60 sptr<SceneSessionManagerProxy>::MakeSptr(iRemoteObjectMocker);
61 EXPECT_NE(sceneSessionManagerProxy, nullptr);
62
63 ASSERT_EQ(WSError::WS_OK,
64 sceneSessionManagerProxy->UpdateSessionWindowVisibilityListener(persistentId, haveListener));
65 }
66
67 /**
68 * @tc.name: PendingSessionToForeground
69 * @tc.desc: normal function
70 * @tc.type: FUNC
71 */
72 HWTEST_F(sceneSessionManagerProxyLifecycleTest, PendingSessionToForeground, TestSize.Level1)
73 {
74 sptr<IRemoteObject> token = nullptr;
75 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
76 sptr<SceneSessionManagerProxy> sceneSessionManagerProxy =
77 sptr<SceneSessionManagerProxy>::MakeSptr(iRemoteObjectMocker);
78 EXPECT_NE(sceneSessionManagerProxy, nullptr);
79
80 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, sceneSessionManagerProxy->PendingSessionToForeground(token));
81 }
82
83 /**
84 * @tc.name: PendingSessionToBackgroundForDelegator
85 * @tc.desc: normal function
86 * @tc.type: FUNC
87 */
88 HWTEST_F(sceneSessionManagerProxyLifecycleTest, PendingSessionToBackgroundForDelegator, TestSize.Level1)
89 {
90 sptr<IRemoteObject> token = nullptr;
91 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
92 sptr<SceneSessionManagerProxy> sceneSessionManagerProxy =
93 sptr<SceneSessionManagerProxy>::MakeSptr(iRemoteObjectMocker);
94 EXPECT_NE(sceneSessionManagerProxy, nullptr);
95
96 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED,
97 sceneSessionManagerProxy->PendingSessionToBackgroundForDelegator(token, true));
98 }
99
100 /**
101 * @tc.name: GetVisibilityWindowInfo
102 * @tc.desc: normal function
103 * @tc.type: FUNC
104 */
105 HWTEST_F(sceneSessionManagerProxyLifecycleTest, GetVisibilityWindowInfo, TestSize.Level1)
106 {
107 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
108 sptr<SceneSessionManagerProxy> sceneSessionManagerProxy =
109 sptr<SceneSessionManagerProxy>::MakeSptr(iRemoteObjectMocker);
110 EXPECT_NE(sceneSessionManagerProxy, nullptr);
111
112 std::vector<sptr<WindowVisibilityInfo>> infos;
113 ASSERT_EQ(WMError::WM_OK, sceneSessionManagerProxy->GetVisibilityWindowInfo(infos));
114 }
115 } // namespace
116 } // namespace Rosen
117 } // namespace OHOS
118