Merge "DALi Version 2.1.16" into devel/master
[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   button1.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID)));
682   button1.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID)));
683
684   // set the navigation properties of button2
685   button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
686   button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
687   button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
688   button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
689   button2.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID)));
690   button2.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID)));
691
692   // Move the focus towards left
693   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
694
695   // Confirm whether focus is moved to button2
696   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
697   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
698   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
699   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
700   focusChangedCallback.Reset();
701
702   // Move the focus towards right
703   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
704
705   // Confirm whether focus is moved to button1
706   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
707   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
708   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
709   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
710   focusChangedCallback.Reset();
711
712   // Move the focus towards up
713   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
714
715   // Confirm whether focus is moved to button2
716   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
717   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
718   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
719   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
720   focusChangedCallback.Reset();
721
722   // Move the focus towards down
723   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
724
725   // Confirm whether focus is moved to button1
726   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
727   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
728   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
729   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
730   focusChangedCallback.Reset();
731
732   // Move the focus towards clockwise
733   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::CLOCKWISE) == true);
734
735   // Confirm whether focus is moved to button2
736   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
737   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
738   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
739   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
740   focusChangedCallback.Reset();
741
742   // Move the focus towards clockwise
743   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::COUNTER_CLOCKWISE) == true);
744
745   // Confirm whether focus is moved to button1
746   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
747   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
748   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
749   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
750   focusChangedCallback.Reset();
751
752   // Create a 1x1 table view and try to move focus inside it
753   TableView tableView = TableView::New(1, 1);
754   application.GetScene().Add(tableView);
755
756   PushButton button = PushButton::New();
757   button.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
758   tableView.AddChild(button, TableView::CellPosition(0, 0));
759
760   // set the navigation properties of button3
761   button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
762
763   // Set the focus to the button
764   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
765   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
766   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
767   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
768   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
769   focusChangedCallback.Reset();
770
771   // Move the focus towards left
772   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
773
774   // Confirm whether focus is moved to button1
775   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
776   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
777   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
778   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
779   focusChangedCallback.Reset();
780
781   END_TEST;
782 }
783
784 int UtcDaliKeyboardFocusManagerClearFocus(void)
785 {
786   ToolkitTestApplication application;
787
788   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
789
790   KeyboardFocusManager manager = KeyboardFocusManager::Get();
791   DALI_TEST_CHECK(manager);
792
793   // Create the first actor and add it to the stage
794   Actor first = Actor::New();
795   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
796   application.GetScene().Add(first);
797
798   // Create the second actor and add it to the stage
799   Actor second = Actor::New();
800   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
801   application.GetScene().Add(second);
802
803   // Check that the focus is set on the first actor
804   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
805   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
806
807   // Check that the focus is set on the second actor
808   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
809   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
810
811   // Clear the focus
812   manager.ClearFocus();
813
814   // Check that no actor is being focused now.
815   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
816   END_TEST;
817 }
818
819 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
820 {
821   ToolkitTestApplication application;
822
823   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
824
825   KeyboardFocusManager manager = KeyboardFocusManager::Get();
826   DALI_TEST_CHECK(manager);
827
828   // Check that the focus movement is not looped within the same focus group by default
829   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
830
831   // Enable the loop
832   manager.SetFocusGroupLoop(true);
833   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
834   END_TEST;
835 }
836
837 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
838 {
839   ToolkitTestApplication application;
840
841   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
842
843   KeyboardFocusManager manager = KeyboardFocusManager::Get();
844   DALI_TEST_CHECK(manager);
845
846   // Create an actor and check that it is not a focus group by default
847   Actor actor = Actor::New();
848   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
849
850   // Set the actor as focus group
851   manager.SetAsFocusGroup(actor, true);
852
853   // flush the queue and render once
854   application.SendNotification();
855   application.Render();
856
857   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
858
859   // Set the actor not as focus group
860   manager.SetAsFocusGroup(actor, false);
861
862   // flush the queue and render once
863   application.SendNotification();
864   application.Render();
865
866   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
867   END_TEST;
868 }
869
870 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
871 {
872   ToolkitTestApplication application;
873
874   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
875
876   KeyboardFocusManager manager = KeyboardFocusManager::Get();
877   DALI_TEST_CHECK(manager);
878
879   // Create an actor with two child actors and add it to the stage
880   Actor parent = Actor::New();
881   Actor child  = Actor::New();
882   parent.Add(child);
883   application.GetScene().Add(parent);
884
885   // Create three actors and add them as the children of the first child actor
886   Actor grandChild = Actor::New();
887   child.Add(grandChild);
888
889   // Set the parent and the first child actor as focus groups
890   manager.SetAsFocusGroup(parent, true);
891
892   // flush the queue and render once
893   application.SendNotification();
894   application.Render();
895
896   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
897
898   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
899   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
900
901   manager.SetAsFocusGroup(child, true);
902
903   // flush the queue and render once
904   application.SendNotification();
905   application.Render();
906
907   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
908
909   // The focus group should be the child, As it is the immediate parent which is also a focus group.
910   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
911
912   manager.SetAsFocusGroup(grandChild, true);
913
914   // flush the queue and render once
915   application.SendNotification();
916   application.Render();
917
918   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
919
920   // The current focus group should be itself, As it is also a focus group.
921   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
922   END_TEST;
923 }
924
925 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
926 {
927   ToolkitTestApplication application;
928
929   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
930
931   KeyboardFocusManager manager = KeyboardFocusManager::Get();
932   DALI_TEST_CHECK(manager);
933
934   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
935   DALI_TEST_CHECK(defaultFocusIndicatorActor);
936
937   Actor newFocusIndicatorActor = Actor::New();
938   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
939   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
940   END_TEST;
941 }
942
943 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
944 {
945   ToolkitTestApplication application;
946
947   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
948
949   KeyboardFocusManager manager = KeyboardFocusManager::Get();
950   DALI_TEST_CHECK(manager);
951
952   bool                          focusedActorActivatedSignalVerified = false;
953   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
954   manager.FocusedActorEnterKeySignal().Connect(&focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback);
955
956   Integration::KeyEvent returnEvent("Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
957
958   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
959   // It makes mIsFocusIndicatorEnabled true
960   application.ProcessEvent(returnEvent);
961
962   // Create the first button and add it to the stage
963   PushButton firstPushButton = PushButton::New();
964   firstPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
965   application.GetScene().Add(firstPushButton);
966
967   // Create the second button and add it to the stage
968   PushButton secondPushButton = PushButton::New();
969   secondPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
970   application.GetScene().Add(secondPushButton);
971
972   // Check that the focus is set on the first button
973   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
974   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
975
976   // Send the return event to activate the first button
977   application.ProcessEvent(returnEvent);
978   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
979   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
980   focusedActorActivatedCallback.Reset();
981
982   // Check that the focus is set on the second button
983   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
984   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
985
986   // Send the return event again to activate the second button
987   application.ProcessEvent(returnEvent);
988   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
989   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
990   focusedActorActivatedCallback.Reset();
991   END_TEST;
992 }
993
994 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
995 {
996   ToolkitTestApplication application;
997
998   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
999
1000   // Register Type
1001   TypeInfo type;
1002   type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1003   DALI_TEST_CHECK(type);
1004   BaseHandle handle = type.CreateInstance();
1005   DALI_TEST_CHECK(handle);
1006
1007   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1008   DALI_TEST_CHECK(manager);
1009
1010   bool                      focusGroupChangedSignalVerified = false;
1011   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
1012   manager.FocusGroupChangedSignal().Connect(&focusGroupChangedCallback, &FocusGroupChangedCallback::Callback);
1013
1014   Integration::KeyEvent tabEvent("Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1015   Integration::KeyEvent shiftTabEvent("Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1016
1017   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1018   // It makes mIsFocusIndicatorEnabled true
1019   application.ProcessEvent(tabEvent);
1020
1021   // Send the tab event to change focus group in the forward direction
1022   application.ProcessEvent(tabEvent);
1023   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1024   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1025   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
1026   focusGroupChangedCallback.Reset();
1027
1028   // Send the shift tab event to change focus group in the backward direction
1029   application.ProcessEvent(shiftTabEvent);
1030   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1031   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1032   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1033   focusGroupChangedCallback.Reset();
1034   END_TEST;
1035 }
1036
1037 int UtcDaliKeyboardFocusManagerSignals(void)
1038 {
1039   ToolkitTestApplication application;
1040
1041   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1042   DALI_TEST_CHECK(manager);
1043
1044   ConnectionTracker* testTracker = new ConnectionTracker();
1045   DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardPreFocusChange", CallbackFunctor()), TEST_LOCATION);
1046   DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusChanged", CallbackFunctor()), TEST_LOCATION);
1047   DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusGroupChanged", CallbackFunctor()), TEST_LOCATION);
1048   DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor()), TEST_LOCATION);
1049
1050   END_TEST;
1051 }
1052
1053 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1054 {
1055   ToolkitTestApplication application;
1056
1057   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1058
1059   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1060   DALI_TEST_CHECK(manager);
1061
1062   // Create the first actor and add it to the stage
1063   Actor first = Actor::New();
1064   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1065   application.GetScene().Add(first);
1066
1067   // Create the second actor and add it to the stage
1068   Actor second = Actor::New();
1069   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1070   application.GetScene().Add(second);
1071
1072   // Create the third actor and add it to the stage
1073   Actor third = Actor::New();
1074   third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1075   application.GetScene().Add(third);
1076
1077   // Create the fourth actor and add it to the stage
1078   Actor fourth = Actor::New();
1079   fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1080   application.GetScene().Add(fourth);
1081
1082   // Check that the focus is set on the second actor
1083   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1084   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1085
1086   // Check that the focus is set on the second actor
1087   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1088   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1089
1090   // Check that the focus is set on the third  actor
1091   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1092   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1093
1094   // Check that the focus is set on the third  actor
1095   DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1096   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1097
1098   // Move the focus backward
1099   manager.MoveFocusBackward();
1100
1101   // Check that it current focused actor is third actor
1102   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1103
1104   // Remove the second actor on stage
1105   second.Unparent();
1106
1107   // Reset the first actor
1108   first.Unparent();
1109   first.Reset();
1110
1111   // Move the focus backward
1112   manager.MoveFocusBackward();
1113
1114   // Check that it current focused actor is third actor
1115   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1116
1117   // Make history stack full
1118   for(int i = 0; i < 31; i++)
1119   {
1120     Actor actor = Actor::New();
1121     actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1122     application.GetScene().Add(actor);
1123     manager.SetCurrentFocusActor(actor);
1124   }
1125
1126   for(int i = 0; i < 31; i++)
1127   {
1128     manager.MoveFocusBackward();
1129   }
1130
1131   // Check that it current focused actor is not second actor
1132   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1133
1134   END_TEST;
1135 }
1136
1137 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1138 {
1139   ToolkitTestApplication application;
1140
1141   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1142
1143   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1144   DALI_TEST_CHECK(manager);
1145
1146   bool                   preFocusChangeSignalVerified = false;
1147   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1148   manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1149
1150   bool                 focusChangedSignalVerified = false;
1151   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1152   manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1153
1154   Integration::KeyEvent leftEvent("Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1155   Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1156   Integration::KeyEvent upEvent("Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1157   Integration::KeyEvent downEvent("Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1158   Integration::KeyEvent pageUpEvent("Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1159   Integration::KeyEvent pageDownEvent("Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1160
1161   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1162   // It makes mIsFocusIndicatorEnabled true
1163   application.ProcessEvent(leftEvent);
1164
1165   // Create a 2x2 table view and try to move focus inside it
1166   TableView tableView = TableView::New(2, 2);
1167   application.GetScene().Add(tableView);
1168
1169   // Create the first actor
1170   Actor first = Actor::New();
1171   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1172
1173   // Create the second actor
1174   Actor second = Actor::New();
1175   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1176
1177   // Create the third actor
1178   Actor third = Actor::New();
1179   third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1180
1181   // Create the fourth actor
1182   Actor fourth = Actor::New();
1183   fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1184
1185   // Add the four children to table view
1186   tableView.AddChild(first, TableView::CellPosition(0, 0));
1187   tableView.AddChild(second, TableView::CellPosition(0, 1));
1188   tableView.AddChild(third, TableView::CellPosition(1, 0));
1189   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1190
1191   // Set the focus to the first actor
1192   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1193   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1194   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1195   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1196   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1197   focusChangedCallback.Reset();
1198
1199   // Send the right key event to move the focus towards right
1200   application.ProcessEvent(rightEvent);
1201   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1202   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1203   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1204   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1205   focusChangedCallback.Reset();
1206
1207   // Send the down key event to move the focus towards down
1208   application.ProcessEvent(downEvent);
1209   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1210   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1211   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1212   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1213   focusChangedCallback.Reset();
1214
1215   // Send the down event to move the focus towards left
1216   application.ProcessEvent(leftEvent);
1217   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1218   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1219   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1220   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1221   focusChangedCallback.Reset();
1222
1223   // Send the up event to move the focus towards up
1224   application.ProcessEvent(upEvent);
1225   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1226   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1227   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1228   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1229   focusChangedCallback.Reset();
1230
1231   // Send the pape up event, but focus should not be moved because page up is not supported by table view
1232   application.ProcessEvent(pageUpEvent);
1233   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1234   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1235   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1236   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1237   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1238   preFocusChangeCallback.Reset();
1239
1240   // Send the pape down event, but focus should not be moved because page down is not supported by table view
1241   application.ProcessEvent(pageDownEvent);
1242   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1243   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1244   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1245   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1246   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1247   preFocusChangeCallback.Reset();
1248
1249   // Clear the focus
1250   manager.ClearFocus();
1251
1252   // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1253   preFocusChangeCallback.Reset();
1254   application.ProcessEvent(pageUpEvent);
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   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1260
1261   // Clear the focus again
1262   manager.ClearFocus();
1263
1264   // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1265   preFocusChangeCallback.Reset();
1266   application.ProcessEvent(pageDownEvent);
1267   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1268   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1269   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1270   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1271   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1272
1273   // Clear the focus again
1274   manager.ClearFocus();
1275
1276   // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1277   preFocusChangeCallback.Reset();
1278   application.ProcessEvent(upEvent);
1279   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1280   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1281   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1282   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1283
1284   // Clear the focus again
1285   manager.ClearFocus();
1286
1287   // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1288   preFocusChangeCallback.Reset();
1289   application.ProcessEvent(downEvent);
1290   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1291   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1292   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1293   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1294
1295   END_TEST;
1296 }
1297
1298 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1299 {
1300   ToolkitTestApplication application;
1301
1302   tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1303
1304   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1305   DALI_TEST_CHECK(manager);
1306
1307   bool                   preFocusChangeSignalVerified = false;
1308   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1309   manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1310
1311   Integration::KeyEvent spaceEvent("space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1312
1313   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1314   // It makes mIsFocusIndicatorEnabled true
1315   application.ProcessEvent(spaceEvent);
1316
1317   // Send the space event
1318   application.ProcessEvent(spaceEvent);
1319   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1320   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1321
1322   // Clear the focus again
1323   manager.ClearFocus();
1324
1325   // Send the space event again for line coverage
1326   preFocusChangeCallback.Reset();
1327   application.ProcessEvent(spaceEvent);
1328   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1329   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1330   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1331   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1332
1333   END_TEST;
1334 }
1335
1336 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1337 {
1338   ToolkitTestApplication application;
1339
1340   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1341
1342   // Register Type
1343   TypeInfo type;
1344   type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1345   DALI_TEST_CHECK(type);
1346   BaseHandle handle = type.CreateInstance();
1347   DALI_TEST_CHECK(handle);
1348
1349   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1350   DALI_TEST_CHECK(manager);
1351
1352   bool                   preFocusChangeSignalVerified = false;
1353   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1354   manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1355
1356   bool                 focusChangedSignalVerified = false;
1357   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1358   manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1359
1360   // Create the first actor and add it to the stage
1361   Control first = Control::New();
1362   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1363   application.GetScene().Add(first);
1364
1365   // Create the second actor and add it to the stage
1366   Control second = Control::New();
1367   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1368   application.GetScene().Add(second);
1369
1370   // Move the focus to the right
1371   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1372
1373   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1374   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1375   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1376   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1377   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1378   preFocusChangeCallback.Reset();
1379
1380   // Check that the focus is set on the first actor
1381   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1382   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1383   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1384   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1385   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1386   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1387   focusChangedCallback.Reset();
1388
1389   // Move the focus towards right
1390   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1391
1392   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1393   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1394   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1395   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1396   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1397   preFocusChangeCallback.Reset();
1398
1399   // Check that the focus is set on the second actor
1400   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1401   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1402   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1403   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1404   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1405   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1406   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1407   focusChangedCallback.Reset();
1408
1409   // Move the focus towards up
1410   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1411
1412   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1413   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1414   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1415   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1416   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1417   preFocusChangeCallback.Reset();
1418   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1419
1420   // Create a 2x2 table view and try to move focus inside it
1421   TableView tableView = TableView::New(2, 2);
1422   application.GetScene().Add(tableView);
1423
1424   // Create the third actor
1425   Control third = Control::New();
1426   third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1427
1428   // Create the fourth actor
1429   Control fourth = Control::New();
1430   fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1431
1432   // Add the four children to table view
1433   tableView.AddChild(first, TableView::CellPosition(0, 0));
1434   tableView.AddChild(second, TableView::CellPosition(0, 1));
1435   tableView.AddChild(third, TableView::CellPosition(1, 0));
1436   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1437
1438   // Set the focus to the first actor
1439   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1440   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1441   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1442   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1443   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1444
1445   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1446   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1447
1448   focusChangedCallback.Reset();
1449
1450   // Move the focus towards right
1451   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1452   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1453   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1454   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1455   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1456   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1457   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1458
1459   focusChangedCallback.Reset();
1460
1461   // Move the focus towards down
1462   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1463   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1464   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1465   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1466   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1467
1468   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1469   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1470   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1471   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1472
1473   focusChangedCallback.Reset();
1474
1475   // Move the focus towards left
1476   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1477   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1478   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1479   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1480   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1481
1482   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1483   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1484   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1485   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1486
1487   focusChangedCallback.Reset();
1488
1489   // Move the focus towards up
1490   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1491   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1492   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1493   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1494   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1495   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1496   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1497   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1498   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1499   focusChangedCallback.Reset();
1500
1501   // Move the focus towards left. The focus move will fail as no way to move it upwards
1502   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1503   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1504   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1505   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1506   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1507   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1508   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1509   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1510   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1511   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1512
1513   preFocusChangeCallback.Reset();
1514   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1515
1516   // Enable the loop
1517   manager.SetFocusGroupLoop(true);
1518   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1519
1520   // Move the focus towards left again. The focus should move to the fourth actor.
1521   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1522   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1523   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1524   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1525   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1526
1527   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1528   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1529   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1530   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1531
1532   focusChangedCallback.Reset();
1533
1534   // Clear the focus
1535   manager.ClearFocus();
1536   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1537   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1538   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1539   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1540
1541   END_TEST;
1542 }
1543
1544 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1545 {
1546   ToolkitTestApplication application;
1547
1548   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");
1549
1550   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1551   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1552
1553   Actor actor = Actor::New();
1554   actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1555
1556   tet_infoline("Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager");
1557   manager.SetCurrentFocusActor(actor);
1558   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1559
1560   tet_infoline("Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager");
1561   application.GetScene().Add(actor);
1562   manager.SetCurrentFocusActor(actor);
1563   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == actor);
1564
1565   tet_infoline("Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager");
1566   actor.Unparent();
1567   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1568
1569   END_TEST;
1570 }
1571
1572 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1573 {
1574   ToolkitTestApplication application;
1575
1576   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");
1577
1578   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1579   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1580
1581   Actor actor = Actor::New();
1582   actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1583   application.GetScene().Add(actor);
1584   manager.SetCurrentFocusActor(actor);
1585
1586   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1587   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1588   Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1589   application.ProcessEvent(rightEvent);
1590
1591   Actor indicatorActor = manager.GetFocusIndicatorActor();
1592
1593   tet_infoline("Indicator is added to focused actor");
1594   DALI_TEST_CHECK(actor == indicatorActor.GetParent());
1595
1596   Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1597   DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager));
1598
1599   tet_infoline("Indicator is removed from focused actor because mUseFocusIndicator is false");
1600   DALI_TEST_CHECK(!indicatorActor.GetParent());
1601
1602   END_TEST;
1603 }
1604
1605 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1606 {
1607   ToolkitTestApplication application;
1608
1609   tet_infoline("Ensure Window can't receive KeyEvent when Control already consumed it");
1610   Dali::Integration::Scene scene = application.GetScene();
1611
1612   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1613   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1614
1615   // Create the first actor and add it to the stage
1616   Control control = Control::New();
1617   control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1618   scene.Add(control);
1619
1620   KeyEventCallback controlCallback(true);
1621   control.KeyEventSignal().Connect(&controlCallback, &KeyEventCallback::Callback);
1622
1623   KeyEventCallback sceneCallback(false);
1624   scene.KeyEventSignal().Connect(&sceneCallback, &KeyEventCallback::Callback);
1625
1626   manager.SetCurrentFocusActor(control);
1627
1628   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1629   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1630   Integration::KeyEvent event1("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1631   application.ProcessEvent(event1);
1632
1633   DALI_TEST_CHECK(controlCallback.mIsCalled);
1634   DALI_TEST_CHECK(!sceneCallback.mIsCalled);
1635
1636   END_TEST;
1637 }
1638
1639 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1640 {
1641   ToolkitTestApplication application;
1642
1643   tet_infoline("Ensure Memory focus actors for each window ");
1644   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1645   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1646
1647   Window firstWindow = Window::New(PositionSize(0, 0, 300, 500), "", false);
1648   DALI_TEST_CHECK(firstWindow);
1649   Control first = Control::New();
1650   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1651   firstWindow.Add(first);
1652
1653   Window secondWindow = Window::New(PositionSize(0, 0, 400, 600), "", false);
1654   DALI_TEST_CHECK(secondWindow);
1655   Control second = Control::New();
1656   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1657   secondWindow.Add(second);
1658
1659   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1660   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1661
1662   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1663   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1664   firstWindow.Raise();
1665   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1666
1667   secondWindow.Remove(second);
1668   secondWindow.Raise();
1669   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1670
1671   secondWindow.Reset();
1672   END_TEST;
1673 }
1674
1675 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1676 {
1677   ToolkitTestApplication application;
1678
1679   tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1680
1681   // Register Type
1682   TypeInfo type;
1683   type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1684   DALI_TEST_CHECK(type);
1685   BaseHandle handle = type.CreateInstance();
1686   DALI_TEST_CHECK(handle);
1687
1688   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1689   DALI_TEST_CHECK(manager);
1690
1691   bool                 focusChangedSignalVerified = false;
1692   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1693   manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1694
1695   PushButton button1 = PushButton::New();
1696   PushButton button2 = PushButton::New();
1697   PushButton button3 = PushButton::New();
1698   PushButton button4 = PushButton::New();
1699   PushButton button5 = PushButton::New();
1700
1701   button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1702   button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1703   button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1704   button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1705   button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1706
1707   button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1708   button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1709   button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1710   button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1711   button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1712
1713   application.GetScene().Add(button1);
1714   application.GetScene().Add(button2);
1715   application.GetScene().Add(button3);
1716   button5.Add(button4);
1717   application.GetScene().Add(button5);
1718
1719   // set position
1720   // button1 -- button2
1721   //   |           |
1722   //   |    button5|
1723   // button3 -- button4
1724   button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1725   button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1726   button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1727   button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1728   button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1729
1730   // flush the queue and render once
1731   application.SendNotification();
1732   application.Render();
1733
1734   // Set the focus to the button1
1735   // [button1] -- button2
1736   //   |           |
1737   //   |    button5|
1738   // button3 -- button4
1739   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1740   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1741   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1742   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1743   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1744   focusChangedCallback.Reset();
1745
1746   // without set the navigation properties, but we can focus move
1747   // enable the default algorithm
1748   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1749   DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1750
1751   // Move the focus towards right
1752   // button1 -- [button2]
1753   //   |           |
1754   //   |    button5|
1755   // button3 -- button4
1756   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1757
1758   // Confirm whether focus is moved to button2
1759   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1760   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1761   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1762   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1763   focusChangedCallback.Reset();
1764
1765   // Move the focus towards down
1766   // button1 -- button2
1767   //   |           |
1768   //   |  [button5]|
1769   // button3 -- button4
1770   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1771
1772   // Confirm whether focus is moved to button5
1773   DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1774   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1775   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1776   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1777   focusChangedCallback.Reset();
1778
1779   // Move the focus towards right
1780   // button1 -- button2
1781   //   |           |
1782   //   |    button5|
1783   // button3 -- [button4]
1784   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1785
1786   // Confirm whether focus is moved to button4
1787   DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1788   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1789   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1790   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1791   focusChangedCallback.Reset();
1792
1793   // Move the focus towards left
1794   // button1 -- button2
1795   //   |           |
1796   //   |  [button5]|
1797   // button3 -- button4
1798   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1799
1800   // Confirm whether focus is moved to button5
1801   DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1802   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1803   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1804   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1805   focusChangedCallback.Reset();
1806
1807   // Move the focus towards left
1808   // button1 -- button2
1809   //   |           |
1810   //   |    button5|
1811   //[button3] -- button4
1812   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1813
1814   // Confirm whether focus is moved to button3
1815   DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1816   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1817   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1818   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1819   focusChangedCallback.Reset();
1820
1821   // Move the focus towards right
1822   // button1 -- button2
1823   //   |           |
1824   //   |  [button5]|
1825   // button3 -- button4
1826   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1827
1828   // Confirm whether focus is moved to button5
1829   DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1830   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1831   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1832   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1833   focusChangedCallback.Reset();
1834
1835   // Move the focus towards left
1836   // button1 -- button2
1837   //   |           |
1838   //   |    button5|
1839   //[button3] -- button4
1840   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1841
1842   // Confirm whether focus is moved to button3
1843   DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1844   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1845   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1846   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1847   focusChangedCallback.Reset();
1848
1849   // Move the focus towards up
1850   //[button1]-- button2
1851   //   |           |
1852   //   |    button5|
1853   // button3 -- button4
1854   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1855
1856   // Confirm whether focus is moved to button1
1857   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1858   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1859   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1860   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1861   focusChangedCallback.Reset();
1862
1863   // Move the focus towards left. The focus move will fail as no way to move it upwards
1864   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1865
1866   // Move the focus toward page up/down. The focus move will fail as invalid direction.
1867   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1868   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1869   focusChangedCallback.Reset();
1870
1871   END_TEST;
1872 }
1873
1874 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode(void)
1875 {
1876   ToolkitTestApplication application;
1877
1878   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode");
1879
1880   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1881   DALI_TEST_CHECK(manager);
1882
1883   // Create the first actor and add it to the stage
1884   Actor first = Actor::New();
1885   first.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1886   first.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1887   first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1888   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1889   first.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1890   application.GetScene().Add(first);
1891
1892   // Create the second actor and add it to the stage
1893   Actor second = Actor::New();
1894   second.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1895   second.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1896   second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1897   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1898   application.GetScene().Add(second);
1899
1900   // flush the queue and render once
1901   application.SendNotification();
1902   application.Render();
1903
1904   // Check that no actor is being focused yet.
1905   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1906
1907   // Check that it will fail to set focus on an invalid actor
1908   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
1909
1910   Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1911   Dali::Integration::Point      pointDown1;
1912   pointDown1.SetState(PointState::DOWN);
1913   pointDown1.SetDeviceId(1);
1914   // touch first actor
1915   pointDown1.SetScreenPosition(Vector2(10.0f, 10.0f));
1916   event1.AddPoint(pointDown1);
1917   application.ProcessEvent(event1);
1918
1919   // flush the queue and render once
1920   application.SendNotification();
1921   application.Render();
1922
1923   // Check that the focus is successfully to the first actor
1924   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1925
1926   Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1927   Dali::Integration::Point      pointDown2;
1928   pointDown2.SetState(PointState::DOWN);
1929   pointDown2.SetDeviceId(1);
1930   // touch second actor
1931   pointDown2.SetScreenPosition(Vector2(110.0f, 10.0f));
1932   event2.AddPoint(pointDown2);
1933   application.ProcessEvent(event2);
1934
1935   // flush the queue and render once
1936   application.SendNotification();
1937   application.Render();
1938
1939   // Since no focus has been moved, the current focus actor is the same.
1940   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1941
1942   // Make the second actor focusableInTouchMode
1943   second.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1944
1945   // touch second actor
1946   application.ProcessEvent(event2);
1947
1948   // flush the queue and render once
1949   application.SendNotification();
1950   application.Render();
1951
1952   // Check that the focus is successfully to the second actor
1953   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1954
1955   END_TEST;
1956 }
1957
1958 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1959 {
1960   ToolkitTestApplication application;
1961
1962   tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1963
1964   // Register Type
1965   TypeInfo type;
1966   type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1967   DALI_TEST_CHECK(type);
1968   BaseHandle handle = type.CreateInstance();
1969   DALI_TEST_CHECK(handle);
1970
1971   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1972   DALI_TEST_CHECK(manager);
1973
1974   bool                 focusChangedSignalVerified = false;
1975   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1976   manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1977
1978   PushButton button1 = PushButton::New();
1979   PushButton button2 = PushButton::New();
1980
1981   button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1982   button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1983
1984   button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1985   button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1986
1987   application.GetScene().Add(button1);
1988   application.GetScene().Add(button2);
1989
1990   // set position
1991   // button1 -- button2
1992   button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1993   button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1994   button1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1995   button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1996
1997   // flush the queue and render once
1998   application.SendNotification();
1999   application.Render();
2000
2001   // Set the focus to the button1
2002   // [button1] -- button2
2003   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
2004   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
2005   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2006   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2007   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2008   focusChangedCallback.Reset();
2009
2010   // without set the navigation properties, but we can focus move
2011   // enable the default algorithm
2012   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2013   DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2014
2015   // Move the focus towards right
2016   // button1 -- [button2]
2017   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2018
2019   // Confirm whether focus is moved to button2
2020   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2021   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2022   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
2023   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
2024   focusChangedCallback.Reset();
2025
2026   // disable the default algorithm
2027   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
2028   DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2029
2030   // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
2031   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
2032
2033   // enable the default algorithm
2034   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2035   DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2036
2037   // Move the focus towards left, The focus move will success because the default algorithm is enabled.
2038   // [button1] -- button2
2039   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2040   // Confirm whether focus is moved to button1
2041   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2042   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2043   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2044   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2045   focusChangedCallback.Reset();
2046
2047   // Clears focus.
2048   manager.ClearFocus();
2049   // There is no actor focused.
2050   // button1 -- button2
2051   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2052
2053   // Move the focus towards right, The focus is on the actor closest to the top left of the window.
2054   // [button1] -- button2
2055   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2056
2057   // Confirm whether focus is moved to button1
2058   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2059   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2060   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2061   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2062   focusChangedCallback.Reset();
2063
2064
2065   END_TEST;
2066 }
2067
2068 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2069 {
2070   ToolkitTestApplication application;
2071
2072   tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2073
2074   KeyboardFocusManager manager = KeyboardFocusManager::Get();
2075   DALI_TEST_CHECK(manager);
2076
2077   // Create the first actor and add it to the stage
2078   Actor first = Actor::New();
2079   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2080   application.GetScene().Add(first);
2081
2082   // Create the second actor and add it to the first actor.
2083   Actor second = Actor::New();
2084   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2085   first.Add(second);
2086
2087   // Check that no actor is being focused yet.
2088   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2089
2090   // Check that the focus is set on the first actor
2091   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2092   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2093
2094   // Set KeyboardFocusableChildren false.
2095   first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2096
2097   // Check that it will fail to set focus on the second actor as it's not focusable
2098   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2099   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2100
2101   // Set KeyboardFocusableChildren true.
2102   first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2103
2104   // Check that the focus is set on the second actor
2105   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2106   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2107
2108   END_TEST;
2109 }
2110
2111 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2112 {
2113   ToolkitTestApplication application;
2114
2115   tet_infoline("UtcDaliKeyboardFocusManagerCheckWheelEvent");
2116   Dali::Integration::Scene scene = application.GetScene();
2117
2118   KeyboardFocusManager manager = KeyboardFocusManager::Get();
2119   DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
2120
2121   // Create the first actor and add it to the stage
2122   Actor parent = Actor::New();
2123   parent.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2124
2125   Actor child = Actor::New();
2126   child.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2127
2128   parent.Add(child);
2129   scene.Add(parent);
2130
2131   WheelEventCallback childCallback(false);
2132   child.WheelEventSignal().Connect(&childCallback, &WheelEventCallback::Callback);
2133
2134   WheelEventCallback parentCallback(true);
2135   parent.WheelEventSignal().Connect(&parentCallback, &WheelEventCallback::Callback);
2136
2137   WheelEventCallback sceneCallback(false);
2138   scene.WheelEventSignal().Connect(&sceneCallback, &WheelEventCallback::Callback);
2139
2140   manager.SetCurrentFocusActor(child);
2141
2142   // Emit custom wheel event is comming to KeyboardFocusManager
2143   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2144   application.ProcessEvent(event);
2145
2146   DALI_TEST_CHECK(childCallback.mIsCalled);
2147   DALI_TEST_CHECK(parentCallback.mIsCalled);
2148   DALI_TEST_CHECK(!sceneCallback.mIsCalled);
2149
2150   END_TEST;
2151 }
2152
2153 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByCustomWheelEvent(void)
2154 {
2155   ToolkitTestApplication application;
2156
2157   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByCustomWheelEvent");
2158   Dali::Integration::Scene scene = application.GetScene();
2159
2160   KeyboardFocusManager manager = KeyboardFocusManager::Get();
2161   DALI_TEST_CHECK(manager);
2162
2163   bool focusChangedSignalVerified = false;
2164   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
2165   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
2166
2167   Integration::WheelEvent clockwiseEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2168   Integration::WheelEvent counterClockwiseEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1100u);
2169
2170   // Create the first button
2171   PushButton first = PushButton::New();
2172   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2173   scene.Add(first);
2174
2175   // Create the second button
2176   PushButton second = PushButton::New();
2177   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2178   scene.Add(second);
2179
2180    // set the navigation properties
2181   first.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)second.GetProperty< int >( Actor::Property::ID )));
2182   second.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)first.GetProperty< int >( Actor::Property::ID )));
2183
2184   // Set the focus to the first actor
2185   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2186   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2187   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2188   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2189   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
2190   focusChangedCallback.Reset();
2191
2192   // Send the clockwise wheel event to move the focus towards clockwise
2193   application.ProcessEvent(clockwiseEvent);
2194   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2195   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2196   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
2197   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
2198   focusChangedCallback.Reset();
2199
2200   // Send the counter clockwise wheel event to move the focus towards count clockwise
2201   application.ProcessEvent(counterClockwiseEvent);
2202   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2203   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2204   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
2205   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
2206   focusChangedCallback.Reset();
2207
2208   // Clear the focus
2209   manager.ClearFocus();
2210
2211   END_TEST;
2212 }
2213
2214 int UtcDaliKeyboardFocusManagerWithUserInteractionEnabled(void)
2215 {
2216   ToolkitTestApplication application;
2217
2218   tet_infoline(" UtcDaliKeyboardFocusManagerWithUserInteractionEnabled");
2219
2220   KeyboardFocusManager manager = KeyboardFocusManager::Get();
2221   DALI_TEST_CHECK(manager);
2222
2223   // Create the first actor and add it to the stage
2224   Actor first = Actor::New();
2225   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2226   application.GetScene().Add(first);
2227
2228   // Create the second actor and add it to the first actor.
2229   Actor second = Actor::New();
2230   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2231   first.Add(second);
2232
2233   // Check that no actor is being focused yet.
2234   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2235
2236   // Check that the focus is set on the first actor
2237   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2238   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2239
2240   // Set USER_INTERACTION_ENABLED false.
2241   second.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
2242
2243   // Check that it will fail to set focus on the second actor as it's not userInteractionEnabled
2244   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2245   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2246
2247   // Set KeyboardFocusableChildren true.
2248   second.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, true);
2249
2250   // Check that the focus is set on the second actor
2251   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2252   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2253
2254   END_TEST;
2255 }