• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "interfaces/include/ws_common.h"
18 #include "session_manager/include/scene_session_manager.h"
19 #include "session_info.h"
20 #include "session/host/include/scene_session.h"
21 #include "window_manager_agent.h"
22 #include "session_manager.h"
23 #include "zidl/window_manager_agent_interface.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace Rosen {
30 namespace {
31     constexpr int WAIT_SLEEP_TIME = 1;
32     using ConfigItem = WindowSceneConfig::ConfigItem;
ReadConfig(const std::string & xmlStr)33     ConfigItem ReadConfig(const std::string& xmlStr)
34     {
35         ConfigItem config;
36         xmlDocPtr docPtr = xmlParseMemory(xmlStr.c_str(), xmlStr.length() + 1);
37         if (docPtr == nullptr) {
38             return config;
39         }
40 
41         xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
42         if (rootPtr == nullptr || rootPtr->name == nullptr ||
43             xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
44             xmlFreeDoc(docPtr);
45             return config;
46         }
47 
48         std::map<std::string, ConfigItem> configMap;
49         config.SetValue(configMap);
50         WindowSceneConfig::ReadConfig(rootPtr, *config.mapValue_);
51         xmlFreeDoc(docPtr);
52         return config;
53     }
54 }
55 class SceneSessionManagerTest : public testing::Test {
56 public:
57     static void SetUpTestCase();
58 
59     static void TearDownTestCase();
60 
61     void SetUp() override;
62 
63     void TearDown() override;
64 
65     static bool gestureNavigationEnabled_;
66     static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
67 };
68 
69 bool SceneSessionManagerTest::gestureNavigationEnabled_ = true;
__anonedf47d230202(bool enable) 70 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest::callbackFunc_ = [](bool enable) {
71     gestureNavigationEnabled_ = enable;
72 };
73 
SetUpTestCase()74 void SceneSessionManagerTest::SetUpTestCase()
75 {
76 }
77 
TearDownTestCase()78 void SceneSessionManagerTest::TearDownTestCase()
79 {
80 }
81 
SetUp()82 void SceneSessionManagerTest::SetUp()
83 {
84 }
85 
TearDown()86 void SceneSessionManagerTest::TearDown()
87 {
88 }
89 
90 namespace {
91 /**
92  * @tc.name: SetBrightness
93  * @tc.desc: ScreenSesionManager set session brightness
94  * @tc.type: FUNC
95  */
96 HWTEST_F(SceneSessionManagerTest, SetBrightness, Function | SmallTest | Level3)
97 {
98     SessionInfo info;
99     info.abilityName_ = "SetBrightness";
100     info.bundleName_ = "SetBrightness1";
101     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
102     WSError result = SceneSessionManager::GetInstance().SetBrightness(sceneSession, 0.5);
103     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
104 }
105 
106 /**
107  * @tc.name: SetGestureNavigaionEnabled
108  * @tc.desc: SceneSessionManager set gesture navigation enabled
109  * @tc.type: FUNC
110  */
111 HWTEST_F(SceneSessionManagerTest, SetGestureNavigaionEnabled, Function | SmallTest | Level3)
112 {
113     ASSERT_NE(callbackFunc_, nullptr);
114 
115     WMError result00 = SceneSessionManager::GetInstance().SetGestureNavigaionEnabled(true);
116     ASSERT_EQ(result00, WMError::WM_DO_NOTHING);
117 
118     SceneSessionManager::GetInstance().SetGestureNavigationEnabledChangeListener(callbackFunc_);
119     WMError result01 = SceneSessionManager::GetInstance().SetGestureNavigaionEnabled(true);
120     ASSERT_EQ(result01, WMError::WM_OK);
121     sleep(WAIT_SLEEP_TIME);
122     ASSERT_EQ(gestureNavigationEnabled_, true);
123 
124     WMError result02 = SceneSessionManager::GetInstance().SetGestureNavigaionEnabled(false);
125     ASSERT_EQ(result02, WMError::WM_OK);
126     sleep(WAIT_SLEEP_TIME);
127     ASSERT_EQ(gestureNavigationEnabled_, false);
128 
129     SceneSessionManager::GetInstance().SetGestureNavigationEnabledChangeListener(nullptr);
130     WMError result03 = SceneSessionManager::GetInstance().SetGestureNavigaionEnabled(true);
131     ASSERT_EQ(result03, WMError::WM_DO_NOTHING);
132 }
133 
134 /**
135  * @tc.name: RegisterWindowManagerAgent
136  * @tc.desc: SceneSesionManager rigister window manager agent
137  * @tc.type: FUNC
138  */
139 HWTEST_F(SceneSessionManagerTest, RegisterWindowManagerAgent, Function | SmallTest | Level3)
140 {
141     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
142     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
143 
144     ASSERT_EQ(WMError::WM_OK, SceneSessionManager::GetInstance().RegisterWindowManagerAgent(type, windowManagerAgent));
145     ASSERT_EQ(WMError::WM_OK, SceneSessionManager::GetInstance().UnregisterWindowManagerAgent(
146         type, windowManagerAgent));
147 }
148 
149 /**
150  * @tc.name: ConfigWindowSizeLimits01
151  * @tc.desc: call ConfigWindowSizeLimits and check the systemConfig_.
152  * @tc.type: FUNC
153  */
154 HWTEST_F(SceneSessionManagerTest, ConfigWindowSizeLimits01, Function | SmallTest | Level3)
155 {
156     std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
157         "<Configs>"
158         "<mainWindowSizeLimits>"
159         "<miniWidth>10</miniWidth>"
160         "<miniHeight>20</miniHeight>"
161         "</mainWindowSizeLimits>"
162         "<subWindowSizeLimits>"
163         "<miniWidth>30</miniWidth>"
164         "<miniHeight>40</miniHeight>"
165         "</subWindowSizeLimits>"
166         "</Configs>";
167     WindowSceneConfig::config_ = ReadConfig(xmlStr);
168     SceneSessionManager* sceneSessionManager = new SceneSessionManager();
169     sceneSessionManager->ConfigWindowSizeLimits();
170     ASSERT_EQ(sceneSessionManager->systemConfig_.miniWidthOfMainWindow_, 10);
171     ASSERT_EQ(sceneSessionManager->systemConfig_.miniHeightOfMainWindow_, 20);
172     ASSERT_EQ(sceneSessionManager->systemConfig_.miniWidthOfSubWindow_, 30);
173     ASSERT_EQ(sceneSessionManager->systemConfig_.miniHeightOfSubWindow_, 40);
174 }
175 }
176 } // namespace Rosen
177 } // namespace OHOS
178 
179