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