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-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;
120 int UtcDaliFocusManagerGet(void)
122 ToolkitTestApplication application;
124 tet_infoline(" UtcDaliFocusManagerGet");
126 FocusManager manager;
128 //Ensure object is created by checking if it's registered
129 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
130 DALI_TEST_CHECK(registry);
132 gObjectCreatedCallBackCalled = false;
133 registry.ObjectCreatedSignal().Connect( &TestCallback );
135 manager = FocusManager::Get();
136 DALI_TEST_CHECK(manager);
138 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
140 FocusManager newManager = FocusManager::Get();
141 DALI_TEST_CHECK(newManager);
143 // Check that focus manager is a singleton
144 DALI_TEST_CHECK(manager == newManager);
148 int UtcDaliFocusManagerSetAndGetAccessibilityAttribute(void)
150 ToolkitTestApplication application;
152 tet_infoline(" UtcDaliFocusManagerSetAndGetAccessibilityAttribute");
154 FocusManager manager = FocusManager::Get();
155 DALI_TEST_CHECK(manager);
157 Actor actor = Actor::New();
158 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "");
160 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "Description");
161 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "Description");
163 manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "New description");
164 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "New description");
168 int UtcDaliFocusManagerSetAndGetFocusOrder(void)
170 ToolkitTestApplication application;
172 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusOrder");
174 FocusManager manager = FocusManager::Get();
175 DALI_TEST_CHECK(manager);
177 Actor first = Actor::New();
178 Actor second = Actor::New();
179 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
180 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 0);
182 // Set the focus order and description for the first actor
183 manager.SetFocusOrder(first, 1);
184 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
185 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
186 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
188 // Set the focus order and description for the second actor
189 manager.SetFocusOrder(second, 2);
190 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
191 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
192 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
194 // check that the focus order of the first actor is changed
195 manager.SetFocusOrder(first, 2);
196 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 2);
197 // make sure the change of focus order doesn't affect the actor's description
198 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
200 // check that the focus order of the second actor is increased to 3
201 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 3);
202 // make sure the change of focus order doesn't affect the actor's description
203 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
205 // check that the focus order of the second actor is changed to 1
206 manager.SetFocusOrder(second, 1);
207 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 1);
208 // make sure the change of focus order doesn't affect the actor's description
209 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
211 // Set the focus order and description for the third actor
212 Actor third = Actor::New();
213 manager.SetFocusOrder(third, 1);
214 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
215 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 1);
216 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
218 // check that the focus order of the second actor is increased to 2.
219 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
220 // make sure the change of focus order doesn't affect the actor's description
221 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
223 // check that the focus order of the first actor is increased to 3.
224 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 3);
225 // make sure the change of focus order doesn't affect the actor's description
226 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
230 int UtcDaliFocusManagerGenerateNewFocusOrder(void)
232 ToolkitTestApplication application;
234 tet_infoline(" UtcDaliFocusManagerGenerateNewFocusOrder");
236 FocusManager manager = FocusManager::Get();
237 DALI_TEST_CHECK(manager);
239 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
240 DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
242 Actor first = Actor::New();
243 Actor second = Actor::New();
245 // Set the focus order for the first actor
246 manager.SetFocusOrder(first, 1);
247 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
248 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
250 //Test for new focus order
251 DALI_TEST_CHECK(2 == manager.GenerateNewFocusOrder());
253 // Set the focus order for the first actor
254 manager.SetFocusOrder(second, 2);
255 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "first");
256 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
260 int UtcDaliFocusManagerGetActorByFocusOrder(void)
262 ToolkitTestApplication application;
264 tet_infoline(" UtcDaliFocusManagerGetActorByFocusOrder");
266 FocusManager manager = FocusManager::Get();
267 DALI_TEST_CHECK(manager);
269 // Create the actors and set their focus orders
270 Actor first = Actor::New();
271 manager.SetFocusOrder(first, 1);
273 Actor second = Actor::New();
274 manager.SetFocusOrder(second, 2);
276 Actor third = Actor::New();
277 manager.SetFocusOrder(third, 3);
279 // Check that we get an empty handle as no actor is added to the stage yet.
280 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == Actor());
281 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == Actor());
282 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == Actor());
284 // Add the actors to the stage
285 Stage::GetCurrent().Add(first);
286 Stage::GetCurrent().Add(second);
287 Stage::GetCurrent().Add(third);
289 // Check that we get an empty handle because focus order 0 means undefined.
290 DALI_TEST_CHECK(manager.GetActorByFocusOrder(0) == Actor());
292 // Check that we get correct actors for the specified focus orders
293 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == first);
294 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == second);
295 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == third);
297 // Change the focus order of the third actor to 1
298 manager.SetFocusOrder(third, 1);
300 // Check that we still get correct actors after changing their focus orders
301 DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == third);
302 DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == first);
303 DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == second);
305 // Check that we get an empty handle because no actor has a focus order of 4
306 DALI_TEST_CHECK(manager.GetActorByFocusOrder(4) == Actor());
310 int UtcDaliFocusManagerSetAndGetCurrentFocusActor(void)
312 ToolkitTestApplication application;
314 tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor");
316 FocusManager manager = FocusManager::Get();
317 DALI_TEST_CHECK(manager);
319 // Create the first actor and add it to the stage
320 Actor first = Actor::New();
321 manager.SetFocusOrder(first, 1);
322 Stage::GetCurrent().Add(first);
324 // Create the second actor and add it to the stage
325 Actor second = Actor::New();
326 manager.SetFocusOrder(second, 2);
327 Stage::GetCurrent().Add(second);
329 // Create the third actor but don't add it to the stage
330 Actor third = Actor::New();
331 manager.SetFocusOrder(third, 3);
333 // Check that no actor is being focused yet.
334 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
336 // Check that it will fail to set focus on an invalid actor
337 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
339 // Check that the focus is set on the first actor
340 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
341 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
343 // Check that the focus is set on the second actor
344 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
345 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
347 // Check that it will fail to set focus on the third actor as it's not in the stage
348 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
350 // Add the third actor to the stage
351 Stage::GetCurrent().Add(third);
353 // make the third actor invisible
354 third.SetVisible(false);
355 // flush the queue and render once
356 application.SendNotification();
357 application.Render();
359 // Check that it will fail to set focus on the third actor as it's invisible
360 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
362 // Make the third actor visible
363 third.SetVisible(true);
364 // flush the queue and render once
365 application.SendNotification();
366 application.Render();
368 // Make the third actor not focusable
369 Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable");
370 third.SetProperty(propertyActorFocusable, false);
371 // flush the queue and render once
372 application.SendNotification();
373 application.Render();
375 // Check that it will fail to set focus on the third actor as it's not focusable
376 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
378 // Make the third actor focusable
379 third.SetProperty(propertyActorFocusable, true);
380 // flush the queue and render once
381 application.SendNotification();
382 application.Render();
384 // Check that the focus is successfully moved to the third actor
385 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
387 // Make the current focused actor to be not focusable by setting its focus order to be 0
388 manager.SetFocusOrder(third, 0);
390 // Check that the focus is automatically cleared
391 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
393 // Set the focus order of the third actor again
394 manager.SetFocusOrder(third, 3);
396 // Check that the third actor can be focused successfully now
397 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
401 int UtcDaliFocusManagerGetCurrentFocusGroup(void)
403 ToolkitTestApplication application;
405 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup");
407 FocusManager manager = FocusManager::Get();
408 DALI_TEST_CHECK(manager);
410 // Create an actor with two child actors and add it to the stage
411 Actor parent = Actor::New();
412 Actor firstChild = Actor::New();
413 Actor secondChild = Actor::New();
414 parent.Add(firstChild);
415 parent.Add(secondChild);
416 Stage::GetCurrent().Add(parent);
418 // Create three actors and add them as the children of the first child actor
419 Actor firstGrandChild = Actor::New();
420 Actor secondGrandChild = Actor::New();
421 Actor thirdGrandChild = Actor::New();
422 firstChild.Add(firstGrandChild);
423 firstChild.Add(secondGrandChild);
424 firstChild.Add(thirdGrandChild);
426 // Set focus order to the actors
427 manager.SetFocusOrder(parent, 1);
428 manager.SetFocusOrder(firstChild, 2);
429 manager.SetFocusOrder(firstGrandChild, 3);
430 manager.SetFocusOrder(secondGrandChild, 4);
431 manager.SetFocusOrder(thirdGrandChild, 5);
432 manager.SetFocusOrder(secondChild, 6);
434 // Set the parent and the first child actor as focus groups
435 manager.SetFocusGroup(parent, true);
436 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
438 // Set focus to the first grand child actor
439 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true);
440 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
442 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
443 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent);
445 manager.SetFocusGroup(firstChild, true);
446 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
448 // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group.
449 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
451 manager.SetFocusGroup(firstGrandChild, true);
452 DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true);
454 // The current focus group should be itself, As it is also a focus group.
455 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild);
457 // Set focus to the second grand child actor
458 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true);
459 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
461 // The current focus group should be the firstChild, As it is the immediate parent which is also a
462 // focus group for the current focus actor.
463 DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
468 int UtcDaliFocusManagerGetCurrentFocusOrder(void)
470 ToolkitTestApplication application;
472 tet_infoline(" UtcDaliFocusManagerGetCurrentFocusOrder");
474 FocusManager manager = FocusManager::Get();
475 DALI_TEST_CHECK(manager);
477 Actor first = Actor::New();
478 Stage::GetCurrent().Add(first);
480 Actor second = Actor::New();
481 Stage::GetCurrent().Add(second);
483 Actor third = Actor::New();
484 Stage::GetCurrent().Add(third);
486 // Set the focus order and description for the first actor
487 manager.SetFocusOrder(first, 1);
488 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
489 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
490 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
492 // Set the focus order and description for the second actor
493 manager.SetFocusOrder(second, 2);
494 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
495 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
496 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
498 // Set the focus order and description for the second actor
499 manager.SetFocusOrder(third, 3);
500 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
501 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
502 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
504 // Check that no actor is being focused yet.
505 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
507 // Set the focus on the first actor and test
508 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
509 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 1);
511 // Move the focus forward to the second actor and test
512 manager.MoveFocusForward();
513 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 2);
515 // Move the focus forward to the third actor and test
516 manager.MoveFocusForward();
517 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 3);
519 // Clear focus and test
520 manager.ClearFocus();
521 DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
525 int UtcDaliFocusManagerMoveFocusForward(void)
527 ToolkitTestApplication application;
529 tet_infoline(" UtcDaliFocusManagerMoveFocusForward");
531 FocusManager manager = FocusManager::Get();
532 DALI_TEST_CHECK(manager);
534 Actor first = Actor::New();
535 Stage::GetCurrent().Add(first);
537 Actor second = Actor::New();
538 Stage::GetCurrent().Add(second);
540 Actor third = Actor::New();
541 Stage::GetCurrent().Add(third);
543 // Set the focus order and description for the first actor
544 manager.SetFocusOrder(first, 1);
545 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
546 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
547 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
549 // Set the focus order and description for the second actor
550 manager.SetFocusOrder(second, 2);
551 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
552 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
553 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
555 // Set the focus order and description for the second actor
556 manager.SetFocusOrder(third, 3);
557 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
558 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
559 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
561 // Check that no actor is being focused yet.
562 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
564 // Set the focus on the first actor
565 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
566 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
567 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
569 // Test the non-wrapped move first
570 manager.SetWrapMode(false);
571 DALI_TEST_CHECK(manager.GetWrapMode() == false);
573 // Move the focus forward to the second actor
574 manager.MoveFocusForward();
575 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
576 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
578 // Move the focus forward to the third actor
579 manager.MoveFocusForward();
580 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
581 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
583 // Check that it will fail to move the focus forward again as the third actor is the last
584 // focusable actor in the focus chain
585 manager.MoveFocusForward();
586 // The focus should still be set on the third actor
587 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
588 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
590 // Now test the wrapped move
591 manager.SetWrapMode(true);
592 DALI_TEST_CHECK(manager.GetWrapMode() == true);
594 // Move the focus forward recursively and this time the first actor should be focused
595 manager.MoveFocusForward();
596 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
597 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
599 // Make the second actor not focusable
600 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
601 second.SetProperty(propertyActorFocusable, false);
602 // flush the queue and render once
603 application.SendNotification();
604 application.Render();
606 // Move the focus forward and check that the second actor should be skipped and
607 // the third actor should be focused now.
608 manager.MoveFocusForward();
609 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
610 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
612 // Make the first actor invisible
613 first.SetVisible(false);
614 // flush the queue and render once
615 application.SendNotification();
616 application.Render();
618 // Move the focus forward and check that the first actor should be skipped as it's
619 // invisible and the second actor should also be skipped as it's not focusable,
620 // so the focus will still be on the third actor
621 manager.MoveFocusForward();
622 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
623 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
625 // Make the third actor invisible so that no actor can be focused.
626 third.SetVisible(false);
627 // flush the queue and render once
628 application.SendNotification();
629 application.Render();
631 // Check that the focus move is failed as all the three actors can not be focused
632 manager.MoveFocusForward();
633 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
634 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
638 int UtcDaliFocusManagerMoveFocusBackward(void)
640 ToolkitTestApplication application;
642 tet_infoline(" UtcDaliFocusManagerMoveFocusBackward");
644 FocusManager manager = FocusManager::Get();
645 DALI_TEST_CHECK(manager);
647 Actor first = Actor::New();
648 Stage::GetCurrent().Add(first);
650 Actor second = Actor::New();
651 Stage::GetCurrent().Add(second);
653 Actor third = Actor::New();
654 Stage::GetCurrent().Add(third);
656 // Set the focus order and description for the first actor
657 manager.SetFocusOrder(first, 1);
658 manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
659 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
660 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
662 // Set the focus order and description for the second actor
663 manager.SetFocusOrder(second, 2);
664 manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
665 DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
666 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
668 // Set the focus order and description for the second actor
669 manager.SetFocusOrder(third, 3);
670 manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
671 DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
672 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
674 // Check that no actor is being focused yet.
675 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
677 // Set the focus on the third actor
678 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
679 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
680 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
682 // Test the non-wrapped move first
683 manager.SetWrapMode(false);
684 DALI_TEST_CHECK(manager.GetWrapMode() == false);
686 // Move the focus backward to the second actor
687 manager.MoveFocusBackward();
688 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
689 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
691 // Move the focus backward to the first actor
692 manager.MoveFocusBackward();
693 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
694 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
696 // Check that it will fail to move the focus backward again as the first actor is the first
697 // focusable actor in the focus chain
698 manager.MoveFocusBackward();
699 // The focus should still be set on the first actor
700 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
701 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
703 // Now test the wrapped move
704 manager.SetWrapMode(true);
705 DALI_TEST_CHECK(manager.GetWrapMode() == true);
707 // Move the focus backward recursively and this time the third actor should be focused
708 manager.MoveFocusBackward();
709 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
710 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
712 // Make the second actor not focusable
713 Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
714 second.SetProperty(propertyActorFocusable, false);
715 // flush the queue and render once
716 application.SendNotification();
717 application.Render();
719 // Move the focus backward and check that the second actor should be skipped and
720 // the first actor should be focused now.
721 manager.MoveFocusBackward();
722 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
723 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
725 // Make the third actor invisible
726 third.SetVisible(false);
727 // flush the queue and render once
728 application.SendNotification();
729 application.Render();
731 // Move the focus backward and check that the third actor should be skipped as it's
732 // invisible and the second actor should also be skipped as it's not focusable,
733 // so the focus will still be on the first actor
734 manager.MoveFocusBackward();
735 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
736 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
738 // Make the first actor invisible so that no actor can be focused.
739 first.SetVisible(false);
740 // flush the queue and render once
741 application.SendNotification();
742 application.Render();
744 // Check that the focus move is failed as all the three actors can not be focused
745 manager.MoveFocusBackward();
746 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
747 DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
751 int UtcDaliFocusManagerClearFocus(void)
753 ToolkitTestApplication application;
755 tet_infoline(" UtcDaliFocusManagerClearFocus");
757 FocusManager manager = FocusManager::Get();
758 DALI_TEST_CHECK(manager);
760 // Create the first actor and add it to the stage
761 Actor first = Actor::New();
762 manager.SetFocusOrder(first, 1);
763 Stage::GetCurrent().Add(first);
765 // Create the second actor and add it to the stage
766 Actor second = Actor::New();
767 manager.SetFocusOrder(second, 2);
768 Stage::GetCurrent().Add(second);
770 // Check that no actor is being focused yet.
771 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
773 // Check that the focus is set on the first actor
774 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
775 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
777 // Check that the focus is set on the second actor
778 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
779 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
782 manager.ClearFocus();
784 // Check that no actor is being focused now.
785 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
789 int UtcDaliFocusManagerReset(void)
791 ToolkitTestApplication application;
793 tet_infoline(" UtcDaliFocusManagerReset");
795 FocusManager manager = FocusManager::Get();
796 DALI_TEST_CHECK(manager);
798 // Create the first actor and add it to the stage
799 Actor first = Actor::New();
800 manager.SetFocusOrder(first, 1);
801 Stage::GetCurrent().Add(first);
803 // Create the second actor and add it to the stage
804 Actor second = Actor::New();
805 manager.SetFocusOrder(second, 2);
806 Stage::GetCurrent().Add(second);
808 // Check that no actor is being focused yet.
809 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
811 // Check that the focus is set on the first actor
812 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
813 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
815 // Check that the focus is set on the second actor
816 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
817 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
822 // Check that no actor is being focused now and the focus order of actors have been cleared
823 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
824 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
825 DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
829 int UtcDaliFocusManagerFocusGroup(void)
831 ToolkitTestApplication application;
833 tet_infoline(" UtcDaliFocusManagerFocusGroup");
835 FocusManager manager = FocusManager::Get();
836 DALI_TEST_CHECK(manager);
838 // Create an actor with two child actors and add it to the stage
839 Actor parent = Actor::New();
840 Actor firstChild = Actor::New();
841 Actor secondChild = Actor::New();
842 parent.Add(firstChild);
843 parent.Add(secondChild);
844 Stage::GetCurrent().Add(parent);
846 // Create three actors and add them as the children of the first child actor
847 Actor firstGrandChild = Actor::New();
848 Actor secondGrandChild = Actor::New();
849 Actor thirdGrandChild = Actor::New();
850 firstChild.Add(firstGrandChild);
851 firstChild.Add(secondGrandChild);
852 firstChild.Add(thirdGrandChild);
854 // Set focus order to the actors
855 manager.SetFocusOrder(parent, 1);
856 manager.SetFocusOrder(firstChild, 2);
857 manager.SetFocusOrder(firstGrandChild, 3);
858 manager.SetFocusOrder(secondGrandChild, 4);
859 manager.SetFocusOrder(thirdGrandChild, 5);
860 manager.SetFocusOrder(secondChild, 6);
862 // Set the parent and the first child actor as focus groups
863 manager.SetFocusGroup(parent, true);
864 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
866 // The focus group of the parent should be itself, as it is set to be a focus group.
867 DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent);
869 // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group.
870 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent);
872 manager.SetFocusGroup(firstChild, true);
873 DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
875 // The focus group of the firstChild should be itself, as it is set to be a focus group now.
876 DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild);
878 // Enable wrap mode for focus movement.
879 manager.SetWrapMode(true);
880 DALI_TEST_CHECK(manager.GetWrapMode() == true);
882 // Check that no actor is being focused yet.
883 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
885 // Check that the focus is set on the parent actor.
886 DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true);
887 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
889 // Check that group mode is disabled.
890 DALI_TEST_CHECK(manager.GetGroupMode() == false);
892 // Check that the focus movement is wrapped as normal.
893 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
894 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
895 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
896 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
897 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
898 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
899 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
900 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
901 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
902 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild);
903 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
904 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
905 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
906 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
907 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
908 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
910 // Enable the group mode.
911 manager.SetGroupMode(true);
912 DALI_TEST_CHECK(manager.GetGroupMode() == true);
914 // Check that the focus movement is now limited to the current focus group.
915 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
916 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
917 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
918 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
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);
926 int UtcDaliFocusManagerSetAndGetFocusIndicator(void)
928 ToolkitTestApplication application;
930 tet_infoline(" UtcDaliFocusManagerSetAndGetFocusIndicator");
932 FocusManager manager = FocusManager::Get();
933 DALI_TEST_CHECK(manager);
935 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
936 DALI_TEST_CHECK(defaultFocusIndicatorActor);
938 Actor newFocusIndicatorActor = Actor::New();
939 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
940 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
944 int UtcDaliFocusManagerSignalFocusChanged(void)
946 ToolkitTestApplication application;
948 tet_infoline(" UtcDaliFocusManagerSignalFocusChanged");
950 FocusManager manager = FocusManager::Get();
951 DALI_TEST_CHECK(manager);
953 bool signalVerified = false;
954 FocusChangedCallback callback(signalVerified);
955 manager.FocusChangedSignal().Connect( &callback, &FocusChangedCallback::Callback );
957 // Create the first actor and add it to the stage
958 Actor first = Actor::New();
959 manager.SetFocusOrder(first, 1);
960 Stage::GetCurrent().Add(first);
962 // Create the second actor and add it to the stage
963 Actor second = Actor::New();
964 manager.SetFocusOrder(second, 2);
965 Stage::GetCurrent().Add(second);
967 // Check that no actor is being focused yet.
968 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
970 // Check that the focus is set on the first actor
971 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
972 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
973 DALI_TEST_CHECK(callback.mSignalVerified);
976 // Check that the focus is set on the second actor
977 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
978 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
979 DALI_TEST_CHECK(callback.mSignalVerified);
983 manager.ClearFocus();
985 // Check that no actor is being focused now.
986 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
987 DALI_TEST_CHECK(callback.mSignalVerified);
991 int UtcDaliFocusManagerSignalFocusOvershot(void)
993 ToolkitTestApplication application;
995 tet_infoline(" UtcDaliFocusManagerSignalFocusOvershot");
997 FocusManager manager = FocusManager::Get();
998 DALI_TEST_CHECK(manager);
1000 bool signalVerified = false;
1001 FocusOvershotCallback callback(signalVerified);
1002 manager.FocusOvershotSignal().Connect(&callback, &FocusOvershotCallback::Callback);
1004 // Create the first actor and add it to the stage
1005 Actor first = Actor::New();
1006 manager.SetFocusOrder(first, 1);
1007 Stage::GetCurrent().Add(first);
1009 // Create the second actor and add it to the stage
1010 Actor second = Actor::New();
1011 manager.SetFocusOrder(second, 2);
1012 Stage::GetCurrent().Add(second);
1014 // Check that the wrap mode is disabled
1015 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1017 // Check that the focus is set on the first actor
1018 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1019 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1021 // Check that the focus is moved to the second actor successfully.
1022 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1023 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1025 // Check that the forward focus movement is overshot.
1026 callback.mCurrentFocusedActor = second;
1027 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_NEXT;
1028 DALI_TEST_CHECK(manager.MoveFocusForward() == false);
1029 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1030 DALI_TEST_CHECK(signalVerified);
1033 // Enable the wrap mode
1034 manager.SetWrapMode(true);
1035 DALI_TEST_CHECK(manager.GetWrapMode() == true);
1037 // Check that the forward focus movement is wrapped and no overshot happens.
1038 DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1039 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1040 DALI_TEST_CHECK(signalVerified == false);
1042 // Disable the wrap mode
1043 manager.SetWrapMode(false);
1044 DALI_TEST_CHECK(manager.GetWrapMode() == false);
1046 // Check that the backward focus movement is overshot.
1047 callback.mCurrentFocusedActor = first;
1048 callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_PREVIOUS;
1049 DALI_TEST_CHECK(manager.MoveFocusBackward() == false);
1050 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1051 DALI_TEST_CHECK(signalVerified);