1 /*
2 * Copyright (c) 2022-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 "test/unittest/core/event/mouse_style_manager_test_ng.h"
17 #include <optional>
18
19 #include "test/mock/core/pipeline/mock_pipeline_context.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS::Ace::NG {
SetUpTestSuite()25 void MouseStyleManagerTestNG::SetUpTestSuite()
26 {
27 GTEST_LOG_(INFO) << "MouseStyleManagerTestNG SetUpTestCase";
28 }
29
TearDownTestSuite()30 void MouseStyleManagerTestNG::TearDownTestSuite()
31 {
32 GTEST_LOG_(INFO) << "MouseStyleManagerTestNG TearDownTestCase";
33 }
34
SetUp()35 void MouseStyleManagerTestNG::SetUp()
36 {
37 MockPipelineContext::SetUp();
38 }
39
TearDown()40 void MouseStyleManagerTestNG::TearDown()
41 {
42 MockPipelineContext::TearDown();
43 }
44
45 /**
46 * @tc.name: MouseStyleManager001
47 * @tc.desc: Test case userSetCursor_ is false.
48 * @tc.type: FUNC
49 */
50 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager001, TestSize.Level1)
51 {
52 /**
53 * @tc.steps: step1. Create mouseStyleManager.
54 * @tc.expected: mouseStyleManager is not null.
55 */
56 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
57 ASSERT_NE(mouseStyleManager, nullptr);
58
59 /*
60 * @tc.steps: step2. Create testCases.
61 * @tc.expected: result is correct.
62 */
63 const std::vector<MockMouseFormatCase> mockMouseFormatCases = {
64 {false, std::nullopt, 0, MouseFormat::EAST, false,
65 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
66 {false, std::nullopt, 0, MouseFormat::EAST, false,
67 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
68 {false, 0, 0, MouseFormat::EAST, false,
69 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, true, MouseFormat::EAST},
70 {false, 0, 0, MouseFormat::EAST, false,
71 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
72 {false, 0, 1, MouseFormat::EAST, false,
73 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
74 {false, 0, 1, MouseFormat::EAST, false,
75 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST}
76 };
77
78 /*
79 * @tc.steps: step3. Run testCases.
80 * @tc.expected: result is correct.
81 */
82 for (auto i = 0; i < mockMouseFormatCases.size(); i++) {
83 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
84 mouseStyleManager->userSetCursor_ = mockMouseFormatCases[i].userSetCursor;
85 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
86 auto result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
87 mockMouseFormatCases[i].mouseFormat,
88 mockMouseFormatCases[i].isByPass,
89 mockMouseFormatCases[i].reason);
90 EXPECT_EQ(result, mockMouseFormatCases[i].expectSetResult);
91 mouseStyleManager->VsyncMouseFormat();
92 EXPECT_EQ(mouseStyleManager->mouseFormat_,
93 mockMouseFormatCases[i].expectMouseFormat);
94 }
95 }
96
97 /**
98 * @tc.name: MouseStyleManager002
99 * @tc.desc: Test case userSetCursor_ is true.
100 * @tc.type: FUNC
101 */
102 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager002, TestSize.Level1)
103 {
104 /**
105 * @tc.steps: step1. Create mouseStyleManager.
106 * @tc.expected: mouseStyleManager is not null.
107 */
108 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
109 ASSERT_NE(mouseStyleManager, nullptr);
110
111 /*
112 * @tc.steps: step2. Create testCases.
113 * @tc.expected: result is correct.
114 */
115 const std::vector<MockMouseFormatCase> mockMouseFormatCases = {
116 {true, std::nullopt, 0, MouseFormat::EAST, false,
117 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
118 {true, std::nullopt, 0, MouseFormat::EAST, false,
119 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
120 {true, 0, 0, MouseFormat::EAST, false,
121 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
122 {true, 0, 0, MouseFormat::EAST, false,
123 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
124 {true, 0, 1, MouseFormat::EAST, false,
125 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
126 {true, 0, 1, MouseFormat::EAST, false,
127 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST}
128 };
129
130 /*
131 * @tc.steps: step3. Run testCases.
132 * @tc.expected: result is correct.
133 */
134 for (auto i = 0; i < mockMouseFormatCases.size(); i++) {
135 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
136 mouseStyleManager->userSetCursor_ = mockMouseFormatCases[i].userSetCursor;
137 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
138 auto result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
139 mockMouseFormatCases[i].mouseFormat,
140 mockMouseFormatCases[i].isByPass,
141 mockMouseFormatCases[i].reason);
142 EXPECT_EQ(result, mockMouseFormatCases[i].expectSetResult);
143 mouseStyleManager->VsyncMouseFormat();
144 EXPECT_EQ(mouseStyleManager->mouseFormat_,
145 mockMouseFormatCases[i].expectMouseFormat);
146 }
147 }
148
149 /**
150 * @tc.name: MouseStyleManager003
151 * @tc.desc: Test case isByPass is true.
152 * @tc.type: FUNC
153 */
154 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager003, TestSize.Level1)
155 {
156 /**
157 * @tc.steps: step1. Create mouseStyleManager.
158 * @tc.expected: mouseStyleManager is not null.
159 */
160 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
161 ASSERT_NE(mouseStyleManager, nullptr);
162
163 /*
164 * @tc.steps: step2. Create testCases.
165 * @tc.expected: result is correct.
166 */
167 const std::vector<MockMouseFormatCase> mockMouseFormatCases = {
168 {false, std::nullopt, 0, MouseFormat::EAST, true,
169 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
170 {false, std::nullopt, 0, MouseFormat::EAST, true,
171 MouseStyleChangeReason::USER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT}
172 };
173
174 /*
175 * @tc.steps: step3. Run testCases.
176 * @tc.expected: result is correct.
177 */
178 for (auto i = 0; i < mockMouseFormatCases.size(); i++) {
179 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
180 mouseStyleManager->userSetCursor_ = mockMouseFormatCases[i].userSetCursor;
181 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
182 auto result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
183 mockMouseFormatCases[i].mouseFormat,
184 mockMouseFormatCases[i].isByPass,
185 mockMouseFormatCases[i].reason);
186 EXPECT_EQ(result, mockMouseFormatCases[i].expectSetResult);
187 mouseStyleManager->VsyncMouseFormat();
188 EXPECT_EQ(mouseStyleManager->mouseFormat_,
189 mockMouseFormatCases[i].expectMouseFormat);
190 }
191 }
192
193 /**
194 * @tc.name: MouseStyleManager004
195 * @tc.desc: Test case one vsync have different input.
196 * @tc.type: FUNC
197 */
198 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager004, TestSize.Level1)
199 {
200 /**
201 * @tc.steps: step1. Create mouseStyleManager.
202 * @tc.expected: mouseStyleManager is not null.
203 */
204 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
205 ASSERT_NE(mouseStyleManager, nullptr);
206 bool result = false;
207
208 /*
209 * @tc.steps: step2. Create testCases.
210 * @tc.expected: result is correct.
211 */
212 const std::vector<MockMouseFormatCase> mockMouseFormatCases = {
213 {false, std::nullopt, 0, MouseFormat::EAST, false,
214 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
215 {false, std::nullopt, 0, MouseFormat::EAST, false,
216 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
217 {false, 0, 0, MouseFormat::EAST, false,
218 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::EAST},
219 {false, 0, 0, MouseFormat::EAST, false,
220 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
221 {false, 0, 1, MouseFormat::EAST, false,
222 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::EAST},
223 {false, 0, 1, MouseFormat::EAST, false,
224 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST}
225 };
226
227 /*
228 * @tc.steps: step3. Run testCases.
229 * @tc.expected: result is correct.
230 */
231 for (auto i = 0; i < mockMouseFormatCases.size() - 1; i++) {
232 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
233 mouseStyleManager->userSetCursor_ = mockMouseFormatCases[i].userSetCursor;
234 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
235 result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
236 mockMouseFormatCases[i].mouseFormat,
237 mockMouseFormatCases[i].isByPass,
238 mockMouseFormatCases[i].reason);
239 result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i + 1].nodeId,
240 mockMouseFormatCases[i + 1].mouseFormat,
241 mockMouseFormatCases[i + 1].isByPass,
242 mockMouseFormatCases[i + 1].reason);
243 EXPECT_EQ(result, mockMouseFormatCases[i + 1].expectSetResult);
244 mouseStyleManager->VsyncMouseFormat();
245 EXPECT_EQ(mouseStyleManager->mouseFormat_,
246 mockMouseFormatCases[i + 1].expectMouseFormat);
247 }
248 }
249
250 /**
251 * @tc.name: MouseStyleManager005
252 * @tc.desc: Test case userSetCursor_ is different.
253 * @tc.type: FUNC
254 */
255 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager005, TestSize.Level1)
256 {
257 /**
258 * @tc.steps: step1. Create mouseStyleManager.
259 * @tc.expected: mouseStyleManager is not null.
260 */
261 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
262 ASSERT_NE(mouseStyleManager, nullptr);
263 bool result = false;
264
265 /*
266 * @tc.steps: step2. Create testCases.
267 * @tc.expected: result is correct.
268 */
269 const std::vector<MockMouseFormatCase> mockMouseFormatCases = {
270 {false, std::nullopt, 0, MouseFormat::EAST, false,
271 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
272 {true, std::nullopt, 0, MouseFormat::EAST, false,
273 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
274 {true, 0, 0, MouseFormat::EAST, false,
275 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
276 {false, 0, 0, MouseFormat::EAST, false,
277 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST},
278 {false, 0, 1, MouseFormat::EAST, false,
279 MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false, MouseFormat::DEFAULT},
280 {true, 0, 1, MouseFormat::EAST, false,
281 MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST}
282 };
283
284 /*
285 * @tc.steps: step3. Run testCases.
286 * @tc.expected: result is correct.
287 */
288 for (auto i = 0; i < mockMouseFormatCases.size(); i++) {
289 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
290 mouseStyleManager->userSetCursor_ = !mockMouseFormatCases[i].userSetCursor;
291 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
292 mouseStyleManager->SetUserSetCursor(mockMouseFormatCases[i].userSetCursor);
293 result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
294 mockMouseFormatCases[i].mouseFormat,
295 mockMouseFormatCases[i].isByPass,
296 mockMouseFormatCases[i].reason);
297 EXPECT_EQ(result, mockMouseFormatCases[i].expectSetResult);
298 mouseStyleManager->VsyncMouseFormat();
299 EXPECT_EQ(mouseStyleManager->mouseFormat_,
300 mockMouseFormatCases[i].expectMouseFormat);
301 }
302 }
303
304 /**
305 * @tc.name: MouseStyleManager006
306 * @tc.desc: Test all case when passBy = true.
307 * @tc.type: FUNC
308 */
309 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager006, TestSize.Level1)
310 {
311 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
312 ASSERT_NE(mouseStyleManager, nullptr);
313
314 // test all case when passBy = true.
315 std::vector<MockMouseFormatCase> mockMouseFormatCases = {};
316 std::vector<bool> userSetCursor = { false, true };
317 std::vector<MouseStyleChangeReason> reason = {
318 MouseStyleChangeReason::INNER_SET_MOUSESTYLE,
319 MouseStyleChangeReason::USER_SET_MOUSESTYLE, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE,
320 MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE,
321 MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE };
322 std::vector<std::optional<int32_t>> mouseStyleNodeId = { std::nullopt, 1 };
323 std::vector<int32_t> nodeId = { -1, 1 };
324
325 for (int32_t i = 0; i < userSetCursor.size(); ++i) {
326 for (int32_t j = 0; j < reason.size(); ++j) {
327 for (int32_t k = 0; k < mouseStyleNodeId.size(); ++k) {
328 for (int32_t m = 0; m < nodeId.size(); ++m) {
329 mockMouseFormatCases.push_back({ userSetCursor[i], mouseStyleNodeId[k], nodeId[m],
330 MouseFormat::EAST, true, reason[j], false, MouseFormat::DEFAULT });
331 }
332 }
333 }
334 }
335
336 for (int32_t i = 0; i < mockMouseFormatCases.size(); ++i) {
337 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
338 mouseStyleManager->userSetCursor_ = mockMouseFormatCases[i].userSetCursor;
339 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
340 auto result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
341 mockMouseFormatCases[i].mouseFormat,
342 mockMouseFormatCases[i].isByPass,
343 mockMouseFormatCases[i].reason);
344 EXPECT_EQ(result, mockMouseFormatCases[i].expectSetResult);
345 mouseStyleManager->VsyncMouseFormat();
346 EXPECT_EQ(mouseStyleManager->mouseFormat_,
347 mockMouseFormatCases[i].expectMouseFormat);
348 }
349 }
350
351 /**
352 * @tc.name: MouseStyleManager007
353 * @tc.desc: Test all case when passBy = false.
354 * @tc.type: FUNC
355 */
356 HWTEST_F(MouseStyleManagerTestNG, MouseStyleManager007, TestSize.Level1)
357 {
358 auto mouseStyleManager = AceType::MakeRefPtr<MouseStyleManager>();
359 ASSERT_NE(mouseStyleManager, nullptr);
360
361 const std::vector<MockMouseFormatCase> mockMouseFormatCases = {
362 // INNER_SET_MOUSESTYLE
363 { false, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
364 MouseFormat::DEFAULT },
365 { false, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
366 MouseFormat::DEFAULT },
367 { false, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
368 MouseFormat::DEFAULT },
369 { false, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, true,
370 MouseFormat::EAST },
371 // USER_SET_MOUSESTYLE
372 { false, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true,
373 MouseFormat::EAST },
374 { false, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true,
375 MouseFormat::EAST },
376 { false, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true,
377 MouseFormat::EAST },
378 { false, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST },
379 // CONTAINER_DESTROY_RESET_MOUSESTYLE
380 { false, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE,
381 true, MouseFormat::EAST },
382 { false, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE,
383 true, MouseFormat::EAST },
384 { false, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE, true,
385 MouseFormat::EAST },
386 { false, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE, true,
387 MouseFormat::EAST },
388 // WINDOW_LOST_FOCUS_RESET_MOUSESTYLE
389 { false, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE,
390 true, MouseFormat::EAST },
391 { false, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE,
392 true, MouseFormat::EAST },
393 { false, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE, true,
394 MouseFormat::EAST },
395 { false, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE, true,
396 MouseFormat::EAST },
397 // WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE
398 { false, std::nullopt, -1, MouseFormat::EAST, false,
399 MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true, MouseFormat::EAST },
400 { false, std::nullopt, 1, MouseFormat::EAST, false,
401 MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true, MouseFormat::EAST },
402 { false, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE,
403 true, MouseFormat::EAST },
404 { false, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true,
405 MouseFormat::EAST },
406 // INNER_SET_MOUSESTYLE
407 { true, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
408 MouseFormat::DEFAULT },
409 { true, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
410 MouseFormat::DEFAULT },
411 { true, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
412 MouseFormat::DEFAULT },
413 { true, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::INNER_SET_MOUSESTYLE, false,
414 MouseFormat::DEFAULT },
415 // USER_SET_MOUSESTYLE
416 { true, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true,
417 MouseFormat::EAST },
418 { true, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true,
419 MouseFormat::EAST },
420 { true, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST },
421 { true, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::USER_SET_MOUSESTYLE, true, MouseFormat::EAST },
422 // CONTAINER_DESTROY_RESET_MOUSESTYLE
423 { true, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE,
424 true, MouseFormat::EAST },
425 { true, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE,
426 true, MouseFormat::EAST },
427 { true, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE, true,
428 MouseFormat::EAST },
429 { true, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::CONTAINER_DESTROY_RESET_MOUSESTYLE, true,
430 MouseFormat::EAST },
431 // WINDOW_LOST_FOCUS_RESET_MOUSESTYLE
432 { true, std::nullopt, -1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE,
433 true, MouseFormat::EAST },
434 { true, std::nullopt, 1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE,
435 true, MouseFormat::EAST },
436 { true, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE, true,
437 MouseFormat::EAST },
438 { true, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_LOST_FOCUS_RESET_MOUSESTYLE, true,
439 MouseFormat::EAST },
440 // WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE
441 { true, std::nullopt, -1, MouseFormat::EAST, false,
442 MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true, MouseFormat::EAST },
443 { true, std::nullopt, 1, MouseFormat::EAST, false,
444 MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true, MouseFormat::EAST },
445 { true, 1, -1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true,
446 MouseFormat::EAST },
447 { true, 1, 1, MouseFormat::EAST, false, MouseStyleChangeReason::WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE, true,
448 MouseFormat::EAST }
449 };
450
451 for (int32_t i = 0; i < mockMouseFormatCases.size(); ++i) {
452 mouseStyleManager->mouseFormat_ = MouseFormat::DEFAULT;
453 mouseStyleManager->userSetCursor_ = mockMouseFormatCases[i].userSetCursor;
454 mouseStyleManager->mouseStyleNodeId_ = mockMouseFormatCases[i].mouseStyleNodeId;
455 auto result = mouseStyleManager->SetMouseFormat(1, mockMouseFormatCases[i].nodeId,
456 mockMouseFormatCases[i].mouseFormat, mockMouseFormatCases[i].isByPass, mockMouseFormatCases[i].reason);
457 EXPECT_EQ(result, mockMouseFormatCases[i].expectSetResult);
458 mouseStyleManager->VsyncMouseFormat();
459 EXPECT_EQ(mouseStyleManager->mouseFormat_, mockMouseFormatCases[i].expectMouseFormat);
460 }
461 }
462 } // namespace OHOS::Ace::NG
463