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