2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
28 using namespace Toolkit;
33 static bool gObjectCreatedCallBackCalled;
35 static void TestCallback(BaseHandle handle)
37 gObjectCreatedCallBackCalled = true;
40 // Functors to test whether focus changed signal is emitted when the focus is changed
41 class FocusChangedCallback : public Dali::ConnectionTracker
44 FocusChangedCallback(bool& signalReceived)
45 : mSignalVerified(signalReceived),
46 mOriginalFocusedActor(),
47 mCurrentFocusedActor()
51 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
53 tet_infoline("Verifying FocusChangedCallback()");
55 if(originalFocusedActor == mCurrentFocusedActor)
57 mSignalVerified = true;
60 mOriginalFocusedActor = originalFocusedActor;
61 mCurrentFocusedActor = currentFocusedActor;
66 mSignalVerified = false;
69 bool& mSignalVerified;
70 Actor mOriginalFocusedActor;
71 Actor mCurrentFocusedActor;
74 // Functors to test whether focus overshot signal is emitted when there is no way to move focus further.
75 class FocusOvershotCallback : public Dali::ConnectionTracker
78 FocusOvershotCallback(bool& signalReceived)
79 : mSignalVerified(signalReceived),
80 mCurrentFocusedActor(),
81 mFocusOvershotDirection(Toolkit::FocusManager::OVERSHOT_NEXT)
85 void Callback(Actor currentFocusedActor, Toolkit::FocusManager::FocusOvershotDirection direction)
87 tet_infoline("Verifying FocusOvershotCallback()");
89 if(currentFocusedActor == mCurrentFocusedActor && direction == mFocusOvershotDirection)
91 mSignalVerified = true;
97 mSignalVerified = false;
100 bool& mSignalVerified;
101 Actor mCurrentFocusedActor;
102 Toolkit::FocusManager::FocusOvershotDirection mFocusOvershotDirection;
107 static void Startup();
108 static void Cleanup();
111 void (*tet_startup)() = Startup;
112 void (*tet_cleanup)() = Cleanup;
116 POSITIVE_TC_IDX = 0x01,
120 #define MAX_NUMBER_OF_TESTS 10000
122 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
125 // Add test functionality for all APIs in the class (Positive and Negative)
126 TEST_FUNCTION( UtcDaliFocusManagerGet, POSITIVE_TC_IDX );
127 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetAccessibilityAttribute, POSITIVE_TC_IDX );
128 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetFocusOrder, POSITIVE_TC_IDX );
129 TEST_FUNCTION( UtcDaliFocusManagerGenerateNewFocusOrder, POSITIVE_TC_IDX );
130 TEST_FUNCTION( UtcDaliFocusManagerGetActorByFocusOrder, POSITIVE_TC_IDX );
131 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetCurrentFocusActor, POSITIVE_TC_IDX );
132 TEST_FUNCTION( UtcDaliFocusManagerGetCurrentFocusGroup, POSITIVE_TC_IDX );
133 TEST_FUNCTION( UtcDaliFocusManagerGetCurrentFocusOrder, POSITIVE_TC_IDX );
134 TEST_FUNCTION( UtcDaliFocusManagerMoveFocusForward, POSITIVE_TC_IDX );
135 TEST_FUNCTION( UtcDaliFocusManagerMoveFocusBackward, POSITIVE_TC_IDX );
136 TEST_FUNCTION( UtcDaliFocusManagerClearFocus, POSITIVE_TC_IDX );
137 TEST_FUNCTION( UtcDaliFocusManagerReset, POSITIVE_TC_IDX );
138 TEST_FUNCTION( UtcDaliFocusManagerFocusGroup, POSITIVE_TC_IDX );
139 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetFocusIndicator, POSITIVE_TC_IDX );
140 TEST_FUNCTION( UtcDaliFocusManagerSignalFocusChanged, POSITIVE_TC_IDX );
141 TEST_FUNCTION( UtcDaliFocusManagerSignalFocusOvershot, POSITIVE_TC_IDX );
143 // Called only once before first test is run.
144 static void Startup()
148 // Called only once after last test is run
149 static void Cleanup()
153 static void UtcDaliFocusManagerGet()
155 ToolkitTestApplication application;
157 tet_infoline(" UtcDaliFocusManagerGet");
159 FocusManager manager;
161 //Ensure object is created by checking if it's registered
162 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
163 DALI_TEST_CHECK(registry);
165 gObjectCreatedCallBackCalled = false;
166 registry.ObjectCreatedSignal().Connect( &TestCallback );
168 manager = FocusManager::Get();
169 DALI_TEST_CHECK(manager);
171 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
173 FocusManager newManager = FocusManager::Get();
174 DALI_TEST_CHECK(newManager);
176 // Check that focus manager is a singleton
177 DALI_TEST_CHECK(manager == newManager);
180 static void UtcDaliFocusManagerSetAndGetAccessibilityAttribute()
182 ToolkitTestApplication application;
184 tet_infoline(" UtcDaliFocusManagerSetAndGetAccessibilityAttribute");
186 FocusManager manager = FocusManager::Get();
187 DALI_TEST_CHECK(manager);
189 Actor actor = Actor::New();
190 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "");
192 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "Description");
193 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "Description");
195 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "New description");
196 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "New description");
199 static void UtcDaliFocusManagerSetAndGetFocusOrder()
201 ToolkitTestApplication application;
203 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusOrder");
205 FocusManager manager = FocusManager::Get();
206 DALI_TEST_CHECK(manager);
208 Actor first = Actor::New();
209 Actor second = Actor::New();
210 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
211 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 0);
213 // Set the focus order and description for the first actor
214 manager.SetFocusOrder(first, 1);
215 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
216 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
217 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
219 // Set the focus order and description for the second actor
220 manager.SetFocusOrder(second, 2);
221 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
222 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
223 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
225 // check that the focus order of the first actor is changed
226 manager.SetFocusOrder(first, 2);
227 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 2);
228 // make sure the change of focus order doesn't affect the actor's description
229 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
231 // check that the focus order of the second actor is increased to 3
232 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 3);
233 // make sure the change of focus order doesn't affect the actor's description
234 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
236 // check that the focus order of the second actor is changed to 1
237 manager.SetFocusOrder(second, 1);
238 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 1);
239 // make sure the change of focus order doesn't affect the actor's description
240 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
242 // Set the focus order and description for the third actor
243 Actor third = Actor::New();
244 manager.SetFocusOrder(third, 1);
245 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
246 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 1);
247 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
249 // check that the focus order of the second actor is increased to 2.
250 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
251 // make sure the change of focus order doesn't affect the actor's description
252 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
254 // check that the focus order of the first actor is increased to 3.
255 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 3);
256 // make sure the change of focus order doesn't affect the actor's description
257 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
260 static void UtcDaliFocusManagerGenerateNewFocusOrder()
262 ToolkitTestApplication application;
264 tet_infoline(" UtcDaliFocusManagerGenerateNewFocusOrder");
266 FocusManager manager = FocusManager::Get();
267 DALI_TEST_CHECK(manager);
269 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
270 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
272 Actor first = Actor::New();
273 Actor second = Actor::New();
275 // Set the focus order for the first actor
276 manager.SetFocusOrder(first, 1);
277 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
278 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
280 //Test for new focus order
281 DALI_TEST_CHECK(2 == manager.GenerateNewFocusOrder());
283 // Set the focus order for the first actor
284 manager.SetFocusOrder(second, 2);
285 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "first");
286 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
289 static void UtcDaliFocusManagerGetActorByFocusOrder()
291 ToolkitTestApplication application;
293 tet_infoline(" UtcDaliFocusManagerGetActorByFocusOrder");
295 FocusManager manager = FocusManager::Get();
296 DALI_TEST_CHECK(manager);
298 // Create the actors and set their focus orders
299 Actor first = Actor::New();
300 manager.SetFocusOrder(first, 1);
302 Actor second = Actor::New();
303 manager.SetFocusOrder(second, 2);
305 Actor third = Actor::New();
306 manager.SetFocusOrder(third, 3);
308 // Check that we get an empty handle as no actor is added to the stage yet.
309 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == Actor());
310 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == Actor());
311 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == Actor());
313 // Add the actors to the stage
314 Stage::GetCurrent().Add(first);
315 Stage::GetCurrent().Add(second);
316 Stage::GetCurrent().Add(third);
318 // Check that we get an empty handle because focus order 0 means undefined.
319 DALI_TEST_CHECK(manager.GetActorByFocusOrder(0) == Actor());
321 // Check that we get correct actors for the specified focus orders
322 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == first);
323 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == second);
324 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == third);
326 // Change the focus order of the third actor to 1
327 manager.SetFocusOrder(third, 1);
329 // Check that we still get correct actors after changing their focus orders
330 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == third);
331 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == first);
332 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == second);
334 // Check that we get an empty handle because no actor has a focus order of 4
335 DALI_TEST_CHECK(manager.GetActorByFocusOrder(4) == Actor());
338 static void UtcDaliFocusManagerSetAndGetCurrentFocusActor()
340 ToolkitTestApplication application;
342 tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor");
344 FocusManager manager = FocusManager::Get();
345 DALI_TEST_CHECK(manager);
347 // Create the first actor and add it to the stage
348 Actor first = Actor::New();
349 manager.SetFocusOrder(first, 1);
350 Stage::GetCurrent().Add(first);
352 // Create the second actor and add it to the stage
353 Actor second = Actor::New();
354 manager.SetFocusOrder(second, 2);
355 Stage::GetCurrent().Add(second);
357 // Create the third actor but don't add it to the stage
358 Actor third = Actor::New();
359 manager.SetFocusOrder(third, 3);
361 // Check that no actor is being focused yet.
362 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
364 // Check that it will fail to set focus on an invalid actor
365 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
367 // Check that the focus is set on the first actor
368 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
369 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
371 // Check that the focus is set on the second actor
372 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
373 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
375 // Check that it will fail to set focus on the third actor as it's not in the stage
376 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
378 // Add the third actor to the stage
379 Stage::GetCurrent().Add(third);
381 // make the third actor invisible
382 third.SetVisible(false);
383 // flush the queue and render once
384 application.SendNotification();
385 application.Render();
387 // Check that it will fail to set focus on the third actor as it's invisible
388 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
390 // Make the third actor visible
391 third.SetVisible(true);
392 // flush the queue and render once
393 application.SendNotification();
394 application.Render();
396 // Make the third actor not focusable
397 Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable");
398 third.SetProperty(propertyActorFocusable, false);
399 // flush the queue and render once
400 application.SendNotification();
401 application.Render();
403 // Check that it will fail to set focus on the third actor as it's not focusable
404 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
406 // Make the third actor focusable
407 third.SetProperty(propertyActorFocusable, true);
408 // flush the queue and render once
409 application.SendNotification();
410 application.Render();
412 // Check that the focus is successfully moved to the third actor
413 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
415 // Make the current focused actor to be not focusable by setting its focus order to be 0
416 manager.SetFocusOrder(third, 0);
418 // Check that the focus is automatically cleared
419 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
421 // Set the focus order of the third actor again
422 manager.SetFocusOrder(third, 3);
424 // Check that the third actor can be focused successfully now
425 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
428 static void UtcDaliFocusManagerGetCurrentFocusGroup()
430 ToolkitTestApplication application;
432 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup");
434 FocusManager manager = FocusManager::Get();
435 DALI_TEST_CHECK(manager);
437 // Create an actor with two child actors and add it to the stage
438 Actor parent = Actor::New();
439 Actor firstChild = Actor::New();
440 Actor secondChild = Actor::New();
441 parent.Add(firstChild);
442 parent.Add(secondChild);
443 Stage::GetCurrent().Add(parent);
445 // Create three actors and add them as the children of the first child actor
446 Actor firstGrandChild = Actor::New();
447 Actor secondGrandChild = Actor::New();
448 Actor thirdGrandChild = Actor::New();
449 firstChild.Add(firstGrandChild);
450 firstChild.Add(secondGrandChild);
451 firstChild.Add(thirdGrandChild);
453 // Set focus order to the actors
454 manager.SetFocusOrder(parent, 1);
455 manager.SetFocusOrder(firstChild, 2);
456 manager.SetFocusOrder(firstGrandChild, 3);
457 manager.SetFocusOrder(secondGrandChild, 4);
458 manager.SetFocusOrder(thirdGrandChild, 5);
459 manager.SetFocusOrder(secondChild, 6);
461 // Set the parent and the first child actor as focus groups
462 manager.SetFocusGroup(parent, true);
463 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
465 // Set focus to the first grand child actor
466 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true);
467 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
469 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
470 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent);
472 manager.SetFocusGroup(firstChild, true);
473 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
475 // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group.
476 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
478 manager.SetFocusGroup(firstGrandChild, true);
479 DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true);
481 // The current focus group should be itself, As it is also a focus group.
482 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild);
484 // Set focus to the second grand child actor
485 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true);
486 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
488 // The current focus group should be the firstChild, As it is the immediate parent which is also a
489 // focus group for the current focus actor.
490 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
494 static void UtcDaliFocusManagerGetCurrentFocusOrder()
496 ToolkitTestApplication application;
498 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusOrder");
500 FocusManager manager = FocusManager::Get();
501 DALI_TEST_CHECK(manager);
503 Actor first = Actor::New();
504 Stage::GetCurrent().Add(first);
506 Actor second = Actor::New();
507 Stage::GetCurrent().Add(second);
509 Actor third = Actor::New();
510 Stage::GetCurrent().Add(third);
512 // Set the focus order and description for the first actor
513 manager.SetFocusOrder(first, 1);
514 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
515 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
516 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
518 // Set the focus order and description for the second actor
519 manager.SetFocusOrder(second, 2);
520 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
521 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
522 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
524 // Set the focus order and description for the second actor
525 manager.SetFocusOrder(third, 3);
526 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
527 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
528 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
530 // Check that no actor is being focused yet.
531 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
533 // Set the focus on the first actor and test
534 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
535 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 1);
537 // Move the focus forward to the second actor and test
538 manager.MoveFocusForward();
539 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 2);
541 // Move the focus forward to the third actor and test
542 manager.MoveFocusForward();
543 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 3);
545 // Clear focus and test
546 manager.ClearFocus();
547 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
550 static void UtcDaliFocusManagerMoveFocusForward()
552 ToolkitTestApplication application;
554 tet_infoline(" UtcDaliFocusManagerMoveFocusForward");
556 FocusManager manager = FocusManager::Get();
557 DALI_TEST_CHECK(manager);
559 Actor first = Actor::New();
560 Stage::GetCurrent().Add(first);
562 Actor second = Actor::New();
563 Stage::GetCurrent().Add(second);
565 Actor third = Actor::New();
566 Stage::GetCurrent().Add(third);
568 // Set the focus order and description for the first actor
569 manager.SetFocusOrder(first, 1);
570 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
571 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
572 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
574 // Set the focus order and description for the second actor
575 manager.SetFocusOrder(second, 2);
576 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
577 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
578 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
580 // Set the focus order and description for the second actor
581 manager.SetFocusOrder(third, 3);
582 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
583 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
584 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
586 // Check that no actor is being focused yet.
587 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
589 // Set the focus on the first actor
590 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
591 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
592 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
594 // Test the non-wrapped move first
595 manager.SetWrapMode(false);
596 DALI_TEST_CHECK(manager.GetWrapMode() == false);
598 // Move the focus forward to the second actor
599 manager.MoveFocusForward();
600 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
601 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
603 // Move the focus forward to the third actor
604 manager.MoveFocusForward();
605 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
606 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
608 // Check that it will fail to move the focus forward again as the third actor is the last
609 // focusable actor in the focus chain
610 manager.MoveFocusForward();
611 // The focus should still be set on the third actor
612 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
613 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
615 // Now test the wrapped move
616 manager.SetWrapMode(true);
617 DALI_TEST_CHECK(manager.GetWrapMode() == true);
619 // Move the focus forward recursively and this time the first actor should be focused
620 manager.MoveFocusForward();
621 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
622 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
624 // Make the second actor not focusable
625 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
626 second.SetProperty(propertyActorFocusable, false);
627 // flush the queue and render once
628 application.SendNotification();
629 application.Render();
631 // Move the focus forward and check that the second actor should be skipped and
632 // the third actor should be focused now.
633 manager.MoveFocusForward();
634 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
635 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
637 // Make the first actor invisible
638 first.SetVisible(false);
639 // flush the queue and render once
640 application.SendNotification();
641 application.Render();
643 // Move the focus forward and check that the first actor should be skipped as it's
644 // invisible and the second actor should also be skipped as it's not focusable,
645 // so the focus will still be on the third actor
646 manager.MoveFocusForward();
647 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
648 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
650 // Make the third actor invisible so that no actor can be focused.
651 third.SetVisible(false);
652 // flush the queue and render once
653 application.SendNotification();
654 application.Render();
656 // Check that the focus move is failed as all the three actors can not be focused
657 manager.MoveFocusForward();
658 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
659 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
662 static void UtcDaliFocusManagerMoveFocusBackward()
664 ToolkitTestApplication application;
666 tet_infoline(" UtcDaliFocusManagerMoveFocusBackward");
668 FocusManager manager = FocusManager::Get();
669 DALI_TEST_CHECK(manager);
671 Actor first = Actor::New();
672 Stage::GetCurrent().Add(first);
674 Actor second = Actor::New();
675 Stage::GetCurrent().Add(second);
677 Actor third = Actor::New();
678 Stage::GetCurrent().Add(third);
680 // Set the focus order and description for the first actor
681 manager.SetFocusOrder(first, 1);
682 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
683 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
684 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
686 // Set the focus order and description for the second actor
687 manager.SetFocusOrder(second, 2);
688 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
689 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
690 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
692 // Set the focus order and description for the second actor
693 manager.SetFocusOrder(third, 3);
694 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
695 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
696 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
698 // Check that no actor is being focused yet.
699 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
701 // Set the focus on the third actor
702 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
703 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
704 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
706 // Test the non-wrapped move first
707 manager.SetWrapMode(false);
708 DALI_TEST_CHECK(manager.GetWrapMode() == false);
710 // Move the focus backward to the second actor
711 manager.MoveFocusBackward();
712 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
713 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
715 // Move the focus backward to the first actor
716 manager.MoveFocusBackward();
717 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
718 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
720 // Check that it will fail to move the focus backward again as the first actor is the first
721 // focusable actor in the focus chain
722 manager.MoveFocusBackward();
723 // The focus should still be set on the first actor
724 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
725 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
727 // Now test the wrapped move
728 manager.SetWrapMode(true);
729 DALI_TEST_CHECK(manager.GetWrapMode() == true);
731 // Move the focus backward recursively and this time the third actor should be focused
732 manager.MoveFocusBackward();
733 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
734 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
736 // Make the second actor not focusable
737 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
738 second.SetProperty(propertyActorFocusable, false);
739 // flush the queue and render once
740 application.SendNotification();
741 application.Render();
743 // Move the focus backward and check that the second actor should be skipped and
744 // the first actor should be focused now.
745 manager.MoveFocusBackward();
746 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
747 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
749 // Make the third actor invisible
750 third.SetVisible(false);
751 // flush the queue and render once
752 application.SendNotification();
753 application.Render();
755 // Move the focus backward and check that the third actor should be skipped as it's
756 // invisible and the second actor should also be skipped as it's not focusable,
757 // so the focus will still be on the first actor
758 manager.MoveFocusBackward();
759 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
760 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
762 // Make the first actor invisible so that no actor can be focused.
763 first.SetVisible(false);
764 // flush the queue and render once
765 application.SendNotification();
766 application.Render();
768 // Check that the focus move is failed as all the three actors can not be focused
769 manager.MoveFocusBackward();
770 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
771 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
774 static void UtcDaliFocusManagerClearFocus()
776 ToolkitTestApplication application;
778 tet_infoline(" UtcDaliFocusManagerClearFocus");
780 FocusManager manager = FocusManager::Get();
781 DALI_TEST_CHECK(manager);
783 // Create the first actor and add it to the stage
784 Actor first = Actor::New();
785 manager.SetFocusOrder(first, 1);
786 Stage::GetCurrent().Add(first);
788 // Create the second actor and add it to the stage
789 Actor second = Actor::New();
790 manager.SetFocusOrder(second, 2);
791 Stage::GetCurrent().Add(second);
793 // Check that no actor is being focused yet.
794 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
796 // Check that the focus is set on the first actor
797 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
798 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
800 // Check that the focus is set on the second actor
801 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
802 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
805 manager.ClearFocus();
807 // Check that no actor is being focused now.
808 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
811 static void UtcDaliFocusManagerReset()
813 ToolkitTestApplication application;
815 tet_infoline(" UtcDaliFocusManagerReset");
817 FocusManager manager = FocusManager::Get();
818 DALI_TEST_CHECK(manager);
820 // Create the first actor and add it to the stage
821 Actor first = Actor::New();
822 manager.SetFocusOrder(first, 1);
823 Stage::GetCurrent().Add(first);
825 // Create the second actor and add it to the stage
826 Actor second = Actor::New();
827 manager.SetFocusOrder(second, 2);
828 Stage::GetCurrent().Add(second);
830 // Check that no actor is being focused yet.
831 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
833 // Check that the focus is set on the first actor
834 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
835 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
837 // Check that the focus is set on the second actor
838 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
839 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
844 // Check that no actor is being focused now and the focus order of actors have been cleared
845 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
846 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
847 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
850 static void UtcDaliFocusManagerFocusGroup()
852 ToolkitTestApplication application;
854 tet_infoline(" UtcDaliFocusManagerFocusGroup");
856 FocusManager manager = FocusManager::Get();
857 DALI_TEST_CHECK(manager);
859 // Create an actor with two child actors and add it to the stage
860 Actor parent = Actor::New();
861 Actor firstChild = Actor::New();
862 Actor secondChild = Actor::New();
863 parent.Add(firstChild);
864 parent.Add(secondChild);
865 Stage::GetCurrent().Add(parent);
867 // Create three actors and add them as the children of the first child actor
868 Actor firstGrandChild = Actor::New();
869 Actor secondGrandChild = Actor::New();
870 Actor thirdGrandChild = Actor::New();
871 firstChild.Add(firstGrandChild);
872 firstChild.Add(secondGrandChild);
873 firstChild.Add(thirdGrandChild);
875 // Set focus order to the actors
876 manager.SetFocusOrder(parent, 1);
877 manager.SetFocusOrder(firstChild, 2);
878 manager.SetFocusOrder(firstGrandChild, 3);
879 manager.SetFocusOrder(secondGrandChild, 4);
880 manager.SetFocusOrder(thirdGrandChild, 5);
881 manager.SetFocusOrder(secondChild, 6);
883 // Set the parent and the first child actor as focus groups
884 manager.SetFocusGroup(parent, true);
885 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
887 // The focus group of the parent should be itself, as it is set to be a focus group.
888 DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent);
890 // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group.
891 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent);
893 manager.SetFocusGroup(firstChild, true);
894 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
896 // The focus group of the firstChild should be itself, as it is set to be a focus group now.
897 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild);
899 // Enable wrap mode for focus movement.
900 manager.SetWrapMode(true);
901 DALI_TEST_CHECK(manager.GetWrapMode() == true);
903 // Check that no actor is being focused yet.
904 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
906 // Check that the focus is set on the parent actor.
907 DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true);
908 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
910 // Check that group mode is disabled.
911 DALI_TEST_CHECK(manager.GetGroupMode() == false);
913 // Check that the focus movement is wrapped as normal.
914 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
915 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
916 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
917 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
918 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
919 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
920 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
921 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
922 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
923 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild);
924 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
925 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
926 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
927 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
928 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
929 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
931 // Enable the group mode.
932 manager.SetGroupMode(true);
933 DALI_TEST_CHECK(manager.GetGroupMode() == true);
935 // Check that the focus movement is now limited to the current focus group.
936 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
937 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
938 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
939 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
940 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
941 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
942 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
943 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
946 static void UtcDaliFocusManagerSetAndGetFocusIndicator()
948 ToolkitTestApplication application;
950 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusIndicator");
952 FocusManager manager = FocusManager::Get();
953 DALI_TEST_CHECK(manager);
955 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
956 DALI_TEST_CHECK(defaultFocusIndicatorActor);
958 Actor newFocusIndicatorActor = Actor::New();
959 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
960 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
963 static void UtcDaliFocusManagerSignalFocusChanged()
965 ToolkitTestApplication application;
967 tet_infoline(" UtcDaliFocusManagerSignalFocusChanged");
969 FocusManager manager = FocusManager::Get();
970 DALI_TEST_CHECK(manager);
972 bool signalVerified = false;
973 FocusChangedCallback callback(signalVerified);
974 manager.FocusChangedSignal().Connect( &callback, &FocusChangedCallback::Callback );
976 // Create the first actor and add it to the stage
977 Actor first = Actor::New();
978 manager.SetFocusOrder(first, 1);
979 Stage::GetCurrent().Add(first);
981 // Create the second actor and add it to the stage
982 Actor second = Actor::New();
983 manager.SetFocusOrder(second, 2);
984 Stage::GetCurrent().Add(second);
986 // Check that no actor is being focused yet.
987 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
989 // Check that the focus is set on the first actor
990 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
991 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
992 DALI_TEST_CHECK(callback.mSignalVerified);
995 // Check that the focus is set on the second actor
996 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
997 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
998 DALI_TEST_CHECK(callback.mSignalVerified);
1002 manager.ClearFocus();
1004 // Check that no actor is being focused now.
1005 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1006 DALI_TEST_CHECK(callback.mSignalVerified);
1009 static void UtcDaliFocusManagerSignalFocusOvershot()
1011 ToolkitTestApplication application;
1013 tet_infoline(" UtcDaliFocusManagerSignalFocusOvershot");
1015 FocusManager manager = FocusManager::Get();
1016 DALI_TEST_CHECK(manager);
1018 bool signalVerified = false;
1019 FocusOvershotCallback callback(signalVerified);
1020 manager.FocusOvershotSignal().Connect(&callback, &FocusOvershotCallback::Callback);
1022 // Create the first actor and add it to the stage
1023 Actor first = Actor::New();
1024 manager.SetFocusOrder(first, 1);
1025 Stage::GetCurrent().Add(first);
1027 // Create the second actor and add it to the stage
1028 Actor second = Actor::New();
1029 manager.SetFocusOrder(second, 2);
1030 Stage::GetCurrent().Add(second);
1032 // Check that the wrap mode is disabled
1033 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1035 // Check that the focus is set on the first actor
1036 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1037 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1039 // Check that the focus is moved to the second actor successfully.
1040 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1041 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1043 // Check that the forward focus movement is overshot.
1044 callback.mCurrentFocusedActor = second;
1045 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_NEXT;
1046 DALI_TEST_CHECK(manager.MoveFocusForward() == false);
1047 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1048 DALI_TEST_CHECK(signalVerified);
1051 // Enable the wrap mode
1052 manager.SetWrapMode(true);
1053 DALI_TEST_CHECK(manager.GetWrapMode() == true);
1055 // Check that the forward focus movement is wrapped and no overshot happens.
1056 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1057 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1058 DALI_TEST_CHECK(signalVerified == false);
1060 // Disable the wrap mode
1061 manager.SetWrapMode(false);
1062 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1064 // Check that the backward focus movement is overshot.
1065 callback.mCurrentFocusedActor = first;
1066 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_PREVIOUS;
1067 DALI_TEST_CHECK(manager.MoveFocusBackward() == false);
1068 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1069 DALI_TEST_CHECK(signalVerified);