[dali_2.0.15] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-KeyboardFocusManager.cpp
1 /*
2  * Copyright (c) 2020 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/focus-manager/keyboard-focus-manager-devel.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
30
31 using namespace Dali;
32 using namespace Dali::Toolkit;
33
34 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44
45 namespace
46 {
47
48 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
49
50 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
51 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
52 {
53 public:
54   CustomAlgorithm(bool& interfaceVerified)
55   : mInterfaceVerified(interfaceVerified),
56     mCurrentFocusedActor(),
57     mProposedActorToFocus(),
58     mDirection(Control::KeyboardFocus::LEFT)
59   {
60   }
61
62   Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
63   {
64     tet_infoline("Verifying CustomAlgorithm()");
65
66     mInterfaceVerified = true;
67
68     mCurrentFocusedActor = currentFocusedActor;
69     mProposedActorToFocus = proposedActorToFocus;
70     mDirection = direction;
71
72     return mProposedActorToFocus;
73   }
74
75   void Reset()
76   {
77     mInterfaceVerified = false;
78     mCurrentFocusedActor = Actor();
79     mProposedActorToFocus = Actor();
80     mDirection = Control::KeyboardFocus::LEFT;
81   }
82
83   bool& mInterfaceVerified;
84   Actor mCurrentFocusedActor;
85   Actor mProposedActorToFocus;
86   Control::KeyboardFocus::Direction mDirection;
87 };
88
89 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
90 class PreFocusChangeCallback : public Dali::ConnectionTracker
91 {
92 public:
93   PreFocusChangeCallback(bool& signalReceived)
94   : mSignalVerified(signalReceived),
95     mCurrentFocusedActor(),
96     mProposedActorToFocus(),
97     mDirection(Control::KeyboardFocus::LEFT)
98   {
99   }
100
101   Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
102   {
103     tet_infoline("Verifying PreFocusChangeCallback()");
104
105     mSignalVerified = true;
106
107     mCurrentFocusedActor = currentFocusedActor;
108     mProposedActorToFocus = proposedActorToFocus;
109     mDirection = direction;
110
111     return mProposedActorToFocus;
112   }
113
114   void Reset()
115   {
116     mSignalVerified = false;
117     mCurrentFocusedActor = Actor();
118     mProposedActorToFocus = Actor();
119     mDirection = Control::KeyboardFocus::LEFT;
120   }
121
122   bool& mSignalVerified;
123   Actor mCurrentFocusedActor;
124   Actor mProposedActorToFocus;
125   Control::KeyboardFocus::Direction mDirection;
126 };
127
128 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
129 class FocusChangedCallback : public Dali::ConnectionTracker
130 {
131 public:
132   FocusChangedCallback(bool& signalReceived)
133   : mSignalVerified(signalReceived),
134     mOriginalFocusedActor(),
135     mCurrentFocusedActor()
136   {
137   }
138
139   void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
140   {
141     tet_infoline("Verifying FocusChangedCallback()");
142
143     if(originalFocusedActor == mCurrentFocusedActor)
144     {
145       mSignalVerified = true;
146     }
147
148     mOriginalFocusedActor = originalFocusedActor;
149     mCurrentFocusedActor = currentFocusedActor;
150   }
151
152   void Reset()
153   {
154     mSignalVerified = false;
155   }
156
157   bool& mSignalVerified;
158   Actor mOriginalFocusedActor;
159   Actor mCurrentFocusedActor;
160 };
161
162 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
163 class FocusGroupChangedCallback : public Dali::ConnectionTracker
164 {
165 public:
166   FocusGroupChangedCallback(bool& signalReceived)
167   : mSignalVerified(signalReceived),
168     mCurrentFocusedActor(),
169     mForward(true)
170   {
171   }
172
173   void Callback(Actor currentFocusedActor, bool forward)
174   {
175     tet_infoline("Verifying FocusGroupChangedCallback()");
176
177     mSignalVerified = true;
178
179     mCurrentFocusedActor = currentFocusedActor;
180     mForward = forward;
181   }
182
183   void Reset()
184   {
185     mSignalVerified = false;
186   }
187
188   bool& mSignalVerified;
189   Actor mCurrentFocusedActor;
190   bool mForward;
191 };
192
193 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
194 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
195 {
196 public:
197   FocusedActorActivatedCallback(bool& signalReceived)
198   : mSignalVerified(signalReceived),
199     mActivatedActor()
200   {
201   }
202
203   void Callback(Actor activatedActor)
204   {
205     tet_infoline("Verifying FocusedActorActivatedCallback()");
206
207     mSignalVerified = true;
208
209     mActivatedActor = activatedActor;
210   }
211
212   void Reset()
213   {
214     mSignalVerified = false;
215   }
216
217   bool& mSignalVerified;
218   Actor mActivatedActor;
219 };
220
221 class KeyEventCallback : public Dali::ConnectionTracker
222 {
223 public:
224   /**
225    * Constructor
226    * @param[in]  returnValue  Set return value of KeyEvent callback.
227    * */
228   KeyEventCallback( bool consumed )
229   : mConsumed( consumed ),
230     mIsCalled( false )
231   {
232   }
233
234   bool Callback( Control control, const KeyEvent& keyEvent )
235   {
236     mIsCalled = true;
237     return mConsumed;
238   }
239
240   void Callback( const KeyEvent& keyEvent )
241   {
242     mIsCalled = true;
243   }
244
245   bool mConsumed;
246   bool mIsCalled;
247 };
248
249 // Used to connect to signals via the ConnectSignal Handle method
250 struct CallbackFunctor
251 {
252   CallbackFunctor()
253   {
254   }
255
256   void operator()()
257   {
258   }
259 };
260
261 } // namespace
262
263 int UtcDaliKeyboardFocusManagerGet(void)
264 {
265   ToolkitTestApplication application;
266
267   tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
268
269   // Register Type
270   TypeInfo type;
271   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
272   DALI_TEST_CHECK( type );
273   BaseHandle handle = type.CreateInstance();
274   DALI_TEST_CHECK( handle );
275
276   KeyboardFocusManager manager;
277
278   manager = KeyboardFocusManager::Get();
279   DALI_TEST_CHECK(manager);
280
281   KeyboardFocusManager newManager = KeyboardFocusManager::Get();
282   DALI_TEST_CHECK(newManager);
283
284   // Check that focus manager is a singleton
285   DALI_TEST_CHECK(manager == newManager);
286   END_TEST;
287 }
288
289 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
290 {
291   ToolkitTestApplication application;
292
293   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
294
295   KeyboardFocusManager manager = KeyboardFocusManager::Get();
296   DALI_TEST_CHECK(manager);
297
298   // Create the first actor and add it to the stage
299   Actor first = Actor::New();
300   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
301   application.GetScene().Add(first);
302
303   // Create the second actor and add it to the stage
304   Actor second = Actor::New();
305   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
306   application.GetScene().Add(second);
307
308   // Create the third actor but don't add it to the stage
309   Actor third = Actor::New();
310
311   // Check that no actor is being focused yet.
312   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
313
314   // Check that it will fail to set focus on an invalid actor
315   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
316
317   // Check that the focus is set on the first actor
318   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
319   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
320
321   // Check that the focus is set on the second actor
322   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
323   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
324
325   // Check that it will fail to set focus on the third actor as it's not in the stage
326   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
327   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
328
329   // Add the third actor to the stage
330   application.GetScene().Add(third);
331
332   // Check that it will fail to set focus on the third actor as it's not focusable
333   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
334   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
335
336   // Make the third actor focusable
337   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
338
339   // Check that the focus is successfully moved to the third actor
340   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
341   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
342   END_TEST;
343 }
344
345 int UtcDaliKeyboardFocusManagerMoveFocus(void)
346 {
347   ToolkitTestApplication application;
348
349   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
350
351   // Register Type
352   TypeInfo type;
353   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
354   DALI_TEST_CHECK( type );
355   BaseHandle handle = type.CreateInstance();
356   DALI_TEST_CHECK( handle );
357
358   KeyboardFocusManager manager = KeyboardFocusManager::Get();
359   DALI_TEST_CHECK(manager);
360
361   bool preFocusChangeSignalVerified = false;
362   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
363   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
364
365   bool focusChangedSignalVerified = false;
366   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
367   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
368
369   // Create the first actor and add it to the stage
370   Actor first = Actor::New();
371   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
372   application.GetScene().Add(first);
373
374   // Create the second actor and add it to the stage
375   Actor second = Actor::New();
376   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
377   application.GetScene().Add(second);
378
379   // Move the focus to the right
380   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
381
382   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
383   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
384   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
385   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
386   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
387   preFocusChangeCallback.Reset();
388
389   // Check that the focus is set on the first actor
390   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
391   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
392   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
393   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
394   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
395   focusChangedCallback.Reset();
396
397   // Move the focus towards right
398   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
399
400   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
401   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
402   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
403   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
404   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
405   preFocusChangeCallback.Reset();
406
407   // Check that the focus is set on the second actor
408   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
409   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
410   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
411   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
412   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
413   focusChangedCallback.Reset();
414
415   // Move the focus towards up
416   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
417
418   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
419   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
420   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
421   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
422   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
423   preFocusChangeCallback.Reset();
424   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
425
426   // Create a 2x2 table view and try to move focus inside it
427   TableView tableView = TableView::New( 2, 2 );
428   application.GetScene().Add(tableView);
429
430   // Create the third actor
431   Actor third = Actor::New();
432   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
433
434   // Create the fourth actor
435   Actor fourth = Actor::New();
436   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
437
438   // Add the four children to table view
439   tableView.AddChild(first, TableView::CellPosition(0, 0));
440   tableView.AddChild(second, TableView::CellPosition(0, 1));
441   tableView.AddChild(third, TableView::CellPosition(1, 0));
442   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
443
444   // Set the focus to the first actor
445   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
446   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
447   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
448   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
449   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
450   focusChangedCallback.Reset();
451
452   // Move the focus towards right
453   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
454   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
455   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
456   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
457   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
458   focusChangedCallback.Reset();
459
460   // Move the focus towards down
461   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
462   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
463   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
464   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
465   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
466   focusChangedCallback.Reset();
467
468   // Move the focus towards left
469   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
470   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
471   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
472   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
473   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
474   focusChangedCallback.Reset();
475
476   // Move the focus towards up
477   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
478   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
479   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
480   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
481   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
482   focusChangedCallback.Reset();
483
484   // Move the focus towards left. The focus move will fail as no way to move it upwards
485   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
486   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
487   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
488   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
489   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
490   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
491   preFocusChangeCallback.Reset();
492   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
493
494   // Enable the loop
495   manager.SetFocusGroupLoop(true);
496   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
497
498   // Move the focus towards left again. The focus should move to the fourth actor.
499   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
500   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
501   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
502   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
503   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
504   focusChangedCallback.Reset();
505   END_TEST;
506 }
507
508 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
509 {
510   ToolkitTestApplication application;
511
512   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
513
514   // Register Type
515   TypeInfo type;
516   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
517   DALI_TEST_CHECK( type );
518   BaseHandle handle = type.CreateInstance();
519   DALI_TEST_CHECK( handle );
520
521   KeyboardFocusManager manager = KeyboardFocusManager::Get();
522   DALI_TEST_CHECK(manager);
523
524   bool preFocusChangeSignalVerified = false;
525   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
526   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
527
528   bool focusChangedSignalVerified = false;
529   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
530   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
531
532   // Create the first actor and add it to the stage
533   Actor first = Actor::New();
534   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
535   application.GetScene().Add(first);
536
537   // Create the second actor and add it to the stage
538   Actor second = Actor::New();
539   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
540   application.GetScene().Add(second);
541
542   // Move the focus to the right
543   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
544
545   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
546   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
547   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
548   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
549   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
550   preFocusChangeCallback.Reset();
551
552   bool customAlgorithmInterfaceVerified = false;
553   CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
554   Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
555
556   // Move the focus towards right
557   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
558
559   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
560   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
561   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
562   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
563   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
564   customAlgorithm.Reset();
565
566   // Check that the focus is set on the first actor
567   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
568   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
569   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
570   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
571   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
572   focusChangedCallback.Reset();
573
574   // Move the focus towards right
575   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
576
577   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
578   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
579   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
580   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
581   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
582   customAlgorithm.Reset();
583
584   // Check that the focus is set on the second actor
585   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
586   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
587   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
588   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
589   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
590   focusChangedCallback.Reset();
591
592   // Move the focus towards up
593   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
594
595   // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
596   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
597   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
598   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
599   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
600   customAlgorithm.Reset();
601   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
602
603   END_TEST;
604 }
605 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
606 {
607   ToolkitTestApplication application;
608
609   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
610
611   // Register Type
612   TypeInfo type;
613   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
614   DALI_TEST_CHECK( type );
615   BaseHandle handle = type.CreateInstance();
616   DALI_TEST_CHECK( handle );
617
618   KeyboardFocusManager manager = KeyboardFocusManager::Get();
619   DALI_TEST_CHECK(manager);
620
621   bool focusChangedSignalVerified = false;
622   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
623   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
624
625   PushButton button1 = PushButton::New();
626   PushButton button2 = PushButton::New();
627   button1.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
628   button2.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
629   application.GetScene().Add(button1);
630   application.GetScene().Add(button2);
631
632   // Set the focus to the button1
633   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
634   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
635   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
636   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
637   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
638   focusChangedCallback.Reset();
639
640   // set the navigation properties of button1
641   button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
642   button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
643   button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
644   button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
645
646   // set the navigation properties of button2
647   button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
648   button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
649   button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
650   button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
651
652   // Move the focus towards left
653   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
654
655   // Confirm whether focus is moved to button2
656   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
657   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
658   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
659   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
660   focusChangedCallback.Reset();
661
662   // Move the focus towards right
663   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
664
665   // Confirm whether focus is moved to button1
666   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
667   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
668   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
669   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
670   focusChangedCallback.Reset();
671
672   // Move the focus towards up
673   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
674
675   // Confirm whether focus is moved to button2
676   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
677   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
678   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
679   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
680   focusChangedCallback.Reset();
681
682   // Move the focus towards down
683   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
684
685   // Confirm whether focus is moved to button1
686   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
687   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
688   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
689   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
690   focusChangedCallback.Reset();
691
692   // Create a 1x1 table view and try to move focus inside it
693   TableView tableView = TableView::New( 1, 1 );
694   application.GetScene().Add(tableView);
695
696   PushButton button = PushButton::New();
697   button.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
698   tableView.AddChild(button, TableView::CellPosition(0, 0));
699
700   // set the navigation properties of button3
701   button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
702
703   // Set the focus to the button
704   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
705   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
706   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
707   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
708   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
709   focusChangedCallback.Reset();
710
711   // Move the focus towards left
712   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
713
714   // Confirm whether focus is moved to button1
715   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
716   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
717   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
718   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
719   focusChangedCallback.Reset();
720
721   END_TEST;
722 }
723
724 int UtcDaliKeyboardFocusManagerClearFocus(void)
725 {
726   ToolkitTestApplication application;
727
728   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
729
730   KeyboardFocusManager manager = KeyboardFocusManager::Get();
731   DALI_TEST_CHECK(manager);
732
733   // Create the first actor and add it to the stage
734   Actor first = Actor::New();
735   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
736   application.GetScene().Add(first);
737
738   // Create the second actor and add it to the stage
739   Actor second = Actor::New();
740   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
741   application.GetScene().Add(second);
742
743   // Check that the focus is set on the first actor
744   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
745   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
746
747   // Check that the focus is set on the second actor
748   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
749   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
750
751   // Clear the focus
752   manager.ClearFocus();
753
754   // Check that no actor is being focused now.
755   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
756   END_TEST;
757 }
758
759 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
760 {
761   ToolkitTestApplication application;
762
763   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
764
765   KeyboardFocusManager manager = KeyboardFocusManager::Get();
766   DALI_TEST_CHECK(manager);
767
768   // Check that the focus movement is not looped within the same focus group by default
769   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
770
771   // Enable the loop
772   manager.SetFocusGroupLoop(true);
773   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
774   END_TEST;
775 }
776
777 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
778 {
779   ToolkitTestApplication application;
780
781   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
782
783   KeyboardFocusManager manager = KeyboardFocusManager::Get();
784   DALI_TEST_CHECK(manager);
785
786   // Create an actor and check that it is not a focus group by default
787   Actor actor = Actor::New();
788   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
789
790   // Set the actor as focus group
791   manager.SetAsFocusGroup(actor, true);
792
793   // flush the queue and render once
794   application.SendNotification();
795   application.Render();
796
797   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
798
799   // Set the actor not as focus group
800   manager.SetAsFocusGroup(actor, false);
801
802   // flush the queue and render once
803   application.SendNotification();
804   application.Render();
805
806   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
807   END_TEST;
808 }
809
810 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
811 {
812   ToolkitTestApplication application;
813
814   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
815
816   KeyboardFocusManager manager = KeyboardFocusManager::Get();
817   DALI_TEST_CHECK(manager);
818
819   // Create an actor with two child actors and add it to the stage
820   Actor parent = Actor::New();
821   Actor child = Actor::New();
822   parent.Add(child);
823   application.GetScene().Add(parent);
824
825   // Create three actors and add them as the children of the first child actor
826   Actor grandChild = Actor::New();
827   child.Add(grandChild);
828
829   // Set the parent and the first child actor as focus groups
830   manager.SetAsFocusGroup(parent, true);
831
832   // flush the queue and render once
833   application.SendNotification();
834   application.Render();
835
836   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
837
838   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
839   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
840
841   manager.SetAsFocusGroup(child, true);
842
843   // flush the queue and render once
844   application.SendNotification();
845   application.Render();
846
847   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
848
849   // The focus group should be the child, As it is the immediate parent which is also a focus group.
850   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
851
852   manager.SetAsFocusGroup(grandChild, true);
853
854   // flush the queue and render once
855   application.SendNotification();
856   application.Render();
857
858   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
859
860   // The current focus group should be itself, As it is also a focus group.
861   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
862   END_TEST;
863 }
864
865 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
866 {
867   ToolkitTestApplication application;
868
869   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
870
871   KeyboardFocusManager manager = KeyboardFocusManager::Get();
872   DALI_TEST_CHECK(manager);
873
874   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
875   DALI_TEST_CHECK(defaultFocusIndicatorActor);
876
877   Actor newFocusIndicatorActor = Actor::New();
878   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
879   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
880   END_TEST;
881 }
882
883
884 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
885 {
886   ToolkitTestApplication application;
887
888   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
889
890   KeyboardFocusManager manager = KeyboardFocusManager::Get();
891   DALI_TEST_CHECK(manager);
892
893   bool focusedActorActivatedSignalVerified = false;
894   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
895   manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
896
897   Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
898
899   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
900   // It makes mIsFocusIndicatorEnabled true
901   application.ProcessEvent(returnEvent);
902
903   // Create the first button and add it to the stage
904   PushButton firstPushButton = PushButton::New();
905   firstPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
906   application.GetScene().Add(firstPushButton);
907
908   // Create the second button and add it to the stage
909   PushButton secondPushButton = PushButton::New();
910   secondPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
911   application.GetScene().Add(secondPushButton);
912
913   // Check that the focus is set on the first button
914   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
915   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
916
917   // Send the return event to activate the first button
918   application.ProcessEvent(returnEvent);
919   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
920   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
921   focusedActorActivatedCallback.Reset();
922
923   // Check that the focus is set on the second button
924   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
925   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
926
927   // Send the return event again to activate the second button
928   application.ProcessEvent(returnEvent);
929   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
930   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
931   focusedActorActivatedCallback.Reset();
932   END_TEST;
933 }
934
935 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
936 {
937   ToolkitTestApplication application;
938
939   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
940
941   // Register Type
942   TypeInfo type;
943   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
944   DALI_TEST_CHECK( type );
945   BaseHandle handle = type.CreateInstance();
946   DALI_TEST_CHECK( handle );
947
948   KeyboardFocusManager manager = KeyboardFocusManager::Get();
949   DALI_TEST_CHECK(manager);
950
951   bool focusGroupChangedSignalVerified = false;
952   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
953   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
954
955   Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
956   Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
957
958   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
959   // It makes mIsFocusIndicatorEnabled true
960   application.ProcessEvent(tabEvent);
961
962   // Send the tab event to change focus group in the forward direction
963   application.ProcessEvent(tabEvent);
964   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
965   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
966   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
967   focusGroupChangedCallback.Reset();
968
969   // Send the shift tab event to change focus group in the backward direction
970   application.ProcessEvent(shiftTabEvent);
971   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
972   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
973   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
974   focusGroupChangedCallback.Reset();
975   END_TEST;
976 }
977
978 int UtcDaliKeyboardFocusManagerSignals(void)
979 {
980   ToolkitTestApplication application;
981
982   KeyboardFocusManager manager = KeyboardFocusManager::Get();
983   DALI_TEST_CHECK( manager );
984
985   ConnectionTracker* testTracker = new ConnectionTracker();
986   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
987   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
988   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
989   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
990
991   END_TEST;
992 }
993
994 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
995 {
996   ToolkitTestApplication application;
997
998   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
999
1000   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1001   DALI_TEST_CHECK(manager);
1002
1003   // Create the first actor and add it to the stage
1004   Actor first = Actor::New();
1005   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1006   application.GetScene().Add(first);
1007
1008   // Create the second actor and add it to the stage
1009   Actor second = Actor::New();
1010   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1011   application.GetScene().Add(second);
1012
1013   // Create the third actor and add it to the stage
1014   Actor third = Actor::New();
1015   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1016   application.GetScene().Add(third);
1017
1018   // Create the fourth actor and add it to the stage
1019   Actor fourth = Actor::New();
1020   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1021   application.GetScene().Add(fourth);
1022
1023   // Check that the focus is set on the second actor
1024   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1025   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1026
1027   // Check that the focus is set on the second actor
1028   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1029   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1030
1031   // Check that the focus is set on the third  actor
1032   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1033   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1034
1035   // Check that the focus is set on the third  actor
1036   DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1037   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1038
1039   // Move the focus backward
1040   manager.MoveFocusBackward();
1041
1042   // Check that it current focused actor is third actor
1043   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1044
1045   // Remove the second actor on stage
1046   second.Unparent();
1047
1048   // Reset the first actor
1049   first.Unparent();
1050   first.Reset();
1051
1052   // Move the focus backward
1053   manager.MoveFocusBackward();
1054
1055   // Check that it current focused actor is third actor
1056   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1057
1058   // Make history stack full
1059   for(int i = 0 ; i < 31 ; i ++)
1060   {
1061     Actor actor = Actor::New();
1062     actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1063     application.GetScene().Add(actor);
1064     manager.SetCurrentFocusActor(actor);
1065   }
1066
1067   for(int i = 0 ; i < 31 ; i ++)
1068   {
1069     manager.MoveFocusBackward();
1070   }
1071
1072   // Check that it current focused actor is not second actor
1073   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1074
1075   END_TEST;
1076 }
1077
1078 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1079 {
1080   ToolkitTestApplication application;
1081
1082   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1083
1084   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1085   DALI_TEST_CHECK(manager);
1086
1087   bool preFocusChangeSignalVerified = false;
1088   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1089   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1090
1091   bool focusChangedSignalVerified = false;
1092   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1093   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1094
1095   Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1096   Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1097   Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1098   Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1099   Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1100   Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1101
1102   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1103   // It makes mIsFocusIndicatorEnabled true
1104   application.ProcessEvent(leftEvent);
1105
1106   // Create a 2x2 table view and try to move focus inside it
1107   TableView tableView = TableView::New( 2, 2 );
1108   application.GetScene().Add(tableView);
1109
1110   // Create the first actor
1111   Actor first = Actor::New();
1112   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1113
1114   // Create the second actor
1115   Actor second = Actor::New();
1116   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1117
1118   // Create the third actor
1119   Actor third = Actor::New();
1120   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1121
1122   // Create the fourth actor
1123   Actor fourth = Actor::New();
1124   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1125
1126   // Add the four children to table view
1127   tableView.AddChild(first, TableView::CellPosition(0, 0));
1128   tableView.AddChild(second, TableView::CellPosition(0, 1));
1129   tableView.AddChild(third, TableView::CellPosition(1, 0));
1130   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1131
1132   // Set the focus to the first actor
1133   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1134   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1135   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1136   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1137   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1138   focusChangedCallback.Reset();
1139
1140   // Send the right key event to move the focus towards right
1141   application.ProcessEvent(rightEvent);
1142   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1143   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1144   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1145   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1146   focusChangedCallback.Reset();
1147
1148   // Send the down key event to move the focus towards down
1149   application.ProcessEvent(downEvent);
1150   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1151   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1152   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1153   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1154   focusChangedCallback.Reset();
1155
1156   // Send the down event to move the focus towards left
1157   application.ProcessEvent(leftEvent);
1158   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1159   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1160   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1161   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1162   focusChangedCallback.Reset();
1163
1164   // Send the up event to move the focus towards up
1165   application.ProcessEvent(upEvent);
1166   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1167   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1168   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1169   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1170   focusChangedCallback.Reset();
1171
1172   // Send the pape up event, but focus should not be moved because page up is not supported by table view
1173   application.ProcessEvent(pageUpEvent);
1174   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1175   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1176   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1177   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1178   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1179   preFocusChangeCallback.Reset();
1180
1181   // Send the pape down event, but focus should not be moved because page down is not supported by table view
1182   application.ProcessEvent(pageDownEvent);
1183   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1184   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1185   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1186   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1187   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1188   preFocusChangeCallback.Reset();
1189
1190   // Clear the focus
1191   manager.ClearFocus();
1192
1193   // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1194   preFocusChangeCallback.Reset();
1195   application.ProcessEvent(pageUpEvent);
1196   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1197   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1198   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1199   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1200   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1201
1202   // Clear the focus again
1203   manager.ClearFocus();
1204
1205   // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1206   preFocusChangeCallback.Reset();
1207   application.ProcessEvent(pageDownEvent);
1208   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1209   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1210   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1211   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1212   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1213
1214   // Clear the focus again
1215   manager.ClearFocus();
1216
1217   // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1218   preFocusChangeCallback.Reset();
1219   application.ProcessEvent(upEvent);
1220   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1221   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1222   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1223   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1224
1225   // Clear the focus again
1226   manager.ClearFocus();
1227
1228   // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1229   preFocusChangeCallback.Reset();
1230   application.ProcessEvent(downEvent);
1231   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1232   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1233   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1234   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1235
1236   END_TEST;
1237 }
1238
1239 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1240 {
1241   ToolkitTestApplication application;
1242
1243   tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1244
1245   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1246   DALI_TEST_CHECK(manager);
1247
1248   bool preFocusChangeSignalVerified = false;
1249   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1250   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1251
1252   Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1253
1254   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1255   // It makes mIsFocusIndicatorEnabled true
1256   application.ProcessEvent(spaceEvent);
1257
1258   // Send the space event
1259   application.ProcessEvent(spaceEvent);
1260   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1261   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1262
1263   // Clear the focus again
1264   manager.ClearFocus();
1265
1266   // Send the space event again for line coverage
1267   preFocusChangeCallback.Reset();
1268   application.ProcessEvent(spaceEvent);
1269   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1270   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1271   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1272   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1273
1274   END_TEST;
1275 }
1276
1277
1278
1279 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1280 {
1281   ToolkitTestApplication application;
1282
1283   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1284
1285   // Register Type
1286   TypeInfo type;
1287   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1288   DALI_TEST_CHECK( type );
1289   BaseHandle handle = type.CreateInstance();
1290   DALI_TEST_CHECK( handle );
1291
1292   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1293   DALI_TEST_CHECK(manager);
1294
1295   bool preFocusChangeSignalVerified = false;
1296   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1297   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1298
1299   bool focusChangedSignalVerified = false;
1300   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1301   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1302
1303   // Create the first actor and add it to the stage
1304   Control first = Control::New();
1305   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1306   application.GetScene().Add(first);
1307
1308   // Create the second actor and add it to the stage
1309   Control second = Control::New();
1310   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1311   application.GetScene().Add(second);
1312
1313   // Move the focus to the right
1314   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1315
1316   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1317   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1318   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1319   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1320   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1321   preFocusChangeCallback.Reset();
1322
1323   // Check that the focus is set on the first actor
1324   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1325   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1326   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1327   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1328   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1329   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1330   focusChangedCallback.Reset();
1331
1332   // Move the focus towards right
1333   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1334
1335   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1336   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1337   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1338   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1339   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1340   preFocusChangeCallback.Reset();
1341
1342   // Check that the focus is set on the second actor
1343   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1344   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1345   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1346   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1347   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1348   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1349   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1350   focusChangedCallback.Reset();
1351
1352   // Move the focus towards up
1353   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1354
1355   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1356   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1357   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1358   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1359   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1360   preFocusChangeCallback.Reset();
1361   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1362
1363   // Create a 2x2 table view and try to move focus inside it
1364   TableView tableView = TableView::New( 2, 2 );
1365   application.GetScene().Add(tableView);
1366
1367   // Create the third actor
1368   Control third = Control::New();
1369   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1370
1371   // Create the fourth actor
1372   Control fourth = Control::New();
1373   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1374
1375   // Add the four children to table view
1376   tableView.AddChild(first, TableView::CellPosition(0, 0));
1377   tableView.AddChild(second, TableView::CellPosition(0, 1));
1378   tableView.AddChild(third, TableView::CellPosition(1, 0));
1379   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1380
1381   // Set the focus to the first actor
1382   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1383   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1384   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1385   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1386   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1387
1388   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1389   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1390
1391   focusChangedCallback.Reset();
1392
1393   // Move the focus towards right
1394   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1395   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1396   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1397   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1398   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1399   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1400   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1401
1402   focusChangedCallback.Reset();
1403
1404   // Move the focus towards down
1405   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1406   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1407   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1408   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1409   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1410
1411   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1412   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1413   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1414   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1415
1416   focusChangedCallback.Reset();
1417
1418   // Move the focus towards left
1419   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1420   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1421   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1422   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1423   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1424
1425   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1426   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1427   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1428   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1429
1430   focusChangedCallback.Reset();
1431
1432   // Move the focus towards up
1433   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1434   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1435   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1436   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1437   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1438   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1439   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1440   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1441   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1442   focusChangedCallback.Reset();
1443
1444   // Move the focus towards left. The focus move will fail as no way to move it upwards
1445   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1446   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1447   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1448   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1449   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1450   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1451   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1452   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1453   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1454   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1455
1456   preFocusChangeCallback.Reset();
1457   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1458
1459   // Enable the loop
1460   manager.SetFocusGroupLoop(true);
1461   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1462
1463   // Move the focus towards left again. The focus should move to the fourth actor.
1464   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1465   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1466   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1467   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1468   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1469
1470   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1471   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1472   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1473   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1474
1475   focusChangedCallback.Reset();
1476
1477   // Clear the focus
1478   manager.ClearFocus();
1479   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1480   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1481   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1482   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1483
1484
1485   END_TEST;
1486 }
1487
1488 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1489 {
1490   ToolkitTestApplication application;
1491
1492   tet_infoline( "Ensure we cannot set an actor to be focused if it is not staged and that we do not retrieve an actor if it has been unstaged" );
1493
1494   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1495   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1496
1497   Actor actor = Actor::New();
1498   actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1499
1500   tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1501   manager.SetCurrentFocusActor( actor );
1502   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1503
1504   tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1505   application.GetScene().Add( actor );
1506   manager.SetCurrentFocusActor( actor );
1507   DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1508
1509   tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1510   actor.Unparent();
1511   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1512
1513   END_TEST;
1514 }
1515
1516 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1517 {
1518   ToolkitTestApplication application;
1519
1520   tet_infoline( "Ensure we cannot set an actor to be focused if it is not staged and that we do not retrieve an actor if it has been unstaged" );
1521
1522   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1523   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1524
1525   Actor actor = Actor::New();
1526   actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1527   application.GetScene().Add( actor );
1528   manager.SetCurrentFocusActor( actor );
1529
1530   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1531   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1532   Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1533   application.ProcessEvent(rightEvent);
1534
1535   Actor indicatorActor = manager.GetFocusIndicatorActor();
1536
1537   tet_infoline( "Indicator is added to focused actor" );
1538   DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1539
1540   Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1541   DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1542
1543   tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1544   DALI_TEST_CHECK( !indicatorActor.GetParent() );
1545
1546   END_TEST;
1547 }
1548
1549 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1550 {
1551   ToolkitTestApplication application;
1552
1553   tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
1554   Dali::Integration::Scene scene = application.GetScene();
1555
1556   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1557   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1558
1559   // Create the first actor and add it to the stage
1560   Control control = Control::New();
1561   control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1562   scene.Add(control);
1563
1564   KeyEventCallback controlCallback( true );
1565   control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
1566
1567   KeyEventCallback sceneCallback( false );
1568   scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
1569
1570   manager.SetCurrentFocusActor( control );
1571
1572   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1573   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1574   Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1575   application.ProcessEvent(event1);
1576
1577   DALI_TEST_CHECK( controlCallback.mIsCalled );
1578   DALI_TEST_CHECK( !sceneCallback.mIsCalled );
1579
1580   END_TEST;
1581 }
1582
1583 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1584 {
1585   ToolkitTestApplication application;
1586
1587   tet_infoline( "Ensure Memory focus actors for each window ");
1588   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1589   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1590
1591   Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false);
1592   DALI_TEST_CHECK( firstWindow );
1593   Control first = Control::New();
1594   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1595   firstWindow.Add(first);
1596
1597   Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false);
1598   DALI_TEST_CHECK( secondWindow );
1599   Control second = Control::New();
1600   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1601   secondWindow.Add( second );
1602
1603   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1604   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1605
1606   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1607   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1608   firstWindow.Raise();
1609   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1610
1611   secondWindow.Remove( second );
1612   secondWindow.Raise();
1613   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1614
1615   secondWindow.Reset();
1616   END_TEST;
1617 }
1618
1619