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.
23 #include <dali/dali.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Toolkit;
34 static bool gObjectCreatedCallBackCalled;
36 static void TestCallback(BaseHandle handle)
38 gObjectCreatedCallBackCalled = true;
41 // Functors to test whether focus changed signal is emitted when the focus is changed
42 class FocusChangedCallback : public Dali::ConnectionTracker
45 FocusChangedCallback(bool& signalReceived)
46 : mSignalVerified(signalReceived),
47 mOriginalFocusedActor(),
48 mCurrentFocusedActor()
52 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
54 tet_infoline("Verifying FocusChangedCallback()");
56 if(originalFocusedActor == mCurrentFocusedActor)
58 mSignalVerified = true;
61 mOriginalFocusedActor = originalFocusedActor;
62 mCurrentFocusedActor = currentFocusedActor;
67 mSignalVerified = false;
70 bool& mSignalVerified;
71 Actor mOriginalFocusedActor;
72 Actor mCurrentFocusedActor;
75 // Functors to test whether focus overshot signal is emitted when there is no way to move focus further.
76 class FocusOvershotCallback : public Dali::ConnectionTracker
79 FocusOvershotCallback(bool& signalReceived)
80 : mSignalVerified(signalReceived),
81 mCurrentFocusedActor(),
82 mFocusOvershotDirection(Toolkit::FocusManager::OVERSHOT_NEXT)
86 void Callback(Actor currentFocusedActor, Toolkit::FocusManager::FocusOvershotDirection direction)
88 tet_infoline("Verifying FocusOvershotCallback()");
90 if(currentFocusedActor == mCurrentFocusedActor && direction == mFocusOvershotDirection)
92 mSignalVerified = true;
98 mSignalVerified = false;
101 bool& mSignalVerified;
102 Actor mCurrentFocusedActor;
103 Toolkit::FocusManager::FocusOvershotDirection mFocusOvershotDirection;
108 static void Startup();
109 static void Cleanup();
112 void (*tet_startup)() = Startup;
113 void (*tet_cleanup)() = Cleanup;
117 POSITIVE_TC_IDX = 0x01,
121 #define MAX_NUMBER_OF_TESTS 10000
123 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
126 // Add test functionality for all APIs in the class (Positive and Negative)
127 TEST_FUNCTION( UtcDaliFocusManagerGet, POSITIVE_TC_IDX );
128 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetAccessibilityAttribute, POSITIVE_TC_IDX );
129 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetFocusOrder, POSITIVE_TC_IDX );
130 TEST_FUNCTION( UtcDaliFocusManagerGenerateNewFocusOrder, POSITIVE_TC_IDX );
131 TEST_FUNCTION( UtcDaliFocusManagerGetActorByFocusOrder, POSITIVE_TC_IDX );
132 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetCurrentFocusActor, POSITIVE_TC_IDX );
133 TEST_FUNCTION( UtcDaliFocusManagerGetCurrentFocusGroup, POSITIVE_TC_IDX );
134 TEST_FUNCTION( UtcDaliFocusManagerGetCurrentFocusOrder, POSITIVE_TC_IDX );
135 TEST_FUNCTION( UtcDaliFocusManagerMoveFocusForward, POSITIVE_TC_IDX );
136 TEST_FUNCTION( UtcDaliFocusManagerMoveFocusBackward, POSITIVE_TC_IDX );
137 TEST_FUNCTION( UtcDaliFocusManagerClearFocus, POSITIVE_TC_IDX );
138 TEST_FUNCTION( UtcDaliFocusManagerReset, POSITIVE_TC_IDX );
139 TEST_FUNCTION( UtcDaliFocusManagerFocusGroup, POSITIVE_TC_IDX );
140 TEST_FUNCTION( UtcDaliFocusManagerSetAndGetFocusIndicator, POSITIVE_TC_IDX );
141 TEST_FUNCTION( UtcDaliFocusManagerSignalFocusChanged, POSITIVE_TC_IDX );
142 TEST_FUNCTION( UtcDaliFocusManagerSignalFocusOvershot, POSITIVE_TC_IDX );
144 // Called only once before first test is run.
145 static void Startup()
149 // Called only once after last test is run
150 static void Cleanup()
154 static void UtcDaliFocusManagerGet()
156 ToolkitTestApplication application;
158 tet_infoline(" UtcDaliFocusManagerGet");
160 FocusManager manager;
162 //Ensure object is created by checking if it's registered
163 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
164 DALI_TEST_CHECK(registry);
166 gObjectCreatedCallBackCalled = false;
167 registry.ObjectCreatedSignal().Connect( &TestCallback );
169 manager = FocusManager::Get();
170 DALI_TEST_CHECK(manager);
172 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
174 FocusManager newManager = FocusManager::Get();
175 DALI_TEST_CHECK(newManager);
177 // Check that focus manager is a singleton
178 DALI_TEST_CHECK(manager == newManager);
181 static void UtcDaliFocusManagerSetAndGetAccessibilityAttribute()
183 ToolkitTestApplication application;
185 tet_infoline(" UtcDaliFocusManagerSetAndGetAccessibilityAttribute");
187 FocusManager manager = FocusManager::Get();
188 DALI_TEST_CHECK(manager);
190 Actor actor = Actor::New();
191 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "");
193 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "Description");
194 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "Description");
196 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "New description");
197 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "New description");
200 static void UtcDaliFocusManagerSetAndGetFocusOrder()
202 ToolkitTestApplication application;
204 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusOrder");
206 FocusManager manager = FocusManager::Get();
207 DALI_TEST_CHECK(manager);
209 Actor first = Actor::New();
210 Actor second = Actor::New();
211 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
212 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 0);
214 // Set the focus order and description for the first actor
215 manager.SetFocusOrder(first, 1);
216 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
217 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
218 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
220 // Set the focus order and description for the second actor
221 manager.SetFocusOrder(second, 2);
222 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
223 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
224 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
226 // check that the focus order of the first actor is changed
227 manager.SetFocusOrder(first, 2);
228 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 2);
229 // make sure the change of focus order doesn't affect the actor's description
230 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
232 // check that the focus order of the second actor is increased to 3
233 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 3);
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 second actor is changed to 1
238 manager.SetFocusOrder(second, 1);
239 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 1);
240 // make sure the change of focus order doesn't affect the actor's description
241 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
243 // Set the focus order and description for the third actor
244 Actor third = Actor::New();
245 manager.SetFocusOrder(third, 1);
246 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
247 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 1);
248 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
250 // check that the focus order of the second actor is increased to 2.
251 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
252 // make sure the change of focus order doesn't affect the actor's description
253 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
255 // check that the focus order of the first actor is increased to 3.
256 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 3);
257 // make sure the change of focus order doesn't affect the actor's description
258 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
261 static void UtcDaliFocusManagerGenerateNewFocusOrder()
263 ToolkitTestApplication application;
265 tet_infoline(" UtcDaliFocusManagerGenerateNewFocusOrder");
267 FocusManager manager = FocusManager::Get();
268 DALI_TEST_CHECK(manager);
270 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
271 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
273 Actor first = Actor::New();
274 Actor second = Actor::New();
276 // Set the focus order for the first actor
277 manager.SetFocusOrder(first, 1);
278 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
279 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
281 //Test for new focus order
282 DALI_TEST_CHECK(2 == manager.GenerateNewFocusOrder());
284 // Set the focus order for the first actor
285 manager.SetFocusOrder(second, 2);
286 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "first");
287 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
290 static void UtcDaliFocusManagerGetActorByFocusOrder()
292 ToolkitTestApplication application;
294 tet_infoline(" UtcDaliFocusManagerGetActorByFocusOrder");
296 FocusManager manager = FocusManager::Get();
297 DALI_TEST_CHECK(manager);
299 // Create the actors and set their focus orders
300 Actor first = Actor::New();
301 manager.SetFocusOrder(first, 1);
303 Actor second = Actor::New();
304 manager.SetFocusOrder(second, 2);
306 Actor third = Actor::New();
307 manager.SetFocusOrder(third, 3);
309 // Check that we get an empty handle as no actor is added to the stage yet.
310 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == Actor());
311 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == Actor());
312 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == Actor());
314 // Add the actors to the stage
315 Stage::GetCurrent().Add(first);
316 Stage::GetCurrent().Add(second);
317 Stage::GetCurrent().Add(third);
319 // Check that we get an empty handle because focus order 0 means undefined.
320 DALI_TEST_CHECK(manager.GetActorByFocusOrder(0) == Actor());
322 // Check that we get correct actors for the specified focus orders
323 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == first);
324 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == second);
325 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == third);
327 // Change the focus order of the third actor to 1
328 manager.SetFocusOrder(third, 1);
330 // Check that we still get correct actors after changing their focus orders
331 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == third);
332 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == first);
333 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == second);
335 // Check that we get an empty handle because no actor has a focus order of 4
336 DALI_TEST_CHECK(manager.GetActorByFocusOrder(4) == Actor());
339 static void UtcDaliFocusManagerSetAndGetCurrentFocusActor()
341 ToolkitTestApplication application;
343 tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor");
345 FocusManager manager = FocusManager::Get();
346 DALI_TEST_CHECK(manager);
348 // Create the first actor and add it to the stage
349 Actor first = Actor::New();
350 manager.SetFocusOrder(first, 1);
351 Stage::GetCurrent().Add(first);
353 // Create the second actor and add it to the stage
354 Actor second = Actor::New();
355 manager.SetFocusOrder(second, 2);
356 Stage::GetCurrent().Add(second);
358 // Create the third actor but don't add it to the stage
359 Actor third = Actor::New();
360 manager.SetFocusOrder(third, 3);
362 // Check that no actor is being focused yet.
363 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
365 // Check that it will fail to set focus on an invalid actor
366 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
368 // Check that the focus is set on the first actor
369 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
370 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
372 // Check that the focus is set on the second actor
373 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
374 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
376 // Check that it will fail to set focus on the third actor as it's not in the stage
377 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
379 // Add the third actor to the stage
380 Stage::GetCurrent().Add(third);
382 // make the third actor invisible
383 third.SetVisible(false);
384 // flush the queue and render once
385 application.SendNotification();
386 application.Render();
388 // Check that it will fail to set focus on the third actor as it's invisible
389 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
391 // Make the third actor visible
392 third.SetVisible(true);
393 // flush the queue and render once
394 application.SendNotification();
395 application.Render();
397 // Make the third actor not focusable
398 Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable");
399 third.SetProperty(propertyActorFocusable, false);
400 // flush the queue and render once
401 application.SendNotification();
402 application.Render();
404 // Check that it will fail to set focus on the third actor as it's not focusable
405 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
407 // Make the third actor focusable
408 third.SetProperty(propertyActorFocusable, true);
409 // flush the queue and render once
410 application.SendNotification();
411 application.Render();
413 // Check that the focus is successfully moved to the third actor
414 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
416 // Make the current focused actor to be not focusable by setting its focus order to be 0
417 manager.SetFocusOrder(third, 0);
419 // Check that the focus is automatically cleared
420 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
422 // Set the focus order of the third actor again
423 manager.SetFocusOrder(third, 3);
425 // Check that the third actor can be focused successfully now
426 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
429 static void UtcDaliFocusManagerGetCurrentFocusGroup()
431 ToolkitTestApplication application;
433 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup");
435 FocusManager manager = FocusManager::Get();
436 DALI_TEST_CHECK(manager);
438 // Create an actor with two child actors and add it to the stage
439 Actor parent = Actor::New();
440 Actor firstChild = Actor::New();
441 Actor secondChild = Actor::New();
442 parent.Add(firstChild);
443 parent.Add(secondChild);
444 Stage::GetCurrent().Add(parent);
446 // Create three actors and add them as the children of the first child actor
447 Actor firstGrandChild = Actor::New();
448 Actor secondGrandChild = Actor::New();
449 Actor thirdGrandChild = Actor::New();
450 firstChild.Add(firstGrandChild);
451 firstChild.Add(secondGrandChild);
452 firstChild.Add(thirdGrandChild);
454 // Set focus order to the actors
455 manager.SetFocusOrder(parent, 1);
456 manager.SetFocusOrder(firstChild, 2);
457 manager.SetFocusOrder(firstGrandChild, 3);
458 manager.SetFocusOrder(secondGrandChild, 4);
459 manager.SetFocusOrder(thirdGrandChild, 5);
460 manager.SetFocusOrder(secondChild, 6);
462 // Set the parent and the first child actor as focus groups
463 manager.SetFocusGroup(parent, true);
464 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
466 // Set focus to the first grand child actor
467 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true);
468 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
470 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
471 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent);
473 manager.SetFocusGroup(firstChild, true);
474 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
476 // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group.
477 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
479 manager.SetFocusGroup(firstGrandChild, true);
480 DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true);
482 // The current focus group should be itself, As it is also a focus group.
483 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild);
485 // Set focus to the second grand child actor
486 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true);
487 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
489 // The current focus group should be the firstChild, As it is the immediate parent which is also a
490 // focus group for the current focus actor.
491 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
495 static void UtcDaliFocusManagerGetCurrentFocusOrder()
497 ToolkitTestApplication application;
499 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusOrder");
501 FocusManager manager = FocusManager::Get();
502 DALI_TEST_CHECK(manager);
504 Actor first = Actor::New();
505 Stage::GetCurrent().Add(first);
507 Actor second = Actor::New();
508 Stage::GetCurrent().Add(second);
510 Actor third = Actor::New();
511 Stage::GetCurrent().Add(third);
513 // Set the focus order and description for the first actor
514 manager.SetFocusOrder(first, 1);
515 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
516 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
517 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
519 // Set the focus order and description for the second actor
520 manager.SetFocusOrder(second, 2);
521 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
522 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
523 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
525 // Set the focus order and description for the second actor
526 manager.SetFocusOrder(third, 3);
527 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
528 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
529 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
531 // Check that no actor is being focused yet.
532 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
534 // Set the focus on the first actor and test
535 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
536 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 1);
538 // Move the focus forward to the second actor and test
539 manager.MoveFocusForward();
540 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 2);
542 // Move the focus forward to the third actor and test
543 manager.MoveFocusForward();
544 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 3);
546 // Clear focus and test
547 manager.ClearFocus();
548 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
551 static void UtcDaliFocusManagerMoveFocusForward()
553 ToolkitTestApplication application;
555 tet_infoline(" UtcDaliFocusManagerMoveFocusForward");
557 FocusManager manager = FocusManager::Get();
558 DALI_TEST_CHECK(manager);
560 Actor first = Actor::New();
561 Stage::GetCurrent().Add(first);
563 Actor second = Actor::New();
564 Stage::GetCurrent().Add(second);
566 Actor third = Actor::New();
567 Stage::GetCurrent().Add(third);
569 // Set the focus order and description for the first actor
570 manager.SetFocusOrder(first, 1);
571 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
572 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
573 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
575 // Set the focus order and description for the second actor
576 manager.SetFocusOrder(second, 2);
577 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
578 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
579 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
581 // Set the focus order and description for the second actor
582 manager.SetFocusOrder(third, 3);
583 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
584 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
585 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
587 // Check that no actor is being focused yet.
588 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
590 // Set the focus on the first actor
591 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
592 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
593 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
595 // Test the non-wrapped move first
596 manager.SetWrapMode(false);
597 DALI_TEST_CHECK(manager.GetWrapMode() == false);
599 // Move the focus forward to the second actor
600 manager.MoveFocusForward();
601 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
602 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
604 // Move the focus forward to the third actor
605 manager.MoveFocusForward();
606 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
607 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
609 // Check that it will fail to move the focus forward again as the third actor is the last
610 // focusable actor in the focus chain
611 manager.MoveFocusForward();
612 // The focus should still be set on the third actor
613 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
614 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
616 // Now test the wrapped move
617 manager.SetWrapMode(true);
618 DALI_TEST_CHECK(manager.GetWrapMode() == true);
620 // Move the focus forward recursively and this time the first actor should be focused
621 manager.MoveFocusForward();
622 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
623 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
625 // Make the second actor not focusable
626 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
627 second.SetProperty(propertyActorFocusable, false);
628 // flush the queue and render once
629 application.SendNotification();
630 application.Render();
632 // Move the focus forward and check that the second actor should be skipped and
633 // the third actor should be focused now.
634 manager.MoveFocusForward();
635 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
636 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
638 // Make the first actor invisible
639 first.SetVisible(false);
640 // flush the queue and render once
641 application.SendNotification();
642 application.Render();
644 // Move the focus forward and check that the first actor should be skipped as it's
645 // invisible and the second actor should also be skipped as it's not focusable,
646 // so the focus will still be on the third actor
647 manager.MoveFocusForward();
648 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
649 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
651 // Make the third actor invisible so that no actor can be focused.
652 third.SetVisible(false);
653 // flush the queue and render once
654 application.SendNotification();
655 application.Render();
657 // Check that the focus move is failed as all the three actors can not be focused
658 manager.MoveFocusForward();
659 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
660 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
663 static void UtcDaliFocusManagerMoveFocusBackward()
665 ToolkitTestApplication application;
667 tet_infoline(" UtcDaliFocusManagerMoveFocusBackward");
669 FocusManager manager = FocusManager::Get();
670 DALI_TEST_CHECK(manager);
672 Actor first = Actor::New();
673 Stage::GetCurrent().Add(first);
675 Actor second = Actor::New();
676 Stage::GetCurrent().Add(second);
678 Actor third = Actor::New();
679 Stage::GetCurrent().Add(third);
681 // Set the focus order and description for the first actor
682 manager.SetFocusOrder(first, 1);
683 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
684 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
685 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
687 // Set the focus order and description for the second actor
688 manager.SetFocusOrder(second, 2);
689 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
690 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
691 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
693 // Set the focus order and description for the second actor
694 manager.SetFocusOrder(third, 3);
695 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
696 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
697 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
699 // Check that no actor is being focused yet.
700 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
702 // Set the focus on the third actor
703 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
704 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
705 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
707 // Test the non-wrapped move first
708 manager.SetWrapMode(false);
709 DALI_TEST_CHECK(manager.GetWrapMode() == false);
711 // Move the focus backward to the second actor
712 manager.MoveFocusBackward();
713 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
714 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
716 // Move the focus backward to the first actor
717 manager.MoveFocusBackward();
718 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
719 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
721 // Check that it will fail to move the focus backward again as the first actor is the first
722 // focusable actor in the focus chain
723 manager.MoveFocusBackward();
724 // The focus should still be set on the first actor
725 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
726 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
728 // Now test the wrapped move
729 manager.SetWrapMode(true);
730 DALI_TEST_CHECK(manager.GetWrapMode() == true);
732 // Move the focus backward recursively and this time the third actor should be focused
733 manager.MoveFocusBackward();
734 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
735 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
737 // Make the second actor not focusable
738 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
739 second.SetProperty(propertyActorFocusable, false);
740 // flush the queue and render once
741 application.SendNotification();
742 application.Render();
744 // Move the focus backward and check that the second actor should be skipped and
745 // the first actor should be focused now.
746 manager.MoveFocusBackward();
747 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
748 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
750 // Make the third actor invisible
751 third.SetVisible(false);
752 // flush the queue and render once
753 application.SendNotification();
754 application.Render();
756 // Move the focus backward and check that the third actor should be skipped as it's
757 // invisible and the second actor should also be skipped as it's not focusable,
758 // so the focus will still be on the first actor
759 manager.MoveFocusBackward();
760 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
761 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
763 // Make the first actor invisible so that no actor can be focused.
764 first.SetVisible(false);
765 // flush the queue and render once
766 application.SendNotification();
767 application.Render();
769 // Check that the focus move is failed as all the three actors can not be focused
770 manager.MoveFocusBackward();
771 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
772 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
775 static void UtcDaliFocusManagerClearFocus()
777 ToolkitTestApplication application;
779 tet_infoline(" UtcDaliFocusManagerClearFocus");
781 FocusManager manager = FocusManager::Get();
782 DALI_TEST_CHECK(manager);
784 // Create the first actor and add it to the stage
785 Actor first = Actor::New();
786 manager.SetFocusOrder(first, 1);
787 Stage::GetCurrent().Add(first);
789 // Create the second actor and add it to the stage
790 Actor second = Actor::New();
791 manager.SetFocusOrder(second, 2);
792 Stage::GetCurrent().Add(second);
794 // Check that no actor is being focused yet.
795 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
797 // Check that the focus is set on the first actor
798 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
799 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
801 // Check that the focus is set on the second actor
802 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
803 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
806 manager.ClearFocus();
808 // Check that no actor is being focused now.
809 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
812 static void UtcDaliFocusManagerReset()
814 ToolkitTestApplication application;
816 tet_infoline(" UtcDaliFocusManagerReset");
818 FocusManager manager = FocusManager::Get();
819 DALI_TEST_CHECK(manager);
821 // Create the first actor and add it to the stage
822 Actor first = Actor::New();
823 manager.SetFocusOrder(first, 1);
824 Stage::GetCurrent().Add(first);
826 // Create the second actor and add it to the stage
827 Actor second = Actor::New();
828 manager.SetFocusOrder(second, 2);
829 Stage::GetCurrent().Add(second);
831 // Check that no actor is being focused yet.
832 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
834 // Check that the focus is set on the first actor
835 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
836 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
838 // Check that the focus is set on the second actor
839 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
840 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
845 // Check that no actor is being focused now and the focus order of actors have been cleared
846 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
847 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
848 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
851 static void UtcDaliFocusManagerFocusGroup()
853 ToolkitTestApplication application;
855 tet_infoline(" UtcDaliFocusManagerFocusGroup");
857 FocusManager manager = FocusManager::Get();
858 DALI_TEST_CHECK(manager);
860 // Create an actor with two child actors and add it to the stage
861 Actor parent = Actor::New();
862 Actor firstChild = Actor::New();
863 Actor secondChild = Actor::New();
864 parent.Add(firstChild);
865 parent.Add(secondChild);
866 Stage::GetCurrent().Add(parent);
868 // Create three actors and add them as the children of the first child actor
869 Actor firstGrandChild = Actor::New();
870 Actor secondGrandChild = Actor::New();
871 Actor thirdGrandChild = Actor::New();
872 firstChild.Add(firstGrandChild);
873 firstChild.Add(secondGrandChild);
874 firstChild.Add(thirdGrandChild);
876 // Set focus order to the actors
877 manager.SetFocusOrder(parent, 1);
878 manager.SetFocusOrder(firstChild, 2);
879 manager.SetFocusOrder(firstGrandChild, 3);
880 manager.SetFocusOrder(secondGrandChild, 4);
881 manager.SetFocusOrder(thirdGrandChild, 5);
882 manager.SetFocusOrder(secondChild, 6);
884 // Set the parent and the first child actor as focus groups
885 manager.SetFocusGroup(parent, true);
886 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
888 // The focus group of the parent should be itself, as it is set to be a focus group.
889 DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent);
891 // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group.
892 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent);
894 manager.SetFocusGroup(firstChild, true);
895 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
897 // The focus group of the firstChild should be itself, as it is set to be a focus group now.
898 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild);
900 // Enable wrap mode for focus movement.
901 manager.SetWrapMode(true);
902 DALI_TEST_CHECK(manager.GetWrapMode() == true);
904 // Check that no actor is being focused yet.
905 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
907 // Check that the focus is set on the parent actor.
908 DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true);
909 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
911 // Check that group mode is disabled.
912 DALI_TEST_CHECK(manager.GetGroupMode() == false);
914 // Check that the focus movement is wrapped as normal.
915 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
916 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
917 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
918 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
919 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
920 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
921 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
922 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
923 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
924 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild);
925 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
926 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
927 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
928 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
929 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
930 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
932 // Enable the group mode.
933 manager.SetGroupMode(true);
934 DALI_TEST_CHECK(manager.GetGroupMode() == true);
936 // Check that the focus movement is now limited to the current focus group.
937 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
938 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
939 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
940 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
941 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
942 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
943 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
944 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
947 static void UtcDaliFocusManagerSetAndGetFocusIndicator()
949 ToolkitTestApplication application;
951 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusIndicator");
953 FocusManager manager = FocusManager::Get();
954 DALI_TEST_CHECK(manager);
956 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
957 DALI_TEST_CHECK(defaultFocusIndicatorActor);
959 Actor newFocusIndicatorActor = Actor::New();
960 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
961 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
964 static void UtcDaliFocusManagerSignalFocusChanged()
966 ToolkitTestApplication application;
968 tet_infoline(" UtcDaliFocusManagerSignalFocusChanged");
970 FocusManager manager = FocusManager::Get();
971 DALI_TEST_CHECK(manager);
973 bool signalVerified = false;
974 FocusChangedCallback callback(signalVerified);
975 manager.FocusChangedSignal().Connect( &callback, &FocusChangedCallback::Callback );
977 // Create the first actor and add it to the stage
978 Actor first = Actor::New();
979 manager.SetFocusOrder(first, 1);
980 Stage::GetCurrent().Add(first);
982 // Create the second actor and add it to the stage
983 Actor second = Actor::New();
984 manager.SetFocusOrder(second, 2);
985 Stage::GetCurrent().Add(second);
987 // Check that no actor is being focused yet.
988 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
990 // Check that the focus is set on the first actor
991 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
992 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
993 DALI_TEST_CHECK(callback.mSignalVerified);
996 // Check that the focus is set on the second actor
997 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
998 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
999 DALI_TEST_CHECK(callback.mSignalVerified);
1003 manager.ClearFocus();
1005 // Check that no actor is being focused now.
1006 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1007 DALI_TEST_CHECK(callback.mSignalVerified);
1010 static void UtcDaliFocusManagerSignalFocusOvershot()
1012 ToolkitTestApplication application;
1014 tet_infoline(" UtcDaliFocusManagerSignalFocusOvershot");
1016 FocusManager manager = FocusManager::Get();
1017 DALI_TEST_CHECK(manager);
1019 bool signalVerified = false;
1020 FocusOvershotCallback callback(signalVerified);
1021 manager.FocusOvershotSignal().Connect(&callback, &FocusOvershotCallback::Callback);
1023 // Create the first actor and add it to the stage
1024 Actor first = Actor::New();
1025 manager.SetFocusOrder(first, 1);
1026 Stage::GetCurrent().Add(first);
1028 // Create the second actor and add it to the stage
1029 Actor second = Actor::New();
1030 manager.SetFocusOrder(second, 2);
1031 Stage::GetCurrent().Add(second);
1033 // Check that the wrap mode is disabled
1034 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1036 // Check that the focus is set on the first actor
1037 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1038 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1040 // Check that the focus is moved to the second actor successfully.
1041 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1042 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1044 // Check that the forward focus movement is overshot.
1045 callback.mCurrentFocusedActor = second;
1046 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_NEXT;
1047 DALI_TEST_CHECK(manager.MoveFocusForward() == false);
1048 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1049 DALI_TEST_CHECK(signalVerified);
1052 // Enable the wrap mode
1053 manager.SetWrapMode(true);
1054 DALI_TEST_CHECK(manager.GetWrapMode() == true);
1056 // Check that the forward focus movement is wrapped and no overshot happens.
1057 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1058 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1059 DALI_TEST_CHECK(signalVerified == false);
1061 // Disable the wrap mode
1062 manager.SetWrapMode(false);
1063 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1065 // Check that the backward focus movement is overshot.
1066 callback.mCurrentFocusedActor = first;
1067 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_PREVIOUS;
1068 DALI_TEST_CHECK(manager.MoveFocusBackward() == false);
1069 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1070 DALI_TEST_CHECK(signalVerified);