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