• 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 <libxml/globals.h>
18 #include <libxml/xmlstring.h>
19 #include "window_scene_config.h"
20 #include "window_manager_hilog.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 using ConfigItem = WindowSceneConfig::ConfigItem;
28 const std::string XML_STR = R"(<?xml version='1.0' encoding="utf-8"?>
29 <!--
30  * Copyright (c) 2022 Huawei Device Co., Ltd.
31  * Licensed under the Apache License, Version 2.0 (the "License");
32  * you may not use this file except in compliance with the License.
33  * You may obtain a copy of the License at
34  *
35  *     http://www.apache.org/licenses/LICENSE-2.0
36  *
37  * Unless required by applicable law or agreed to in writing, software
38  * distributed under the License is distributed on an "AS IS" BASIS,
39  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40  * See the License for the specific language governing permissions and
41  * limitations under the License.
42  -->
43 <Configs>
44     <!--decor enable is true means app main window show decoration-->
45     <decor enable="false"></decor>
46     <!--max number of main window that could be shown on display-->
47     <maxAppWindowNumber>100</maxAppWindowNumber>
48     <!--minimizeByOther enable is true means fullscreen window will be minmized by other fullscreen window-->
49     <minimizeByOther enable="true"></minimizeByOther>
50     <!--window mdoe change hot zones config, fullscreen primary secondary-->
51     <modeChangeHotZones>50 50 50</modeChangeHotZones>
52     <!--stretchable enable is true means all window be stretchable-->
53     <stretchable enable="false"></stretchable>
54     <!--exit split screen mode ratio config-->
55     <exitSplitRatios>0.1 0.9</exitSplitRatios>
56     <!--split screen ratios config-->
57     <splitRatios>0.5 0.33 0.67</splitRatios>
58     <!--default window mode config-->
59     <defaultWindowMode>1</defaultWindowMode>
60     <!--window animation config-->
61     <windowAnimation>
62         <timing>
63             <!--duration of animation when add/remove window, unit is ms-->
64             <duration>350</duration>
65             <!--timing curve of animation, config it as below:
66             name=ease, easeIn, easeOut, easeInOut, default, linear,
67             spring, interactiveSpring, cubic(float float float float)-->
68             <curve name="easeOut"></curve>
69         </timing>
70         <!--scaleX and scaleY of animation start state-->
71         <scale>0.7 0.7</scale>
72         <!--rotation of animation start state, 4 numbers is axis and angle-->
73         <rotation>0 0 1 0</rotation>
74         <!--translateX and translateY of animation start state-->
75         <translate>0 0</translate>
76         <!--opacity of animation start state-->
77         <opacity>0</opacity>
78     </windowAnimation>
79     <!--keyboard animation config-->
80     <keyboardAnimation>
81         <timing>
82             <!--duration of animation when add keyboard, unit is ms-->
83             <durationIn>500</durationIn>
84             <!--duration of animation when remove keyboard, unit is ms-->
85             <durationOut>300</durationOut>
86             <!--friction curve-->
87             <curve name="cubic">0.2 0.0 0.2 1.0</curve>
88         </timing>
89     </keyboardAnimation>
90     <!--enable/disable remote animation-->
91     <remoteAnimation enable="true"></remoteAnimation>
92     <!--window effect config-->
93     <windowEffect>
94         <appWindows>
95             <cornerRadius>
96                 <!--off: no corner, defaultCornerRadiusXS: 4vp, defaultCornerRadiusS: 8vp-->
97                 <!--defaultCornerRadiusM: 12vp, defaultCornerRadiusL: 16vp, defaultCornerRadiusXL: 24vp-->
98                 <fullScreen>off</fullScreen>
99                 <split>off</split>
100                 <float>off</float>
101             </cornerRadius>
102             <shadow>
103                 <focused>
104                     <elevation>0</elevation>
105                     <color>#000000</color>
106                     <offsetX>0</offsetX>
107                     <offsetY>0</offsetY>
108                     <alpha>0</alpha>
109                 </focused>
110                 <unfocused>
111                     <elevation>0</elevation>
112                     <color>#000000</color>
113                     <offsetX>0</offsetX>
114                     <offsetY>0</offsetY>
115                     <alpha>0</alpha>
116                 </unfocused>
117             </shadow>
118         </appWindows>
119     </windowEffect>
120 </Configs>
121 )";
122 
123 class WindowSceneConfigTest : public testing::Test {
124 public:
125     static void SetUpTestCase();
126     static void TearDownTestCase();
127     void SetUp() override;
128     void TearDown() override;
129     ConfigItem ReadConfig(const std::string& xmlStr);
130 };
131 
SetUpTestCase()132 void WindowSceneConfigTest::SetUpTestCase()
133 {
134 }
135 
TearDownTestCase()136 void WindowSceneConfigTest::TearDownTestCase()
137 {
138 }
139 
SetUp()140 void WindowSceneConfigTest::SetUp()
141 {
142 }
143 
TearDown()144 void WindowSceneConfigTest::TearDown()
145 {
146 }
147 
ReadConfig(const std::string & xmlStr)148 ConfigItem WindowSceneConfigTest::ReadConfig(const std::string& xmlStr)
149 {
150     ConfigItem config;
151     xmlDocPtr docPtr = xmlParseMemory(xmlStr.c_str(), xmlStr.length() + 1);
152     if (docPtr == nullptr) {
153         return config;
154     }
155 
156     xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
157     if (rootPtr == nullptr || rootPtr->name == nullptr ||
158         xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
159         xmlFreeDoc(docPtr);
160         return config;
161     }
162 
163     std::map<std::string, ConfigItem> configMap;
164     config.SetValue(configMap);
165     WindowSceneConfig::ReadConfig(rootPtr, *config.mapValue_);
166     xmlFreeDoc(docPtr);
167     return config;
168 }
169 namespace {
170 /**
171  * @tc.name: AnimationConfig
172  * @tc.desc: animation config test
173  * @tc.type: FUNC
174  * @tc.require issueI5N26H
175  */
176 HWTEST_F(WindowSceneConfigTest, AnimationConfig, Function | SmallTest | Level2)
177 {
178     WindowSceneConfig::config_ = ReadConfig(XML_STR);
179     ConfigItem item = WindowSceneConfig::config_["windowAnimation"];
180     ASSERT_EQ(true, item.IsMap());
181     item = WindowSceneConfig::config_["windowAnimation"]["timing"]["duration"];
182     ASSERT_EQ(true, item.IsInts());
183 
184     auto value = *item.intsValue_;
185     ASSERT_EQ(true, value.size() == 1);
186     ASSERT_EQ(350, value[0]);
187 
188     item = WindowSceneConfig::config_["windowAnimation"]["timing"]["curve"].GetProp("name");
189     ASSERT_EQ(true, item.IsString());
190     ASSERT_EQ("easeOut", item.stringValue_);
191 
192     item = WindowSceneConfig::config_["windowAnimation"]["scale"];
193     ASSERT_EQ(true, item.IsFloats());
194     ASSERT_EQ(true, item.floatsValue_->size() == 2);
195 
196     item = WindowSceneConfig::config_["windowAnimation"]["rotation"];
197     ASSERT_EQ(true, item.IsFloats());
198     ASSERT_EQ(true, item.floatsValue_->size() == 4);
199 
200     item = WindowSceneConfig::config_["windowAnimation"]["translate"];
201     ASSERT_EQ(true, item.IsFloats());
202     ASSERT_EQ(true, item.floatsValue_->size() == 2);
203 
204     item = WindowSceneConfig::config_["windowAnimation"]["opacity"];
205     ASSERT_EQ(true, item.IsFloats());
206     ASSERT_EQ(true, item.floatsValue_->size() == 1);
207 }
208 
209 /**
210  * @tc.name: maxAppWindowNumber
211  * @tc.desc: maxAppWindowNumber test
212  * @tc.type: FUNC
213  */
214 HWTEST_F(WindowSceneConfigTest, MaxAppWindowNumber, Function | SmallTest | Level2)
215 {
216     std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
217         "<Configs>"
218         "<maxAppWindowNumber>0</maxAppWindowNumber>"
219         "</Configs>";
220     WindowSceneConfig::config_ = ReadConfig(xmlStr);
221     WindowSceneConfig::ConfigItem item;
222     std::vector<int> value;
223     item = WindowSceneConfig::config_["maxAppWindowNumber"];
224     ASSERT_EQ(false, item.IsMap());
225     ASSERT_EQ(true, item.IsInts());
226     value = *item.intsValue_;
227     ASSERT_EQ(true, value.size() >= 1);
228     ASSERT_EQ(0, value[0]);
229 
230     xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
231         "<Configs>"
232         "<maxAppWindowNumber>-2</maxAppWindowNumber>"
233         "</Configs>";
234     WindowSceneConfig::config_ = ReadConfig(xmlStr);
235     item = WindowSceneConfig::config_["maxAppWindowNumber"];
236     ASSERT_EQ(false, item.IsMap());
237     ASSERT_EQ(true, item.IsInts());
238     ASSERT_EQ(true, item.intsValue_->size() == 0);
239 
240     xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
241         "<Configs>"
242         "<maxAppWindowNumber>4</maxAppWindowNumber>"
243         "</Configs>";
244     WindowSceneConfig::config_ = ReadConfig(xmlStr);
245     item = WindowSceneConfig::config_["maxAppWindowNumber"];
246     ASSERT_EQ(false, item.IsMap());
247     ASSERT_EQ(true, item.IsInts());
248     ASSERT_EQ(1, item.intsValue_->size());
249     value = *item.intsValue_;
250     ASSERT_EQ(4, value[0]);
251 
252     xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
253         "<Configs>"
254         "<maxAppWindowNumber>1000</maxAppWindowNumber>"
255         "</Configs>";
256     WindowSceneConfig::config_ = ReadConfig(xmlStr);
257     item = WindowSceneConfig::config_["maxAppWindowNumber"];
258     ASSERT_EQ(false, item.IsMap());
259     ASSERT_EQ(true, item.IsInts());
260     ASSERT_EQ(1, item.intsValue_->size());
261     value = *item.intsValue_;
262     ASSERT_EQ(1000, value[0]);
263 }
264 
265 /**
266  * @tc.name: DecorConfig01
267  * @tc.desc: set decor true and false without mode support.
268  * @tc.type: FUNC
269  * @tc.require: issueI68QCO
270  */
271 HWTEST_F(WindowSceneConfigTest, DecorConfig01, Function | SmallTest | Level2)
272 {
273     std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
274         "<Configs>"
275         "<decor enable=\"true\"/>"
276         "</Configs>";
277     WindowSceneConfig::config_ = ReadConfig(xmlStr);
278     ASSERT_EQ(true, WindowSceneConfig::config_["decor"].GetProp("enable").boolValue_);
279 
280     xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
281         "<Configs>"
282         "<decor enable=\"false\"/>"
283         "</Configs>";
284     WindowSceneConfig::config_ = ReadConfig(xmlStr);
285     ASSERT_EQ(false, WindowSceneConfig::config_["decor"].GetProp("enable").boolValue_);
286 }
287 
288 /**
289  * @tc.name: DecorConfig02
290  * @tc.desc: set decor true and mode support fullscreen.
291  * @tc.type: FUNC
292  * @tc.require: issueI68QCO
293  */
294 HWTEST_F(WindowSceneConfigTest, DecorConfig02, Function | SmallTest | Level2)
295 {
296     std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
297         "<Configs>"
298         "<decor enable=\"true\">"
299         "<supportedMode>fullscreen</supportedMode>"
300         "</decor>"
301         "</Configs>";
302     WindowSceneConfig::config_ = ReadConfig(xmlStr);
303     WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"];
304     ASSERT_EQ(false, item.IsMap());
305     ASSERT_EQ(false, item.IsString());
306     ASSERT_EQ(true, item.IsStrings());
307     ASSERT_EQ(1, item.stringsValue_->size());
308     std::vector<std::string> supportedModes;
309     supportedModes = *item.stringsValue_;
310     ASSERT_EQ("fullscreen", supportedModes[0]);
311 }
312 
313 /**
314  * @tc.name: DecorConfig03
315  * @tc.desc: set decor true and mode support floating.
316  * @tc.type: FUNC
317  * @tc.require: issueI68QCO
318  */
319 HWTEST_F(WindowSceneConfigTest, DecorConfig03, Function | SmallTest | Level2)
320 {
321     std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
322         "<Configs>"
323         "<decor enable=\"true\">"
324         "<supportedMode>floating</supportedMode>"
325         "</decor>"
326         "</Configs>";
327     WindowSceneConfig::config_ = ReadConfig(xmlStr);
328     WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"];
329     ASSERT_EQ(false, item.IsMap());
330     ASSERT_EQ(false, item.IsString());
331     ASSERT_EQ(true, item.IsStrings());
332     ASSERT_EQ(1, item.stringsValue_->size());
333     std::vector<std::string> supportedModes;
334     supportedModes = *item.stringsValue_;
335     ASSERT_EQ("floating", supportedModes[0]);
336 }
337 
338 /**
339  * @tc.name: DecorConfig04
340  * @tc.desc: set decor true and mode support fullscreen|floating.
341  * @tc.type: FUNC
342  * @tc.require: issueI68QCO
343  */
344 HWTEST_F(WindowSceneConfigTest, DecorConfig04, Function | SmallTest | Level2)
345 {
346     std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
347         "<Configs>"
348         "<decor enable=\"true\">"
349         "<supportedMode>fullscreen floating</supportedMode>"
350         "</decor>"
351         "</Configs>";
352     WindowSceneConfig::config_ = ReadConfig(xmlStr);
353     WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"];
354     ASSERT_EQ(false, item.IsMap());
355     ASSERT_EQ(false, item.IsString());
356     ASSERT_EQ(true, item.IsStrings());
357     ASSERT_EQ(2, item.stringsValue_->size());
358     std::vector<std::string> supportedModes;
359     supportedModes = *item.stringsValue_;
360     ASSERT_NE("fullscreen floating", supportedModes[0]);
361 }
362 
363 /**
364  * @tc.name: LoadconfigXml
365  * @tc.desc: load config xml
366  * @tc.type: FUNC
367  * @tc.require:
368  */
369 HWTEST_F(WindowSceneConfigTest, LoadConfigXml, Function | SmallTest | Level2)
370 {
371     auto result = WindowSceneConfig::LoadConfigXml();
372     ASSERT_EQ(true, result);
373 }
374 
375 } // namespace
376 } // namespace Rosen
377 } // namespace OHOS
378