2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali-toolkit-test-suite-utils.h>
30 using namespace Dali::Toolkit;
35 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
36 class PreFocusChangeCallback : public Dali::ConnectionTracker
39 PreFocusChangeCallback(bool& signalReceived)
40 : mSignalVerified(signalReceived),
41 mCurrentFocusedActor(),
42 mProposedActorToFocus(),
43 mDirection(Control::Left)
47 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction)
49 tet_infoline("Verifying PreFocusChangeCallback()");
51 mSignalVerified = true;
53 mCurrentFocusedActor = currentFocusedActor;
54 mProposedActorToFocus = proposedActorToFocus;
55 mDirection = direction;
57 return mProposedActorToFocus;
62 mSignalVerified = false;
63 mCurrentFocusedActor = Actor();
64 mProposedActorToFocus = Actor();
65 mDirection = Control::Left;
68 bool& mSignalVerified;
69 Actor mCurrentFocusedActor;
70 Actor mProposedActorToFocus;
71 Control::KeyboardFocusNavigationDirection mDirection;
74 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
75 class FocusChangedCallback : public Dali::ConnectionTracker
78 FocusChangedCallback(bool& signalReceived)
79 : mSignalVerified(signalReceived),
80 mOriginalFocusedActor(),
81 mCurrentFocusedActor()
85 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
87 tet_infoline("Verifying FocusChangedCallback()");
89 if(originalFocusedActor == mCurrentFocusedActor)
91 mSignalVerified = true;
94 mOriginalFocusedActor = originalFocusedActor;
95 mCurrentFocusedActor = currentFocusedActor;
100 mSignalVerified = false;
103 bool& mSignalVerified;
104 Actor mOriginalFocusedActor;
105 Actor mCurrentFocusedActor;
108 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
109 class FocusGroupChangedCallback : public Dali::ConnectionTracker
112 FocusGroupChangedCallback(bool& signalReceived)
113 : mSignalVerified(signalReceived),
114 mCurrentFocusedActor(),
119 void Callback(Actor currentFocusedActor, bool forward)
121 tet_infoline("Verifying FocusGroupChangedCallback()");
123 mSignalVerified = true;
125 mCurrentFocusedActor = currentFocusedActor;
131 mSignalVerified = false;
134 bool& mSignalVerified;
135 Actor mCurrentFocusedActor;
139 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
140 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
143 FocusedActorActivatedCallback(bool& signalReceived)
144 : mSignalVerified(signalReceived),
149 void Callback(Actor activatedActor)
151 tet_infoline("Verifying FocusedActorActivatedCallback()");
153 mSignalVerified = true;
155 mActivatedActor = activatedActor;
160 mSignalVerified = false;
163 bool& mSignalVerified;
164 Actor mActivatedActor;
169 static void Startup();
170 static void Cleanup();
173 void (*tet_startup)() = Startup;
174 void (*tet_cleanup)() = Cleanup;
178 POSITIVE_TC_IDX = 0x01,
182 #define MAX_NUMBER_OF_TESTS 10000
184 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
187 // Add test functionality for all APIs in the class (Positive and Negative)
188 TEST_FUNCTION( UtcDaliKeyboardFocusManagerGet, POSITIVE_TC_IDX );
189 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor, POSITIVE_TC_IDX );
190 TEST_FUNCTION( UtcDaliKeyboardFocusManagerMoveFocus, POSITIVE_TC_IDX );
191 TEST_FUNCTION( UtcDaliKeyboardFocusManagerClearFocus, POSITIVE_TC_IDX );
192 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop, POSITIVE_TC_IDX );
193 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAsFocusGroup, POSITIVE_TC_IDX );
194 TEST_FUNCTION( UtcDaliKeyboardFocusManagerGetFocusGroup, POSITIVE_TC_IDX );
195 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator, POSITIVE_TC_IDX );
196 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSignalFocusGroupChanged, POSITIVE_TC_IDX );
197 TEST_FUNCTION( UtcDaliKeyboardFocusManagerSignalFocusedActorActivated, POSITIVE_TC_IDX );
199 // Called only once before first test is run.
200 static void Startup()
204 // Called only once after last test is run
205 static void Cleanup()
209 static void UtcDaliKeyboardFocusManagerGet()
211 ToolkitTestApplication application;
213 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
217 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
218 DALI_TEST_CHECK( type );
219 BaseHandle handle = type.CreateInstance();
220 DALI_TEST_CHECK( handle );
222 KeyboardFocusManager manager;
224 manager = KeyboardFocusManager::Get();
225 DALI_TEST_CHECK(manager);
227 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
228 DALI_TEST_CHECK(newManager);
230 // Check that focus manager is a singleton
231 DALI_TEST_CHECK(manager == newManager);
234 static void UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor()
236 ToolkitTestApplication application;
238 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
242 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
243 DALI_TEST_CHECK( type );
244 BaseHandle handle = type.CreateInstance();
245 DALI_TEST_CHECK( handle );
247 KeyboardFocusManager manager = KeyboardFocusManager::Get();
248 DALI_TEST_CHECK(manager);
250 // Create the first actor and add it to the stage
251 Actor first = Actor::New();
252 first.SetKeyboardFocusable(true);
253 Stage::GetCurrent().Add(first);
255 // Create the second actor and add it to the stage
256 Actor second = Actor::New();
257 second.SetKeyboardFocusable(true);
258 Stage::GetCurrent().Add(second);
260 // Create the third actor but don't add it to the stage
261 Actor third = Actor::New();
263 // Check that no actor is being focused yet.
264 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
266 // Check that it will fail to set focus on an invalid actor
267 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
269 // Check that the focus is set on the first actor
270 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
271 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
273 // Check that the focus is set on the second actor
274 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
275 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
277 // Check that it will fail to set focus on the third actor as it's not in the stage
278 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
279 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
281 // Add the third actor to the stage
282 Stage::GetCurrent().Add(third);
284 // Check that it will fail to set focus on the third actor as it's not focusable
285 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
286 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
288 // Make the third actor focusable
289 third.SetKeyboardFocusable(true);
291 // Check that the focus is successfully moved to the third actor
292 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
293 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
296 static void UtcDaliKeyboardFocusManagerMoveFocus()
298 ToolkitTestApplication application;
300 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
304 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
305 DALI_TEST_CHECK( type );
306 BaseHandle handle = type.CreateInstance();
307 DALI_TEST_CHECK( handle );
309 KeyboardFocusManager manager = KeyboardFocusManager::Get();
310 DALI_TEST_CHECK(manager);
312 bool preFocusChangeSignalVerified = false;
313 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
314 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
316 bool focusChangedSignalVerified = false;
317 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
318 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
320 // Create the first actor and add it to the stage
321 Actor first = Actor::New();
322 first.SetKeyboardFocusable(true);
323 Stage::GetCurrent().Add(first);
325 // Create the second actor and add it to the stage
326 Actor second = Actor::New();
327 second.SetKeyboardFocusable(true);
328 Stage::GetCurrent().Add(second);
330 // Move the focus to the right
331 DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
333 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
334 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
335 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
336 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
337 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Right);
338 preFocusChangeCallback.Reset();
340 // Check that the focus is set on the first actor
341 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
342 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
343 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
344 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
345 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
346 focusChangedCallback.Reset();
348 // Move the focus towards right
349 DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
351 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
352 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
353 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
354 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
355 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Right);
356 preFocusChangeCallback.Reset();
358 // Check that the focus is set on the second actor
359 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
360 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
361 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
362 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
363 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
364 focusChangedCallback.Reset();
366 // Move the focus towards up
367 DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == false);
369 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
370 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
371 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
372 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
373 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Up);
374 preFocusChangeCallback.Reset();
375 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
377 // Create a 2x2 table view and try to move focus inside it
378 TableView tableView = TableView::New( 2, 2 );
379 Stage::GetCurrent().Add(tableView);
381 // Create the third actor
382 Actor third = Actor::New();
383 third.SetKeyboardFocusable(true);
385 // Create the fourth actor
386 Actor fourth = Actor::New();
387 fourth.SetKeyboardFocusable(true);
389 // Add the four children to table view
390 tableView.AddChild(first, TableView::CellPosition(0, 0));
391 tableView.AddChild(second, TableView::CellPosition(0, 1));
392 tableView.AddChild(third, TableView::CellPosition(1, 0));
393 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
395 // Set the focus to the first actor
396 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
397 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
398 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
399 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
400 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
401 focusChangedCallback.Reset();
403 // Move the focus towards right
404 DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == true);
405 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
406 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
407 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
408 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
409 focusChangedCallback.Reset();
411 // Move the focus towards down
412 DALI_TEST_CHECK(manager.MoveFocus(Control::Down) == true);
413 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
414 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
415 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
416 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
417 focusChangedCallback.Reset();
419 // Move the focus towards left
420 DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == true);
421 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
422 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
423 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
424 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
425 focusChangedCallback.Reset();
427 // Move the focus towards up
428 DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == true);
429 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
430 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
431 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
432 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
433 focusChangedCallback.Reset();
435 // Move the focus towards left. The focus move will fail as no way to move it upwards
436 DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == false);
437 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
438 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
439 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
440 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
441 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Left);
442 preFocusChangeCallback.Reset();
443 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
446 manager.SetFocusGroupLoop(true);
447 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
449 // Move the focus towards left again. The focus should move to the fourth actor.
450 DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == true);
451 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
452 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
453 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
454 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
455 focusChangedCallback.Reset();
458 static void UtcDaliKeyboardFocusManagerClearFocus()
460 ToolkitTestApplication application;
462 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
466 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
467 DALI_TEST_CHECK( type );
468 BaseHandle handle = type.CreateInstance();
469 DALI_TEST_CHECK( handle );
471 KeyboardFocusManager manager = KeyboardFocusManager::Get();
472 DALI_TEST_CHECK(manager);
474 // Create the first actor and add it to the stage
475 Actor first = Actor::New();
476 first.SetKeyboardFocusable(true);
477 Stage::GetCurrent().Add(first);
479 // Create the second actor and add it to the stage
480 Actor second = Actor::New();
481 second.SetKeyboardFocusable(true);
482 Stage::GetCurrent().Add(second);
484 // Check that the focus is set on the first actor
485 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
486 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
488 // Check that the focus is set on the second actor
489 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
490 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
493 manager.ClearFocus();
495 // Check that no actor is being focused now.
496 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
499 static void UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop()
501 ToolkitTestApplication application;
503 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
507 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
508 DALI_TEST_CHECK( type );
509 BaseHandle handle = type.CreateInstance();
510 DALI_TEST_CHECK( handle );
512 KeyboardFocusManager manager = KeyboardFocusManager::Get();
513 DALI_TEST_CHECK(manager);
515 // Check that the focus movement is not looped within the same focus group by default
516 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
519 manager.SetFocusGroupLoop(true);
520 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
523 static void UtcDaliKeyboardFocusManagerSetAsFocusGroup()
525 ToolkitTestApplication application;
527 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
531 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
532 DALI_TEST_CHECK( type );
533 BaseHandle handle = type.CreateInstance();
534 DALI_TEST_CHECK( handle );
536 KeyboardFocusManager manager = KeyboardFocusManager::Get();
537 DALI_TEST_CHECK(manager);
539 // Create an actor and check that it is not a focus group by default
540 Actor actor = Actor::New();
541 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
543 // Set the actor as focus group
544 manager.SetAsFocusGroup(actor, true);
546 // flush the queue and render once
547 application.SendNotification();
548 application.Render();
550 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
552 // Set the actor not as focus group
553 manager.SetAsFocusGroup(actor, false);
555 // flush the queue and render once
556 application.SendNotification();
557 application.Render();
559 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
562 static void UtcDaliKeyboardFocusManagerGetFocusGroup()
564 ToolkitTestApplication application;
566 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
570 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
571 DALI_TEST_CHECK( type );
572 BaseHandle handle = type.CreateInstance();
573 DALI_TEST_CHECK( handle );
575 KeyboardFocusManager manager = KeyboardFocusManager::Get();
576 DALI_TEST_CHECK(manager);
578 // Create an actor with two child actors and add it to the stage
579 Actor parent = Actor::New();
580 Actor child = Actor::New();
582 Stage::GetCurrent().Add(parent);
584 // Create three actors and add them as the children of the first child actor
585 Actor grandChild = Actor::New();
586 child.Add(grandChild);
588 // Set the parent and the first child actor as focus groups
589 manager.SetAsFocusGroup(parent, true);
591 // flush the queue and render once
592 application.SendNotification();
593 application.Render();
595 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
597 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
598 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
600 manager.SetAsFocusGroup(child, true);
602 // flush the queue and render once
603 application.SendNotification();
604 application.Render();
606 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
608 // The focus group should be the child, As it is the immediate parent which is also a focus group.
609 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
611 manager.SetAsFocusGroup(grandChild, true);
613 // flush the queue and render once
614 application.SendNotification();
615 application.Render();
617 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
619 // The current focus group should be itself, As it is also a focus group.
620 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
623 static void UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator()
625 ToolkitTestApplication application;
627 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
631 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
632 DALI_TEST_CHECK( type );
633 BaseHandle handle = type.CreateInstance();
634 DALI_TEST_CHECK( handle );
636 KeyboardFocusManager manager = KeyboardFocusManager::Get();
637 DALI_TEST_CHECK(manager);
639 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
640 DALI_TEST_CHECK(defaultFocusIndicatorActor);
642 Actor newFocusIndicatorActor = Actor::New();
643 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
644 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
647 static void UtcDaliKeyboardFocusManagerSignalFocusGroupChanged()
649 ToolkitTestApplication application;
651 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
655 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
656 DALI_TEST_CHECK( type );
657 BaseHandle handle = type.CreateInstance();
658 DALI_TEST_CHECK( handle );
660 KeyboardFocusManager manager = KeyboardFocusManager::Get();
661 DALI_TEST_CHECK(manager);
663 bool focusGroupChangedSignalVerified = false;
664 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
665 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
667 Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down);
668 Integration::KeyEvent shiftTabEvent("Tab", "", 1, 0, 0, Integration::KeyEvent::Down);
670 // Send the tab event to change focus group in the forward direction
671 application.ProcessEvent(tabEvent);
672 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
673 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
674 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
675 focusGroupChangedCallback.Reset();
677 // Send the shift tab event to change focus group in the backward direction
678 application.ProcessEvent(shiftTabEvent);
679 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
680 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
681 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
682 focusGroupChangedCallback.Reset();
685 static void UtcDaliKeyboardFocusManagerSignalFocusedActorActivated()
687 ToolkitTestApplication application;
689 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
693 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
694 DALI_TEST_CHECK( type );
695 BaseHandle handle = type.CreateInstance();
696 DALI_TEST_CHECK( handle );
698 KeyboardFocusManager manager = KeyboardFocusManager::Get();
699 DALI_TEST_CHECK(manager);
701 bool focusedActorActivatedSignalVerified = false;
702 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
703 manager.FocusedActorActivatedSignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
705 Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up);
707 // Create the first button and add it to the stage
708 PushButton firstPushButton = PushButton::New();
709 firstPushButton.SetKeyboardFocusable(true);
710 Stage::GetCurrent().Add(firstPushButton);
712 // Create the second button and add it to the stage
713 PushButton secondPushButton = PushButton::New();
714 secondPushButton.SetKeyboardFocusable(true);
715 Stage::GetCurrent().Add(secondPushButton);
717 // Check that the focus is set on the first button
718 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
719 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
721 // Send the return event to activate the first button
722 application.ProcessEvent(returnEvent);
723 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
724 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
725 focusedActorActivatedCallback.Reset();
727 // Check that the focus is set on the second button
728 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
729 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
731 // Send the return event again to activate the second button
732 application.ProcessEvent(returnEvent);
733 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
734 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
735 focusedActorActivatedCallback.Reset();