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