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