e58375a2907b6a42d3e81aeec32cf7c7e7aab384
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-KeyboardFocusManager.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
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>
24
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
28
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43
44 namespace
45 {
46
47 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
48 class PreFocusChangeCallback : public Dali::ConnectionTracker
49 {
50 public:
51   PreFocusChangeCallback(bool& signalReceived)
52   : mSignalVerified(signalReceived),
53     mCurrentFocusedActor(),
54     mProposedActorToFocus(),
55     mDirection(Control::Left)
56   {
57   }
58
59   Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction)
60   {
61     tet_infoline("Verifying PreFocusChangeCallback()");
62
63     mSignalVerified = true;
64
65     mCurrentFocusedActor = currentFocusedActor;
66     mProposedActorToFocus = proposedActorToFocus;
67     mDirection = direction;
68
69     return mProposedActorToFocus;
70   }
71
72   void Reset()
73   {
74     mSignalVerified = false;
75     mCurrentFocusedActor = Actor();
76     mProposedActorToFocus = Actor();
77     mDirection = Control::Left;
78   }
79
80   bool& mSignalVerified;
81   Actor mCurrentFocusedActor;
82   Actor mProposedActorToFocus;
83   Control::KeyboardFocusNavigationDirection mDirection;
84 };
85
86 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
87 class FocusChangedCallback : public Dali::ConnectionTracker
88 {
89 public:
90   FocusChangedCallback(bool& signalReceived)
91   : mSignalVerified(signalReceived),
92     mOriginalFocusedActor(),
93     mCurrentFocusedActor()
94   {
95   }
96
97   void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
98   {
99     tet_infoline("Verifying FocusChangedCallback()");
100
101     if(originalFocusedActor == mCurrentFocusedActor)
102     {
103       mSignalVerified = true;
104     }
105
106     mOriginalFocusedActor = originalFocusedActor;
107     mCurrentFocusedActor = currentFocusedActor;
108   }
109
110   void Reset()
111   {
112     mSignalVerified = false;
113   }
114
115   bool& mSignalVerified;
116   Actor mOriginalFocusedActor;
117   Actor mCurrentFocusedActor;
118 };
119
120 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
121 class FocusGroupChangedCallback : public Dali::ConnectionTracker
122 {
123 public:
124   FocusGroupChangedCallback(bool& signalReceived)
125   : mSignalVerified(signalReceived),
126     mCurrentFocusedActor(),
127     mForward(true)
128   {
129   }
130
131   void Callback(Actor currentFocusedActor, bool forward)
132   {
133     tet_infoline("Verifying FocusGroupChangedCallback()");
134
135     mSignalVerified = true;
136
137     mCurrentFocusedActor = currentFocusedActor;
138     mForward = forward;
139   }
140
141   void Reset()
142   {
143     mSignalVerified = false;
144   }
145
146   bool& mSignalVerified;
147   Actor mCurrentFocusedActor;
148   bool mForward;
149 };
150
151 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
152 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
153 {
154 public:
155   FocusedActorActivatedCallback(bool& signalReceived)
156   : mSignalVerified(signalReceived),
157     mActivatedActor()
158   {
159   }
160
161   void Callback(Actor activatedActor)
162   {
163     tet_infoline("Verifying FocusedActorActivatedCallback()");
164
165     mSignalVerified = true;
166
167     mActivatedActor = activatedActor;
168   }
169
170   void Reset()
171   {
172     mSignalVerified = false;
173   }
174
175   bool& mSignalVerified;
176   Actor mActivatedActor;
177 };
178
179 } // namespace
180
181
182 int UtcDaliKeyboardFocusManagerGet(void)
183 {
184   ToolkitTestApplication application;
185
186   tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
187
188   // Register Type
189   TypeInfo type;
190   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
191   DALI_TEST_CHECK( type );
192   BaseHandle handle = type.CreateInstance();
193   DALI_TEST_CHECK( handle );
194
195   KeyboardFocusManager manager;
196
197   manager = KeyboardFocusManager::Get();
198   DALI_TEST_CHECK(manager);
199
200   KeyboardFocusManager newManager = KeyboardFocusManager::Get();
201   DALI_TEST_CHECK(newManager);
202
203   // Check that focus manager is a singleton
204   DALI_TEST_CHECK(manager == newManager);
205   END_TEST;
206 }
207
208 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
209 {
210   ToolkitTestApplication application;
211
212   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
213
214   KeyboardFocusManager manager = KeyboardFocusManager::Get();
215   DALI_TEST_CHECK(manager);
216
217   // Create the first actor and add it to the stage
218   Actor first = Actor::New();
219   first.SetKeyboardFocusable(true);
220   Stage::GetCurrent().Add(first);
221
222   // Create the second actor and add it to the stage
223   Actor second = Actor::New();
224   second.SetKeyboardFocusable(true);
225   Stage::GetCurrent().Add(second);
226
227   // Create the third actor but don't add it to the stage
228   Actor third = Actor::New();
229
230   // Check that no actor is being focused yet.
231   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
232
233   // Check that it will fail to set focus on an invalid actor
234   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
235
236   // Check that the focus is set on the first actor
237   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
238   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
239
240   // Check that the focus is set on the second actor
241   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
242   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
243
244   // Check that it will fail to set focus on the third actor as it's not in the stage
245   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
246   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
247
248   // Add the third actor to the stage
249   Stage::GetCurrent().Add(third);
250
251   // Check that it will fail to set focus on the third actor as it's not focusable
252   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
253   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
254
255   // Make the third actor focusable
256   third.SetKeyboardFocusable(true);
257
258   // Check that the focus is successfully moved to the third actor
259   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
260   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
261   END_TEST;
262 }
263
264 int UtcDaliKeyboardFocusManagerMoveFocus(void)
265 {
266   ToolkitTestApplication application;
267
268   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
269
270   // Register Type
271   TypeInfo type;
272   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
273   DALI_TEST_CHECK( type );
274   BaseHandle handle = type.CreateInstance();
275   DALI_TEST_CHECK( handle );
276
277   KeyboardFocusManager manager = KeyboardFocusManager::Get();
278   DALI_TEST_CHECK(manager);
279
280   bool preFocusChangeSignalVerified = false;
281   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
282   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
283
284   bool focusChangedSignalVerified = false;
285   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
286   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
287
288   // Create the first actor and add it to the stage
289   Actor first = Actor::New();
290   first.SetKeyboardFocusable(true);
291   Stage::GetCurrent().Add(first);
292
293   // Create the second actor and add it to the stage
294   Actor second = Actor::New();
295   second.SetKeyboardFocusable(true);
296   Stage::GetCurrent().Add(second);
297
298   // Move the focus to the right
299   DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
300
301   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
302   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
303   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
304   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
305   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Right);
306   preFocusChangeCallback.Reset();
307
308   // Check that the focus is set on the first actor
309   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
310   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
311   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
312   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
313   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
314   focusChangedCallback.Reset();
315
316   // Move the focus towards right
317   DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
318
319   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
320   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
321   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
322   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
323   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Right);
324   preFocusChangeCallback.Reset();
325
326   // Check that the focus is set on the second actor
327   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
328   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
329   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
330   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
331   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
332   focusChangedCallback.Reset();
333
334   // Move the focus towards up
335   DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == false);
336
337   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
338   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
339   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
340   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
341   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Up);
342   preFocusChangeCallback.Reset();
343   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
344
345   // Create a 2x2 table view and try to move focus inside it
346   TableView tableView = TableView::New( 2, 2 );
347   Stage::GetCurrent().Add(tableView);
348
349   // Create the third actor
350   Actor third = Actor::New();
351   third.SetKeyboardFocusable(true);
352
353   // Create the fourth actor
354   Actor fourth = Actor::New();
355   fourth.SetKeyboardFocusable(true);
356
357   // Add the four children to table view
358   tableView.AddChild(first, TableView::CellPosition(0, 0));
359   tableView.AddChild(second, TableView::CellPosition(0, 1));
360   tableView.AddChild(third, TableView::CellPosition(1, 0));
361   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
362
363   // Set the focus to the first actor
364   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
365   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
366   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
367   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
368   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
369   focusChangedCallback.Reset();
370
371   // Move the focus towards right
372   DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == true);
373   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
374   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
375   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
376   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
377   focusChangedCallback.Reset();
378
379   // Move the focus towards down
380   DALI_TEST_CHECK(manager.MoveFocus(Control::Down) == true);
381   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
382   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
383   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
384   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
385   focusChangedCallback.Reset();
386
387   // Move the focus towards left
388   DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == true);
389   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
390   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
391   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
392   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
393   focusChangedCallback.Reset();
394
395   // Move the focus towards up
396   DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == true);
397   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
398   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
399   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
400   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
401   focusChangedCallback.Reset();
402
403   // Move the focus towards left. The focus move will fail as no way to move it upwards
404   DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == false);
405   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
406   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
407   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
408   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
409   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::Left);
410   preFocusChangeCallback.Reset();
411   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
412
413   // Enable the loop
414   manager.SetFocusGroupLoop(true);
415   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
416
417   // Move the focus towards left again. The focus should move to the fourth actor.
418   DALI_TEST_CHECK(manager.MoveFocus(Control::Left) == true);
419   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
420   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
421   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
422   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
423   focusChangedCallback.Reset();
424   END_TEST;
425 }
426
427 int UtcDaliKeyboardFocusManagerClearFocus(void)
428 {
429   ToolkitTestApplication application;
430
431   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
432
433   KeyboardFocusManager manager = KeyboardFocusManager::Get();
434   DALI_TEST_CHECK(manager);
435
436   // Create the first actor and add it to the stage
437   Actor first = Actor::New();
438   first.SetKeyboardFocusable(true);
439   Stage::GetCurrent().Add(first);
440
441   // Create the second actor and add it to the stage
442   Actor second = Actor::New();
443   second.SetKeyboardFocusable(true);
444   Stage::GetCurrent().Add(second);
445
446   // Check that the focus is set on the first actor
447   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
448   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
449
450   // Check that the focus is set on the second actor
451   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
452   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
453
454   // Clear the focus
455   manager.ClearFocus();
456
457   // Check that no actor is being focused now.
458   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
459   END_TEST;
460 }
461
462 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
463 {
464   ToolkitTestApplication application;
465
466   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
467
468   KeyboardFocusManager manager = KeyboardFocusManager::Get();
469   DALI_TEST_CHECK(manager);
470
471   // Check that the focus movement is not looped within the same focus group by default
472   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
473
474   // Enable the loop
475   manager.SetFocusGroupLoop(true);
476   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
477   END_TEST;
478 }
479
480 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
481 {
482   ToolkitTestApplication application;
483
484   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
485
486   KeyboardFocusManager manager = KeyboardFocusManager::Get();
487   DALI_TEST_CHECK(manager);
488
489   // Create an actor and check that it is not a focus group by default
490   Actor actor = Actor::New();
491   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
492
493   // Set the actor as focus group
494   manager.SetAsFocusGroup(actor, true);
495
496   // flush the queue and render once
497   application.SendNotification();
498   application.Render();
499
500   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
501
502   // Set the actor not as focus group
503   manager.SetAsFocusGroup(actor, false);
504
505   // flush the queue and render once
506   application.SendNotification();
507   application.Render();
508
509   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
510   END_TEST;
511 }
512
513 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
514 {
515   ToolkitTestApplication application;
516
517   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
518
519   KeyboardFocusManager manager = KeyboardFocusManager::Get();
520   DALI_TEST_CHECK(manager);
521
522   // Create an actor with two child actors and add it to the stage
523   Actor parent = Actor::New();
524   Actor child = Actor::New();
525   parent.Add(child);
526   Stage::GetCurrent().Add(parent);
527
528   // Create three actors and add them as the children of the first child actor
529   Actor grandChild = Actor::New();
530   child.Add(grandChild);
531
532   // Set the parent and the first child actor as focus groups
533   manager.SetAsFocusGroup(parent, true);
534
535   // flush the queue and render once
536   application.SendNotification();
537   application.Render();
538
539   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
540
541   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
542   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
543
544   manager.SetAsFocusGroup(child, true);
545
546   // flush the queue and render once
547   application.SendNotification();
548   application.Render();
549
550   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
551
552   // The focus group should be the child, As it is the immediate parent which is also a focus group.
553   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
554
555   manager.SetAsFocusGroup(grandChild, true);
556
557   // flush the queue and render once
558   application.SendNotification();
559   application.Render();
560
561   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
562
563   // The current focus group should be itself, As it is also a focus group.
564   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
565   END_TEST;
566 }
567
568 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
569 {
570   ToolkitTestApplication application;
571
572   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
573
574   KeyboardFocusManager manager = KeyboardFocusManager::Get();
575   DALI_TEST_CHECK(manager);
576
577   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
578   DALI_TEST_CHECK(defaultFocusIndicatorActor);
579
580   Actor newFocusIndicatorActor = Actor::New();
581   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
582   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
583   END_TEST;
584 }
585
586
587 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
588 {
589   ToolkitTestApplication application;
590
591   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
592
593   KeyboardFocusManager manager = KeyboardFocusManager::Get();
594   DALI_TEST_CHECK(manager);
595
596   bool focusedActorActivatedSignalVerified = false;
597   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
598   manager.FocusedActorActivatedSignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
599
600   Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up);
601
602   // Create the first button and add it to the stage
603   PushButton firstPushButton = PushButton::New();
604   firstPushButton.SetKeyboardFocusable(true);
605   Stage::GetCurrent().Add(firstPushButton);
606
607   // Create the second button and add it to the stage
608   PushButton secondPushButton = PushButton::New();
609   secondPushButton.SetKeyboardFocusable(true);
610   Stage::GetCurrent().Add(secondPushButton);
611
612   // Check that the focus is set on the first button
613   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
614   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
615
616   // Send the return event to activate the first button
617   application.ProcessEvent(returnEvent);
618   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
619   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
620   focusedActorActivatedCallback.Reset();
621
622   // Check that the focus is set on the second button
623   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
624   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
625
626   // Send the return event again to activate the second button
627   application.ProcessEvent(returnEvent);
628   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
629   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
630   focusedActorActivatedCallback.Reset();
631   END_TEST;
632 }
633
634 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
635 {
636   ToolkitTestApplication application;
637
638   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
639
640   // Register Type
641   TypeInfo type;
642   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
643   DALI_TEST_CHECK( type );
644   BaseHandle handle = type.CreateInstance();
645   DALI_TEST_CHECK( handle );
646
647   KeyboardFocusManager manager = KeyboardFocusManager::Get();
648   DALI_TEST_CHECK(manager);
649
650   bool focusGroupChangedSignalVerified = false;
651   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
652   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
653
654   Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down);
655   Integration::KeyEvent shiftTabEvent("Tab", "", 0, 1, 0, Integration::KeyEvent::Down);
656
657   // Send the tab event to change focus group in the forward direction
658   application.ProcessEvent(tabEvent);
659   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
660   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
661   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
662   focusGroupChangedCallback.Reset();
663
664   // Send the shift tab event to change focus group in the backward direction
665   application.ProcessEvent(shiftTabEvent);
666   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
667   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
668   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
669   focusGroupChangedCallback.Reset();
670   END_TEST;
671 }