Merge "Added PathConstraint support to Javascript API" into tizen
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-FocusManager.cpp
1 /*
2  * Copyright (c) 2014 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
27 using namespace Dali;
28 using namespace Toolkit;
29
30
31 void utc_dali_toolkit_focus_manager_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_toolkit_focus_manager_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41
42 namespace
43 {
44
45 static bool gObjectCreatedCallBackCalled;
46
47 static void TestCallback(BaseHandle handle)
48 {
49   gObjectCreatedCallBackCalled = true;
50 }
51
52 // Functors to test whether focus changed signal is emitted when the focus is changed
53 class FocusChangedCallback : public Dali::ConnectionTracker
54 {
55 public:
56   FocusChangedCallback(bool& signalReceived)
57   : mSignalVerified(signalReceived),
58     mOriginalFocusedActor(),
59     mCurrentFocusedActor()
60   {
61   }
62
63   void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
64   {
65     tet_infoline("Verifying FocusChangedCallback()");
66
67     if(originalFocusedActor == mCurrentFocusedActor)
68     {
69       mSignalVerified = true;
70     }
71
72     mOriginalFocusedActor = originalFocusedActor;
73     mCurrentFocusedActor = currentFocusedActor;
74   }
75
76   void Reset()
77   {
78     mSignalVerified = false;
79   }
80
81   bool& mSignalVerified;
82   Actor mOriginalFocusedActor;
83   Actor mCurrentFocusedActor;
84 };
85
86 // Functors to test whether focus overshot signal is emitted when there is no way to move focus further.
87 class FocusOvershotCallback : public Dali::ConnectionTracker
88 {
89 public:
90   FocusOvershotCallback(bool& signalReceived)
91   : mSignalVerified(signalReceived),
92     mCurrentFocusedActor(),
93     mFocusOvershotDirection(Toolkit::FocusManager::OVERSHOT_NEXT)
94   {
95   }
96
97   void Callback(Actor currentFocusedActor, Toolkit::FocusManager::FocusOvershotDirection direction)
98   {
99     tet_infoline("Verifying FocusOvershotCallback()");
100
101     if(currentFocusedActor == mCurrentFocusedActor && direction == mFocusOvershotDirection)
102     {
103       mSignalVerified = true;
104     }
105   }
106
107   void Reset()
108   {
109     mSignalVerified = false;
110   }
111
112   bool& mSignalVerified;
113   Actor mCurrentFocusedActor;
114   Toolkit::FocusManager::FocusOvershotDirection mFocusOvershotDirection;
115 };
116
117 } // namespace
118
119
120 int UtcDaliFocusManagerGet(void)
121 {
122   ToolkitTestApplication application;
123
124   tet_infoline(" UtcDaliFocusManagerGet");
125
126   FocusManager manager;
127
128   //Ensure object is created by checking if it's registered
129   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
130   DALI_TEST_CHECK(registry);
131
132   gObjectCreatedCallBackCalled = false;
133   registry.ObjectCreatedSignal().Connect( &TestCallback );
134   {
135     manager = FocusManager::Get();
136     DALI_TEST_CHECK(manager);
137   }
138   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
139
140   FocusManager newManager = FocusManager::Get();
141   DALI_TEST_CHECK(newManager);
142
143   // Check that focus manager is a singleton
144   DALI_TEST_CHECK(manager == newManager);
145   END_TEST;
146 }
147
148 int UtcDaliFocusManagerSetAndGetAccessibilityAttribute(void)
149 {
150   ToolkitTestApplication application;
151
152   tet_infoline(" UtcDaliFocusManagerSetAndGetAccessibilityAttribute");
153
154   FocusManager manager = FocusManager::Get();
155   DALI_TEST_CHECK(manager);
156
157   Actor actor = Actor::New();
158   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "");
159
160   manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "Description");
161   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "Description");
162
163   manager.SetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL, "New description");
164   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(actor, FocusManager::ACCESSIBILITY_LABEL) == "New description");
165   END_TEST;
166 }
167
168 int UtcDaliFocusManagerSetAndGetFocusOrder(void)
169 {
170   ToolkitTestApplication application;
171
172   tet_infoline(" UtcDaliFocusManagerSetAndGetFocusOrder");
173
174   FocusManager manager = FocusManager::Get();
175   DALI_TEST_CHECK(manager);
176
177   Actor first = Actor::New();
178   Actor second = Actor::New();
179   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
180   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 0);
181
182   // Set the focus order and description for the first actor
183   manager.SetFocusOrder(first, 1);
184   manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
185   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
186   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
187
188   // Set the focus order and description for the second actor
189   manager.SetFocusOrder(second, 2);
190   manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
191   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
192   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
193
194   // check that the focus order of the first actor is changed
195   manager.SetFocusOrder(first, 2);
196   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 2);
197   // make sure the change of focus order doesn't affect the actor's description
198   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
199
200   // check that the focus order of the second actor is increased to 3
201   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 3);
202   // make sure the change of focus order doesn't affect the actor's description
203   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
204
205   // check that the focus order of the second actor is changed to 1
206   manager.SetFocusOrder(second, 1);
207   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 1);
208   // make sure the change of focus order doesn't affect the actor's description
209   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
210
211   // Set the focus order and description for the third actor
212   Actor third = Actor::New();
213   manager.SetFocusOrder(third, 1);
214   manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
215   DALI_TEST_CHECK(manager.GetFocusOrder(third) == 1);
216   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
217
218   // check that the focus order of the second actor is increased to 2.
219   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
220   // make sure the change of focus order doesn't affect the actor's description
221   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
222
223   // check that the focus order of the first actor is increased to 3.
224   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 3);
225   // make sure the change of focus order doesn't affect the actor's description
226   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
227   END_TEST;
228 }
229
230 int UtcDaliFocusManagerGenerateNewFocusOrder(void)
231 {
232   ToolkitTestApplication application;
233
234   tet_infoline(" UtcDaliFocusManagerGenerateNewFocusOrder");
235
236   FocusManager manager = FocusManager::Get();
237   DALI_TEST_CHECK(manager);
238
239   DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
240   DALI_TEST_CHECK(1 == manager.GenerateNewFocusOrder());
241
242   Actor first = Actor::New();
243   Actor second = Actor::New();
244
245   // Set the focus order for the first actor
246   manager.SetFocusOrder(first, 1);
247   manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
248   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
249
250   //Test for new focus order
251   DALI_TEST_CHECK(2 == manager.GenerateNewFocusOrder());
252
253   // Set the focus order for the first actor
254   manager.SetFocusOrder(second, 2);
255   manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "first");
256   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
257   END_TEST;
258 }
259
260 int UtcDaliFocusManagerGetActorByFocusOrder(void)
261 {
262   ToolkitTestApplication application;
263
264   tet_infoline(" UtcDaliFocusManagerGetActorByFocusOrder");
265
266   FocusManager manager = FocusManager::Get();
267   DALI_TEST_CHECK(manager);
268
269   // Create the actors and set their focus orders
270   Actor first = Actor::New();
271   manager.SetFocusOrder(first, 1);
272
273   Actor second = Actor::New();
274   manager.SetFocusOrder(second, 2);
275
276   Actor third = Actor::New();
277   manager.SetFocusOrder(third, 3);
278
279   // Check that we get an empty handle as no actor is added to the stage yet.
280   DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == Actor());
281   DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == Actor());
282   DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == Actor());
283
284   // Add the actors to the stage
285   Stage::GetCurrent().Add(first);
286   Stage::GetCurrent().Add(second);
287   Stage::GetCurrent().Add(third);
288
289   // Check that we get an empty handle because focus order 0 means undefined.
290   DALI_TEST_CHECK(manager.GetActorByFocusOrder(0) == Actor());
291
292   // Check that we get correct actors for the specified focus orders
293   DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == first);
294   DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == second);
295   DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == third);
296
297   // Change the focus order of the third actor to 1
298   manager.SetFocusOrder(third, 1);
299
300   // Check that we still get correct actors after changing their focus orders
301   DALI_TEST_CHECK(manager.GetActorByFocusOrder(1) == third);
302   DALI_TEST_CHECK(manager.GetActorByFocusOrder(2) == first);
303   DALI_TEST_CHECK(manager.GetActorByFocusOrder(3) == second);
304
305   // Check that we get an empty handle because no actor has a focus order of 4
306   DALI_TEST_CHECK(manager.GetActorByFocusOrder(4) == Actor());
307   END_TEST;
308 }
309
310 int UtcDaliFocusManagerSetAndGetCurrentFocusActor(void)
311 {
312   ToolkitTestApplication application;
313
314   tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor");
315
316   FocusManager manager = FocusManager::Get();
317   DALI_TEST_CHECK(manager);
318
319   // Create the first actor and add it to the stage
320   Actor first = Actor::New();
321   manager.SetFocusOrder(first, 1);
322   Stage::GetCurrent().Add(first);
323
324   // Create the second actor and add it to the stage
325   Actor second = Actor::New();
326   manager.SetFocusOrder(second, 2);
327   Stage::GetCurrent().Add(second);
328
329   // Create the third actor but don't add it to the stage
330   Actor third = Actor::New();
331   manager.SetFocusOrder(third, 3);
332
333   // Check that no actor is being focused yet.
334   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
335
336   // Check that it will fail to set focus on an invalid actor
337   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
338
339   // Check that the focus is set on the first actor
340   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
341   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
342
343   // Check that the focus is set on the second actor
344   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
345   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
346
347   // Check that it will fail to set focus on the third actor as it's not in the stage
348   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
349
350   // Add the third actor to the stage
351   Stage::GetCurrent().Add(third);
352
353   // make the third actor invisible
354   third.SetVisible(false);
355   // flush the queue and render once
356   application.SendNotification();
357   application.Render();
358
359   // Check that it will fail to set focus on the third actor as it's invisible
360   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
361
362   // Make the third actor visible
363   third.SetVisible(true);
364   // flush the queue and render once
365   application.SendNotification();
366   application.Render();
367
368   // Make the third actor not focusable
369   Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable");
370   third.SetProperty(propertyActorFocusable, false);
371   // flush the queue and render once
372   application.SendNotification();
373   application.Render();
374
375   // Check that it will fail to set focus on the third actor as it's not focusable
376   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
377
378   // Make the third actor focusable
379   third.SetProperty(propertyActorFocusable, true);
380   // flush the queue and render once
381   application.SendNotification();
382   application.Render();
383
384   // Check that the focus is successfully moved to the third actor
385   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
386
387   // Make the current focused actor to be not focusable by setting its focus order to be 0
388   manager.SetFocusOrder(third, 0);
389
390   // Check that the focus is automatically cleared
391   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
392
393   // Set the focus order of the third actor again
394   manager.SetFocusOrder(third, 3);
395
396   // Check that the third actor can be focused successfully now
397   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
398   END_TEST;
399 }
400
401 int UtcDaliFocusManagerGetCurrentFocusGroup(void)
402 {
403   ToolkitTestApplication application;
404
405   tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup");
406
407   FocusManager manager = FocusManager::Get();
408   DALI_TEST_CHECK(manager);
409
410   // Create an actor with two child actors and add it to the stage
411   Actor parent = Actor::New();
412   Actor firstChild = Actor::New();
413   Actor secondChild = Actor::New();
414   parent.Add(firstChild);
415   parent.Add(secondChild);
416   Stage::GetCurrent().Add(parent);
417
418   // Create three actors and add them as the children of the first child actor
419   Actor firstGrandChild = Actor::New();
420   Actor secondGrandChild = Actor::New();
421   Actor thirdGrandChild = Actor::New();
422   firstChild.Add(firstGrandChild);
423   firstChild.Add(secondGrandChild);
424   firstChild.Add(thirdGrandChild);
425
426   // Set focus order to the actors
427   manager.SetFocusOrder(parent, 1);
428   manager.SetFocusOrder(firstChild, 2);
429   manager.SetFocusOrder(firstGrandChild, 3);
430   manager.SetFocusOrder(secondGrandChild, 4);
431   manager.SetFocusOrder(thirdGrandChild, 5);
432   manager.SetFocusOrder(secondChild, 6);
433
434   // Set the parent and the first child actor as focus groups
435   manager.SetFocusGroup(parent, true);
436   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
437
438   // Set focus to the first grand child actor
439   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true);
440   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
441
442   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
443   DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent);
444
445   manager.SetFocusGroup(firstChild, true);
446   DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
447
448   // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group.
449   DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
450
451   manager.SetFocusGroup(firstGrandChild, true);
452   DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true);
453
454   // The current focus group should be itself, As it is also a focus group.
455   DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild);
456
457   // Set focus to the second grand child actor
458   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true);
459   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
460
461   // The current focus group should be the firstChild, As it is the immediate parent which is also a
462   // focus group for the current focus actor.
463   DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild);
464
465   END_TEST;
466 }
467
468 int UtcDaliFocusManagerGetCurrentFocusOrder(void)
469 {
470   ToolkitTestApplication application;
471
472   tet_infoline(" UtcDaliFocusManagerGetCurrentFocusOrder");
473
474   FocusManager manager = FocusManager::Get();
475   DALI_TEST_CHECK(manager);
476
477   Actor first = Actor::New();
478   Stage::GetCurrent().Add(first);
479
480   Actor second = Actor::New();
481   Stage::GetCurrent().Add(second);
482
483   Actor third = Actor::New();
484   Stage::GetCurrent().Add(third);
485
486   // Set the focus order and description for the first actor
487   manager.SetFocusOrder(first, 1);
488   manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
489   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
490   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
491
492   // Set the focus order and description for the second actor
493   manager.SetFocusOrder(second, 2);
494   manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
495   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
496   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
497
498   // Set the focus order and description for the second actor
499   manager.SetFocusOrder(third, 3);
500   manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
501   DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
502   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
503
504   // Check that no actor is being focused yet.
505   DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
506
507   // Set the focus on the first actor and test
508   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
509   DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 1);
510
511   // Move the focus forward to the second actor and test
512   manager.MoveFocusForward();
513   DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 2);
514
515   // Move the focus forward to the third actor and test
516   manager.MoveFocusForward();
517   DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 3);
518
519   // Clear focus and test
520   manager.ClearFocus();
521   DALI_TEST_CHECK(manager.GetCurrentFocusOrder() == 0);
522   END_TEST;
523 }
524
525 int UtcDaliFocusManagerMoveFocusForward(void)
526 {
527   ToolkitTestApplication application;
528
529   tet_infoline(" UtcDaliFocusManagerMoveFocusForward");
530
531   FocusManager manager = FocusManager::Get();
532   DALI_TEST_CHECK(manager);
533
534   Actor first = Actor::New();
535   Stage::GetCurrent().Add(first);
536
537   Actor second = Actor::New();
538   Stage::GetCurrent().Add(second);
539
540   Actor third = Actor::New();
541   Stage::GetCurrent().Add(third);
542
543   // Set the focus order and description for the first actor
544   manager.SetFocusOrder(first, 1);
545   manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
546   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
547   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
548
549   // Set the focus order and description for the second actor
550   manager.SetFocusOrder(second, 2);
551   manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
552   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
553   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
554
555   // Set the focus order and description for the second actor
556   manager.SetFocusOrder(third, 3);
557   manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
558   DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
559   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
560
561   // Check that no actor is being focused yet.
562   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
563
564   // Set the focus on the first actor
565   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
566   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
567   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
568
569   // Test the non-wrapped move first
570   manager.SetWrapMode(false);
571   DALI_TEST_CHECK(manager.GetWrapMode() == false);
572
573   // Move the focus forward to the second actor
574   manager.MoveFocusForward();
575   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
576   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
577
578   // Move the focus forward to the third actor
579   manager.MoveFocusForward();
580   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
581   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
582
583   // Check that it will fail to move the focus forward again as the third actor is the last
584   // focusable actor in the focus chain
585   manager.MoveFocusForward();
586   // The focus should still be set on the third actor
587   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
588   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
589
590   // Now test the wrapped move
591   manager.SetWrapMode(true);
592   DALI_TEST_CHECK(manager.GetWrapMode() == true);
593
594   // Move the focus forward recursively and this time the first actor should be focused
595   manager.MoveFocusForward();
596   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
597   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
598
599   // Make the second actor not focusable
600   Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
601   second.SetProperty(propertyActorFocusable, false);
602   // flush the queue and render once
603   application.SendNotification();
604   application.Render();
605
606   // Move the focus forward and check that the second actor should be skipped and
607   // the third actor should be focused now.
608   manager.MoveFocusForward();
609   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
610   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
611
612   // Make the first actor invisible
613   first.SetVisible(false);
614   // flush the queue and render once
615   application.SendNotification();
616   application.Render();
617
618   // Move the focus forward and check that the first actor should be skipped as it's
619   // invisible and the second actor should also be skipped as it's not focusable,
620   // so the focus will still be on the third actor
621   manager.MoveFocusForward();
622   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
623   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
624
625   // Make the third actor invisible so that no actor can be focused.
626   third.SetVisible(false);
627   // flush the queue and render once
628   application.SendNotification();
629   application.Render();
630
631   // Check that the focus move is failed as all the three actors can not be focused
632   manager.MoveFocusForward();
633   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
634   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
635   END_TEST;
636 }
637
638 int UtcDaliFocusManagerMoveFocusBackward(void)
639 {
640   ToolkitTestApplication application;
641
642   tet_infoline(" UtcDaliFocusManagerMoveFocusBackward");
643
644   FocusManager manager = FocusManager::Get();
645   DALI_TEST_CHECK(manager);
646
647   Actor first = Actor::New();
648   Stage::GetCurrent().Add(first);
649
650   Actor second = Actor::New();
651   Stage::GetCurrent().Add(second);
652
653   Actor third = Actor::New();
654   Stage::GetCurrent().Add(third);
655
656   // Set the focus order and description for the first actor
657   manager.SetFocusOrder(first, 1);
658   manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first");
659   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1);
660   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first");
661
662   // Set the focus order and description for the second actor
663   manager.SetFocusOrder(second, 2);
664   manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second");
665   DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2);
666   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second");
667
668   // Set the focus order and description for the second actor
669   manager.SetFocusOrder(third, 3);
670   manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third");
671   DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3);
672   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third");
673
674   // Check that no actor is being focused yet.
675   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
676
677   // Set the focus on the third actor
678   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
679   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
680   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
681
682   // Test the non-wrapped move first
683   manager.SetWrapMode(false);
684   DALI_TEST_CHECK(manager.GetWrapMode() == false);
685
686   // Move the focus backward to the second actor
687   manager.MoveFocusBackward();
688   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
689   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second");
690
691   // Move the focus backward to the first actor
692   manager.MoveFocusBackward();
693   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
694   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
695
696   // Check that it will fail to move the focus backward again as the first actor is the first
697   // focusable actor in the focus chain
698   manager.MoveFocusBackward();
699   // The focus should still be set on the first actor
700   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
701   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
702
703   // Now test the wrapped move
704   manager.SetWrapMode(true);
705   DALI_TEST_CHECK(manager.GetWrapMode() == true);
706
707   // Move the focus backward recursively and this time the third actor should be focused
708   manager.MoveFocusBackward();
709   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
710   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third");
711
712   // Make the second actor not focusable
713   Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable");
714   second.SetProperty(propertyActorFocusable, false);
715   // flush the queue and render once
716   application.SendNotification();
717   application.Render();
718
719   // Move the focus backward and check that the second actor should be skipped and
720   // the first actor should be focused now.
721   manager.MoveFocusBackward();
722   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
723   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
724
725   // Make the third actor invisible
726   third.SetVisible(false);
727   // flush the queue and render once
728   application.SendNotification();
729   application.Render();
730
731   // Move the focus backward and check that the third actor should be skipped as it's
732   // invisible and the second actor should also be skipped as it's not focusable,
733   // so the focus will still be on the first actor
734   manager.MoveFocusBackward();
735   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
736   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
737
738   // Make the first actor invisible so that no actor can be focused.
739   first.SetVisible(false);
740   // flush the queue and render once
741   application.SendNotification();
742   application.Render();
743
744   // Check that the focus move is failed as all the three actors can not be focused
745   manager.MoveFocusBackward();
746   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
747   DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first");
748   END_TEST;
749 }
750
751 int UtcDaliFocusManagerClearFocus(void)
752 {
753   ToolkitTestApplication application;
754
755   tet_infoline(" UtcDaliFocusManagerClearFocus");
756
757   FocusManager manager = FocusManager::Get();
758   DALI_TEST_CHECK(manager);
759
760   // Create the first actor and add it to the stage
761   Actor first = Actor::New();
762   manager.SetFocusOrder(first, 1);
763   Stage::GetCurrent().Add(first);
764
765   // Create the second actor and add it to the stage
766   Actor second = Actor::New();
767   manager.SetFocusOrder(second, 2);
768   Stage::GetCurrent().Add(second);
769
770   // Check that no actor is being focused yet.
771   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
772
773   // Check that the focus is set on the first actor
774   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
775   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
776
777   // Check that the focus is set on the second actor
778   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
779   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
780
781   // Clear the focus
782   manager.ClearFocus();
783
784   // Check that no actor is being focused now.
785   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
786   END_TEST;
787 }
788
789 int UtcDaliFocusManagerReset(void)
790 {
791   ToolkitTestApplication application;
792
793   tet_infoline(" UtcDaliFocusManagerReset");
794
795   FocusManager manager = FocusManager::Get();
796   DALI_TEST_CHECK(manager);
797
798   // Create the first actor and add it to the stage
799   Actor first = Actor::New();
800   manager.SetFocusOrder(first, 1);
801   Stage::GetCurrent().Add(first);
802
803   // Create the second actor and add it to the stage
804   Actor second = Actor::New();
805   manager.SetFocusOrder(second, 2);
806   Stage::GetCurrent().Add(second);
807
808   // Check that no actor is being focused yet.
809   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
810
811   // Check that the focus is set on the first actor
812   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
813   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
814
815   // Check that the focus is set on the second actor
816   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
817   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
818
819   // Clear the focus
820   manager.Reset();
821
822   // Check that no actor is being focused now and the focus order of actors have been cleared
823   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
824   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
825   DALI_TEST_CHECK(manager.GetFocusOrder(first) == 0);
826   END_TEST;
827 }
828
829 int UtcDaliFocusManagerFocusGroup(void)
830 {
831   ToolkitTestApplication application;
832
833   tet_infoline(" UtcDaliFocusManagerFocusGroup");
834
835   FocusManager manager = FocusManager::Get();
836   DALI_TEST_CHECK(manager);
837
838   // Create an actor with two child actors and add it to the stage
839   Actor parent = Actor::New();
840   Actor firstChild = Actor::New();
841   Actor secondChild = Actor::New();
842   parent.Add(firstChild);
843   parent.Add(secondChild);
844   Stage::GetCurrent().Add(parent);
845
846   // Create three actors and add them as the children of the first child actor
847   Actor firstGrandChild = Actor::New();
848   Actor secondGrandChild = Actor::New();
849   Actor thirdGrandChild = Actor::New();
850   firstChild.Add(firstGrandChild);
851   firstChild.Add(secondGrandChild);
852   firstChild.Add(thirdGrandChild);
853
854   // Set focus order to the actors
855   manager.SetFocusOrder(parent, 1);
856   manager.SetFocusOrder(firstChild, 2);
857   manager.SetFocusOrder(firstGrandChild, 3);
858   manager.SetFocusOrder(secondGrandChild, 4);
859   manager.SetFocusOrder(thirdGrandChild, 5);
860   manager.SetFocusOrder(secondChild, 6);
861
862   // Set the parent and the first child actor as focus groups
863   manager.SetFocusGroup(parent, true);
864   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
865
866   // The focus group of the parent should be itself, as it is set to be a focus group.
867   DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent);
868
869   // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group.
870   DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent);
871
872   manager.SetFocusGroup(firstChild, true);
873   DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true);
874
875   // The focus group of the firstChild should be itself, as it is set to be a focus group now.
876   DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild);
877
878   // Enable wrap mode for focus movement.
879   manager.SetWrapMode(true);
880   DALI_TEST_CHECK(manager.GetWrapMode() == true);
881
882   // Check that no actor is being focused yet.
883   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
884
885   // Check that the focus is set on the parent actor.
886   DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true);
887   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
888
889   // Check that group mode is disabled.
890   DALI_TEST_CHECK(manager.GetGroupMode() == false);
891
892   // Check that the focus movement is wrapped as normal.
893   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
894   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
895   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
896   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
897   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
898   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
899   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
900   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
901   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
902   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild);
903   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
904   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent);
905   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
906   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
907   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
908   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
909
910   // Enable the group mode.
911   manager.SetGroupMode(true);
912   DALI_TEST_CHECK(manager.GetGroupMode() == true);
913
914   // Check that the focus movement is now limited to the current focus group.
915   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
916   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild);
917   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
918   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild);
919   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
920   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild);
921   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
922   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild);
923   END_TEST;
924 }
925
926 int UtcDaliFocusManagerSetAndGetFocusIndicator(void)
927 {
928   ToolkitTestApplication application;
929
930   tet_infoline(" UtcDaliFocusManagerSetAndGetFocusIndicator");
931
932   FocusManager manager = FocusManager::Get();
933   DALI_TEST_CHECK(manager);
934
935   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
936   DALI_TEST_CHECK(defaultFocusIndicatorActor);
937
938   Actor newFocusIndicatorActor = Actor::New();
939   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
940   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
941   END_TEST;
942 }
943
944 int UtcDaliFocusManagerSignalFocusChanged(void)
945 {
946   ToolkitTestApplication application;
947
948   tet_infoline(" UtcDaliFocusManagerSignalFocusChanged");
949
950   FocusManager manager = FocusManager::Get();
951   DALI_TEST_CHECK(manager);
952
953   bool signalVerified = false;
954   FocusChangedCallback callback(signalVerified);
955   manager.FocusChangedSignal().Connect( &callback, &FocusChangedCallback::Callback );
956
957   // Create the first actor and add it to the stage
958   Actor first = Actor::New();
959   manager.SetFocusOrder(first, 1);
960   Stage::GetCurrent().Add(first);
961
962   // Create the second actor and add it to the stage
963   Actor second = Actor::New();
964   manager.SetFocusOrder(second, 2);
965   Stage::GetCurrent().Add(second);
966
967   // Check that no actor is being focused yet.
968   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
969
970   // Check that the focus is set on the first actor
971   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
972   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
973   DALI_TEST_CHECK(callback.mSignalVerified);
974   callback.Reset();
975
976   // Check that the focus is set on the second actor
977   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
978   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
979   DALI_TEST_CHECK(callback.mSignalVerified);
980   callback.Reset();
981
982   // Clear the focus
983   manager.ClearFocus();
984
985   // Check that no actor is being focused now.
986   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
987   DALI_TEST_CHECK(callback.mSignalVerified);
988   END_TEST;
989 }
990
991 int UtcDaliFocusManagerSignalFocusOvershot(void)
992 {
993   ToolkitTestApplication application;
994
995   tet_infoline(" UtcDaliFocusManagerSignalFocusOvershot");
996
997   FocusManager manager = FocusManager::Get();
998   DALI_TEST_CHECK(manager);
999
1000   bool signalVerified = false;
1001   FocusOvershotCallback callback(signalVerified);
1002   manager.FocusOvershotSignal().Connect(&callback, &FocusOvershotCallback::Callback);
1003
1004   // Create the first actor and add it to the stage
1005   Actor first = Actor::New();
1006   manager.SetFocusOrder(first, 1);
1007   Stage::GetCurrent().Add(first);
1008
1009   // Create the second actor and add it to the stage
1010   Actor second = Actor::New();
1011   manager.SetFocusOrder(second, 2);
1012   Stage::GetCurrent().Add(second);
1013
1014   // Check that the wrap mode is disabled
1015   DALI_TEST_CHECK(manager.GetWrapMode() == false);
1016
1017   // Check that the focus is set on the first actor
1018   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1019   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1020
1021   // Check that the focus is moved to the second actor successfully.
1022   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1023   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1024
1025   // Check that the forward focus movement is overshot.
1026   callback.mCurrentFocusedActor = second;
1027   callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_NEXT;
1028   DALI_TEST_CHECK(manager.MoveFocusForward() == false);
1029   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1030   DALI_TEST_CHECK(signalVerified);
1031   callback.Reset();
1032
1033   // Enable the wrap mode
1034   manager.SetWrapMode(true);
1035   DALI_TEST_CHECK(manager.GetWrapMode() == true);
1036
1037   // Check that the forward focus movement is wrapped and no overshot happens.
1038   DALI_TEST_CHECK(manager.MoveFocusForward() == true);
1039   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1040   DALI_TEST_CHECK(signalVerified == false);
1041
1042   // Disable the wrap mode
1043   manager.SetWrapMode(false);
1044   DALI_TEST_CHECK(manager.GetWrapMode() == false);
1045
1046   // Check that the backward focus movement is overshot.
1047   callback.mCurrentFocusedActor = first;
1048   callback.mFocusOvershotDirection = Toolkit::FocusManager::OVERSHOT_PREVIOUS;
1049   DALI_TEST_CHECK(manager.MoveFocusBackward() == false);
1050   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1051   DALI_TEST_CHECK(signalVerified);
1052   END_TEST;
1053 }