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