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