Merge "Added Control::SetSubState handling" into 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 #include <dali-toolkit/devel-api/controls/control-devel.h>
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   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
613   // It makes mIsFocusIndicatorEnabled true
614   application.ProcessEvent(returnEvent);
615
616   // Create the first button and add it to the stage
617   PushButton firstPushButton = PushButton::New();
618   firstPushButton.SetKeyboardFocusable(true);
619   Stage::GetCurrent().Add(firstPushButton);
620
621   // Create the second button and add it to the stage
622   PushButton secondPushButton = PushButton::New();
623   secondPushButton.SetKeyboardFocusable(true);
624   Stage::GetCurrent().Add(secondPushButton);
625
626   // Check that the focus is set on the first button
627   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
628   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
629
630   // Send the return event to activate the first button
631   application.ProcessEvent(returnEvent);
632   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
633   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
634   focusedActorActivatedCallback.Reset();
635
636   // Check that the focus is set on the second button
637   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
638   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
639
640   // Send the return event again to activate the second button
641   application.ProcessEvent(returnEvent);
642   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
643   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
644   focusedActorActivatedCallback.Reset();
645   END_TEST;
646 }
647
648 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
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", "", 0, 1, 0, Integration::KeyEvent::Down);
670
671   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
672   // It makes mIsFocusIndicatorEnabled true
673   application.ProcessEvent(tabEvent);
674
675   // Send the tab event to change focus group in the forward direction
676   application.ProcessEvent(tabEvent);
677   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
678   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
679   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
680   focusGroupChangedCallback.Reset();
681
682   // Send the shift tab event to change focus group in the backward direction
683   application.ProcessEvent(shiftTabEvent);
684   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
685   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
686   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
687   focusGroupChangedCallback.Reset();
688   END_TEST;
689 }
690
691 int UtcDaliKeyboardFocusManagerSignals(void)
692 {
693   ToolkitTestApplication application;
694
695   KeyboardFocusManager manager = KeyboardFocusManager::Get();
696   DALI_TEST_CHECK( manager );
697
698   ConnectionTracker* testTracker = new ConnectionTracker();
699   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
700   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
701   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
702   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
703
704   END_TEST;
705 }
706
707 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
708 {
709   ToolkitTestApplication application;
710
711   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
712
713   KeyboardFocusManager manager = KeyboardFocusManager::Get();
714   DALI_TEST_CHECK(manager);
715
716   // Make history stack full
717   for(int i = 0 ; i < 31 ; i ++)
718   {
719     Actor actor = Actor::New();
720     actor.SetKeyboardFocusable(true);
721     Stage::GetCurrent().Add(actor);
722     manager.SetCurrentFocusActor(actor);
723   }
724
725   // Create the first actor and add it to the stage
726   Actor first = Actor::New();
727   first.SetKeyboardFocusable(true);
728   Stage::GetCurrent().Add(first);
729
730   // Create the second actor and add it to the stage
731   Actor second = Actor::New();
732   second.SetKeyboardFocusable(true);
733   Stage::GetCurrent().Add(second);
734
735   // Create the second actor and add it to the stage
736   Actor third = Actor::New();
737   third.SetKeyboardFocusable(true);
738   Stage::GetCurrent().Add(third);
739
740   // Check that the focus is set on the second actor
741   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
742   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
743
744   // Check that the focus is set on the second actor
745   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
746   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
747
748   // Check that the focus is set on the third  actor
749   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
750   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
751
752   // Move the focus backward
753   manager.MoveFocusBackward();
754
755   // Check that it current focused actor is second actor
756   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
757
758   // Check that the focus is set on the third actor
759   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
760   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
761
762   // Remove the second actor on stage
763   second.Unparent();
764
765   // Move the focus backward
766   manager.MoveFocusBackward();
767
768   // Check that it current focused actor is first actor
769   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
770
771   END_TEST;
772 }
773
774 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
775 {
776   ToolkitTestApplication application;
777
778   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
779
780   KeyboardFocusManager manager = KeyboardFocusManager::Get();
781   DALI_TEST_CHECK(manager);
782
783   bool preFocusChangeSignalVerified = false;
784   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
785   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
786
787   bool focusChangedSignalVerified = false;
788   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
789   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
790
791   Integration::KeyEvent leftEvent("Left", "", 0, 0, 0, Integration::KeyEvent::Down);
792   Integration::KeyEvent rightEvent("Right", "", 0, 0, 0, Integration::KeyEvent::Down);
793   Integration::KeyEvent upEvent("Up", "", 0, 0, 0, Integration::KeyEvent::Down);
794   Integration::KeyEvent downEvent("Down", "", 0, 0, 0, Integration::KeyEvent::Down);
795   Integration::KeyEvent pageUpEvent("Prior", "", 0, 0, 0, Integration::KeyEvent::Down);
796   Integration::KeyEvent pageDownEvent("Next", "", 0, 0, 0, Integration::KeyEvent::Down);
797
798   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
799   // It makes mIsFocusIndicatorEnabled true
800   application.ProcessEvent(leftEvent);
801
802   // Create a 2x2 table view and try to move focus inside it
803   TableView tableView = TableView::New( 2, 2 );
804   Stage::GetCurrent().Add(tableView);
805
806   // Create the first actor
807   Actor first = Actor::New();
808   first.SetKeyboardFocusable(true);
809
810   // Create the second actor
811   Actor second = Actor::New();
812   second.SetKeyboardFocusable(true);
813
814   // Create the third actor
815   Actor third = Actor::New();
816   third.SetKeyboardFocusable(true);
817
818   // Create the fourth actor
819   Actor fourth = Actor::New();
820   fourth.SetKeyboardFocusable(true);
821
822   // Add the four children to table view
823   tableView.AddChild(first, TableView::CellPosition(0, 0));
824   tableView.AddChild(second, TableView::CellPosition(0, 1));
825   tableView.AddChild(third, TableView::CellPosition(1, 0));
826   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
827
828   // Set the focus to the first actor
829   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
830   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
831   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
832   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
833   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
834   focusChangedCallback.Reset();
835
836   // Send the right key event to move the focus towards right
837   application.ProcessEvent(rightEvent);
838   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
839   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
840   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
841   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
842   focusChangedCallback.Reset();
843
844   // Send the down key event to move the focus towards down
845   application.ProcessEvent(downEvent);
846   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
847   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
848   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
849   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
850   focusChangedCallback.Reset();
851
852   // Send the down event to move the focus towards left
853   application.ProcessEvent(leftEvent);
854   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
855   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
856   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
857   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
858   focusChangedCallback.Reset();
859
860   // Send the up event to move the focus towards up
861   application.ProcessEvent(upEvent);
862   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
863   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
864   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
865   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
866   focusChangedCallback.Reset();
867
868   // Send the pape up event, but focus should not be moved because page up is not supported by table view
869   application.ProcessEvent(pageUpEvent);
870   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
871   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
872   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
873   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
874   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
875   preFocusChangeCallback.Reset();
876
877   // Send the pape down event, but focus should not be moved because page down is not supported by table view
878   application.ProcessEvent(pageDownEvent);
879   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
880   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
881   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
882   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
883   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
884   preFocusChangeCallback.Reset();
885
886   // Clear the focus
887   manager.ClearFocus();
888
889   // Send the pape up event, but nothing was focued so focus manager will try the initial focus
890   preFocusChangeCallback.Reset();
891   application.ProcessEvent(pageUpEvent);
892   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
893   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
894   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
895   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
896   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
897
898   // Clear the focus again
899   manager.ClearFocus();
900
901   // Send the pape down event, but nothing was focued so focus manager will try the initial focus
902   preFocusChangeCallback.Reset();
903   application.ProcessEvent(pageDownEvent);
904   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
905   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
906   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
907   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
908   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
909
910   END_TEST;
911 }
912
913
914
915
916
917 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
918 {
919   ToolkitTestApplication application;
920
921   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
922
923   // Register Type
924   TypeInfo type;
925   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
926   DALI_TEST_CHECK( type );
927   BaseHandle handle = type.CreateInstance();
928   DALI_TEST_CHECK( handle );
929
930   KeyboardFocusManager manager = KeyboardFocusManager::Get();
931   DALI_TEST_CHECK(manager);
932
933   bool preFocusChangeSignalVerified = false;
934   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
935   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
936
937   bool focusChangedSignalVerified = false;
938   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
939   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
940
941   // Create the first actor and add it to the stage
942   Control first = Control::New();
943   first.SetKeyboardFocusable(true);
944   Stage::GetCurrent().Add(first);
945
946   // Create the second actor and add it to the stage
947   Control second = Control::New();
948   second.SetKeyboardFocusable(true);
949   Stage::GetCurrent().Add(second);
950
951   // Move the focus to the right
952   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
953
954   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
955   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
956   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
957   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
958   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
959   preFocusChangeCallback.Reset();
960
961   // Check that the focus is set on the first actor
962   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
963   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
964   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
965   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
966   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
967   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
968   focusChangedCallback.Reset();
969
970   // Move the focus towards right
971   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
972
973   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
974   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
975   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
976   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
977   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
978   preFocusChangeCallback.Reset();
979
980   // Check that the focus is set on the second actor
981   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
982   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
983   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
984   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
985   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
986   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
987   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
988   focusChangedCallback.Reset();
989
990   // Move the focus towards up
991   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
992
993   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
994   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
995   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
996   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
997   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
998   preFocusChangeCallback.Reset();
999   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1000
1001   // Create a 2x2 table view and try to move focus inside it
1002   TableView tableView = TableView::New( 2, 2 );
1003   Stage::GetCurrent().Add(tableView);
1004
1005   // Create the third actor
1006   Control third = Control::New();
1007   third.SetKeyboardFocusable(true);
1008
1009   // Create the fourth actor
1010   Control fourth = Control::New();
1011   fourth.SetKeyboardFocusable(true);
1012
1013   // Add the four children to table view
1014   tableView.AddChild(first, TableView::CellPosition(0, 0));
1015   tableView.AddChild(second, TableView::CellPosition(0, 1));
1016   tableView.AddChild(third, TableView::CellPosition(1, 0));
1017   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1018
1019   // Set the focus to the first actor
1020   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1021   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1022   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1023   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1024   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1025
1026   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1027   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1028
1029   focusChangedCallback.Reset();
1030
1031   // Move the focus towards right
1032   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1033   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1034   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1035   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1036   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1037   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1038   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1039
1040   focusChangedCallback.Reset();
1041
1042   // Move the focus towards down
1043   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1044   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1045   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1046   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1047   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1048
1049   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1050   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1051   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1052   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1053
1054   focusChangedCallback.Reset();
1055
1056   // Move the focus towards left
1057   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1058   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1059   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1060   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1061   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1062
1063   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1064   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1065   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1066   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1067
1068   focusChangedCallback.Reset();
1069
1070   // Move the focus towards up
1071   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1072   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1073   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1074   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1075   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1076   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1077   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1078   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1079   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1080   focusChangedCallback.Reset();
1081
1082   // Move the focus towards left. The focus move will fail as no way to move it upwards
1083   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1084   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1085   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1086   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1087   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1088   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1089   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1090   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1091   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1092   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1093
1094   preFocusChangeCallback.Reset();
1095   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1096
1097   // Enable the loop
1098   manager.SetFocusGroupLoop(true);
1099   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1100
1101   // Move the focus towards left again. The focus should move to the fourth actor.
1102   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1103   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1104   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1105   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1106   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1107
1108   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1109   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1110   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1111   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1112
1113   focusChangedCallback.Reset();
1114
1115   // Clear the focus
1116   manager.ClearFocus();
1117   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1118   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1119   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1120   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1121
1122
1123   END_TEST;
1124 }