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/integration-api/events/key-event-integ.h>
28 #include <dali-toolkit-test-suite-utils.h>
31 using namespace Dali::Toolkit;
36 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
37 class PreFocusChangeCallback : public Dali::ConnectionTracker
40 PreFocusChangeCallback(bool& signalReceived)
41 : mSignalVerified(signalReceived),
42 mCurrentFocusedActor(),
43 mProposedActorToFocus(),
44 mDirection(Control::Left)
48 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction)
50 tet_infoline("Verifying PreFocusChangeCallback()");
52 mSignalVerified = true;
54 mCurrentFocusedActor = currentFocusedActor;
55 mProposedActorToFocus = proposedActorToFocus;
56 mDirection = direction;
58 return mProposedActorToFocus;
63 mSignalVerified = false;
64 mCurrentFocusedActor = Actor();
65 mProposedActorToFocus = Actor();
66 mDirection = Control::Left;
69 bool& mSignalVerified;
70 Actor mCurrentFocusedActor;
71 Actor mProposedActorToFocus;
72 Control::KeyboardFocusNavigationDirection mDirection;
75 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
76 class FocusChangedCallback : public Dali::ConnectionTracker
79 FocusChangedCallback(bool& signalReceived)
80 : mSignalVerified(signalReceived),
81 mOriginalFocusedActor(),
82 mCurrentFocusedActor()
86 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
88 tet_infoline("Verifying FocusChangedCallback()");
90 if(originalFocusedActor == mCurrentFocusedActor)
92 mSignalVerified = true;
95 mOriginalFocusedActor = originalFocusedActor;
96 mCurrentFocusedActor = currentFocusedActor;
101 mSignalVerified = false;
104 bool& mSignalVerified;
105 Actor mOriginalFocusedActor;
106 Actor mCurrentFocusedActor;
109 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
110 class FocusGroupChangedCallback : public Dali::ConnectionTracker
113 FocusGroupChangedCallback(bool& signalReceived)
114 : mSignalVerified(signalReceived),
115 mCurrentFocusedActor(),
120 void Callback(Actor currentFocusedActor, bool forward)
122 tet_infoline("Verifying FocusGroupChangedCallback()");
124 mSignalVerified = true;
126 mCurrentFocusedActor = currentFocusedActor;
132 mSignalVerified = false;
135 bool& mSignalVerified;
136 Actor mCurrentFocusedActor;
140 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
141 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
144 FocusedActorActivatedCallback(bool& signalReceived)
145 : mSignalVerified(signalReceived),
150 void Callback(Actor activatedActor)
152 tet_infoline("Verifying FocusedActorActivatedCallback()");
154 mSignalVerified = true;
156 mActivatedActor = activatedActor;
161 mSignalVerified = false;
164 bool& mSignalVerified;
165 Actor mActivatedActor;
170 static void Startup();
171 static void Cleanup();
174 void (*tet_startup)() = Startup;
175 void (*tet_cleanup)() = Cleanup;
179 POSITIVE_TC_IDX = 0x01,
183 #define MAX_NUMBER_OF_TESTS 10000
185 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
188 // Add test functionality for all APIs in the class (Positive and Negative)
189 TEST_FUNCTION( UtcDaliKeyboardFocusManagerGet, POSITIVE_TC_IDX );
190 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor, POSITIVE_TC_IDX );
191 TEST_FUNCTION( UtcDaliKeyboardFocusManagerMoveFocus, POSITIVE_TC_IDX );
192 TEST_FUNCTION( UtcDaliKeyboardFocusManagerClearFocus, POSITIVE_TC_IDX );
193 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop, POSITIVE_TC_IDX );
194 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAsFocusGroup, POSITIVE_TC_IDX );
195 TEST_FUNCTION( UtcDaliKeyboardFocusManagerGetFocusGroup, POSITIVE_TC_IDX );
196 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator, POSITIVE_TC_IDX );
197 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSignalFocusGroupChanged, POSITIVE_TC_IDX );
198 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSignalFocusedActorActivated, POSITIVE_TC_IDX );
200 // Called only once before first test is run.
201 static void Startup()
205 // Called only once after last test is run
206 static void Cleanup()
210 static void UtcDaliKeyboardFocusManagerGet()
212 ToolkitTestApplication application;
214 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
218 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
219 DALI_TEST_CHECK( type );
220 BaseHandle handle = type.CreateInstance();
221 DALI_TEST_CHECK( handle );
223 KeyboardFocusManager manager;
225 manager = KeyboardFocusManager::Get();
226 DALI_TEST_CHECK(manager);
228 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
229 DALI_TEST_CHECK(newManager);
231 // Check that focus manager is a singleton
232 DALI_TEST_CHECK(manager == newManager);
235 static void UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor()
237 ToolkitTestApplication application;
239 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
243 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
244 DALI_TEST_CHECK( type );
245 BaseHandle handle = type.CreateInstance();
246 DALI_TEST_CHECK( handle );
248 KeyboardFocusManager manager = KeyboardFocusManager::Get();
249 DALI_TEST_CHECK(manager);
251 // Create the first actor and add it to the stage
252 Actor first = Actor::New();
253 first.SetKeyboardFocusable(true);
254 Stage::GetCurrent().Add(first);
256 // Create the second actor and add it to the stage
257 Actor second = Actor::New();
258 second.SetKeyboardFocusable(true);
259 Stage::GetCurrent().Add(second);
261 // Create the third actor but don't add it to the stage
262 Actor third = Actor::New();
264 // Check that no actor is being focused yet.
265 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
267 // Check that it will fail to set focus on an invalid actor
268 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
270 // Check that the focus is set on the first actor
271 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
272 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
274 // Check that the focus is set on the second actor
275 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
276 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
278 // Check that it will fail to set focus on the third actor as it's not in the stage
279 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
280 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
282 // Add the third actor to the stage
283 Stage::GetCurrent().Add(third);
285 // Check that it will fail to set focus on the third actor as it's not focusable
286 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
287 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
289 // Make the third actor focusable
290 third.SetKeyboardFocusable(true);
292 // Check that the focus is successfully moved to the third actor
293 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
294 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
297 static void UtcDaliKeyboardFocusManagerMoveFocus()
299 ToolkitTestApplication application;
301 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
305 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
306 DALI_TEST_CHECK( type );
307 BaseHandle handle = type.CreateInstance();
308 DALI_TEST_CHECK( handle );
310 KeyboardFocusManager manager = KeyboardFocusManager::Get();
311 DALI_TEST_CHECK(manager);
313 bool preFocusChangeSignalVerified = false;
314 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
315 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
317 bool focusChangedSignalVerified = false;
318 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
319 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
321 // Create the first actor and add it to the stage
322 Actor first = Actor::New();
323 first.SetKeyboardFocusable(true);
324 Stage::GetCurrent().Add(first);
326 // Create the second actor and add it to the stage
327 Actor second = Actor::New();
328 second.SetKeyboardFocusable(true);
329 Stage::GetCurrent().Add(second);
331 // Move the focus to the right
332 DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
334 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
335 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
336 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
337 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
338 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Right);
339 preFocusChangeCallback.Reset();
341 // Check that the focus is set on the first actor
342 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
343 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
344 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
345 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
346 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
347 focusChangedCallback.Reset();
349 // Move the focus towards right
350 DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
352 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
353 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
354 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
355 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
356 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Right);
357 preFocusChangeCallback.Reset();
359 // Check that the focus is set on the second actor
360 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
361 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
362 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
363 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
364 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
365 focusChangedCallback.Reset();
367 // Move the focus towards up
368 DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == false);
370 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
371 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
372 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
373 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
374 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Up);
375 preFocusChangeCallback.Reset();
376 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
378 // Create a 2x2 table view and try to move focus inside it
379 TableView tableView = TableView::New( 2, 2 );
380 Stage::GetCurrent().Add(tableView);
382 // Create the third actor
383 Actor third = Actor::New();
384 third.SetKeyboardFocusable(true);
386 // Create the fourth actor
387 Actor fourth = Actor::New();
388 fourth.SetKeyboardFocusable(true);
390 // Add the four children to table view
391 tableView.AddChild(first, TableView::CellPosition(0, 0));
392 tableView.AddChild(second, TableView::CellPosition(0, 1));
393 tableView.AddChild(third, TableView::CellPosition(1, 0));
394 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
396 // Set the focus to the first actor
397 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
398 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
399 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
400 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
401 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
402 focusChangedCallback.Reset();
404 // Move the focus towards right
405 DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == true);
406 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
407 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
408 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
409 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
410 focusChangedCallback.Reset();
412 // Move the focus towards down
413 DALI_TEST_CHECK(manager.MoveFocus(Control::Down) == true);
414 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
415 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
416 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
417 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
418 focusChangedCallback.Reset();
420 // Move the focus towards left
421 DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == true);
422 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
423 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
424 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
425 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
426 focusChangedCallback.Reset();
428 // Move the focus towards up
429 DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == true);
430 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
431 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
432 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
433 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
434 focusChangedCallback.Reset();
436 // Move the focus towards left. The focus move will fail as no way to move it upwards
437 DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == false);
438 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
439 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
440 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
441 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
442 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Left);
443 preFocusChangeCallback.Reset();
444 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
447 manager.SetFocusGroupLoop(true);
448 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
450 // Move the focus towards left again. The focus should move to the fourth actor.
451 DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == true);
452 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
453 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
454 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
455 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
456 focusChangedCallback.Reset();
459 static void UtcDaliKeyboardFocusManagerClearFocus()
461 ToolkitTestApplication application;
463 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
467 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
468 DALI_TEST_CHECK( type );
469 BaseHandle handle = type.CreateInstance();
470 DALI_TEST_CHECK( handle );
472 KeyboardFocusManager manager = KeyboardFocusManager::Get();
473 DALI_TEST_CHECK(manager);
475 // Create the first actor and add it to the stage
476 Actor first = Actor::New();
477 first.SetKeyboardFocusable(true);
478 Stage::GetCurrent().Add(first);
480 // Create the second actor and add it to the stage
481 Actor second = Actor::New();
482 second.SetKeyboardFocusable(true);
483 Stage::GetCurrent().Add(second);
485 // Check that the focus is set on the first actor
486 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
487 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
489 // Check that the focus is set on the second actor
490 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
491 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
494 manager.ClearFocus();
496 // Check that no actor is being focused now.
497 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
500 static void UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop()
502 ToolkitTestApplication application;
504 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
508 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
509 DALI_TEST_CHECK( type );
510 BaseHandle handle = type.CreateInstance();
511 DALI_TEST_CHECK( handle );
513 KeyboardFocusManager manager = KeyboardFocusManager::Get();
514 DALI_TEST_CHECK(manager);
516 // Check that the focus movement is not looped within the same focus group by default
517 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
520 manager.SetFocusGroupLoop(true);
521 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
524 static void UtcDaliKeyboardFocusManagerSetAsFocusGroup()
526 ToolkitTestApplication application;
528 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
532 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
533 DALI_TEST_CHECK( type );
534 BaseHandle handle = type.CreateInstance();
535 DALI_TEST_CHECK( handle );
537 KeyboardFocusManager manager = KeyboardFocusManager::Get();
538 DALI_TEST_CHECK(manager);
540 // Create an actor and check that it is not a focus group by default
541 Actor actor = Actor::New();
542 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
544 // Set the actor as focus group
545 manager.SetAsFocusGroup(actor, true);
547 // flush the queue and render once
548 application.SendNotification();
549 application.Render();
551 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
553 // Set the actor not as focus group
554 manager.SetAsFocusGroup(actor, false);
556 // flush the queue and render once
557 application.SendNotification();
558 application.Render();
560 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
563 static void UtcDaliKeyboardFocusManagerGetFocusGroup()
565 ToolkitTestApplication application;
567 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
571 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
572 DALI_TEST_CHECK( type );
573 BaseHandle handle = type.CreateInstance();
574 DALI_TEST_CHECK( handle );
576 KeyboardFocusManager manager = KeyboardFocusManager::Get();
577 DALI_TEST_CHECK(manager);
579 // Create an actor with two child actors and add it to the stage
580 Actor parent = Actor::New();
581 Actor child = Actor::New();
583 Stage::GetCurrent().Add(parent);
585 // Create three actors and add them as the children of the first child actor
586 Actor grandChild = Actor::New();
587 child.Add(grandChild);
589 // Set the parent and the first child actor as focus groups
590 manager.SetAsFocusGroup(parent, true);
592 // flush the queue and render once
593 application.SendNotification();
594 application.Render();
596 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
598 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
599 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
601 manager.SetAsFocusGroup(child, true);
603 // flush the queue and render once
604 application.SendNotification();
605 application.Render();
607 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
609 // The focus group should be the child, As it is the immediate parent which is also a focus group.
610 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
612 manager.SetAsFocusGroup(grandChild, true);
614 // flush the queue and render once
615 application.SendNotification();
616 application.Render();
618 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
620 // The current focus group should be itself, As it is also a focus group.
621 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
624 static void UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator()
626 ToolkitTestApplication application;
628 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
632 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
633 DALI_TEST_CHECK( type );
634 BaseHandle handle = type.CreateInstance();
635 DALI_TEST_CHECK( handle );
637 KeyboardFocusManager manager = KeyboardFocusManager::Get();
638 DALI_TEST_CHECK(manager);
640 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
641 DALI_TEST_CHECK(defaultFocusIndicatorActor);
643 Actor newFocusIndicatorActor = Actor::New();
644 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
645 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
648 static void UtcDaliKeyboardFocusManagerSignalFocusGroupChanged()
650 ToolkitTestApplication application;
652 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
656 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
657 DALI_TEST_CHECK( type );
658 BaseHandle handle = type.CreateInstance();
659 DALI_TEST_CHECK( handle );
661 KeyboardFocusManager manager = KeyboardFocusManager::Get();
662 DALI_TEST_CHECK(manager);
664 bool focusGroupChangedSignalVerified = false;
665 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
666 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
668 Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down);
669 Integration::KeyEvent shiftTabEvent("Tab", "", 1, 0, 0, Integration::KeyEvent::Down);
671 // Send the tab event to change focus group in the forward direction
672 application.ProcessEvent(tabEvent);
673 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
674 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
675 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
676 focusGroupChangedCallback.Reset();
678 // Send the shift tab event to change focus group in the backward direction
679 application.ProcessEvent(shiftTabEvent);
680 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
681 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
682 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
683 focusGroupChangedCallback.Reset();
686 static void UtcDaliKeyboardFocusManagerSignalFocusedActorActivated()
688 ToolkitTestApplication application;
690 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
694 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
695 DALI_TEST_CHECK( type );
696 BaseHandle handle = type.CreateInstance();
697 DALI_TEST_CHECK( handle );
699 KeyboardFocusManager manager = KeyboardFocusManager::Get();
700 DALI_TEST_CHECK(manager);
702 bool focusedActorActivatedSignalVerified = false;
703 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
704 manager.FocusedActorActivatedSignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
706 Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up);
708 // Create the first button and add it to the stage
709 PushButton firstPushButton = PushButton::New();
710 firstPushButton.SetKeyboardFocusable(true);
711 Stage::GetCurrent().Add(firstPushButton);
713 // Create the second button and add it to the stage
714 PushButton secondPushButton = PushButton::New();
715 secondPushButton.SetKeyboardFocusable(true);
716 Stage::GetCurrent().Add(secondPushButton);
718 // Check that the focus is set on the first button
719 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
720 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
722 // Send the return event to activate the first button
723 application.ProcessEvent(returnEvent);
724 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
725 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
726 focusedActorActivatedCallback.Reset();
728 // Check that the focus is set on the second button
729 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
730 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
732 // Send the return event again to activate the second button
733 application.ProcessEvent(returnEvent);
734 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
735 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
736 focusedActorActivatedCallback.Reset();