Merge "Add Visual descriptions to generate doxygen page" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-KeyInputFocusManager.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 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali/integration-api/events/key-event-integ.h>
23 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
24
25 #include "dummy-control.h"
26
27 using namespace Dali;
28 using namespace Toolkit;
29
30 namespace
31 {
32
33 /**
34  * Callback class for KeyInputFocusChanged signal.
35  */
36 class KeyInputFocusChangedCallback : public Dali::ConnectionTracker
37 {
38 public:
39   /**
40    * Constructor
41    * @param[in]  gainActor  Ref to the actor that should be set as the one that gains key input focus.
42    * @param[in]  lostActor  Ref to the actor that should be set as the one that loses key input focus.
43    */
44   KeyInputFocusChangedCallback( Control& gainActor, Control& lostActor )
45   : mActorGain( gainActor ),
46     mActorLost( lostActor )
47   {
48   }
49
50   void Callback( Control gainingActor, Control lostActor )
51   {
52     mActorGain = gainingActor;
53     mActorLost = lostActor;
54   }
55
56   Control& mActorGain;
57   Control& mActorLost;
58 };
59
60 // Stores data that is populated in the callback and will be read by the TET cases
61 struct SignalData
62 {
63   SignalData()
64   : functorCalled(false)
65   {}
66
67   void Reset()
68   {
69     functorCalled = false;
70
71     receivedKeyEvent.keyModifier = 0;
72     receivedKeyEvent.keyPressedName.clear();
73     receivedKeyEvent.keyPressed.clear();
74
75   }
76
77   bool functorCalled;
78   KeyEvent receivedKeyEvent;
79 };
80
81 /**
82  * Callback class to test SignalUnhandledKeyEvent signal
83  */
84 class SignalUnhandledKeyEventCallback : public Dali::ConnectionTracker
85 {
86 public:
87   SignalUnhandledKeyEventCallback( SignalData& data ) : mSignalData( data ) { }
88
89   void Callback(const KeyEvent& event)
90   {
91     mSignalData.functorCalled = true;
92     mSignalData.receivedKeyEvent = event;
93   }
94
95   SignalData& mSignalData;
96 };
97
98 } // namespace
99
100 void key_input_focus_manager_startup(void)
101 {
102   test_return_value = TET_UNDEF;
103 }
104
105 void key_input_focus_manager_cleanup(void)
106 {
107   test_return_value = TET_PASS;
108 }
109
110 int UtcDaliKeyInputFocusManagerGet(void)
111 {
112   ToolkitTestApplication application;
113
114   tet_infoline(" UtcDaliKeyInputFocusManagerGet");
115
116   KeyInputFocusManager manager;
117   {
118     manager = KeyInputFocusManager::Get();
119     DALI_TEST_CHECK(manager);
120   }
121
122   KeyInputFocusManager newManager = KeyInputFocusManager::Get();
123   DALI_TEST_CHECK(newManager);
124
125   // Check that focus manager is a singleton
126   DALI_TEST_CHECK(manager == newManager);
127   END_TEST;
128 }
129
130 int UtcDaliKeyInputFocusManagerSetFocus01(void)
131 {
132   ToolkitTestApplication application;
133   Stage stage = Stage::GetCurrent();
134
135   tet_infoline(" Check that there is no focused control. Add a control to the stack. Check it is now the focused actor and receives KeyInputFocusGained signal");
136
137   KeyInputFocusManager manager = KeyInputFocusManager::Get();
138   DALI_TEST_CHECK(manager);
139
140   Control focusedControl = manager.GetCurrentFocusControl();
141   DALI_TEST_CHECK( ! focusedControl );
142
143   DummyControl dummy = DummyControl::New(true);
144   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
145   dummy.SetSize(100.0f, 100.0f);
146   stage.Add( dummy );
147   DALI_TEST_CHECK( ! dummyImpl.keyInputFocusGained );
148
149   manager.SetFocus( dummy );
150   DALI_TEST_CHECK( dummy.HasKeyInputFocus()); // Also tests IsKeyboardListener() API
151   DALI_TEST_CHECK( dummyImpl.keyInputFocusGained );
152
153   focusedControl = manager.GetCurrentFocusControl();
154   DALI_TEST_CHECK( focusedControl );
155   DALI_TEST_CHECK( focusedControl == dummy );
156
157   END_TEST;
158 }
159
160 int UtcDaliKeyInputFocusManagerSetFocus02(void)
161 {
162   ToolkitTestApplication application;
163   Stage stage = Stage::GetCurrent();
164
165   tet_infoline(" Add a control to the stack. Check it is now the focused actor and receives KeyInputFocusGained signal. Add another control - check that the first control receives KeyInputFocusLost");
166
167   KeyInputFocusManager manager = KeyInputFocusManager::Get();
168   DALI_TEST_CHECK(manager);
169
170   DummyControl dummy1 = DummyControl::New(true);
171   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
172   dummy1.SetSize(100.0f, 100.0f);
173   stage.Add( dummy1 );
174   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
175   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
176
177   stage.Add( dummy1 );
178
179   manager.SetFocus( dummy1 );
180   DALI_TEST_CHECK( dummy1.HasKeyInputFocus()); // Also tests IsKeyboardListener() API
181   DALI_TEST_CHECK( dummy1Impl.keyInputFocusGained );
182   dummy1Impl.keyInputFocusGained = false;
183
184   DummyControl dummy2 = DummyControl::New(true);
185   Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
186   dummy2.SetSize(100.0f, 100.0f);
187   stage.Add( dummy2 );
188   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
189   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
190
191   stage.Add( dummy2 );
192
193   manager.SetFocus( dummy2 );
194   DALI_TEST_CHECK( dummy2.HasKeyInputFocus()); // Also tests IsKeyboardListener() API
195   DALI_TEST_CHECK( dummy2Impl.keyInputFocusGained );
196   dummy1Impl.keyInputFocusGained = false;
197
198   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
199   DALI_TEST_CHECK( dummy1Impl.keyInputFocusLost );
200
201
202   END_TEST;
203 }
204
205 int UtcDaliKeyInputFocusManagerGetCurrentFocusControl(void)
206 {
207   ToolkitTestApplication application;
208   Stage stage = Stage::GetCurrent();
209
210   tet_infoline(" Add 2 controls, check they each get focused. Re-focus the first control - ensure it's now got focus (check signals)");
211
212   KeyInputFocusManager manager = KeyInputFocusManager::Get();
213   DALI_TEST_CHECK(manager);
214
215   DummyControl dummy1 = DummyControl::New(true);
216   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
217   dummy1.SetSize(100.0f, 100.0f);
218   stage.Add( dummy1 );
219   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
220   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
221
222   DummyControl dummy2 = DummyControl::New(true);
223   Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
224   dummy2.SetSize(100.0f, 100.0f);
225   stage.Add( dummy2 );
226   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
227   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
228
229   manager.SetFocus(dummy1);
230   DALI_TEST_CHECK( dummy1 == manager.GetCurrentFocusControl() );
231   DALI_TEST_CHECK( dummy1Impl.keyInputFocusGained );
232   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
233   dummy1Impl.keyInputFocusGained = false;
234   dummy1Impl.keyInputFocusLost = false;
235
236   manager.SetFocus(dummy2);
237   DALI_TEST_CHECK( dummy2 == manager.GetCurrentFocusControl() );
238   DALI_TEST_CHECK( dummy1Impl.keyInputFocusLost );
239   DALI_TEST_CHECK( dummy2Impl.keyInputFocusGained );
240   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
241   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
242   // Reset signal received
243   dummy1Impl.keyInputFocusGained = false;
244   dummy1Impl.keyInputFocusLost = false;
245   dummy2Impl.keyInputFocusGained = false;
246   dummy2Impl.keyInputFocusLost = false;
247
248   manager.SetFocus(dummy1);
249   DALI_TEST_CHECK( dummy1 == manager.GetCurrentFocusControl());
250   DALI_TEST_CHECK( dummy1Impl.keyInputFocusGained );
251   DALI_TEST_CHECK( dummy2Impl.keyInputFocusLost );
252   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
253   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
254   END_TEST;
255 }
256
257 int UtcDaliKeyInputFocusManagerRemoveFocus01(void)
258 {
259   ToolkitTestApplication application;
260   Stage stage = Stage::GetCurrent();
261
262   tet_infoline(" Add 3 focus controls. Test that removing the topmost informs the next control that it now has focus, Test that the bottommost control doesn't receive anything. ");
263
264   KeyInputFocusManager manager = KeyInputFocusManager::Get();
265   DALI_TEST_CHECK(manager);
266
267   DummyControl dummy1 = DummyControl::New(true);
268   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
269   dummy1.SetSize(100.0f, 100.0f);
270   stage.Add( dummy1 );
271   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
272   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
273
274   DummyControl dummy2 = DummyControl::New(true);
275   Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
276   dummy2.SetSize(100.0f, 100.0f);
277   stage.Add( dummy2 );
278   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
279   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
280
281   manager.SetFocus(dummy1);
282   DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
283
284   manager.SetFocus(dummy2);
285   DALI_TEST_CHECK(dummy2 == manager.GetCurrentFocusControl());
286   dummy1Impl.keyInputFocusGained = false;
287   dummy1Impl.keyInputFocusLost = false;
288   dummy2Impl.keyInputFocusGained = false;
289   dummy2Impl.keyInputFocusLost = false;
290
291   manager.RemoveFocus(dummy2);
292   DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
293   DALI_TEST_CHECK( dummy1Impl.keyInputFocusGained );
294   DALI_TEST_CHECK( dummy2Impl.keyInputFocusLost );
295   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
296   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
297   dummy1Impl.keyInputFocusGained = false;
298   dummy1Impl.keyInputFocusLost = false;
299   dummy2Impl.keyInputFocusGained = false;
300   dummy2Impl.keyInputFocusLost = false;
301
302   manager.RemoveFocus(dummy1);
303   DALI_TEST_CHECK(Control() == manager.GetCurrentFocusControl());
304   DALI_TEST_CHECK( dummy1Impl.keyInputFocusLost );
305   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
306   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
307   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
308
309   END_TEST;
310 }
311
312 int UtcDaliKeyInputFocusManagerRemoveFocus02(void)
313 {
314   ToolkitTestApplication application;
315   Stage stage = Stage::GetCurrent();
316
317   tet_infoline(" Add 3 focus controls. Test that removing the bottommost doesn't change the focused control" );
318
319   KeyInputFocusManager manager = KeyInputFocusManager::Get();
320   DALI_TEST_CHECK(manager);
321
322   DummyControl dummy1 = DummyControl::New(true);
323   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
324   dummy1.SetSize(100.0f, 100.0f);
325   stage.Add( dummy1 );
326   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
327   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
328
329   DummyControl dummy2 = DummyControl::New(true);
330   Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
331   dummy2.SetSize(100.0f, 100.0f);
332   stage.Add( dummy2 );
333   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
334   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
335
336   DummyControl dummy3 = DummyControl::New(true);
337   Impl::DummyControl& dummy3Impl = static_cast<Impl::DummyControl&>(dummy3.GetImplementation());
338   dummy3.SetSize(100.0f, 100.0f);
339   stage.Add( dummy3 );
340   DALI_TEST_CHECK( ! dummy3Impl.keyInputFocusGained );
341   DALI_TEST_CHECK( ! dummy3Impl.keyInputFocusLost );
342
343   manager.SetFocus(dummy1);
344   DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
345
346   manager.SetFocus(dummy2);
347   DALI_TEST_CHECK(dummy2 == manager.GetCurrentFocusControl());
348
349   manager.SetFocus(dummy3);
350   DALI_TEST_CHECK(dummy3 == manager.GetCurrentFocusControl());
351   dummy1Impl.keyInputFocusGained = false;
352   dummy1Impl.keyInputFocusLost = false;
353   dummy2Impl.keyInputFocusGained = false;
354   dummy2Impl.keyInputFocusLost = false;
355   dummy3Impl.keyInputFocusGained = false;
356   dummy3Impl.keyInputFocusLost = false;
357
358   manager.RemoveFocus(dummy1);
359   DALI_TEST_CHECK(dummy3 == manager.GetCurrentFocusControl());
360   DALI_TEST_CHECK( dummy1Impl.keyInputFocusLost );
361   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
362   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
363   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
364   DALI_TEST_CHECK( ! dummy3Impl.keyInputFocusLost );
365   DALI_TEST_CHECK( ! dummy3Impl.keyInputFocusGained );
366   dummy1Impl.keyInputFocusGained = false;
367   dummy1Impl.keyInputFocusLost = false;
368   dummy2Impl.keyInputFocusGained = false;
369   dummy2Impl.keyInputFocusLost = false;
370   dummy3Impl.keyInputFocusGained = false;
371   dummy3Impl.keyInputFocusLost = false;
372
373   END_TEST;
374 }
375
376 int UtcDaliKeyInputFocusManagerRemoveFocus03(void)
377 {
378   ToolkitTestApplication application;
379   Stage stage = Stage::GetCurrent();
380
381   tet_infoline(" Add 2 focus controls. Remove each of them from the bottom up. Test that the stack is now empty. Add a new control - check that it correctly has focus" );
382
383   KeyInputFocusManager manager = KeyInputFocusManager::Get();
384   DALI_TEST_CHECK(manager);
385
386   DummyControl dummy1 = DummyControl::New(true);
387   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
388   dummy1.SetSize(100.0f, 100.0f);
389   stage.Add( dummy1 );
390   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
391   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
392
393   DummyControl dummy2 = DummyControl::New(true);
394   Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
395   dummy2.SetSize(100.0f, 100.0f);
396   stage.Add( dummy2 );
397   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
398   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
399
400   manager.SetFocus(dummy1);
401   DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
402
403   manager.SetFocus(dummy2);
404   DALI_TEST_CHECK(dummy2 == manager.GetCurrentFocusControl());
405
406   dummy1Impl.keyInputFocusGained = false;
407   dummy1Impl.keyInputFocusLost = false;
408   dummy2Impl.keyInputFocusGained = false;
409   dummy2Impl.keyInputFocusLost = false;
410
411   manager.RemoveFocus(dummy1);
412   DALI_TEST_CHECK(dummy2 == manager.GetCurrentFocusControl());
413   DALI_TEST_CHECK( dummy1Impl.keyInputFocusLost );
414   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
415   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
416   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
417   dummy1Impl.keyInputFocusGained = false;
418   dummy1Impl.keyInputFocusLost = false;
419   dummy2Impl.keyInputFocusGained = false;
420   dummy2Impl.keyInputFocusLost = false;
421
422   manager.RemoveFocus(dummy2);
423   DALI_TEST_CHECK(Control() == manager.GetCurrentFocusControl());
424   DALI_TEST_CHECK( dummy2Impl.keyInputFocusLost );
425   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
426   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
427   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
428   dummy1Impl.keyInputFocusGained = false;
429   dummy1Impl.keyInputFocusLost = false;
430   dummy2Impl.keyInputFocusGained = false;
431   dummy2Impl.keyInputFocusLost = false;
432
433   PushButton pushButton1 = PushButton::New();
434   stage.Add( pushButton1 );
435   manager.SetFocus( pushButton1 );
436   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
437   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
438   DALI_TEST_CHECK( pushButton1 == manager.GetCurrentFocusControl());
439   END_TEST;
440 }
441
442 int UtcDaliKeyInputFocusManagerRemoveFocus04(void)
443 {
444   ToolkitTestApplication application;
445   Stage stage = Stage::GetCurrent();
446
447   tet_infoline(" Test what happens if the removed control is not on the focus stack");
448   KeyInputFocusManager manager = KeyInputFocusManager::Get();
449   DALI_TEST_CHECK(manager);
450
451   PushButton pushButton1 = PushButton::New();
452   PushButton pushButton2 = PushButton::New();
453   stage.Add( pushButton1 );
454   stage.Add( pushButton2 );
455   manager.SetFocus( pushButton1 );
456   manager.SetFocus( pushButton2 );
457
458   PushButton pushButton3 = PushButton::New();
459   stage.Add( pushButton3 );
460   manager.RemoveFocus( pushButton3 );
461   DALI_TEST_CHECK( pushButton2 == manager.GetCurrentFocusControl());
462   END_TEST;
463 }
464
465 int UtcDaliKeyInputFocusManagerDestroyObject01(void)
466 {
467   ToolkitTestApplication application;
468   Stage stage = Stage::GetCurrent();
469
470   tet_infoline(" Add 2 controls to the stack. Unparent and destroy the topmost. Check that it is removed from the stack, and that the bottommost is correctly focused" );
471
472   KeyInputFocusManager manager = KeyInputFocusManager::Get();
473   DALI_TEST_CHECK(manager);
474
475   DummyControl dummy1 = DummyControl::New(true);
476   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
477   dummy1.SetSize(100.0f, 100.0f);
478   stage.Add( dummy1 );
479   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
480   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
481
482   {
483     DummyControl dummy2 = DummyControl::New(true);
484     Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
485     dummy2.SetSize(100.0f, 100.0f);
486     stage.Add( dummy2 );
487     DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
488     DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
489
490     manager.SetFocus(dummy1);
491     DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
492
493     manager.SetFocus(dummy2);
494     DALI_TEST_CHECK(dummy2 == manager.GetCurrentFocusControl());
495
496     dummy1Impl.keyInputFocusGained = false;
497     dummy1Impl.keyInputFocusLost = false;
498     dummy2Impl.keyInputFocusGained = false;
499     dummy2Impl.keyInputFocusLost = false;
500
501     stage.Remove(dummy2);
502   }
503
504   DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
505   DALI_TEST_CHECK( dummy1Impl.keyInputFocusGained );
506   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
507   END_TEST;
508 }
509
510 int UtcDaliKeyInputFocusManagerDestroyObject02(void)
511 {
512   ToolkitTestApplication application;
513   Stage stage = Stage::GetCurrent();
514
515   tet_infoline(" Add 2 controls to the stack. Destroy a different actor entirely. Check that the stack is un-affected.");
516
517   KeyInputFocusManager manager = KeyInputFocusManager::Get();
518   DALI_TEST_CHECK(manager);
519
520   DummyControl dummy1 = DummyControl::New(true);
521   Impl::DummyControl& dummy1Impl = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
522   dummy1.SetSize(100.0f, 100.0f);
523   stage.Add( dummy1 );
524   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusGained );
525   DALI_TEST_CHECK( ! dummy1Impl.keyInputFocusLost );
526
527
528   DummyControl dummy2 = DummyControl::New(true);
529   Impl::DummyControl& dummy2Impl = static_cast<Impl::DummyControl&>(dummy2.GetImplementation());
530   dummy2.SetSize(100.0f, 100.0f);
531   stage.Add( dummy2 );
532   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusGained );
533   DALI_TEST_CHECK( ! dummy2Impl.keyInputFocusLost );
534
535   manager.SetFocus(dummy1);
536   DALI_TEST_CHECK(dummy1 == manager.GetCurrentFocusControl());
537
538   manager.SetFocus(dummy2);
539   DALI_TEST_CHECK(dummy2 == manager.GetCurrentFocusControl());
540
541   dummy1Impl.keyInputFocusGained = false;
542   dummy1Impl.keyInputFocusLost = false;
543   dummy2Impl.keyInputFocusGained = false;
544   dummy2Impl.keyInputFocusLost = false;
545
546   {
547     BufferImage image = CreateBufferImage();
548     Actor actor = CreateRenderableActor( image );
549     stage.Add( actor );
550     actor.SetSize(100, 100);
551
552     application.SendNotification();
553     application.Render();
554
555     stage.Remove( actor );
556   }
557
558   DALI_TEST_CHECK( dummy2 == manager.GetCurrentFocusControl());
559   END_TEST;
560 }
561
562 int UtcDaliKeyInputFocusManagerIsKeyboardListener(void)
563 {
564   ToolkitTestApplication application;
565   Stage stage = Stage::GetCurrent();
566
567   tet_infoline(" UtcDaliKeyInputFocusManagerIsKeyboardListener");
568
569   KeyInputFocusManager manager = KeyInputFocusManager::Get();
570   DALI_TEST_CHECK(manager);
571
572   PushButton pushButton1 = PushButton::New();
573   PushButton pushButton2 = PushButton::New();
574   stage.Add( pushButton1 );
575   stage.Add( pushButton2 );
576
577   manager.SetFocus(pushButton1);
578   DALI_TEST_CHECK(pushButton1 == manager.GetCurrentFocusControl());
579
580   manager.SetFocus(pushButton2);
581   DALI_TEST_CHECK(pushButton2 == manager.GetCurrentFocusControl());
582
583   DALI_TEST_CHECK(manager.IsKeyboardListener(pushButton1));
584   DALI_TEST_CHECK(manager.IsKeyboardListener(pushButton2));
585
586   manager.RemoveFocus(pushButton2);
587   DALI_TEST_CHECK(!manager.IsKeyboardListener(pushButton2));
588
589   manager.RemoveFocus(pushButton1);
590   DALI_TEST_CHECK(!manager.IsKeyboardListener(pushButton1));
591
592   manager.SetFocus(pushButton2);
593   DALI_TEST_CHECK(manager.IsKeyboardListener(pushButton2));
594   pushButton2.ClearKeyInputFocus();
595   DALI_TEST_CHECK(!manager.IsKeyboardListener(pushButton2));
596   END_TEST;
597 }
598
599 int UtcDaliKeyInputFocusManagerSignalKeyInputFocusChanged(void)
600 {
601   ToolkitTestApplication application;
602   KeyInputFocusManager manager = KeyInputFocusManager::Get();
603   Stage stage = Stage::GetCurrent();
604
605   tet_infoline(" UtcDaliKeyInputFocusManagerSignalKeyInputFocusChanged");
606
607   PushButton pushButton1 = PushButton::New();
608   PushButton pushButton2 = PushButton::New();
609
610   stage.Add( pushButton1 );
611   stage.Add( pushButton2 );
612
613   PushButton gainActor, lostActor;
614   KeyInputFocusChangedCallback callback( gainActor, lostActor );
615   manager.KeyInputFocusChangedSignal().Connect( &callback, &KeyInputFocusChangedCallback::Callback );
616
617   manager.SetFocus(pushButton1);
618
619   DALI_TEST_CHECK( gainActor == pushButton1 );
620   DALI_TEST_CHECK( lostActor == Control() );
621
622   gainActor.Reset();
623   lostActor.Reset();
624
625   manager.SetFocus(pushButton2);
626
627   DALI_TEST_CHECK( gainActor == pushButton2 );
628   DALI_TEST_CHECK( lostActor == pushButton1 );
629
630   gainActor.Reset();
631   lostActor.Reset();
632
633   // Removing the focus actor from the stage would also result in signal emission.
634   stage.Remove( pushButton1 );
635   stage.Remove( pushButton2 );
636
637   DALI_TEST_CHECK( gainActor == Control() );
638   DALI_TEST_CHECK( lostActor == Control() );
639   END_TEST;
640 }
641
642 int UtcDaliKeyInputFocusManagerSignalUnhandledKeyEvent(void)
643 {
644   ToolkitTestApplication application;
645
646   tet_infoline("UtcDaliKeyInputFocusManagerSignalUnhandledKeyEvent");
647
648   SignalData data;
649   SignalUnhandledKeyEventCallback callback( data );
650
651   KeyInputFocusManager manager = KeyInputFocusManager::Get();
652   manager.UnhandledKeyEventSignal().Connect( &callback, &SignalUnhandledKeyEventCallback::Callback );
653
654
655   Integration::KeyEvent event("a", "a", 0, 0, 0, Integration::KeyEvent::Up);
656   application.ProcessEvent(event);
657
658   DALI_TEST_CHECK(data.functorCalled);
659   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.keyPressedName );
660   DALI_TEST_CHECK(event.keyCode == data.receivedKeyEvent.keyCode);
661   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.keyPressed );
662   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.state) );
663
664   data.Reset();
665
666   Integration::KeyEvent event2("v", "v", 0, 0, 0, Integration::KeyEvent::Up);
667   application.ProcessEvent(event2);
668
669   DALI_TEST_CHECK(data.functorCalled);
670   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.keyPressedName );
671   DALI_TEST_CHECK(event2.keyCode == data.receivedKeyEvent.keyCode);
672   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.keyPressed );
673   END_TEST;
674 }