9f85920f91c81cdaaabedfa03a57183a4f6dfc70
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / focus-manager / utc-Dali-KeyboardFocusManager.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24
25 #include <dali/integration-api/events/key-event-integ.h>
26
27 #include <dali-toolkit-test-suite-utils.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 namespace
33 {
34
35 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
36 class PreFocusChangeCallback : public Dali::ConnectionTracker
37 {
38 public:
39   PreFocusChangeCallback(bool& signalReceived)
40   : mSignalVerified(signalReceived),
41     mCurrentFocusedActor(),
42     mProposedActorToFocus(),
43     mDirection(Control::Left)
44   {
45   }
46
47   Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction)
48   {
49     tet_infoline("Verifying PreFocusChangeCallback()");
50
51     mSignalVerified = true;
52
53     mCurrentFocusedActor = currentFocusedActor;
54     mProposedActorToFocus = proposedActorToFocus;
55     mDirection = direction;
56
57     return mProposedActorToFocus;
58   }
59
60   void Reset()
61   {
62     mSignalVerified = false;
63     mCurrentFocusedActor = Actor();
64     mProposedActorToFocus = Actor();
65     mDirection = Control::Left;
66   }
67
68   bool& mSignalVerified;
69   Actor mCurrentFocusedActor;
70   Actor mProposedActorToFocus;
71   Control::KeyboardFocusNavigationDirection mDirection;
72 };
73
74 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
75 class FocusChangedCallback : public Dali::ConnectionTracker
76 {
77 public:
78   FocusChangedCallback(bool& signalReceived)
79   : mSignalVerified(signalReceived),
80     mOriginalFocusedActor(),
81     mCurrentFocusedActor()
82   {
83   }
84
85   void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
86   {
87     tet_infoline("Verifying FocusChangedCallback()");
88
89     if(originalFocusedActor == mCurrentFocusedActor)
90     {
91       mSignalVerified = true;
92     }
93
94     mOriginalFocusedActor = originalFocusedActor;
95     mCurrentFocusedActor = currentFocusedActor;
96   }
97
98   void Reset()
99   {
100     mSignalVerified = false;
101   }
102
103   bool& mSignalVerified;
104   Actor mOriginalFocusedActor;
105   Actor mCurrentFocusedActor;
106 };
107
108 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
109 class FocusGroupChangedCallback : public Dali::ConnectionTracker
110 {
111 public:
112   FocusGroupChangedCallback(bool& signalReceived)
113   : mSignalVerified(signalReceived),
114     mCurrentFocusedActor(),
115     mForward(true)
116   {
117   }
118
119   void Callback(Actor currentFocusedActor, bool forward)
120   {
121     tet_infoline("Verifying FocusGroupChangedCallback()");
122
123     mSignalVerified = true;
124
125     mCurrentFocusedActor = currentFocusedActor;
126     mForward = forward;
127   }
128
129   void Reset()
130   {
131     mSignalVerified = false;
132   }
133
134   bool& mSignalVerified;
135   Actor mCurrentFocusedActor;
136   bool mForward;
137 };
138
139 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
140 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
141 {
142 public:
143   FocusedActorActivatedCallback(bool& signalReceived)
144   : mSignalVerified(signalReceived),
145     mActivatedActor()
146   {
147   }
148
149   void Callback(Actor activatedActor)
150   {
151     tet_infoline("Verifying FocusedActorActivatedCallback()");
152
153     mSignalVerified = true;
154
155     mActivatedActor = activatedActor;
156   }
157
158   void Reset()
159   {
160     mSignalVerified = false;
161   }
162
163   bool& mSignalVerified;
164   Actor mActivatedActor;
165 };
166
167 } // namespace
168
169 static void Startup();
170 static void Cleanup();
171
172 extern "C" {
173   void (*tet_startup)() = Startup;
174   void (*tet_cleanup)() = Cleanup;
175 }
176
177 enum {
178   POSITIVE_TC_IDX = 0x01,
179   NEGATIVE_TC_IDX,
180 };
181
182 #define MAX_NUMBER_OF_TESTS 10000
183 extern "C" {
184   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
185 }
186
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 );
198
199 // Called only once before first test is run.
200 static void Startup()
201 {
202 }
203
204 // Called only once after last test is run
205 static void Cleanup()
206 {
207 }
208
209 static void UtcDaliKeyboardFocusManagerGet()
210 {
211   ToolkitTestApplication application;
212
213   tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
214
215   // Register Type
216   TypeInfo type;
217   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
218   DALI_TEST_CHECK( type );
219   BaseHandle handle = type.CreateInstance();
220   DALI_TEST_CHECK( handle );
221
222   KeyboardFocusManager manager;
223
224   manager = KeyboardFocusManager::Get();
225   DALI_TEST_CHECK(manager);
226
227   KeyboardFocusManager newManager = KeyboardFocusManager::Get();
228   DALI_TEST_CHECK(newManager);
229
230   // Check that focus manager is a singleton
231   DALI_TEST_CHECK(manager == newManager);
232 }
233
234 static void UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor()
235 {
236   ToolkitTestApplication application;
237
238   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
239
240   // Register Type
241   TypeInfo type;
242   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
243   DALI_TEST_CHECK( type );
244   BaseHandle handle = type.CreateInstance();
245   DALI_TEST_CHECK( handle );
246
247   KeyboardFocusManager manager = KeyboardFocusManager::Get();
248   DALI_TEST_CHECK(manager);
249
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);
254
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);
259
260   // Create the third actor but don't add it to the stage
261   Actor third = Actor::New();
262
263   // Check that no actor is being focused yet.
264   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
265
266   // Check that it will fail to set focus on an invalid actor
267   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
268
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);
272
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);
276
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);
280
281   // Add the third actor to the stage
282   Stage::GetCurrent().Add(third);
283
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);
287
288   // Make the third actor focusable
289   third.SetKeyboardFocusable(true);
290
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);
294 }
295
296 static void UtcDaliKeyboardFocusManagerMoveFocus()
297 {
298   ToolkitTestApplication application;
299
300   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
301
302   // Register Type
303   TypeInfo type;
304   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
305   DALI_TEST_CHECK( type );
306   BaseHandle handle = type.CreateInstance();
307   DALI_TEST_CHECK( handle );
308
309   KeyboardFocusManager manager = KeyboardFocusManager::Get();
310   DALI_TEST_CHECK(manager);
311
312   bool preFocusChangeSignalVerified = false;
313   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
314   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
315
316   bool focusChangedSignalVerified = false;
317   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
318   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
319
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);
324
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);
329
330   // Move the focus to the right
331   DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
332
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();
339
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();
347
348   // Move the focus towards right
349   DALI_TEST_CHECK(manager.MoveFocus(Control::Right) == false);
350
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();
357
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();
365
366   // Move the focus towards up
367   DALI_TEST_CHECK(manager.MoveFocus(Control::Up) == false);
368
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);
376
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);
380
381   // Create the third actor
382   Actor third = Actor::New();
383   third.SetKeyboardFocusable(true);
384
385   // Create the fourth actor
386   Actor fourth = Actor::New();
387   fourth.SetKeyboardFocusable(true);
388
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));
394
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();
402
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();
410
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();
418
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();
426
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();
434
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);
444
445   // Enable the loop
446   manager.SetFocusGroupLoop(true);
447   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
448
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();
456 }
457
458 static void UtcDaliKeyboardFocusManagerClearFocus()
459 {
460   ToolkitTestApplication application;
461
462   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
463
464   // Register Type
465   TypeInfo type;
466   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
467   DALI_TEST_CHECK( type );
468   BaseHandle handle = type.CreateInstance();
469   DALI_TEST_CHECK( handle );
470
471   KeyboardFocusManager manager = KeyboardFocusManager::Get();
472   DALI_TEST_CHECK(manager);
473
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);
478
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);
483
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);
487
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);
491
492   // Clear the focus
493   manager.ClearFocus();
494
495   // Check that no actor is being focused now.
496   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
497 }
498
499 static void UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop()
500 {
501   ToolkitTestApplication application;
502
503   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
504
505   // Register Type
506   TypeInfo type;
507   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
508   DALI_TEST_CHECK( type );
509   BaseHandle handle = type.CreateInstance();
510   DALI_TEST_CHECK( handle );
511
512   KeyboardFocusManager manager = KeyboardFocusManager::Get();
513   DALI_TEST_CHECK(manager);
514
515   // Check that the focus movement is not looped within the same focus group by default
516   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
517
518   // Enable the loop
519   manager.SetFocusGroupLoop(true);
520   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
521 }
522
523 static void UtcDaliKeyboardFocusManagerSetAsFocusGroup()
524 {
525   ToolkitTestApplication application;
526
527   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
528
529   // Register Type
530   TypeInfo type;
531   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
532   DALI_TEST_CHECK( type );
533   BaseHandle handle = type.CreateInstance();
534   DALI_TEST_CHECK( handle );
535
536   KeyboardFocusManager manager = KeyboardFocusManager::Get();
537   DALI_TEST_CHECK(manager);
538
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);
542
543   // Set the actor as focus group
544   manager.SetAsFocusGroup(actor, true);
545
546   // flush the queue and render once
547   application.SendNotification();
548   application.Render();
549
550   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
551
552   // Set the actor not as focus group
553   manager.SetAsFocusGroup(actor, false);
554
555   // flush the queue and render once
556   application.SendNotification();
557   application.Render();
558
559   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
560 }
561
562 static void UtcDaliKeyboardFocusManagerGetFocusGroup()
563 {
564   ToolkitTestApplication application;
565
566   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
567
568   // Register Type
569   TypeInfo type;
570   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
571   DALI_TEST_CHECK( type );
572   BaseHandle handle = type.CreateInstance();
573   DALI_TEST_CHECK( handle );
574
575   KeyboardFocusManager manager = KeyboardFocusManager::Get();
576   DALI_TEST_CHECK(manager);
577
578   // Create an actor with two child actors and add it to the stage
579   Actor parent = Actor::New();
580   Actor child = Actor::New();
581   parent.Add(child);
582   Stage::GetCurrent().Add(parent);
583
584   // Create three actors and add them as the children of the first child actor
585   Actor grandChild = Actor::New();
586   child.Add(grandChild);
587
588   // Set the parent and the first child actor as focus groups
589   manager.SetAsFocusGroup(parent, true);
590
591   // flush the queue and render once
592   application.SendNotification();
593   application.Render();
594
595   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
596
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);
599
600   manager.SetAsFocusGroup(child, true);
601
602   // flush the queue and render once
603   application.SendNotification();
604   application.Render();
605
606   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
607
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);
610
611   manager.SetAsFocusGroup(grandChild, true);
612
613   // flush the queue and render once
614   application.SendNotification();
615   application.Render();
616
617   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
618
619   // The current focus group should be itself, As it is also a focus group.
620   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
621 }
622
623 static void UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator()
624 {
625   ToolkitTestApplication application;
626
627   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
628
629   // Register Type
630   TypeInfo type;
631   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
632   DALI_TEST_CHECK( type );
633   BaseHandle handle = type.CreateInstance();
634   DALI_TEST_CHECK( handle );
635
636   KeyboardFocusManager manager = KeyboardFocusManager::Get();
637   DALI_TEST_CHECK(manager);
638
639   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
640   DALI_TEST_CHECK(defaultFocusIndicatorActor);
641
642   Actor newFocusIndicatorActor = Actor::New();
643   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
644   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
645 }
646
647 static void UtcDaliKeyboardFocusManagerSignalFocusGroupChanged()
648 {
649   ToolkitTestApplication application;
650
651   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
652
653   // Register Type
654   TypeInfo type;
655   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
656   DALI_TEST_CHECK( type );
657   BaseHandle handle = type.CreateInstance();
658   DALI_TEST_CHECK( handle );
659
660   KeyboardFocusManager manager = KeyboardFocusManager::Get();
661   DALI_TEST_CHECK(manager);
662
663   bool focusGroupChangedSignalVerified = false;
664   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
665   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
666
667   Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down);
668   Integration::KeyEvent shiftTabEvent("Tab", "", 1, 0, 0, Integration::KeyEvent::Down);
669
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();
676
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();
683 }
684
685 static void UtcDaliKeyboardFocusManagerSignalFocusedActorActivated()
686 {
687   ToolkitTestApplication application;
688
689   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
690
691   // Register Type
692   TypeInfo type;
693   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
694   DALI_TEST_CHECK( type );
695   BaseHandle handle = type.CreateInstance();
696   DALI_TEST_CHECK( handle );
697
698   KeyboardFocusManager manager = KeyboardFocusManager::Get();
699   DALI_TEST_CHECK(manager);
700
701   bool focusedActorActivatedSignalVerified = false;
702   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
703   manager.FocusedActorActivatedSignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
704
705   Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up);
706
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);
711
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);
716
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);
720
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();
726
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);
730
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();
736 }