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