Merge "DALi Version 1.3.54" into devel/master
[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 // Used to connect to signals via the ConnectSignal Handle method
221 struct CallbackFunctor
222 {
223   CallbackFunctor()
224   {
225   }
226
227   void operator()()
228   {
229   }
230 };
231
232 } // namespace
233
234 int UtcDaliKeyboardFocusManagerGet(void)
235 {
236   ToolkitTestApplication application;
237
238   tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
239
240   // Register Type
241   TypeInfo type;
242   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
243   DALI_TEST_CHECK( type );
244   BaseHandle handle = type.CreateInstance();
245   DALI_TEST_CHECK( handle );
246
247   KeyboardFocusManager manager;
248
249   manager = KeyboardFocusManager::Get();
250   DALI_TEST_CHECK(manager);
251
252   KeyboardFocusManager newManager = KeyboardFocusManager::Get();
253   DALI_TEST_CHECK(newManager);
254
255   // Check that focus manager is a singleton
256   DALI_TEST_CHECK(manager == newManager);
257   END_TEST;
258 }
259
260 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
261 {
262   ToolkitTestApplication application;
263
264   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
265
266   KeyboardFocusManager manager = KeyboardFocusManager::Get();
267   DALI_TEST_CHECK(manager);
268
269   // Create the first actor and add it to the stage
270   Actor first = Actor::New();
271   first.SetKeyboardFocusable(true);
272   Stage::GetCurrent().Add(first);
273
274   // Create the second actor and add it to the stage
275   Actor second = Actor::New();
276   second.SetKeyboardFocusable(true);
277   Stage::GetCurrent().Add(second);
278
279   // Create the third actor but don't add it to the stage
280   Actor third = Actor::New();
281
282   // Check that no actor is being focused yet.
283   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
284
285   // Check that it will fail to set focus on an invalid actor
286   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
287
288   // Check that the focus is set on the first actor
289   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
290   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
291
292   // Check that the focus is set on the second actor
293   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
294   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
295
296   // Check that it will fail to set focus on the third actor as it's not in the stage
297   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
298   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
299
300   // Add the third actor to the stage
301   Stage::GetCurrent().Add(third);
302
303   // Check that it will fail to set focus on the third actor as it's not focusable
304   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
305   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
306
307   // Make the third actor focusable
308   third.SetKeyboardFocusable(true);
309
310   // Check that the focus is successfully moved to the third actor
311   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
312   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
313   END_TEST;
314 }
315
316 int UtcDaliKeyboardFocusManagerMoveFocus(void)
317 {
318   ToolkitTestApplication application;
319
320   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
321
322   // Register Type
323   TypeInfo type;
324   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
325   DALI_TEST_CHECK( type );
326   BaseHandle handle = type.CreateInstance();
327   DALI_TEST_CHECK( handle );
328
329   KeyboardFocusManager manager = KeyboardFocusManager::Get();
330   DALI_TEST_CHECK(manager);
331
332   bool preFocusChangeSignalVerified = false;
333   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
334   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
335
336   bool focusChangedSignalVerified = false;
337   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
338   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
339
340   // Create the first actor and add it to the stage
341   Actor first = Actor::New();
342   first.SetKeyboardFocusable(true);
343   Stage::GetCurrent().Add(first);
344
345   // Create the second actor and add it to the stage
346   Actor second = Actor::New();
347   second.SetKeyboardFocusable(true);
348   Stage::GetCurrent().Add(second);
349
350   // Move the focus to the right
351   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
352
353   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
354   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
355   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
356   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
357   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
358   preFocusChangeCallback.Reset();
359
360   // Check that the focus is set on the first actor
361   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
362   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
363   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
364   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
365   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
366   focusChangedCallback.Reset();
367
368   // Move the focus towards right
369   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
370
371   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
372   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
373   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
374   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
375   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
376   preFocusChangeCallback.Reset();
377
378   // Check that the focus is set on the second actor
379   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
380   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
381   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
382   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
383   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
384   focusChangedCallback.Reset();
385
386   // Move the focus towards up
387   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
388
389   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
390   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
391   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
392   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
393   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
394   preFocusChangeCallback.Reset();
395   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
396
397   // Create a 2x2 table view and try to move focus inside it
398   TableView tableView = TableView::New( 2, 2 );
399   Stage::GetCurrent().Add(tableView);
400
401   // Create the third actor
402   Actor third = Actor::New();
403   third.SetKeyboardFocusable(true);
404
405   // Create the fourth actor
406   Actor fourth = Actor::New();
407   fourth.SetKeyboardFocusable(true);
408
409   // Add the four children to table view
410   tableView.AddChild(first, TableView::CellPosition(0, 0));
411   tableView.AddChild(second, TableView::CellPosition(0, 1));
412   tableView.AddChild(third, TableView::CellPosition(1, 0));
413   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
414
415   // Set the focus to the first actor
416   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
417   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
418   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
419   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
420   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
421   focusChangedCallback.Reset();
422
423   // Move the focus towards right
424   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
425   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
426   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
427   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
428   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
429   focusChangedCallback.Reset();
430
431   // Move the focus towards down
432   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
433   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
434   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
435   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
436   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
437   focusChangedCallback.Reset();
438
439   // Move the focus towards left
440   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
441   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
442   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
443   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
444   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
445   focusChangedCallback.Reset();
446
447   // Move the focus towards up
448   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
449   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
450   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
451   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
452   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
453   focusChangedCallback.Reset();
454
455   // Move the focus towards left. The focus move will fail as no way to move it upwards
456   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
457   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
458   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
459   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
460   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
461   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
462   preFocusChangeCallback.Reset();
463   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
464
465   // Enable the loop
466   manager.SetFocusGroupLoop(true);
467   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
468
469   // Move the focus towards left again. The focus should move to the fourth actor.
470   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
471   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
472   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
473   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
474   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
475   focusChangedCallback.Reset();
476   END_TEST;
477 }
478
479 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
480 {
481   ToolkitTestApplication application;
482
483   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
484
485   // Register Type
486   TypeInfo type;
487   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
488   DALI_TEST_CHECK( type );
489   BaseHandle handle = type.CreateInstance();
490   DALI_TEST_CHECK( handle );
491
492   KeyboardFocusManager manager = KeyboardFocusManager::Get();
493   DALI_TEST_CHECK(manager);
494
495   bool preFocusChangeSignalVerified = false;
496   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
497   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
498
499   bool focusChangedSignalVerified = false;
500   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
501   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
502
503   // Create the first actor and add it to the stage
504   Actor first = Actor::New();
505   first.SetKeyboardFocusable(true);
506   Stage::GetCurrent().Add(first);
507
508   // Create the second actor and add it to the stage
509   Actor second = Actor::New();
510   second.SetKeyboardFocusable(true);
511   Stage::GetCurrent().Add(second);
512
513   // Move the focus to the right
514   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
515
516   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
517   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
518   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
519   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
520   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
521   preFocusChangeCallback.Reset();
522
523   bool customAlgorithmInterfaceVerified = false;
524   CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
525   Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
526
527   // Move the focus towards right
528   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
529
530   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
531   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
532   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
533   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
534   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
535   customAlgorithm.Reset();
536
537   // Check that the focus is set on the first actor
538   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
539   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
540   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
541   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
542   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
543   focusChangedCallback.Reset();
544
545   // Move the focus towards right
546   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
547
548   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
549   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
550   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
551   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
552   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
553   customAlgorithm.Reset();
554
555   // Check that the focus is set on the second actor
556   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
557   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
558   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
559   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
560   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
561   focusChangedCallback.Reset();
562
563   // Move the focus towards up
564   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
565
566   // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
567   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
568   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
569   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
570   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
571   customAlgorithm.Reset();
572   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
573
574   END_TEST;
575 }
576 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
577 {
578   ToolkitTestApplication application;
579
580   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
581
582   // Register Type
583   TypeInfo type;
584   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
585   DALI_TEST_CHECK( type );
586   BaseHandle handle = type.CreateInstance();
587   DALI_TEST_CHECK( handle );
588
589   KeyboardFocusManager manager = KeyboardFocusManager::Get();
590   DALI_TEST_CHECK(manager);
591
592   bool focusChangedSignalVerified = false;
593   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
594   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
595
596   PushButton button1 = PushButton::New();
597   PushButton button2 = PushButton::New();
598   button1.SetKeyboardFocusable(true);
599   button2.SetKeyboardFocusable(true);
600   Stage::GetCurrent().Add(button1);
601   Stage::GetCurrent().Add(button2);
602
603   // Set the focus to the button1
604   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
605   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
606   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
607   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
608   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
609   focusChangedCallback.Reset();
610
611   // set the navigation properties of button1
612   button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
613   button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
614   button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
615   button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
616
617   // set the navigation properties of button2
618   button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
619   button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
620   button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
621   button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
622
623   // Move the focus towards left
624   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
625
626   // Confirm whether focus is moved to button2
627   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
628   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
629   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
630   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
631   focusChangedCallback.Reset();
632
633   // Move the focus towards right
634   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
635
636   // Confirm whether focus is moved to button1
637   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
638   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
639   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
640   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
641   focusChangedCallback.Reset();
642
643   // Move the focus towards up
644   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
645
646   // Confirm whether focus is moved to button2
647   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
648   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
649   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
650   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
651   focusChangedCallback.Reset();
652
653   // Move the focus towards down
654   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
655
656   // Confirm whether focus is moved to button1
657   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
658   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
659   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
660   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
661   focusChangedCallback.Reset();
662
663   // Create a 1x1 table view and try to move focus inside it
664   TableView tableView = TableView::New( 1, 1 );
665   Stage::GetCurrent().Add(tableView);
666
667   PushButton button = PushButton::New();
668   button.SetKeyboardFocusable(true);
669   tableView.AddChild(button, TableView::CellPosition(0, 0));
670
671   // set the navigation properties of button3
672   button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
673
674   // Set the focus to the button
675   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
676   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
677   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
678   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
679   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
680   focusChangedCallback.Reset();
681
682   // Move the focus towards left
683   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
684
685   // Confirm whether focus is moved to button1
686   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
687   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
688   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
689   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
690   focusChangedCallback.Reset();
691
692   END_TEST;
693 }
694
695 int UtcDaliKeyboardFocusManagerClearFocus(void)
696 {
697   ToolkitTestApplication application;
698
699   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
700
701   KeyboardFocusManager manager = KeyboardFocusManager::Get();
702   DALI_TEST_CHECK(manager);
703
704   // Create the first actor and add it to the stage
705   Actor first = Actor::New();
706   first.SetKeyboardFocusable(true);
707   Stage::GetCurrent().Add(first);
708
709   // Create the second actor and add it to the stage
710   Actor second = Actor::New();
711   second.SetKeyboardFocusable(true);
712   Stage::GetCurrent().Add(second);
713
714   // Check that the focus is set on the first actor
715   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
716   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
717
718   // Check that the focus is set on the second actor
719   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
720   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
721
722   // Clear the focus
723   manager.ClearFocus();
724
725   // Check that no actor is being focused now.
726   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
727   END_TEST;
728 }
729
730 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
731 {
732   ToolkitTestApplication application;
733
734   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
735
736   KeyboardFocusManager manager = KeyboardFocusManager::Get();
737   DALI_TEST_CHECK(manager);
738
739   // Check that the focus movement is not looped within the same focus group by default
740   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
741
742   // Enable the loop
743   manager.SetFocusGroupLoop(true);
744   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
745   END_TEST;
746 }
747
748 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
749 {
750   ToolkitTestApplication application;
751
752   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
753
754   KeyboardFocusManager manager = KeyboardFocusManager::Get();
755   DALI_TEST_CHECK(manager);
756
757   // Create an actor and check that it is not a focus group by default
758   Actor actor = Actor::New();
759   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
760
761   // Set the actor as focus group
762   manager.SetAsFocusGroup(actor, true);
763
764   // flush the queue and render once
765   application.SendNotification();
766   application.Render();
767
768   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
769
770   // Set the actor not as focus group
771   manager.SetAsFocusGroup(actor, false);
772
773   // flush the queue and render once
774   application.SendNotification();
775   application.Render();
776
777   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
778   END_TEST;
779 }
780
781 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
782 {
783   ToolkitTestApplication application;
784
785   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
786
787   KeyboardFocusManager manager = KeyboardFocusManager::Get();
788   DALI_TEST_CHECK(manager);
789
790   // Create an actor with two child actors and add it to the stage
791   Actor parent = Actor::New();
792   Actor child = Actor::New();
793   parent.Add(child);
794   Stage::GetCurrent().Add(parent);
795
796   // Create three actors and add them as the children of the first child actor
797   Actor grandChild = Actor::New();
798   child.Add(grandChild);
799
800   // Set the parent and the first child actor as focus groups
801   manager.SetAsFocusGroup(parent, true);
802
803   // flush the queue and render once
804   application.SendNotification();
805   application.Render();
806
807   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
808
809   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
810   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
811
812   manager.SetAsFocusGroup(child, true);
813
814   // flush the queue and render once
815   application.SendNotification();
816   application.Render();
817
818   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
819
820   // The focus group should be the child, As it is the immediate parent which is also a focus group.
821   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
822
823   manager.SetAsFocusGroup(grandChild, true);
824
825   // flush the queue and render once
826   application.SendNotification();
827   application.Render();
828
829   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
830
831   // The current focus group should be itself, As it is also a focus group.
832   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
833   END_TEST;
834 }
835
836 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
837 {
838   ToolkitTestApplication application;
839
840   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
841
842   KeyboardFocusManager manager = KeyboardFocusManager::Get();
843   DALI_TEST_CHECK(manager);
844
845   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
846   DALI_TEST_CHECK(defaultFocusIndicatorActor);
847
848   Actor newFocusIndicatorActor = Actor::New();
849   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
850   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
851   END_TEST;
852 }
853
854
855 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
856 {
857   ToolkitTestApplication application;
858
859   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
860
861   KeyboardFocusManager manager = KeyboardFocusManager::Get();
862   DALI_TEST_CHECK(manager);
863
864   bool focusedActorActivatedSignalVerified = false;
865   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
866   manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
867
868   Integration::KeyEvent returnEvent( "Return", "", 0, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
869
870   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
871   // It makes mIsFocusIndicatorEnabled true
872   application.ProcessEvent(returnEvent);
873
874   // Create the first button and add it to the stage
875   PushButton firstPushButton = PushButton::New();
876   firstPushButton.SetKeyboardFocusable(true);
877   Stage::GetCurrent().Add(firstPushButton);
878
879   // Create the second button and add it to the stage
880   PushButton secondPushButton = PushButton::New();
881   secondPushButton.SetKeyboardFocusable(true);
882   Stage::GetCurrent().Add(secondPushButton);
883
884   // Check that the focus is set on the first button
885   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
886   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
887
888   // Send the return event to activate the first button
889   application.ProcessEvent(returnEvent);
890   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
891   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
892   focusedActorActivatedCallback.Reset();
893
894   // Check that the focus is set on the second button
895   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
896   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
897
898   // Send the return event again to activate the second button
899   application.ProcessEvent(returnEvent);
900   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
901   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
902   focusedActorActivatedCallback.Reset();
903   END_TEST;
904 }
905
906 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
907 {
908   ToolkitTestApplication application;
909
910   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
911
912   // Register Type
913   TypeInfo type;
914   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
915   DALI_TEST_CHECK( type );
916   BaseHandle handle = type.CreateInstance();
917   DALI_TEST_CHECK( handle );
918
919   KeyboardFocusManager manager = KeyboardFocusManager::Get();
920   DALI_TEST_CHECK(manager);
921
922   bool focusGroupChangedSignalVerified = false;
923   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
924   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
925
926   Integration::KeyEvent tabEvent( "Tab", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
927   Integration::KeyEvent shiftTabEvent( "Tab", "", 0, 1, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
928
929   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
930   // It makes mIsFocusIndicatorEnabled true
931   application.ProcessEvent(tabEvent);
932
933   // Send the tab event to change focus group in the forward direction
934   application.ProcessEvent(tabEvent);
935   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
936   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
937   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
938   focusGroupChangedCallback.Reset();
939
940   // Send the shift tab event to change focus group in the backward direction
941   application.ProcessEvent(shiftTabEvent);
942   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
943   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
944   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
945   focusGroupChangedCallback.Reset();
946   END_TEST;
947 }
948
949 int UtcDaliKeyboardFocusManagerSignals(void)
950 {
951   ToolkitTestApplication application;
952
953   KeyboardFocusManager manager = KeyboardFocusManager::Get();
954   DALI_TEST_CHECK( manager );
955
956   ConnectionTracker* testTracker = new ConnectionTracker();
957   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
958   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
959   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
960   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
961
962   END_TEST;
963 }
964
965 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
966 {
967   ToolkitTestApplication application;
968
969   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
970
971   KeyboardFocusManager manager = KeyboardFocusManager::Get();
972   DALI_TEST_CHECK(manager);
973
974   // Create the first actor and add it to the stage
975   Actor first = Actor::New();
976   first.SetKeyboardFocusable(true);
977   Stage::GetCurrent().Add(first);
978
979   // Create the second actor and add it to the stage
980   Actor second = Actor::New();
981   second.SetKeyboardFocusable(true);
982   Stage::GetCurrent().Add(second);
983
984   // Create the third actor and add it to the stage
985   Actor third = Actor::New();
986   third.SetKeyboardFocusable(true);
987   Stage::GetCurrent().Add(third);
988
989   // Create the fourth actor and add it to the stage
990   Actor fourth = Actor::New();
991   fourth.SetKeyboardFocusable(true);
992   Stage::GetCurrent().Add(fourth);
993
994   // Check that the focus is set on the second actor
995   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
996   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
997
998   // Check that the focus is set on the second actor
999   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1000   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1001
1002   // Check that the focus is set on the third  actor
1003   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1004   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1005
1006   // Check that the focus is set on the third  actor
1007   DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1008   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1009
1010   // Move the focus backward
1011   manager.MoveFocusBackward();
1012
1013   // Check that it current focused actor is third actor
1014   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1015
1016   // Remove the second actor on stage
1017   second.Unparent();
1018
1019   // Reset the first actor
1020   first.Unparent();
1021   first.Reset();
1022
1023   // Move the focus backward
1024   manager.MoveFocusBackward();
1025
1026   // Check that it current focused actor is third actor
1027   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1028
1029   // Make history stack full
1030   for(int i = 0 ; i < 31 ; i ++)
1031   {
1032     Actor actor = Actor::New();
1033     actor.SetKeyboardFocusable(true);
1034     Stage::GetCurrent().Add(actor);
1035     manager.SetCurrentFocusActor(actor);
1036   }
1037
1038   for(int i = 0 ; i < 31 ; i ++)
1039   {
1040     manager.MoveFocusBackward();
1041   }
1042
1043   // Check that it current focused actor is not second actor
1044   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1045
1046   END_TEST;
1047 }
1048
1049 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1050 {
1051   ToolkitTestApplication application;
1052
1053   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1054
1055   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1056   DALI_TEST_CHECK(manager);
1057
1058   bool preFocusChangeSignalVerified = false;
1059   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1060   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1061
1062   bool focusChangedSignalVerified = false;
1063   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1064   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1065
1066   Integration::KeyEvent leftEvent( "Left", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1067   Integration::KeyEvent rightEvent( "Right", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1068   Integration::KeyEvent upEvent( "Up", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1069   Integration::KeyEvent downEvent( "Down", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1070   Integration::KeyEvent pageUpEvent( "Prior", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1071   Integration::KeyEvent pageDownEvent( "Next", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1072
1073   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1074   // It makes mIsFocusIndicatorEnabled true
1075   application.ProcessEvent(leftEvent);
1076
1077   // Create a 2x2 table view and try to move focus inside it
1078   TableView tableView = TableView::New( 2, 2 );
1079   Stage::GetCurrent().Add(tableView);
1080
1081   // Create the first actor
1082   Actor first = Actor::New();
1083   first.SetKeyboardFocusable(true);
1084
1085   // Create the second actor
1086   Actor second = Actor::New();
1087   second.SetKeyboardFocusable(true);
1088
1089   // Create the third actor
1090   Actor third = Actor::New();
1091   third.SetKeyboardFocusable(true);
1092
1093   // Create the fourth actor
1094   Actor fourth = Actor::New();
1095   fourth.SetKeyboardFocusable(true);
1096
1097   // Add the four children to table view
1098   tableView.AddChild(first, TableView::CellPosition(0, 0));
1099   tableView.AddChild(second, TableView::CellPosition(0, 1));
1100   tableView.AddChild(third, TableView::CellPosition(1, 0));
1101   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1102
1103   // Set the focus to the first actor
1104   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1105   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1106   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1107   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1108   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1109   focusChangedCallback.Reset();
1110
1111   // Send the right key event to move the focus towards right
1112   application.ProcessEvent(rightEvent);
1113   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1114   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1115   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1116   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1117   focusChangedCallback.Reset();
1118
1119   // Send the down key event to move the focus towards down
1120   application.ProcessEvent(downEvent);
1121   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1122   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1123   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1124   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1125   focusChangedCallback.Reset();
1126
1127   // Send the down event to move the focus towards left
1128   application.ProcessEvent(leftEvent);
1129   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1130   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1131   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1132   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1133   focusChangedCallback.Reset();
1134
1135   // Send the up event to move the focus towards up
1136   application.ProcessEvent(upEvent);
1137   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1138   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1139   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1140   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1141   focusChangedCallback.Reset();
1142
1143   // Send the pape up event, but focus should not be moved because page up is not supported by table view
1144   application.ProcessEvent(pageUpEvent);
1145   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1146   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1147   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1148   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1149   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1150   preFocusChangeCallback.Reset();
1151
1152   // Send the pape down event, but focus should not be moved because page down is not supported by table view
1153   application.ProcessEvent(pageDownEvent);
1154   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1155   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1156   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1157   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1158   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1159   preFocusChangeCallback.Reset();
1160
1161   // Clear the focus
1162   manager.ClearFocus();
1163
1164   // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1165   preFocusChangeCallback.Reset();
1166   application.ProcessEvent(pageUpEvent);
1167   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1168   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1169   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1170   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1171   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1172
1173   // Clear the focus again
1174   manager.ClearFocus();
1175
1176   // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1177   preFocusChangeCallback.Reset();
1178   application.ProcessEvent(pageDownEvent);
1179   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1180   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1181   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1182   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1183   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1184
1185   // Clear the focus again
1186   manager.ClearFocus();
1187
1188   // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1189   preFocusChangeCallback.Reset();
1190   application.ProcessEvent(upEvent);
1191   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1192   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1193   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1194   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1195
1196   // Clear the focus again
1197   manager.ClearFocus();
1198
1199   // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1200   preFocusChangeCallback.Reset();
1201   application.ProcessEvent(downEvent);
1202   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1203   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1204   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1205   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1206
1207   END_TEST;
1208 }
1209
1210 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1211 {
1212   ToolkitTestApplication application;
1213
1214   tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1215
1216   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1217   DALI_TEST_CHECK(manager);
1218
1219   bool preFocusChangeSignalVerified = false;
1220   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1221   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1222
1223   Integration::KeyEvent spaceEvent( "space", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1224
1225   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1226   // It makes mIsFocusIndicatorEnabled true
1227   application.ProcessEvent(spaceEvent);
1228
1229   // Send the space event
1230   application.ProcessEvent(spaceEvent);
1231   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1232   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1233
1234   // Clear the focus again
1235   manager.ClearFocus();
1236
1237   // Send the space event again for line coverage
1238   preFocusChangeCallback.Reset();
1239   application.ProcessEvent(spaceEvent);
1240   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1241   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1242   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1243   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1244
1245   END_TEST;
1246 }
1247
1248
1249
1250 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1251 {
1252   ToolkitTestApplication application;
1253
1254   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1255
1256   // Register Type
1257   TypeInfo type;
1258   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1259   DALI_TEST_CHECK( type );
1260   BaseHandle handle = type.CreateInstance();
1261   DALI_TEST_CHECK( handle );
1262
1263   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1264   DALI_TEST_CHECK(manager);
1265
1266   bool preFocusChangeSignalVerified = false;
1267   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1268   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1269
1270   bool focusChangedSignalVerified = false;
1271   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1272   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1273
1274   // Create the first actor and add it to the stage
1275   Control first = Control::New();
1276   first.SetKeyboardFocusable(true);
1277   Stage::GetCurrent().Add(first);
1278
1279   // Create the second actor and add it to the stage
1280   Control second = Control::New();
1281   second.SetKeyboardFocusable(true);
1282   Stage::GetCurrent().Add(second);
1283
1284   // Move the focus to the right
1285   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1286
1287   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1288   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1289   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1290   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1291   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1292   preFocusChangeCallback.Reset();
1293
1294   // Check that the focus is set on the first actor
1295   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1296   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1297   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1298   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1299   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1300   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1301   focusChangedCallback.Reset();
1302
1303   // Move the focus towards right
1304   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1305
1306   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1307   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1308   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1309   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1310   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1311   preFocusChangeCallback.Reset();
1312
1313   // Check that the focus is set on the second actor
1314   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1315   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1316   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1317   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1318   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1319   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1320   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1321   focusChangedCallback.Reset();
1322
1323   // Move the focus towards up
1324   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1325
1326   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1327   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1328   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1329   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1330   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1331   preFocusChangeCallback.Reset();
1332   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1333
1334   // Create a 2x2 table view and try to move focus inside it
1335   TableView tableView = TableView::New( 2, 2 );
1336   Stage::GetCurrent().Add(tableView);
1337
1338   // Create the third actor
1339   Control third = Control::New();
1340   third.SetKeyboardFocusable(true);
1341
1342   // Create the fourth actor
1343   Control fourth = Control::New();
1344   fourth.SetKeyboardFocusable(true);
1345
1346   // Add the four children to table view
1347   tableView.AddChild(first, TableView::CellPosition(0, 0));
1348   tableView.AddChild(second, TableView::CellPosition(0, 1));
1349   tableView.AddChild(third, TableView::CellPosition(1, 0));
1350   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1351
1352   // Set the focus to the first actor
1353   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1354   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1355   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1356   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1357   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1358
1359   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1360   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1361
1362   focusChangedCallback.Reset();
1363
1364   // Move the focus towards right
1365   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1366   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1367   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1368   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1369   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1370   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1371   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1372
1373   focusChangedCallback.Reset();
1374
1375   // Move the focus towards down
1376   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1377   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1378   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1379   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1380   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1381
1382   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1383   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1384   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1385   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1386
1387   focusChangedCallback.Reset();
1388
1389   // Move the focus towards left
1390   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1391   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1392   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1393   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1394   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1395
1396   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1397   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1398   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1399   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1400
1401   focusChangedCallback.Reset();
1402
1403   // Move the focus towards up
1404   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1405   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1406   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1407   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1408   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1409   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1410   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1411   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1412   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1413   focusChangedCallback.Reset();
1414
1415   // Move the focus towards left. The focus move will fail as no way to move it upwards
1416   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1417   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1418   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1419   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1420   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1421   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1422   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1423   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1424   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1425   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1426
1427   preFocusChangeCallback.Reset();
1428   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1429
1430   // Enable the loop
1431   manager.SetFocusGroupLoop(true);
1432   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1433
1434   // Move the focus towards left again. The focus should move to the fourth actor.
1435   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1436   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1437   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1438   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1439   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1440
1441   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1442   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1443   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1444   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1445
1446   focusChangedCallback.Reset();
1447
1448   // Clear the focus
1449   manager.ClearFocus();
1450   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1451   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1452   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1453   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1454
1455
1456   END_TEST;
1457 }
1458
1459 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1460 {
1461   ToolkitTestApplication application;
1462
1463   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" );
1464
1465   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1466   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1467
1468   Actor actor = Actor::New();
1469   actor.SetKeyboardFocusable( true );
1470
1471   tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1472   manager.SetCurrentFocusActor( actor );
1473   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1474
1475   tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1476   Stage::GetCurrent().Add( actor );
1477   manager.SetCurrentFocusActor( actor );
1478   DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1479
1480   tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1481   actor.Unparent();
1482   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1483
1484   END_TEST;
1485 }
1486
1487 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(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.SetKeyboardFocusable( true );
1498   Stage::GetCurrent().Add( actor );
1499   manager.SetCurrentFocusActor( actor );
1500
1501   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1502   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1503   Integration::KeyEvent rightEvent( "Right", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1504   application.ProcessEvent(rightEvent);
1505
1506   Actor indicatorActor = manager.GetFocusIndicatorActor();
1507
1508   tet_infoline( "Indicator is added to focused actor" );
1509   DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1510
1511   Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1512   DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1513
1514   tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1515   DALI_TEST_CHECK( !indicatorActor.GetParent() );
1516
1517   END_TEST;
1518 }
1519
1520
1521