Replace some Dali::Actor public APIs with new properties
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-KeyboardFocusManager.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43
44 namespace
45 {
46
47 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
48
49 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
50 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
51 {
52 public:
53   CustomAlgorithm(bool& interfaceVerified)
54   : mInterfaceVerified(interfaceVerified),
55     mCurrentFocusedActor(),
56     mProposedActorToFocus(),
57     mDirection(Control::KeyboardFocus::LEFT)
58   {
59   }
60
61   Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
62   {
63     tet_infoline("Verifying CustomAlgorithm()");
64
65     mInterfaceVerified = true;
66
67     mCurrentFocusedActor = currentFocusedActor;
68     mProposedActorToFocus = proposedActorToFocus;
69     mDirection = direction;
70
71     return mProposedActorToFocus;
72   }
73
74   void Reset()
75   {
76     mInterfaceVerified = false;
77     mCurrentFocusedActor = Actor();
78     mProposedActorToFocus = Actor();
79     mDirection = Control::KeyboardFocus::LEFT;
80   }
81
82   bool& mInterfaceVerified;
83   Actor mCurrentFocusedActor;
84   Actor mProposedActorToFocus;
85   Control::KeyboardFocus::Direction mDirection;
86 };
87
88 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
89 class PreFocusChangeCallback : public Dali::ConnectionTracker
90 {
91 public:
92   PreFocusChangeCallback(bool& signalReceived)
93   : mSignalVerified(signalReceived),
94     mCurrentFocusedActor(),
95     mProposedActorToFocus(),
96     mDirection(Control::KeyboardFocus::LEFT)
97   {
98   }
99
100   Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
101   {
102     tet_infoline("Verifying PreFocusChangeCallback()");
103
104     mSignalVerified = true;
105
106     mCurrentFocusedActor = currentFocusedActor;
107     mProposedActorToFocus = proposedActorToFocus;
108     mDirection = direction;
109
110     return mProposedActorToFocus;
111   }
112
113   void Reset()
114   {
115     mSignalVerified = false;
116     mCurrentFocusedActor = Actor();
117     mProposedActorToFocus = Actor();
118     mDirection = Control::KeyboardFocus::LEFT;
119   }
120
121   bool& mSignalVerified;
122   Actor mCurrentFocusedActor;
123   Actor mProposedActorToFocus;
124   Control::KeyboardFocus::Direction mDirection;
125 };
126
127 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
128 class FocusChangedCallback : public Dali::ConnectionTracker
129 {
130 public:
131   FocusChangedCallback(bool& signalReceived)
132   : mSignalVerified(signalReceived),
133     mOriginalFocusedActor(),
134     mCurrentFocusedActor()
135   {
136   }
137
138   void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
139   {
140     tet_infoline("Verifying FocusChangedCallback()");
141
142     if(originalFocusedActor == mCurrentFocusedActor)
143     {
144       mSignalVerified = true;
145     }
146
147     mOriginalFocusedActor = originalFocusedActor;
148     mCurrentFocusedActor = currentFocusedActor;
149   }
150
151   void Reset()
152   {
153     mSignalVerified = false;
154   }
155
156   bool& mSignalVerified;
157   Actor mOriginalFocusedActor;
158   Actor mCurrentFocusedActor;
159 };
160
161 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
162 class FocusGroupChangedCallback : public Dali::ConnectionTracker
163 {
164 public:
165   FocusGroupChangedCallback(bool& signalReceived)
166   : mSignalVerified(signalReceived),
167     mCurrentFocusedActor(),
168     mForward(true)
169   {
170   }
171
172   void Callback(Actor currentFocusedActor, bool forward)
173   {
174     tet_infoline("Verifying FocusGroupChangedCallback()");
175
176     mSignalVerified = true;
177
178     mCurrentFocusedActor = currentFocusedActor;
179     mForward = forward;
180   }
181
182   void Reset()
183   {
184     mSignalVerified = false;
185   }
186
187   bool& mSignalVerified;
188   Actor mCurrentFocusedActor;
189   bool mForward;
190 };
191
192 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
193 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
194 {
195 public:
196   FocusedActorActivatedCallback(bool& signalReceived)
197   : mSignalVerified(signalReceived),
198     mActivatedActor()
199   {
200   }
201
202   void Callback(Actor activatedActor)
203   {
204     tet_infoline("Verifying FocusedActorActivatedCallback()");
205
206     mSignalVerified = true;
207
208     mActivatedActor = activatedActor;
209   }
210
211   void Reset()
212   {
213     mSignalVerified = false;
214   }
215
216   bool& mSignalVerified;
217   Actor mActivatedActor;
218 };
219
220 class KeyEventCallback : public Dali::ConnectionTracker
221 {
222 public:
223   /**
224    * Constructor
225    * @param[in]  returnValue  Set return value of KeyEvent callback.
226    * */
227   KeyEventCallback( bool consumed )
228   : mConsumed( consumed ),
229     mIsCalled( false )
230   {
231   }
232
233   bool Callback( Control control, const KeyEvent& keyEvent )
234   {
235     mIsCalled = true;
236     return mConsumed;
237   }
238
239   void Callback( const KeyEvent& keyEvent )
240   {
241     mIsCalled = true;
242   }
243
244   bool mConsumed;
245   bool mIsCalled;
246 };
247
248 // Used to connect to signals via the ConnectSignal Handle method
249 struct CallbackFunctor
250 {
251   CallbackFunctor()
252   {
253   }
254
255   void operator()()
256   {
257   }
258 };
259
260 } // namespace
261
262 int UtcDaliKeyboardFocusManagerGet(void)
263 {
264   ToolkitTestApplication application;
265
266   tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
267
268   // Register Type
269   TypeInfo type;
270   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
271   DALI_TEST_CHECK( type );
272   BaseHandle handle = type.CreateInstance();
273   DALI_TEST_CHECK( handle );
274
275   KeyboardFocusManager manager;
276
277   manager = KeyboardFocusManager::Get();
278   DALI_TEST_CHECK(manager);
279
280   KeyboardFocusManager newManager = KeyboardFocusManager::Get();
281   DALI_TEST_CHECK(newManager);
282
283   // Check that focus manager is a singleton
284   DALI_TEST_CHECK(manager == newManager);
285   END_TEST;
286 }
287
288 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
289 {
290   ToolkitTestApplication application;
291
292   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
293
294   KeyboardFocusManager manager = KeyboardFocusManager::Get();
295   DALI_TEST_CHECK(manager);
296
297   // Create the first actor and add it to the stage
298   Actor first = Actor::New();
299   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
300   Stage::GetCurrent().Add(first);
301
302   // Create the second actor and add it to the stage
303   Actor second = Actor::New();
304   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
305   Stage::GetCurrent().Add(second);
306
307   // Create the third actor but don't add it to the stage
308   Actor third = Actor::New();
309
310   // Check that no actor is being focused yet.
311   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
312
313   // Check that it will fail to set focus on an invalid actor
314   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
315
316   // Check that the focus is set on the first actor
317   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
318   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
319
320   // Check that the focus is set on the second actor
321   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
322   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
323
324   // Check that it will fail to set focus on the third actor as it's not in the stage
325   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
326   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
327
328   // Add the third actor to the stage
329   Stage::GetCurrent().Add(third);
330
331   // Check that it will fail to set focus on the third actor as it's not focusable
332   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
333   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
334
335   // Make the third actor focusable
336   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
337
338   // Check that the focus is successfully moved to the third actor
339   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
340   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
341   END_TEST;
342 }
343
344 int UtcDaliKeyboardFocusManagerMoveFocus(void)
345 {
346   ToolkitTestApplication application;
347
348   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
349
350   // Register Type
351   TypeInfo type;
352   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
353   DALI_TEST_CHECK( type );
354   BaseHandle handle = type.CreateInstance();
355   DALI_TEST_CHECK( handle );
356
357   KeyboardFocusManager manager = KeyboardFocusManager::Get();
358   DALI_TEST_CHECK(manager);
359
360   bool preFocusChangeSignalVerified = false;
361   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
362   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
363
364   bool focusChangedSignalVerified = false;
365   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
366   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
367
368   // Create the first actor and add it to the stage
369   Actor first = Actor::New();
370   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
371   Stage::GetCurrent().Add(first);
372
373   // Create the second actor and add it to the stage
374   Actor second = Actor::New();
375   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
376   Stage::GetCurrent().Add(second);
377
378   // Move the focus to the right
379   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
380
381   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
382   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
383   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
384   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
385   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
386   preFocusChangeCallback.Reset();
387
388   // Check that the focus is set on the first actor
389   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
390   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
391   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
392   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
393   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
394   focusChangedCallback.Reset();
395
396   // Move the focus towards right
397   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
398
399   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
400   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
401   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
402   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
403   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
404   preFocusChangeCallback.Reset();
405
406   // Check that the focus is set on the second actor
407   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
408   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
409   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
410   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
411   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
412   focusChangedCallback.Reset();
413
414   // Move the focus towards up
415   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
416
417   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
418   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
419   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
420   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
421   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
422   preFocusChangeCallback.Reset();
423   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
424
425   // Create a 2x2 table view and try to move focus inside it
426   TableView tableView = TableView::New( 2, 2 );
427   Stage::GetCurrent().Add(tableView);
428
429   // Create the third actor
430   Actor third = Actor::New();
431   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
432
433   // Create the fourth actor
434   Actor fourth = Actor::New();
435   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
436
437   // Add the four children to table view
438   tableView.AddChild(first, TableView::CellPosition(0, 0));
439   tableView.AddChild(second, TableView::CellPosition(0, 1));
440   tableView.AddChild(third, TableView::CellPosition(1, 0));
441   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
442
443   // Set the focus to the first actor
444   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
445   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
446   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
447   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
448   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
449   focusChangedCallback.Reset();
450
451   // Move the focus towards right
452   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
453   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
454   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
455   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
456   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
457   focusChangedCallback.Reset();
458
459   // Move the focus towards down
460   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
461   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
462   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
463   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
464   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
465   focusChangedCallback.Reset();
466
467   // Move the focus towards left
468   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
469   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
470   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
471   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
472   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
473   focusChangedCallback.Reset();
474
475   // Move the focus towards up
476   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
477   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
478   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
479   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
480   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
481   focusChangedCallback.Reset();
482
483   // Move the focus towards left. The focus move will fail as no way to move it upwards
484   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
485   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
486   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
487   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
488   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
489   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
490   preFocusChangeCallback.Reset();
491   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
492
493   // Enable the loop
494   manager.SetFocusGroupLoop(true);
495   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
496
497   // Move the focus towards left again. The focus should move to the fourth actor.
498   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
499   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
500   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
501   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
502   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
503   focusChangedCallback.Reset();
504   END_TEST;
505 }
506
507 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
508 {
509   ToolkitTestApplication application;
510
511   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
512
513   // Register Type
514   TypeInfo type;
515   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
516   DALI_TEST_CHECK( type );
517   BaseHandle handle = type.CreateInstance();
518   DALI_TEST_CHECK( handle );
519
520   KeyboardFocusManager manager = KeyboardFocusManager::Get();
521   DALI_TEST_CHECK(manager);
522
523   bool preFocusChangeSignalVerified = false;
524   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
525   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
526
527   bool focusChangedSignalVerified = false;
528   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
529   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
530
531   // Create the first actor and add it to the stage
532   Actor first = Actor::New();
533   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
534   Stage::GetCurrent().Add(first);
535
536   // Create the second actor and add it to the stage
537   Actor second = Actor::New();
538   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
539   Stage::GetCurrent().Add(second);
540
541   // Move the focus to the right
542   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
543
544   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
545   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
546   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
547   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
548   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
549   preFocusChangeCallback.Reset();
550
551   bool customAlgorithmInterfaceVerified = false;
552   CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
553   Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
554
555   // Move the focus towards right
556   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
557
558   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
559   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
560   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
561   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
562   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
563   customAlgorithm.Reset();
564
565   // Check that the focus is set on the first actor
566   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
567   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
568   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
569   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
570   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
571   focusChangedCallback.Reset();
572
573   // Move the focus towards right
574   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
575
576   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
577   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
578   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
579   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
580   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
581   customAlgorithm.Reset();
582
583   // Check that the focus is set on the second actor
584   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
585   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
586   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
587   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
588   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
589   focusChangedCallback.Reset();
590
591   // Move the focus towards up
592   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
593
594   // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
595   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
596   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
597   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
598   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
599   customAlgorithm.Reset();
600   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
601
602   END_TEST;
603 }
604 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
605 {
606   ToolkitTestApplication application;
607
608   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
609
610   // Register Type
611   TypeInfo type;
612   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
613   DALI_TEST_CHECK( type );
614   BaseHandle handle = type.CreateInstance();
615   DALI_TEST_CHECK( handle );
616
617   KeyboardFocusManager manager = KeyboardFocusManager::Get();
618   DALI_TEST_CHECK(manager);
619
620   bool focusChangedSignalVerified = false;
621   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
622   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
623
624   PushButton button1 = PushButton::New();
625   PushButton button2 = PushButton::New();
626   button1.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
627   button2.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
628   Stage::GetCurrent().Add(button1);
629   Stage::GetCurrent().Add(button2);
630
631   // Set the focus to the button1
632   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
633   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
634   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
635   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
636   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
637   focusChangedCallback.Reset();
638
639   // set the navigation properties of button1
640   button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
641   button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
642   button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
643   button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
644
645   // set the navigation properties of button2
646   button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
647   button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
648   button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
649   button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
650
651   // Move the focus towards left
652   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
653
654   // Confirm whether focus is moved to button2
655   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
656   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
657   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
658   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
659   focusChangedCallback.Reset();
660
661   // Move the focus towards right
662   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
663
664   // Confirm whether focus is moved to button1
665   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
666   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
667   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
668   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
669   focusChangedCallback.Reset();
670
671   // Move the focus towards up
672   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
673
674   // Confirm whether focus is moved to button2
675   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
676   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
677   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
678   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
679   focusChangedCallback.Reset();
680
681   // Move the focus towards down
682   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
683
684   // Confirm whether focus is moved to button1
685   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
686   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
687   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
688   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
689   focusChangedCallback.Reset();
690
691   // Create a 1x1 table view and try to move focus inside it
692   TableView tableView = TableView::New( 1, 1 );
693   Stage::GetCurrent().Add(tableView);
694
695   PushButton button = PushButton::New();
696   button.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
697   tableView.AddChild(button, TableView::CellPosition(0, 0));
698
699   // set the navigation properties of button3
700   button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
701
702   // Set the focus to the button
703   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
704   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
705   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
706   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
707   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
708   focusChangedCallback.Reset();
709
710   // Move the focus towards left
711   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
712
713   // Confirm whether focus is moved to button1
714   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
715   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
716   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
717   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
718   focusChangedCallback.Reset();
719
720   END_TEST;
721 }
722
723 int UtcDaliKeyboardFocusManagerClearFocus(void)
724 {
725   ToolkitTestApplication application;
726
727   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
728
729   KeyboardFocusManager manager = KeyboardFocusManager::Get();
730   DALI_TEST_CHECK(manager);
731
732   // Create the first actor and add it to the stage
733   Actor first = Actor::New();
734   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
735   Stage::GetCurrent().Add(first);
736
737   // Create the second actor and add it to the stage
738   Actor second = Actor::New();
739   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
740   Stage::GetCurrent().Add(second);
741
742   // Check that the focus is set on the first actor
743   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
744   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
745
746   // Check that the focus is set on the second actor
747   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
748   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
749
750   // Clear the focus
751   manager.ClearFocus();
752
753   // Check that no actor is being focused now.
754   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
755   END_TEST;
756 }
757
758 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
759 {
760   ToolkitTestApplication application;
761
762   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
763
764   KeyboardFocusManager manager = KeyboardFocusManager::Get();
765   DALI_TEST_CHECK(manager);
766
767   // Check that the focus movement is not looped within the same focus group by default
768   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
769
770   // Enable the loop
771   manager.SetFocusGroupLoop(true);
772   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
773   END_TEST;
774 }
775
776 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
777 {
778   ToolkitTestApplication application;
779
780   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
781
782   KeyboardFocusManager manager = KeyboardFocusManager::Get();
783   DALI_TEST_CHECK(manager);
784
785   // Create an actor and check that it is not a focus group by default
786   Actor actor = Actor::New();
787   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
788
789   // Set the actor as focus group
790   manager.SetAsFocusGroup(actor, true);
791
792   // flush the queue and render once
793   application.SendNotification();
794   application.Render();
795
796   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
797
798   // Set the actor not as focus group
799   manager.SetAsFocusGroup(actor, false);
800
801   // flush the queue and render once
802   application.SendNotification();
803   application.Render();
804
805   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
806   END_TEST;
807 }
808
809 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
810 {
811   ToolkitTestApplication application;
812
813   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
814
815   KeyboardFocusManager manager = KeyboardFocusManager::Get();
816   DALI_TEST_CHECK(manager);
817
818   // Create an actor with two child actors and add it to the stage
819   Actor parent = Actor::New();
820   Actor child = Actor::New();
821   parent.Add(child);
822   Stage::GetCurrent().Add(parent);
823
824   // Create three actors and add them as the children of the first child actor
825   Actor grandChild = Actor::New();
826   child.Add(grandChild);
827
828   // Set the parent and the first child actor as focus groups
829   manager.SetAsFocusGroup(parent, true);
830
831   // flush the queue and render once
832   application.SendNotification();
833   application.Render();
834
835   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
836
837   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
838   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
839
840   manager.SetAsFocusGroup(child, true);
841
842   // flush the queue and render once
843   application.SendNotification();
844   application.Render();
845
846   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
847
848   // The focus group should be the child, As it is the immediate parent which is also a focus group.
849   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
850
851   manager.SetAsFocusGroup(grandChild, true);
852
853   // flush the queue and render once
854   application.SendNotification();
855   application.Render();
856
857   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
858
859   // The current focus group should be itself, As it is also a focus group.
860   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
861   END_TEST;
862 }
863
864 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
865 {
866   ToolkitTestApplication application;
867
868   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
869
870   KeyboardFocusManager manager = KeyboardFocusManager::Get();
871   DALI_TEST_CHECK(manager);
872
873   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
874   DALI_TEST_CHECK(defaultFocusIndicatorActor);
875
876   Actor newFocusIndicatorActor = Actor::New();
877   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
878   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
879   END_TEST;
880 }
881
882
883 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
884 {
885   ToolkitTestApplication application;
886
887   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
888
889   KeyboardFocusManager manager = KeyboardFocusManager::Get();
890   DALI_TEST_CHECK(manager);
891
892   bool focusedActorActivatedSignalVerified = false;
893   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
894   manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
895
896   Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
897
898   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
899   // It makes mIsFocusIndicatorEnabled true
900   application.ProcessEvent(returnEvent);
901
902   // Create the first button and add it to the stage
903   PushButton firstPushButton = PushButton::New();
904   firstPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
905   Stage::GetCurrent().Add(firstPushButton);
906
907   // Create the second button and add it to the stage
908   PushButton secondPushButton = PushButton::New();
909   secondPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
910   Stage::GetCurrent().Add(secondPushButton);
911
912   // Check that the focus is set on the first button
913   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
914   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
915
916   // Send the return event to activate the first button
917   application.ProcessEvent(returnEvent);
918   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
919   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
920   focusedActorActivatedCallback.Reset();
921
922   // Check that the focus is set on the second button
923   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
924   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
925
926   // Send the return event again to activate the second button
927   application.ProcessEvent(returnEvent);
928   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
929   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
930   focusedActorActivatedCallback.Reset();
931   END_TEST;
932 }
933
934 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
935 {
936   ToolkitTestApplication application;
937
938   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
939
940   // Register Type
941   TypeInfo type;
942   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
943   DALI_TEST_CHECK( type );
944   BaseHandle handle = type.CreateInstance();
945   DALI_TEST_CHECK( handle );
946
947   KeyboardFocusManager manager = KeyboardFocusManager::Get();
948   DALI_TEST_CHECK(manager);
949
950   bool focusGroupChangedSignalVerified = false;
951   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
952   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
953
954   Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
955   Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
956
957   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
958   // It makes mIsFocusIndicatorEnabled true
959   application.ProcessEvent(tabEvent);
960
961   // Send the tab event to change focus group in the forward direction
962   application.ProcessEvent(tabEvent);
963   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
964   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
965   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
966   focusGroupChangedCallback.Reset();
967
968   // Send the shift tab event to change focus group in the backward direction
969   application.ProcessEvent(shiftTabEvent);
970   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
971   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
972   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
973   focusGroupChangedCallback.Reset();
974   END_TEST;
975 }
976
977 int UtcDaliKeyboardFocusManagerSignals(void)
978 {
979   ToolkitTestApplication application;
980
981   KeyboardFocusManager manager = KeyboardFocusManager::Get();
982   DALI_TEST_CHECK( manager );
983
984   ConnectionTracker* testTracker = new ConnectionTracker();
985   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
986   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
987   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
988   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
989
990   END_TEST;
991 }
992
993 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
994 {
995   ToolkitTestApplication application;
996
997   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
998
999   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1000   DALI_TEST_CHECK(manager);
1001
1002   // Create the first actor and add it to the stage
1003   Actor first = Actor::New();
1004   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1005   Stage::GetCurrent().Add(first);
1006
1007   // Create the second actor and add it to the stage
1008   Actor second = Actor::New();
1009   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1010   Stage::GetCurrent().Add(second);
1011
1012   // Create the third actor and add it to the stage
1013   Actor third = Actor::New();
1014   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1015   Stage::GetCurrent().Add(third);
1016
1017   // Create the fourth actor and add it to the stage
1018   Actor fourth = Actor::New();
1019   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1020   Stage::GetCurrent().Add(fourth);
1021
1022   // Check that the focus is set on the second actor
1023   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1024   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1025
1026   // Check that the focus is set on the second actor
1027   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1028   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1029
1030   // Check that the focus is set on the third  actor
1031   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1032   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1033
1034   // Check that the focus is set on the third  actor
1035   DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1036   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1037
1038   // Move the focus backward
1039   manager.MoveFocusBackward();
1040
1041   // Check that it current focused actor is third actor
1042   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1043
1044   // Remove the second actor on stage
1045   second.Unparent();
1046
1047   // Reset the first actor
1048   first.Unparent();
1049   first.Reset();
1050
1051   // Move the focus backward
1052   manager.MoveFocusBackward();
1053
1054   // Check that it current focused actor is third actor
1055   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1056
1057   // Make history stack full
1058   for(int i = 0 ; i < 31 ; i ++)
1059   {
1060     Actor actor = Actor::New();
1061     actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1062     Stage::GetCurrent().Add(actor);
1063     manager.SetCurrentFocusActor(actor);
1064   }
1065
1066   for(int i = 0 ; i < 31 ; i ++)
1067   {
1068     manager.MoveFocusBackward();
1069   }
1070
1071   // Check that it current focused actor is not second actor
1072   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1073
1074   END_TEST;
1075 }
1076
1077 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1078 {
1079   ToolkitTestApplication application;
1080
1081   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1082
1083   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1084   DALI_TEST_CHECK(manager);
1085
1086   bool preFocusChangeSignalVerified = false;
1087   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1088   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1089
1090   bool focusChangedSignalVerified = false;
1091   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1092   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1093
1094   Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1095   Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1096   Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1097   Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1098   Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1099   Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1100
1101   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1102   // It makes mIsFocusIndicatorEnabled true
1103   application.ProcessEvent(leftEvent);
1104
1105   // Create a 2x2 table view and try to move focus inside it
1106   TableView tableView = TableView::New( 2, 2 );
1107   Stage::GetCurrent().Add(tableView);
1108
1109   // Create the first actor
1110   Actor first = Actor::New();
1111   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1112
1113   // Create the second actor
1114   Actor second = Actor::New();
1115   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1116
1117   // Create the third actor
1118   Actor third = Actor::New();
1119   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1120
1121   // Create the fourth actor
1122   Actor fourth = Actor::New();
1123   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1124
1125   // Add the four children to table view
1126   tableView.AddChild(first, TableView::CellPosition(0, 0));
1127   tableView.AddChild(second, TableView::CellPosition(0, 1));
1128   tableView.AddChild(third, TableView::CellPosition(1, 0));
1129   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1130
1131   // Set the focus to the first actor
1132   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1133   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1134   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1135   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1136   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1137   focusChangedCallback.Reset();
1138
1139   // Send the right key event to move the focus towards right
1140   application.ProcessEvent(rightEvent);
1141   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1142   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1143   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1144   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1145   focusChangedCallback.Reset();
1146
1147   // Send the down key event to move the focus towards down
1148   application.ProcessEvent(downEvent);
1149   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1150   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1151   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1152   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1153   focusChangedCallback.Reset();
1154
1155   // Send the down event to move the focus towards left
1156   application.ProcessEvent(leftEvent);
1157   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1158   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1159   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1160   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1161   focusChangedCallback.Reset();
1162
1163   // Send the up event to move the focus towards up
1164   application.ProcessEvent(upEvent);
1165   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1166   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1167   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1168   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1169   focusChangedCallback.Reset();
1170
1171   // Send the pape up event, but focus should not be moved because page up is not supported by table view
1172   application.ProcessEvent(pageUpEvent);
1173   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1174   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1175   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1176   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1177   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1178   preFocusChangeCallback.Reset();
1179
1180   // Send the pape down event, but focus should not be moved because page down is not supported by table view
1181   application.ProcessEvent(pageDownEvent);
1182   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1183   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1184   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1185   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1186   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1187   preFocusChangeCallback.Reset();
1188
1189   // Clear the focus
1190   manager.ClearFocus();
1191
1192   // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1193   preFocusChangeCallback.Reset();
1194   application.ProcessEvent(pageUpEvent);
1195   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1196   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1197   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1198   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1199   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1200
1201   // Clear the focus again
1202   manager.ClearFocus();
1203
1204   // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1205   preFocusChangeCallback.Reset();
1206   application.ProcessEvent(pageDownEvent);
1207   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1208   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1209   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1210   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1211   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1212
1213   // Clear the focus again
1214   manager.ClearFocus();
1215
1216   // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1217   preFocusChangeCallback.Reset();
1218   application.ProcessEvent(upEvent);
1219   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1220   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1221   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1222   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1223
1224   // Clear the focus again
1225   manager.ClearFocus();
1226
1227   // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1228   preFocusChangeCallback.Reset();
1229   application.ProcessEvent(downEvent);
1230   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1231   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1232   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1233   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1234
1235   END_TEST;
1236 }
1237
1238 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1239 {
1240   ToolkitTestApplication application;
1241
1242   tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1243
1244   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1245   DALI_TEST_CHECK(manager);
1246
1247   bool preFocusChangeSignalVerified = false;
1248   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1249   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1250
1251   Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1252
1253   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1254   // It makes mIsFocusIndicatorEnabled true
1255   application.ProcessEvent(spaceEvent);
1256
1257   // Send the space event
1258   application.ProcessEvent(spaceEvent);
1259   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1260   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1261
1262   // Clear the focus again
1263   manager.ClearFocus();
1264
1265   // Send the space event again for line coverage
1266   preFocusChangeCallback.Reset();
1267   application.ProcessEvent(spaceEvent);
1268   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1269   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1270   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1271   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1272
1273   END_TEST;
1274 }
1275
1276
1277
1278 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1279 {
1280   ToolkitTestApplication application;
1281
1282   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1283
1284   // Register Type
1285   TypeInfo type;
1286   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1287   DALI_TEST_CHECK( type );
1288   BaseHandle handle = type.CreateInstance();
1289   DALI_TEST_CHECK( handle );
1290
1291   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1292   DALI_TEST_CHECK(manager);
1293
1294   bool preFocusChangeSignalVerified = false;
1295   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1296   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1297
1298   bool focusChangedSignalVerified = false;
1299   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1300   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1301
1302   // Create the first actor and add it to the stage
1303   Control first = Control::New();
1304   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1305   Stage::GetCurrent().Add(first);
1306
1307   // Create the second actor and add it to the stage
1308   Control second = Control::New();
1309   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1310   Stage::GetCurrent().Add(second);
1311
1312   // Move the focus to the right
1313   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1314
1315   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1316   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1317   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1318   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1319   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1320   preFocusChangeCallback.Reset();
1321
1322   // Check that the focus is set on the first actor
1323   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1324   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1325   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1326   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1327   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1328   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1329   focusChangedCallback.Reset();
1330
1331   // Move the focus towards right
1332   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1333
1334   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1335   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1336   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1337   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1338   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1339   preFocusChangeCallback.Reset();
1340
1341   // Check that the focus is set on the second actor
1342   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1343   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1344   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1345   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1346   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1347   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1348   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1349   focusChangedCallback.Reset();
1350
1351   // Move the focus towards up
1352   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1353
1354   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1355   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1356   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1357   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1358   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1359   preFocusChangeCallback.Reset();
1360   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1361
1362   // Create a 2x2 table view and try to move focus inside it
1363   TableView tableView = TableView::New( 2, 2 );
1364   Stage::GetCurrent().Add(tableView);
1365
1366   // Create the third actor
1367   Control third = Control::New();
1368   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1369
1370   // Create the fourth actor
1371   Control fourth = Control::New();
1372   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1373
1374   // Add the four children to table view
1375   tableView.AddChild(first, TableView::CellPosition(0, 0));
1376   tableView.AddChild(second, TableView::CellPosition(0, 1));
1377   tableView.AddChild(third, TableView::CellPosition(1, 0));
1378   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1379
1380   // Set the focus to the first actor
1381   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1382   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1383   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1384   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1385   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1386
1387   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1388   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1389
1390   focusChangedCallback.Reset();
1391
1392   // Move the focus towards right
1393   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1394   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1395   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1396   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1397   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1398   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1399   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1400
1401   focusChangedCallback.Reset();
1402
1403   // Move the focus towards down
1404   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1405   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1406   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1407   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1408   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1409
1410   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1411   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1412   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1413   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1414
1415   focusChangedCallback.Reset();
1416
1417   // Move the focus towards left
1418   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1419   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1420   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1421   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1422   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1423
1424   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1425   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1426   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1427   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1428
1429   focusChangedCallback.Reset();
1430
1431   // Move the focus towards up
1432   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1433   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1434   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1435   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1436   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
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   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1440   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1441   focusChangedCallback.Reset();
1442
1443   // Move the focus towards left. The focus move will fail as no way to move it upwards
1444   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1445   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1446   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1447   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1448   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1449   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1450   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1451   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1452   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1453   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1454
1455   preFocusChangeCallback.Reset();
1456   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1457
1458   // Enable the loop
1459   manager.SetFocusGroupLoop(true);
1460   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1461
1462   // Move the focus towards left again. The focus should move to the fourth actor.
1463   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1464   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1465   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1466   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1467   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1468
1469   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1470   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1471   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1472   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1473
1474   focusChangedCallback.Reset();
1475
1476   // Clear the focus
1477   manager.ClearFocus();
1478   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1479   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1480   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1481   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1482
1483
1484   END_TEST;
1485 }
1486
1487 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1488 {
1489   ToolkitTestApplication application;
1490
1491   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" );
1492
1493   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1494   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1495
1496   Actor actor = Actor::New();
1497   actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1498
1499   tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1500   manager.SetCurrentFocusActor( actor );
1501   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1502
1503   tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1504   Stage::GetCurrent().Add( actor );
1505   manager.SetCurrentFocusActor( actor );
1506   DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1507
1508   tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1509   actor.Unparent();
1510   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1511
1512   END_TEST;
1513 }
1514
1515 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1516 {
1517   ToolkitTestApplication application;
1518
1519   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" );
1520
1521   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1522   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1523
1524   Actor actor = Actor::New();
1525   actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1526   Stage::GetCurrent().Add( actor );
1527   manager.SetCurrentFocusActor( actor );
1528
1529   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1530   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1531   Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1532   application.ProcessEvent(rightEvent);
1533
1534   Actor indicatorActor = manager.GetFocusIndicatorActor();
1535
1536   tet_infoline( "Indicator is added to focused actor" );
1537   DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1538
1539   Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1540   DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1541
1542   tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1543   DALI_TEST_CHECK( !indicatorActor.GetParent() );
1544
1545   END_TEST;
1546 }
1547
1548 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1549 {
1550   ToolkitTestApplication application;
1551
1552   tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
1553   Dali::Integration::Scene scene = application.GetScene();
1554
1555   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1556   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1557
1558   // Create the first actor and add it to the stage
1559   Control control = Control::New();
1560   control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1561   scene.Add(control);
1562
1563   KeyEventCallback controlCallback( true );
1564   control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
1565
1566   KeyEventCallback sceneCallback( false );
1567   scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
1568
1569   manager.SetCurrentFocusActor( control );
1570
1571   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1572   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1573   Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1574   application.ProcessEvent(event1);
1575
1576   DALI_TEST_CHECK( controlCallback.mIsCalled );
1577   DALI_TEST_CHECK( !sceneCallback.mIsCalled );
1578
1579   END_TEST;
1580 }
1581
1582 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1583 {
1584   ToolkitTestApplication application;
1585
1586   tet_infoline( "Ensure Memory focus actors for each window ");
1587   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1588   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1589
1590   Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false);
1591   DALI_TEST_CHECK( firstWindow );
1592   Control first = Control::New();
1593   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1594   firstWindow.Add(first);
1595
1596   Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false);
1597   DALI_TEST_CHECK( secondWindow );
1598   Control second = Control::New();
1599   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1600   secondWindow.Add( second );
1601
1602   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1603   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1604
1605   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1606   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1607   firstWindow.Raise();
1608   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1609
1610   secondWindow.Remove( second );
1611   secondWindow.Raise();
1612   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1613
1614   secondWindow.Reset();
1615   END_TEST;
1616 }
1617
1618