2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Toolkit;
31 void utc_dali_toolkit_focus_manager_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_focus_manager_cleanup(void)
38 test_return_value = TET_PASS;
45 static bool gObjectCreatedCallBackCalled;
47 static void TestCallback(BaseHandle handle)
49 gObjectCreatedCallBackCalled = true;
52 // Functors to test whether focus changed signal is emitted when the focus is changed
53 class FocusChangedCallback : public Dali::ConnectionTracker
56 FocusChangedCallback(bool& signalReceived)
57 : mSignalVerified(signalReceived),
58 mOriginalFocusedActor(),
59 mCurrentFocusedActor()
63 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
65 tet_infoline("Verifying FocusChangedCallback()");
67 if(originalFocusedActor == mCurrentFocusedActor)
69 mSignalVerified = true;
72 mOriginalFocusedActor = originalFocusedActor;
73 mCurrentFocusedActor = currentFocusedActor;
78 mSignalVerified = false;
81 bool& mSignalVerified;
82 Actor mOriginalFocusedActor;
83 Actor mCurrentFocusedActor;
86 // Functors to test whether focus overshot signal is emitted when there is no way to move focus further.
87 class FocusOvershotCallback : public Dali::ConnectionTracker
90 FocusOvershotCallback(bool& signalReceived)
91 : mSignalVerified(signalReceived),
92 mCurrentFocusedActor(),
93 mFocusOvershotDirection(Toolkit::FocusManager::OVERSHOT_NEXT)
97 void Callback(Actor currentFocusedActor, Toolkit::FocusManager::FocusOvershotDirection direction)
99 tet_infoline("Verifying FocusOvershotCallback()");
101 if(currentFocusedActor == mCurrentFocusedActor && direction == mFocusOvershotDirection)
103 mSignalVerified = true;
109 mSignalVerified = false;
112 bool& mSignalVerified;
113 Actor mCurrentFocusedActor;
114 Toolkit::FocusManager::FocusOvershotDirection mFocusOvershotDirection;
117 // Functor to test whether focused actor activated signal is emitted.
118 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
121 FocusedActorActivatedCallback()
125 void Callback(Actor activatedActor)
127 tet_infoline("Verifying FocusedActorActivatedCallback()");
134 int UtcDaliFocusManagerGet(void)
136 ToolkitTestApplication application;
138 tet_infoline(" UtcDaliFocusManagerGet");
140 FocusManager manager;
142 //Ensure object is created by checking if it's registered
143 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
144 DALI_TEST_CHECK(registry);
146 gObjectCreatedCallBackCalled = false;
147 registry.ObjectCreatedSignal().Connect( &TestCallback );
149 manager = FocusManager::Get();
150 DALI_TEST_CHECK(manager);
152 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
154 FocusManager newManager = FocusManager::Get();
155 DALI_TEST_CHECK(newManager);
157 // Check that focus manager is a singleton
158 DALI_TEST_CHECK(manager == newManager);
162 int UtcDaliFocusManagerSetAndGetAccessibilityAttribute(void)
164 ToolkitTestApplication application;
166 tet_infoline(" UtcDaliFocusManagerSetAndGetAccessibilityAttribute");
168 FocusManager manager = FocusManager::Get();
169 DALI_TEST_CHECK(manager);
171 Actor actor = Actor::New();
172 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "");
174 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "Description");
175 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "Description");
177 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "New description");
178 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "New description");
182 int UtcDaliFocusManagerSetAndGetFocusOrder(void)
184 ToolkitTestApplication application;
186 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusOrder");
188 FocusManager manager = FocusManager::Get();
189 DALI_TEST_CHECK(manager);
191 Actor first = Actor::New();
192 Actor second = Actor::New();
193 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
194 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 0);
196 // Set the focus order and description for the first actor
197 manager.SetFocusOrder(first, 1);
198 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
199 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
200 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
202 // Set the focus order and description for the second actor
203 manager.SetFocusOrder(second, 2);
204 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
205 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
206 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
208 // check that the focus order of the first actor is changed
209 manager.SetFocusOrder(first, 2);
210 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 2);
211 // make sure the change of focus order doesn't affect the actor's description
212 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
214 // check that the focus order of the second actor is increased to 3
215 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 3);
216 // make sure the change of focus order doesn't affect the actor's description
217 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
219 // check that the focus order of the second actor is changed to 1
220 manager.SetFocusOrder(second, 1);
221 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 1);
222 // make sure the change of focus order doesn't affect the actor's description
223 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
225 // Set the focus order and description for the third actor
226 Actor third = Actor::New();
227 manager.SetFocusOrder(third, 1);
228 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
229 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 1);
230 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
232 // check that the focus order of the second actor is increased to 2.
233 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
234 // make sure the change of focus order doesn't affect the actor's description
235 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
237 // check that the focus order of the first actor is increased to 3.
238 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 3);
239 // make sure the change of focus order doesn't affect the actor's description
240 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
244 int UtcDaliFocusManagerGenerateNewFocusOrder(void)
246 ToolkitTestApplication application;
248 tet_infoline(" UtcDaliFocusManagerGenerateNewFocusOrder");
250 FocusManager manager = FocusManager::Get();
251 DALI_TEST_CHECK(manager);
253 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
254 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
256 Actor first = Actor::New();
257 Actor second = Actor::New();
259 // Set the focus order for the first actor
260 manager.SetFocusOrder(first, 1);
261 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
262 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
264 //Test for new focus order
265 DALI_TEST_CHECK(2 == manager.GenerateNewFocusOrder());
267 // Set the focus order for the first actor
268 manager.SetFocusOrder(second, 2);
269 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "first");
270 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
274 int UtcDaliFocusManagerGetActorByFocusOrder(void)
276 ToolkitTestApplication application;
278 tet_infoline(" UtcDaliFocusManagerGetActorByFocusOrder");
280 FocusManager manager = FocusManager::Get();
281 DALI_TEST_CHECK(manager);
283 // Create the actors and set their focus orders
284 Actor first = Actor::New();
285 manager.SetFocusOrder(first, 1);
287 Actor second = Actor::New();
288 manager.SetFocusOrder(second, 2);
290 Actor third = Actor::New();
291 manager.SetFocusOrder(third, 3);
293 // Check that we get an empty handle as no actor is added to the stage yet.
294 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == Actor());
295 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == Actor());
296 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == Actor());
298 // Add the actors to the stage
299 Stage::GetCurrent().Add(first);
300 Stage::GetCurrent().Add(second);
301 Stage::GetCurrent().Add(third);
303 // Check that we get an empty handle because focus order 0 means undefined.
304 DALI_TEST_CHECK(manager.GetActorByFocusOrder(0) == Actor());
306 // Check that we get correct actors for the specified focus orders
307 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == first);
308 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == second);
309 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == third);
311 // Change the focus order of the third actor to 1
312 manager.SetFocusOrder(third, 1);
314 // Check that we still get correct actors after changing their focus orders
315 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == third);
316 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == first);
317 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == second);
319 // Check that we get an empty handle because no actor has a focus order of 4
320 DALI_TEST_CHECK(manager.GetActorByFocusOrder(4) == Actor());
324 int UtcDaliFocusManagerSetAndGetCurrentFocusActor(void)
326 ToolkitTestApplication application;
328 tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor");
330 FocusManager manager = FocusManager::Get();
331 DALI_TEST_CHECK(manager);
333 // Create the first actor and add it to the stage
334 Actor first = Actor::New();
335 manager.SetFocusOrder(first, 1);
336 Stage::GetCurrent().Add(first);
338 // Create the second actor and add it to the stage
339 Actor second = Actor::New();
340 manager.SetFocusOrder(second, 2);
341 Stage::GetCurrent().Add(second);
343 // Create the third actor but don't add it to the stage
344 Actor third = Actor::New();
345 manager.SetFocusOrder(third, 3);
347 // Check that no actor is being focused yet.
348 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
350 // Check that it will fail to set focus on an invalid actor
351 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
353 // Check that the focus is set on the first actor
354 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
355 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
357 // Check that the focus is set on the second actor
358 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
359 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
361 // Check that it will fail to set focus on the third actor as it's not in the stage
362 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
364 // Add the third actor to the stage
365 Stage::GetCurrent().Add(third);
367 // make the third actor invisible
368 third.SetVisible(false);
369 // flush the queue and render once
370 application.SendNotification();
371 application.Render();
373 // Check that it will fail to set focus on the third actor as it's invisible
374 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
376 // Make the third actor visible
377 third.SetVisible(true);
378 // flush the queue and render once
379 application.SendNotification();
380 application.Render();
382 // Make the third actor not focusable
383 Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable");
384 third.SetProperty(propertyActorFocusable, false);
385 // flush the queue and render once
386 application.SendNotification();
387 application.Render();
389 // Check that it will fail to set focus on the third actor as it's not focusable
390 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
392 // Make the third actor focusable
393 third.SetProperty(propertyActorFocusable, true);
394 // flush the queue and render once
395 application.SendNotification();
396 application.Render();
398 // Check that the focus is successfully moved to the third actor
399 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
401 // Make the current focused actor to be not focusable by setting its focus order to be 0
402 manager.SetFocusOrder(third, 0);
404 // Check that the focus is automatically cleared
405 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
407 // Set the focus order of the third actor again
408 manager.SetFocusOrder(third, 3);
410 // Check that the third actor can be focused successfully now
411 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
415 int UtcDaliFocusManagerGetCurrentFocusGroup(void)
417 ToolkitTestApplication application;
419 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup");
421 FocusManager manager = FocusManager::Get();
422 DALI_TEST_CHECK(manager);
424 // Create an actor with two child actors and add it to the stage
425 Actor parent = Actor::New();
426 Actor firstChild = Actor::New();
427 Actor secondChild = Actor::New();
428 parent.Add(firstChild);
429 parent.Add(secondChild);
430 Stage::GetCurrent().Add(parent);
432 // Create three actors and add them as the children of the first child actor
433 Actor firstGrandChild = Actor::New();
434 Actor secondGrandChild = Actor::New();
435 Actor thirdGrandChild = Actor::New();
436 firstChild.Add(firstGrandChild);
437 firstChild.Add(secondGrandChild);
438 firstChild.Add(thirdGrandChild);
440 // Set focus order to the actors
441 manager.SetFocusOrder(parent, 1);
442 manager.SetFocusOrder(firstChild, 2);
443 manager.SetFocusOrder(firstGrandChild, 3);
444 manager.SetFocusOrder(secondGrandChild, 4);
445 manager.SetFocusOrder(thirdGrandChild, 5);
446 manager.SetFocusOrder(secondChild, 6);
448 // Set the parent and the first child actor as focus groups
449 manager.SetFocusGroup(parent, true);
450 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
452 // Set focus to the first grand child actor
453 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true);
454 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
456 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
457 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent);
459 manager.SetFocusGroup(firstChild, true);
460 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
462 // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group.
463 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
465 manager.SetFocusGroup(firstGrandChild, true);
466 DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true);
468 // The current focus group should be itself, As it is also a focus group.
469 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild);
471 // Set focus to the second grand child actor
472 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true);
473 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
475 // The current focus group should be the firstChild, As it is the immediate parent which is also a
476 // focus group for the current focus actor.
477 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
482 int UtcDaliFocusManagerGetCurrentFocusOrder(void)
484 ToolkitTestApplication application;
486 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusOrder");
488 FocusManager manager = FocusManager::Get();
489 DALI_TEST_CHECK(manager);
491 Actor first = Actor::New();
492 Stage::GetCurrent().Add(first);
494 Actor second = Actor::New();
495 Stage::GetCurrent().Add(second);
497 Actor third = Actor::New();
498 Stage::GetCurrent().Add(third);
500 // Set the focus order and description for the first actor
501 manager.SetFocusOrder(first, 1);
502 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
503 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
504 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
506 // Set the focus order and description for the second actor
507 manager.SetFocusOrder(second, 2);
508 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
509 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
510 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
512 // Set the focus order and description for the second actor
513 manager.SetFocusOrder(third, 3);
514 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
515 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
516 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
518 // Check that no actor is being focused yet.
519 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
521 // Set the focus on the first actor and test
522 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
523 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 1);
525 // Move the focus forward to the second actor and test
526 manager.MoveFocusForward();
527 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 2);
529 // Move the focus forward to the third actor and test
530 manager.MoveFocusForward();
531 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 3);
533 // Clear focus and test
534 manager.ClearFocus();
535 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
539 int UtcDaliFocusManagerMoveFocusForward(void)
541 ToolkitTestApplication application;
543 tet_infoline(" UtcDaliFocusManagerMoveFocusForward");
545 FocusManager manager = FocusManager::Get();
546 DALI_TEST_CHECK(manager);
548 Actor first = Actor::New();
549 Stage::GetCurrent().Add(first);
551 Actor second = Actor::New();
552 Stage::GetCurrent().Add(second);
554 Actor third = Actor::New();
555 Stage::GetCurrent().Add(third);
557 // Set the focus order and description for the first actor
558 manager.SetFocusOrder(first, 1);
559 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
560 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
561 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
563 // Set the focus order and description for the second actor
564 manager.SetFocusOrder(second, 2);
565 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
566 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
567 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
569 // Set the focus order and description for the second actor
570 manager.SetFocusOrder(third, 3);
571 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
572 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
573 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
575 // Check that no actor is being focused yet.
576 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
578 // Set the focus on the first actor
579 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
580 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
581 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
583 // Test the non-wrapped move first
584 manager.SetWrapMode(false);
585 DALI_TEST_CHECK(manager.GetWrapMode() == false);
587 // Move the focus forward to the second actor
588 manager.MoveFocusForward();
589 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
590 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
592 // Move the focus forward to the third actor
593 manager.MoveFocusForward();
594 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
595 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
597 // Check that it will fail to move the focus forward again as the third actor is the last
598 // focusable actor in the focus chain
599 manager.MoveFocusForward();
600 // The focus should still be set on the third actor
601 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
602 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
604 // Now test the wrapped move
605 manager.SetWrapMode(true);
606 DALI_TEST_CHECK(manager.GetWrapMode() == true);
608 // Move the focus forward recursively and this time the first actor should be focused
609 manager.MoveFocusForward();
610 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
611 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
613 // Make the second actor not focusable
614 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
615 second.SetProperty(propertyActorFocusable, false);
616 // flush the queue and render once
617 application.SendNotification();
618 application.Render();
620 // Move the focus forward and check that the second actor should be skipped and
621 // the third actor should be focused now.
622 manager.MoveFocusForward();
623 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
624 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
626 // Make the first actor invisible
627 first.SetVisible(false);
628 // flush the queue and render once
629 application.SendNotification();
630 application.Render();
632 // Move the focus forward and check that the first actor should be skipped as it's
633 // invisible and the second actor should also be skipped as it's not focusable,
634 // so the focus will still be on the third actor
635 manager.MoveFocusForward();
636 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
637 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
639 // Make the third actor invisible so that no actor can be focused.
640 third.SetVisible(false);
641 // flush the queue and render once
642 application.SendNotification();
643 application.Render();
645 // Check that the focus move is failed as all the three actors can not be focused
646 manager.MoveFocusForward();
647 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
648 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
652 int UtcDaliFocusManagerMoveFocusBackward(void)
654 ToolkitTestApplication application;
656 tet_infoline(" UtcDaliFocusManagerMoveFocusBackward");
658 FocusManager manager = FocusManager::Get();
659 DALI_TEST_CHECK(manager);
661 Actor first = Actor::New();
662 Stage::GetCurrent().Add(first);
664 Actor second = Actor::New();
665 Stage::GetCurrent().Add(second);
667 Actor third = Actor::New();
668 Stage::GetCurrent().Add(third);
670 // Set the focus order and description for the first actor
671 manager.SetFocusOrder(first, 1);
672 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
673 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
674 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
676 // Set the focus order and description for the second actor
677 manager.SetFocusOrder(second, 2);
678 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
679 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
680 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
682 // Set the focus order and description for the second actor
683 manager.SetFocusOrder(third, 3);
684 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
685 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
686 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
688 // Check that no actor is being focused yet.
689 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
691 // Set the focus on the third actor
692 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
693 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
694 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
696 // Test the non-wrapped move first
697 manager.SetWrapMode(false);
698 DALI_TEST_CHECK(manager.GetWrapMode() == false);
700 // Move the focus backward to the second actor
701 manager.MoveFocusBackward();
702 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
703 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
705 // Move the focus backward to the first actor
706 manager.MoveFocusBackward();
707 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
708 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
710 // Check that it will fail to move the focus backward again as the first actor is the first
711 // focusable actor in the focus chain
712 manager.MoveFocusBackward();
713 // The focus should still be set on the first actor
714 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
715 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
717 // Now test the wrapped move
718 manager.SetWrapMode(true);
719 DALI_TEST_CHECK(manager.GetWrapMode() == true);
721 // Move the focus backward recursively and this time the third actor should be focused
722 manager.MoveFocusBackward();
723 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
724 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
726 // Make the second actor not focusable
727 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
728 second.SetProperty(propertyActorFocusable, false);
729 // flush the queue and render once
730 application.SendNotification();
731 application.Render();
733 // Move the focus backward and check that the second actor should be skipped and
734 // the first actor should be focused now.
735 manager.MoveFocusBackward();
736 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
737 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
739 // Make the third actor invisible
740 third.SetVisible(false);
741 // flush the queue and render once
742 application.SendNotification();
743 application.Render();
745 // Move the focus backward and check that the third actor should be skipped as it's
746 // invisible and the second actor should also be skipped as it's not focusable,
747 // so the focus will still be on the first actor
748 manager.MoveFocusBackward();
749 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
750 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
752 // Make the first actor invisible so that no actor can be focused.
753 first.SetVisible(false);
754 // flush the queue and render once
755 application.SendNotification();
756 application.Render();
758 // Check that the focus move is failed as all the three actors can not be focused
759 manager.MoveFocusBackward();
760 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
761 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
765 int UtcDaliFocusManagerClearFocus(void)
767 ToolkitTestApplication application;
769 tet_infoline(" UtcDaliFocusManagerClearFocus");
771 FocusManager manager = FocusManager::Get();
772 DALI_TEST_CHECK(manager);
774 // Create the first actor and add it to the stage
775 Actor first = Actor::New();
776 manager.SetFocusOrder(first, 1);
777 Stage::GetCurrent().Add(first);
779 // Create the second actor and add it to the stage
780 Actor second = Actor::New();
781 manager.SetFocusOrder(second, 2);
782 Stage::GetCurrent().Add(second);
784 // Check that no actor is being focused yet.
785 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
787 // Check that the focus is set on the first actor
788 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
789 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
791 // Check that the focus is set on the second actor
792 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
793 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
796 manager.ClearFocus();
798 // Check that no actor is being focused now.
799 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
803 int UtcDaliFocusManagerReset(void)
805 ToolkitTestApplication application;
807 tet_infoline(" UtcDaliFocusManagerReset");
809 FocusManager manager = FocusManager::Get();
810 DALI_TEST_CHECK(manager);
812 // Create the first actor and add it to the stage
813 Actor first = Actor::New();
814 manager.SetFocusOrder(first, 1);
815 Stage::GetCurrent().Add(first);
817 // Create the second actor and add it to the stage
818 Actor second = Actor::New();
819 manager.SetFocusOrder(second, 2);
820 Stage::GetCurrent().Add(second);
822 // Check that no actor is being focused yet.
823 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
825 // Check that the focus is set on the first actor
826 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
827 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
829 // Check that the focus is set on the second actor
830 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
831 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
836 // Check that no actor is being focused now and the focus order of actors have been cleared
837 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
838 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
839 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
843 int UtcDaliFocusManagerFocusGroup(void)
845 ToolkitTestApplication application;
847 tet_infoline(" UtcDaliFocusManagerFocusGroup");
849 FocusManager manager = FocusManager::Get();
850 DALI_TEST_CHECK(manager);
852 // Create an actor with two child actors and add it to the stage
853 Actor parent = Actor::New();
854 Actor firstChild = Actor::New();
855 Actor secondChild = Actor::New();
856 parent.Add(firstChild);
857 parent.Add(secondChild);
858 Stage::GetCurrent().Add(parent);
860 // Create three actors and add them as the children of the first child actor
861 Actor firstGrandChild = Actor::New();
862 Actor secondGrandChild = Actor::New();
863 Actor thirdGrandChild = Actor::New();
864 firstChild.Add(firstGrandChild);
865 firstChild.Add(secondGrandChild);
866 firstChild.Add(thirdGrandChild);
868 // Set focus order to the actors
869 manager.SetFocusOrder(parent, 1);
870 manager.SetFocusOrder(firstChild, 2);
871 manager.SetFocusOrder(firstGrandChild, 3);
872 manager.SetFocusOrder(secondGrandChild, 4);
873 manager.SetFocusOrder(thirdGrandChild, 5);
874 manager.SetFocusOrder(secondChild, 6);
876 // Set the parent and the first child actor as focus groups
877 manager.SetFocusGroup(parent, true);
878 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
880 // The focus group of the parent should be itself, as it is set to be a focus group.
881 DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent);
883 // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group.
884 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent);
886 manager.SetFocusGroup(firstChild, true);
887 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
889 // The focus group of the firstChild should be itself, as it is set to be a focus group now.
890 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild);
892 // Enable wrap mode for focus movement.
893 manager.SetWrapMode(true);
894 DALI_TEST_CHECK(manager.GetWrapMode() == true);
896 // Check that no actor is being focused yet.
897 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
899 // Check that the focus is set on the parent actor.
900 DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true);
901 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
903 // Check that group mode is disabled.
904 DALI_TEST_CHECK(manager.GetGroupMode() == false);
906 // Check that the focus movement is wrapped as normal.
907 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
908 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
909 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
910 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
911 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
912 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
913 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
914 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
915 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
916 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild);
917 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
918 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
919 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
920 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
921 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
922 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
924 // Enable the group mode.
925 manager.SetGroupMode(true);
926 DALI_TEST_CHECK(manager.GetGroupMode() == true);
928 // Check that the focus movement is now limited to the current focus group.
929 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
930 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
931 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
932 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
933 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
934 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
935 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
936 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
940 int UtcDaliFocusManagerSetAndGetFocusIndicator(void)
942 ToolkitTestApplication application;
944 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusIndicator");
946 FocusManager manager = FocusManager::Get();
947 DALI_TEST_CHECK(manager);
949 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
950 DALI_TEST_CHECK(defaultFocusIndicatorActor);
952 Actor newFocusIndicatorActor = Actor::New();
953 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
954 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
958 int UtcDaliFocusManagerSignalFocusChanged(void)
960 ToolkitTestApplication application;
962 tet_infoline(" UtcDaliFocusManagerSignalFocusChanged");
964 FocusManager manager = FocusManager::Get();
965 DALI_TEST_CHECK(manager);
967 bool signalVerified = false;
968 FocusChangedCallback callback(signalVerified);
969 manager.FocusChangedSignal().Connect( &callback, &FocusChangedCallback::Callback );
971 // Create the first actor and add it to the stage
972 Actor first = Actor::New();
973 manager.SetFocusOrder(first, 1);
974 Stage::GetCurrent().Add(first);
976 // Create the second actor and add it to the stage
977 Actor second = Actor::New();
978 manager.SetFocusOrder(second, 2);
979 Stage::GetCurrent().Add(second);
981 // Check that no actor is being focused yet.
982 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
984 // Check that the focus is set on the first actor
985 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
986 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
987 DALI_TEST_CHECK(callback.mSignalVerified);
990 // Check that the focus is set on the second actor
991 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
992 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
993 DALI_TEST_CHECK(callback.mSignalVerified);
997 manager.ClearFocus();
999 // Check that no actor is being focused now.
1000 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1001 DALI_TEST_CHECK(callback.mSignalVerified);
1005 int UtcDaliFocusManagerSignalFocusOvershot(void)
1007 ToolkitTestApplication application;
1009 tet_infoline(" UtcDaliFocusManagerSignalFocusOvershot");
1011 FocusManager manager = FocusManager::Get();
1012 DALI_TEST_CHECK(manager);
1014 bool signalVerified = false;
1015 FocusOvershotCallback callback(signalVerified);
1016 manager.FocusOvershotSignal().Connect(&callback, &FocusOvershotCallback::Callback);
1018 // Create the first actor and add it to the stage
1019 Actor first = Actor::New();
1020 manager.SetFocusOrder(first, 1);
1021 Stage::GetCurrent().Add(first);
1023 // Create the second actor and add it to the stage
1024 Actor second = Actor::New();
1025 manager.SetFocusOrder(second, 2);
1026 Stage::GetCurrent().Add(second);
1028 // Check that the wrap mode is disabled
1029 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1031 // Check that the focus is set on the first actor
1032 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1033 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1035 // Check that the focus is moved to the second actor successfully.
1036 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1037 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1039 // Check that the forward focus movement is overshot.
1040 callback.mCurrentFocusedActor = second;
1041 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_NEXT;
1042 DALI_TEST_CHECK(manager.MoveFocusForward() == false);
1043 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1044 DALI_TEST_CHECK(signalVerified);
1047 // Enable the wrap mode
1048 manager.SetWrapMode(true);
1049 DALI_TEST_CHECK(manager.GetWrapMode() == true);
1051 // Check that the forward focus movement is wrapped and no overshot happens.
1052 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1053 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1054 DALI_TEST_CHECK(signalVerified == false);
1056 // Disable the wrap mode
1057 manager.SetWrapMode(false);
1058 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1060 // Check that the backward focus movement is overshot.
1061 callback.mCurrentFocusedActor = first;
1062 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_PREVIOUS;
1063 DALI_TEST_CHECK(manager.MoveFocusBackward() == false);
1064 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1065 DALI_TEST_CHECK(signalVerified);
1069 int UtcDaliFocusManagerSignalFocusedActorActivated(void)
1071 ToolkitTestApplication application;
1073 tet_infoline(" UtcDaliFocusManagerSignalFocusedActorActivated");
1075 FocusManager manager = FocusManager::Get();
1076 DALI_TEST_CHECK(manager);
1078 FocusedActorActivatedCallback callback;
1079 manager.FocusedActorActivatedSignal().Connect(&callback, &FocusedActorActivatedCallback::Callback);
1080 DALI_TEST_CHECK(true);