2 * Copyright (c) 2014 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/dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Toolkit;
32 void utc_dali_toolkit_focus_manager_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_focus_manager_cleanup(void)
39 test_return_value = TET_PASS;
46 static bool gObjectCreatedCallBackCalled;
48 static void TestCallback(BaseHandle handle)
50 gObjectCreatedCallBackCalled = true;
53 // Functors to test whether focus changed signal is emitted when the focus is changed
54 class FocusChangedCallback : public Dali::ConnectionTracker
57 FocusChangedCallback(bool& signalReceived)
58 : mSignalVerified(signalReceived),
59 mOriginalFocusedActor(),
60 mCurrentFocusedActor()
64 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
66 tet_infoline("Verifying FocusChangedCallback()");
68 if(originalFocusedActor == mCurrentFocusedActor)
70 mSignalVerified = true;
73 mOriginalFocusedActor = originalFocusedActor;
74 mCurrentFocusedActor = currentFocusedActor;
79 mSignalVerified = false;
82 bool& mSignalVerified;
83 Actor mOriginalFocusedActor;
84 Actor mCurrentFocusedActor;
87 // Functors to test whether focus overshot signal is emitted when there is no way to move focus further.
88 class FocusOvershotCallback : public Dali::ConnectionTracker
91 FocusOvershotCallback(bool& signalReceived)
92 : mSignalVerified(signalReceived),
93 mCurrentFocusedActor(),
94 mFocusOvershotDirection(Toolkit::FocusManager::OVERSHOT_NEXT)
98 void Callback(Actor currentFocusedActor, Toolkit::FocusManager::FocusOvershotDirection direction)
100 tet_infoline("Verifying FocusOvershotCallback()");
102 if(currentFocusedActor == mCurrentFocusedActor && direction == mFocusOvershotDirection)
104 mSignalVerified = true;
110 mSignalVerified = false;
113 bool& mSignalVerified;
114 Actor mCurrentFocusedActor;
115 Toolkit::FocusManager::FocusOvershotDirection mFocusOvershotDirection;
121 int UtcDaliFocusManagerGet(void)
123 ToolkitTestApplication application;
125 tet_infoline(" UtcDaliFocusManagerGet");
127 FocusManager manager;
129 //Ensure object is created by checking if it's registered
130 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
131 DALI_TEST_CHECK(registry);
133 gObjectCreatedCallBackCalled = false;
134 registry.ObjectCreatedSignal().Connect( &TestCallback );
136 manager = FocusManager::Get();
137 DALI_TEST_CHECK(manager);
139 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
141 FocusManager newManager = FocusManager::Get();
142 DALI_TEST_CHECK(newManager);
144 // Check that focus manager is a singleton
145 DALI_TEST_CHECK(manager == newManager);
149 int UtcDaliFocusManagerSetAndGetAccessibilityAttribute(void)
151 ToolkitTestApplication application;
153 tet_infoline(" UtcDaliFocusManagerSetAndGetAccessibilityAttribute");
155 FocusManager manager = FocusManager::Get();
156 DALI_TEST_CHECK(manager);
158 Actor actor = Actor::New();
159 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "");
161 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "Description");
162 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "Description");
164 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "New description");
165 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "New description");
169 int UtcDaliFocusManagerSetAndGetFocusOrder(void)
171 ToolkitTestApplication application;
173 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusOrder");
175 FocusManager manager = FocusManager::Get();
176 DALI_TEST_CHECK(manager);
178 Actor first = Actor::New();
179 Actor second = Actor::New();
180 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
181 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 0);
183 // Set the focus order and description for the first actor
184 manager.SetFocusOrder(first, 1);
185 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
186 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
187 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
189 // Set the focus order and description for the second actor
190 manager.SetFocusOrder(second, 2);
191 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
192 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
193 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
195 // check that the focus order of the first actor is changed
196 manager.SetFocusOrder(first, 2);
197 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 2);
198 // make sure the change of focus order doesn't affect the actor's description
199 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
201 // check that the focus order of the second actor is increased to 3
202 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 3);
203 // make sure the change of focus order doesn't affect the actor's description
204 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
206 // check that the focus order of the second actor is changed to 1
207 manager.SetFocusOrder(second, 1);
208 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 1);
209 // make sure the change of focus order doesn't affect the actor's description
210 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
212 // Set the focus order and description for the third actor
213 Actor third = Actor::New();
214 manager.SetFocusOrder(third, 1);
215 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
216 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 1);
217 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
219 // check that the focus order of the second actor is increased to 2.
220 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
221 // make sure the change of focus order doesn't affect the actor's description
222 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
224 // check that the focus order of the first actor is increased to 3.
225 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 3);
226 // make sure the change of focus order doesn't affect the actor's description
227 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
231 int UtcDaliFocusManagerGenerateNewFocusOrder(void)
233 ToolkitTestApplication application;
235 tet_infoline(" UtcDaliFocusManagerGenerateNewFocusOrder");
237 FocusManager manager = FocusManager::Get();
238 DALI_TEST_CHECK(manager);
240 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
241 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
243 Actor first = Actor::New();
244 Actor second = Actor::New();
246 // Set the focus order for the first actor
247 manager.SetFocusOrder(first, 1);
248 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
249 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
251 //Test for new focus order
252 DALI_TEST_CHECK(2 == manager.GenerateNewFocusOrder());
254 // Set the focus order for the first actor
255 manager.SetFocusOrder(second, 2);
256 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "first");
257 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
261 int UtcDaliFocusManagerGetActorByFocusOrder(void)
263 ToolkitTestApplication application;
265 tet_infoline(" UtcDaliFocusManagerGetActorByFocusOrder");
267 FocusManager manager = FocusManager::Get();
268 DALI_TEST_CHECK(manager);
270 // Create the actors and set their focus orders
271 Actor first = Actor::New();
272 manager.SetFocusOrder(first, 1);
274 Actor second = Actor::New();
275 manager.SetFocusOrder(second, 2);
277 Actor third = Actor::New();
278 manager.SetFocusOrder(third, 3);
280 // Check that we get an empty handle as no actor is added to the stage yet.
281 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == Actor());
282 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == Actor());
283 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == Actor());
285 // Add the actors to the stage
286 Stage::GetCurrent().Add(first);
287 Stage::GetCurrent().Add(second);
288 Stage::GetCurrent().Add(third);
290 // Check that we get an empty handle because focus order 0 means undefined.
291 DALI_TEST_CHECK(manager.GetActorByFocusOrder(0) == Actor());
293 // Check that we get correct actors for the specified focus orders
294 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == first);
295 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == second);
296 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == third);
298 // Change the focus order of the third actor to 1
299 manager.SetFocusOrder(third, 1);
301 // Check that we still get correct actors after changing their focus orders
302 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == third);
303 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == first);
304 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == second);
306 // Check that we get an empty handle because no actor has a focus order of 4
307 DALI_TEST_CHECK(manager.GetActorByFocusOrder(4) == Actor());
311 int UtcDaliFocusManagerSetAndGetCurrentFocusActor(void)
313 ToolkitTestApplication application;
315 tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor");
317 FocusManager manager = FocusManager::Get();
318 DALI_TEST_CHECK(manager);
320 // Create the first actor and add it to the stage
321 Actor first = Actor::New();
322 manager.SetFocusOrder(first, 1);
323 Stage::GetCurrent().Add(first);
325 // Create the second actor and add it to the stage
326 Actor second = Actor::New();
327 manager.SetFocusOrder(second, 2);
328 Stage::GetCurrent().Add(second);
330 // Create the third actor but don't add it to the stage
331 Actor third = Actor::New();
332 manager.SetFocusOrder(third, 3);
334 // Check that no actor is being focused yet.
335 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
337 // Check that it will fail to set focus on an invalid actor
338 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
340 // Check that the focus is set on the first actor
341 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
342 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
344 // Check that the focus is set on the second actor
345 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
346 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
348 // Check that it will fail to set focus on the third actor as it's not in the stage
349 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
351 // Add the third actor to the stage
352 Stage::GetCurrent().Add(third);
354 // make the third actor invisible
355 third.SetVisible(false);
356 // flush the queue and render once
357 application.SendNotification();
358 application.Render();
360 // Check that it will fail to set focus on the third actor as it's invisible
361 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
363 // Make the third actor visible
364 third.SetVisible(true);
365 // flush the queue and render once
366 application.SendNotification();
367 application.Render();
369 // Make the third actor not focusable
370 Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable");
371 third.SetProperty(propertyActorFocusable, false);
372 // flush the queue and render once
373 application.SendNotification();
374 application.Render();
376 // Check that it will fail to set focus on the third actor as it's not focusable
377 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
379 // Make the third actor focusable
380 third.SetProperty(propertyActorFocusable, true);
381 // flush the queue and render once
382 application.SendNotification();
383 application.Render();
385 // Check that the focus is successfully moved to the third actor
386 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
388 // Make the current focused actor to be not focusable by setting its focus order to be 0
389 manager.SetFocusOrder(third, 0);
391 // Check that the focus is automatically cleared
392 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
394 // Set the focus order of the third actor again
395 manager.SetFocusOrder(third, 3);
397 // Check that the third actor can be focused successfully now
398 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
402 int UtcDaliFocusManagerGetCurrentFocusGroup(void)
404 ToolkitTestApplication application;
406 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup");
408 FocusManager manager = FocusManager::Get();
409 DALI_TEST_CHECK(manager);
411 // Create an actor with two child actors and add it to the stage
412 Actor parent = Actor::New();
413 Actor firstChild = Actor::New();
414 Actor secondChild = Actor::New();
415 parent.Add(firstChild);
416 parent.Add(secondChild);
417 Stage::GetCurrent().Add(parent);
419 // Create three actors and add them as the children of the first child actor
420 Actor firstGrandChild = Actor::New();
421 Actor secondGrandChild = Actor::New();
422 Actor thirdGrandChild = Actor::New();
423 firstChild.Add(firstGrandChild);
424 firstChild.Add(secondGrandChild);
425 firstChild.Add(thirdGrandChild);
427 // Set focus order to the actors
428 manager.SetFocusOrder(parent, 1);
429 manager.SetFocusOrder(firstChild, 2);
430 manager.SetFocusOrder(firstGrandChild, 3);
431 manager.SetFocusOrder(secondGrandChild, 4);
432 manager.SetFocusOrder(thirdGrandChild, 5);
433 manager.SetFocusOrder(secondChild, 6);
435 // Set the parent and the first child actor as focus groups
436 manager.SetFocusGroup(parent, true);
437 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
439 // Set focus to the first grand child actor
440 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true);
441 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
443 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
444 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent);
446 manager.SetFocusGroup(firstChild, true);
447 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
449 // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group.
450 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
452 manager.SetFocusGroup(firstGrandChild, true);
453 DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true);
455 // The current focus group should be itself, As it is also a focus group.
456 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild);
458 // Set focus to the second grand child actor
459 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true);
460 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
462 // The current focus group should be the firstChild, As it is the immediate parent which is also a
463 // focus group for the current focus actor.
464 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
469 int UtcDaliFocusManagerGetCurrentFocusOrder(void)
471 ToolkitTestApplication application;
473 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusOrder");
475 FocusManager manager = FocusManager::Get();
476 DALI_TEST_CHECK(manager);
478 Actor first = Actor::New();
479 Stage::GetCurrent().Add(first);
481 Actor second = Actor::New();
482 Stage::GetCurrent().Add(second);
484 Actor third = Actor::New();
485 Stage::GetCurrent().Add(third);
487 // Set the focus order and description for the first actor
488 manager.SetFocusOrder(first, 1);
489 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
490 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
491 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
493 // Set the focus order and description for the second actor
494 manager.SetFocusOrder(second, 2);
495 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
496 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
497 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
499 // Set the focus order and description for the second actor
500 manager.SetFocusOrder(third, 3);
501 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
502 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
503 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
505 // Check that no actor is being focused yet.
506 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
508 // Set the focus on the first actor and test
509 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
510 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 1);
512 // Move the focus forward to the second actor and test
513 manager.MoveFocusForward();
514 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 2);
516 // Move the focus forward to the third actor and test
517 manager.MoveFocusForward();
518 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 3);
520 // Clear focus and test
521 manager.ClearFocus();
522 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
526 int UtcDaliFocusManagerMoveFocusForward(void)
528 ToolkitTestApplication application;
530 tet_infoline(" UtcDaliFocusManagerMoveFocusForward");
532 FocusManager manager = FocusManager::Get();
533 DALI_TEST_CHECK(manager);
535 Actor first = Actor::New();
536 Stage::GetCurrent().Add(first);
538 Actor second = Actor::New();
539 Stage::GetCurrent().Add(second);
541 Actor third = Actor::New();
542 Stage::GetCurrent().Add(third);
544 // Set the focus order and description for the first actor
545 manager.SetFocusOrder(first, 1);
546 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
547 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
548 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
550 // Set the focus order and description for the second actor
551 manager.SetFocusOrder(second, 2);
552 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
553 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
554 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
556 // Set the focus order and description for the second actor
557 manager.SetFocusOrder(third, 3);
558 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
559 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
560 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
562 // Check that no actor is being focused yet.
563 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
565 // Set the focus on the first actor
566 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
567 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
568 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
570 // Test the non-wrapped move first
571 manager.SetWrapMode(false);
572 DALI_TEST_CHECK(manager.GetWrapMode() == false);
574 // Move the focus forward to the second actor
575 manager.MoveFocusForward();
576 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
577 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
579 // Move the focus forward to the third actor
580 manager.MoveFocusForward();
581 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
582 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
584 // Check that it will fail to move the focus forward again as the third actor is the last
585 // focusable actor in the focus chain
586 manager.MoveFocusForward();
587 // The focus should still be set on the third actor
588 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
589 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
591 // Now test the wrapped move
592 manager.SetWrapMode(true);
593 DALI_TEST_CHECK(manager.GetWrapMode() == true);
595 // Move the focus forward recursively and this time the first actor should be focused
596 manager.MoveFocusForward();
597 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
598 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
600 // Make the second actor not focusable
601 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
602 second.SetProperty(propertyActorFocusable, false);
603 // flush the queue and render once
604 application.SendNotification();
605 application.Render();
607 // Move the focus forward and check that the second actor should be skipped and
608 // the third actor should be focused now.
609 manager.MoveFocusForward();
610 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
611 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
613 // Make the first actor invisible
614 first.SetVisible(false);
615 // flush the queue and render once
616 application.SendNotification();
617 application.Render();
619 // Move the focus forward and check that the first actor should be skipped as it's
620 // invisible and the second actor should also be skipped as it's not focusable,
621 // so the focus will still be on the third actor
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 third actor invisible so that no actor can be focused.
627 third.SetVisible(false);
628 // flush the queue and render once
629 application.SendNotification();
630 application.Render();
632 // Check that the focus move is failed as all the three actors can not be focused
633 manager.MoveFocusForward();
634 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
635 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
639 int UtcDaliFocusManagerMoveFocusBackward(void)
641 ToolkitTestApplication application;
643 tet_infoline(" UtcDaliFocusManagerMoveFocusBackward");
645 FocusManager manager = FocusManager::Get();
646 DALI_TEST_CHECK(manager);
648 Actor first = Actor::New();
649 Stage::GetCurrent().Add(first);
651 Actor second = Actor::New();
652 Stage::GetCurrent().Add(second);
654 Actor third = Actor::New();
655 Stage::GetCurrent().Add(third);
657 // Set the focus order and description for the first actor
658 manager.SetFocusOrder(first, 1);
659 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
660 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
661 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
663 // Set the focus order and description for the second actor
664 manager.SetFocusOrder(second, 2);
665 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
666 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
667 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
669 // Set the focus order and description for the second actor
670 manager.SetFocusOrder(third, 3);
671 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
672 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
673 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
675 // Check that no actor is being focused yet.
676 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
678 // Set the focus on the third actor
679 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
680 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
681 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
683 // Test the non-wrapped move first
684 manager.SetWrapMode(false);
685 DALI_TEST_CHECK(manager.GetWrapMode() == false);
687 // Move the focus backward to the second actor
688 manager.MoveFocusBackward();
689 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
690 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
692 // Move the focus backward to the first actor
693 manager.MoveFocusBackward();
694 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
695 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
697 // Check that it will fail to move the focus backward again as the first actor is the first
698 // focusable actor in the focus chain
699 manager.MoveFocusBackward();
700 // The focus should still be set on the first actor
701 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
702 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
704 // Now test the wrapped move
705 manager.SetWrapMode(true);
706 DALI_TEST_CHECK(manager.GetWrapMode() == true);
708 // Move the focus backward recursively and this time the third actor should be focused
709 manager.MoveFocusBackward();
710 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
711 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
713 // Make the second actor not focusable
714 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
715 second.SetProperty(propertyActorFocusable, false);
716 // flush the queue and render once
717 application.SendNotification();
718 application.Render();
720 // Move the focus backward and check that the second actor should be skipped and
721 // the first actor should be focused now.
722 manager.MoveFocusBackward();
723 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
724 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
726 // Make the third actor invisible
727 third.SetVisible(false);
728 // flush the queue and render once
729 application.SendNotification();
730 application.Render();
732 // Move the focus backward and check that the third actor should be skipped as it's
733 // invisible and the second actor should also be skipped as it's not focusable,
734 // so the focus will still be on the first actor
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 first actor invisible so that no actor can be focused.
740 first.SetVisible(false);
741 // flush the queue and render once
742 application.SendNotification();
743 application.Render();
745 // Check that the focus move is failed as all the three actors can not be focused
746 manager.MoveFocusBackward();
747 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
748 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
752 int UtcDaliFocusManagerClearFocus(void)
754 ToolkitTestApplication application;
756 tet_infoline(" UtcDaliFocusManagerClearFocus");
758 FocusManager manager = FocusManager::Get();
759 DALI_TEST_CHECK(manager);
761 // Create the first actor and add it to the stage
762 Actor first = Actor::New();
763 manager.SetFocusOrder(first, 1);
764 Stage::GetCurrent().Add(first);
766 // Create the second actor and add it to the stage
767 Actor second = Actor::New();
768 manager.SetFocusOrder(second, 2);
769 Stage::GetCurrent().Add(second);
771 // Check that no actor is being focused yet.
772 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
774 // Check that the focus is set on the first actor
775 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
776 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
778 // Check that the focus is set on the second actor
779 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
780 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
783 manager.ClearFocus();
785 // Check that no actor is being focused now.
786 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
790 int UtcDaliFocusManagerReset(void)
792 ToolkitTestApplication application;
794 tet_infoline(" UtcDaliFocusManagerReset");
796 FocusManager manager = FocusManager::Get();
797 DALI_TEST_CHECK(manager);
799 // Create the first actor and add it to the stage
800 Actor first = Actor::New();
801 manager.SetFocusOrder(first, 1);
802 Stage::GetCurrent().Add(first);
804 // Create the second actor and add it to the stage
805 Actor second = Actor::New();
806 manager.SetFocusOrder(second, 2);
807 Stage::GetCurrent().Add(second);
809 // Check that no actor is being focused yet.
810 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
812 // Check that the focus is set on the first actor
813 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
814 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
816 // Check that the focus is set on the second actor
817 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
818 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
823 // Check that no actor is being focused now and the focus order of actors have been cleared
824 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
825 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
826 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
830 int UtcDaliFocusManagerFocusGroup(void)
832 ToolkitTestApplication application;
834 tet_infoline(" UtcDaliFocusManagerFocusGroup");
836 FocusManager manager = FocusManager::Get();
837 DALI_TEST_CHECK(manager);
839 // Create an actor with two child actors and add it to the stage
840 Actor parent = Actor::New();
841 Actor firstChild = Actor::New();
842 Actor secondChild = Actor::New();
843 parent.Add(firstChild);
844 parent.Add(secondChild);
845 Stage::GetCurrent().Add(parent);
847 // Create three actors and add them as the children of the first child actor
848 Actor firstGrandChild = Actor::New();
849 Actor secondGrandChild = Actor::New();
850 Actor thirdGrandChild = Actor::New();
851 firstChild.Add(firstGrandChild);
852 firstChild.Add(secondGrandChild);
853 firstChild.Add(thirdGrandChild);
855 // Set focus order to the actors
856 manager.SetFocusOrder(parent, 1);
857 manager.SetFocusOrder(firstChild, 2);
858 manager.SetFocusOrder(firstGrandChild, 3);
859 manager.SetFocusOrder(secondGrandChild, 4);
860 manager.SetFocusOrder(thirdGrandChild, 5);
861 manager.SetFocusOrder(secondChild, 6);
863 // Set the parent and the first child actor as focus groups
864 manager.SetFocusGroup(parent, true);
865 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
867 // The focus group of the parent should be itself, as it is set to be a focus group.
868 DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent);
870 // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group.
871 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent);
873 manager.SetFocusGroup(firstChild, true);
874 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
876 // The focus group of the firstChild should be itself, as it is set to be a focus group now.
877 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild);
879 // Enable wrap mode for focus movement.
880 manager.SetWrapMode(true);
881 DALI_TEST_CHECK(manager.GetWrapMode() == true);
883 // Check that no actor is being focused yet.
884 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
886 // Check that the focus is set on the parent actor.
887 DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true);
888 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
890 // Check that group mode is disabled.
891 DALI_TEST_CHECK(manager.GetGroupMode() == false);
893 // Check that the focus movement is wrapped as normal.
894 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
895 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
896 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
897 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
898 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
899 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
900 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
901 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
902 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
903 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild);
904 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
905 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
906 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
907 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
908 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
909 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
911 // Enable the group mode.
912 manager.SetGroupMode(true);
913 DALI_TEST_CHECK(manager.GetGroupMode() == true);
915 // Check that the focus movement is now limited to the current focus group.
916 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
917 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
918 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
919 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
920 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
921 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
922 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
923 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
927 int UtcDaliFocusManagerSetAndGetFocusIndicator(void)
929 ToolkitTestApplication application;
931 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusIndicator");
933 FocusManager manager = FocusManager::Get();
934 DALI_TEST_CHECK(manager);
936 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
937 DALI_TEST_CHECK(defaultFocusIndicatorActor);
939 Actor newFocusIndicatorActor = Actor::New();
940 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
941 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
945 int UtcDaliFocusManagerSignalFocusChanged(void)
947 ToolkitTestApplication application;
949 tet_infoline(" UtcDaliFocusManagerSignalFocusChanged");
951 FocusManager manager = FocusManager::Get();
952 DALI_TEST_CHECK(manager);
954 bool signalVerified = false;
955 FocusChangedCallback callback(signalVerified);
956 manager.FocusChangedSignal().Connect( &callback, &FocusChangedCallback::Callback );
958 // Create the first actor and add it to the stage
959 Actor first = Actor::New();
960 manager.SetFocusOrder(first, 1);
961 Stage::GetCurrent().Add(first);
963 // Create the second actor and add it to the stage
964 Actor second = Actor::New();
965 manager.SetFocusOrder(second, 2);
966 Stage::GetCurrent().Add(second);
968 // Check that no actor is being focused yet.
969 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
971 // Check that the focus is set on the first actor
972 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
973 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
974 DALI_TEST_CHECK(callback.mSignalVerified);
977 // Check that the focus is set on the second actor
978 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
979 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
980 DALI_TEST_CHECK(callback.mSignalVerified);
984 manager.ClearFocus();
986 // Check that no actor is being focused now.
987 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
988 DALI_TEST_CHECK(callback.mSignalVerified);
992 int UtcDaliFocusManagerSignalFocusOvershot(void)
994 ToolkitTestApplication application;
996 tet_infoline(" UtcDaliFocusManagerSignalFocusOvershot");
998 FocusManager manager = FocusManager::Get();
999 DALI_TEST_CHECK(manager);
1001 bool signalVerified = false;
1002 FocusOvershotCallback callback(signalVerified);
1003 manager.FocusOvershotSignal().Connect(&callback, &FocusOvershotCallback::Callback);
1005 // Create the first actor and add it to the stage
1006 Actor first = Actor::New();
1007 manager.SetFocusOrder(first, 1);
1008 Stage::GetCurrent().Add(first);
1010 // Create the second actor and add it to the stage
1011 Actor second = Actor::New();
1012 manager.SetFocusOrder(second, 2);
1013 Stage::GetCurrent().Add(second);
1015 // Check that the wrap mode is disabled
1016 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1018 // Check that the focus is set on the first actor
1019 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1020 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1022 // Check that the focus is moved to the second actor successfully.
1023 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1024 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1026 // Check that the forward focus movement is overshot.
1027 callback.mCurrentFocusedActor = second;
1028 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_NEXT;
1029 DALI_TEST_CHECK(manager.MoveFocusForward() == false);
1030 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1031 DALI_TEST_CHECK(signalVerified);
1034 // Enable the wrap mode
1035 manager.SetWrapMode(true);
1036 DALI_TEST_CHECK(manager.GetWrapMode() == true);
1038 // Check that the forward focus movement is wrapped and no overshot happens.
1039 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1040 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1041 DALI_TEST_CHECK(signalVerified == false);
1043 // Disable the wrap mode
1044 manager.SetWrapMode(false);
1045 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1047 // Check that the backward focus movement is overshot.
1048 callback.mCurrentFocusedActor = first;
1049 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_PREVIOUS;
1050 DALI_TEST_CHECK(manager.MoveFocusBackward() == false);
1051 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1052 DALI_TEST_CHECK(signalVerified);