Handle becomes Animatable
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Popup.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <stdlib.h>
19
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include "dali-toolkit-test-utils/toolkit-timer.h"
24
25 #include <dali.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/devel-api/scripting/scripting.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include <dali-toolkit/devel-api/controls/popup/popup.h>
31
32 using namespace Dali;
33 using namespace Toolkit;
34
35 void utc_dali_toolkit_popup_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void utc_dali_toolkit_popup_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 namespace
46 {
47 static bool gObjectCreatedCallBackCalled;
48
49 static void TestCallback(BaseHandle handle)
50 {
51   gObjectCreatedCallBackCalled = true;
52 }
53
54 const int RENDER_FRAME_INTERVAL = 10;                          ///< Duration of each frame in ms.
55 const int RENDER_ANIMATION_TEST_DURATION_MS = 2000;            ///< 2000ms to test animation.
56 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
57 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
58
59 Dali::Integration::Point GetPointDown()
60 {
61   Dali::Integration::Point point;
62   point.SetState( PointState::DOWN );
63   point.SetScreenPosition( Vector2( 10, 10 ) );
64   return point;
65 }
66
67 Dali::Integration::Point GetPointUp()
68 {
69   Dali::Integration::Point point;
70   point.SetState( PointState::UP );
71   point.SetScreenPosition( Vector2( 10, 10 ) );
72   return point;
73 }
74
75 /**
76  * Counts how many descendants root Actor has, including
77  * itself.
78  *
79  * @param[in] root The root actor to count from.
80  * @return The number of descendants including root actor itself.
81  */
82 int DescendentCount( const Actor& root )
83 {
84   unsigned int numChildren = root.GetChildCount();
85
86   int count = 1;
87
88   for( unsigned int i = 0; i < numChildren; ++i )
89   {
90     count += DescendentCount( root.GetChildAt( i ) );
91   }
92
93   return count;
94 }
95
96 bool HasAncestor( Actor child, Actor ancestor )
97 {
98   while( child && child != ancestor )
99   {
100     child = child.GetParent();
101   }
102
103   return ( child == ancestor );
104 }
105
106 static Toolkit::Popup::DisplayState gPopupState = Toolkit::Popup::HIDDEN;
107 static bool gTouchedOutside;
108
109 // Signal callbacks
110
111 static void OnPopupTouchedOutside()
112 {
113   gTouchedOutside = true;
114 }
115
116 static void OnPopupShowing()
117 {
118   gPopupState = Toolkit::Popup::SHOWING;
119 }
120
121 static void OnPopupShown()
122 {
123   gPopupState = Toolkit::Popup::SHOWN;
124 }
125
126 static void OnPopupHiding()
127 {
128   gPopupState = Toolkit::Popup::HIDING;
129 }
130
131 static void OnPopupHidden()
132 {
133   gPopupState = Toolkit::Popup::HIDDEN;
134 }
135
136 void ConnectStateSignals( Toolkit::Popup popup )
137 {
138   popup.ShowingSignal().Connect( &OnPopupShowing );
139   popup.ShownSignal().Connect( &OnPopupShown );
140   popup.HidingSignal().Connect( &OnPopupHiding );
141   popup.HiddenSignal().Connect( &OnPopupHidden );
142 }
143
144 void WaitAnimation( ToolkitTestApplication& application )
145 {
146   // Wait for a while (allow animation to complete), and then check state.
147   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
148   {
149     application.SendNotification();
150     application.Render( RENDER_FRAME_INTERVAL );
151   }
152 }
153
154 /**
155  * A connection tracker is required when connecting to a signal with a functor.
156  */
157 class TestConnectionTrackerObject : public ConnectionTracker
158 {
159 };
160
161 /**
162  * This functor is used to test the popup's signal connection.
163  */
164 struct PopupTestFunctor
165 {
166   PopupTestFunctor()
167   {
168   }
169
170   void operator()()
171   {
172   }
173 };
174
175 // Generate a KeyEvent to send to Core.
176 Integration::KeyEvent GenerateKey( const std::string& keyName,
177                                    const std::string& keyString,
178                                    int keyCode,
179                                    int keyModifier,
180                                    unsigned long timeStamp,
181                                    const Integration::KeyEvent::State& keyState,
182                                    const std::string& deviceName
183                                    )
184 {
185   return Integration::KeyEvent( keyName,
186                                 keyString,
187                                 keyCode,
188                                 keyModifier,
189                                 timeStamp,
190                                 keyState,
191                                 deviceName);
192 }
193
194 } // Anonymous namespace
195
196 /*
197  * This test checks popup creation.
198  */
199 int UtcDaliPopupNewP( void )
200 {
201   ToolkitTestApplication application;
202   tet_infoline( " UtcDaliPopupNewP" );
203
204   // Create the Popup actor.
205   Popup popup;
206
207   DALI_TEST_CHECK( !popup );
208
209   popup = Popup::New();
210
211   DALI_TEST_CHECK( popup );
212
213   Popup popup2( popup );
214
215   DALI_TEST_CHECK( popup2 == popup );
216
217   // Additional check to ensure object is created by checking if it's registered.
218   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
219   DALI_TEST_CHECK( registry );
220
221   gObjectCreatedCallBackCalled = false;
222   registry.ObjectCreatedSignal().Connect( &TestCallback );
223   {
224     Popup popup = Popup::New();
225   }
226   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
227   END_TEST;
228 }
229
230 /*
231  * This test checks popup destruction.
232  */
233 int UtcDaliPopupDestructorP( void )
234 {
235   ToolkitTestApplication application;
236   tet_infoline( " UtcDaliPopupDestructorP" );
237
238   Popup* popup = new Popup();
239   delete popup;
240
241   DALI_TEST_CHECK( true );
242   END_TEST;
243 }
244
245 int UtcDaliPopupDownCastP(void)
246 {
247   ToolkitTestApplication application;
248   tet_infoline( " UtcDaliPopupDownCastP" );
249
250   Handle handle = Popup::New();
251
252   Popup popup = Popup::DownCast( handle );
253
254   DALI_TEST_CHECK( popup == handle );
255   END_TEST;
256 }
257
258 int UtcDaliPopupSetPropertyP(void)
259 {
260   ToolkitTestApplication application;
261   tet_infoline( " UtcDaliPopupSetProperty" );
262
263   Popup popup = Popup::New();
264
265   //Test properties
266   std::string testString = "Hello World";
267
268   TextLabel textActorIn = TextLabel::New( testString );
269   Property::Map map;
270   Scripting::CreatePropertyMap( textActorIn, map );
271   popup.SetProperty( popup.GetPropertyIndex( "title" ), map );
272   TextLabel textActorOut = TextLabel::DownCast( popup.GetTitle() );
273   std::string resultText;
274   DALI_TEST_CHECK( textActorOut.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
275   DALI_TEST_EQUALS( testString, resultText, TEST_LOCATION );
276
277   END_TEST;
278 }
279
280 int UtcDaliPopupSetTitleP(void)
281 {
282   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
283   tet_infoline( " UtcDaliPopupSetTitleP" );
284
285   // Create the Popup actor
286   Popup popup = Popup::New();
287
288   // Put in show state so it's layer is connected to popup (for ancestor check).
289   popup.SetDisplayState( Popup::SHOWN );
290
291   TextLabel titleActor = TextLabel::New();
292   titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, "title" );
293
294   DALI_TEST_CHECK( !popup.GetTitle() );
295   popup.SetTitle( titleActor );
296   TextLabel textActor = TextLabel::DownCast( popup.GetTitle() );
297   DALI_TEST_CHECK( textActor == titleActor );
298
299   std::string resultText;
300   DALI_TEST_CHECK( textActor.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
301
302   DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "title" ) );
303   // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
304   DALI_TEST_CHECK( HasAncestor( titleActor, popup ) );
305
306   TextLabel titleActor2 = TextLabel::New();
307   titleActor2.SetProperty( Toolkit::TextLabel::Property::TEXT, "anothertitle" );
308   popup.SetTitle( titleActor2 );
309   DALI_TEST_CHECK( popup.GetTitle() != titleActor );
310   DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
311   DALI_TEST_CHECK( TextLabel::DownCast( popup.GetTitle() ).GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
312
313   DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "anothertitle" ) );
314
315   // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
316   DALI_TEST_CHECK( HasAncestor( titleActor2, popup ) );
317   END_TEST;
318 }
319
320 int UtcDaliPopupSetTitleN(void)
321 {
322   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
323   tet_infoline( " UtcDaliPopupSetTitleN" );
324
325   // Create the Popup actor
326   Popup popup = Popup::New();
327
328   TextLabel titleActor = TextLabel::New( "text" );
329   popup.SetTitle( titleActor );
330
331   DALI_TEST_CHECK( popup.GetTitle() );
332
333   // Set a bad title value.
334   // Confirm this has disabled the title.
335   Actor badActor;
336   popup.SetTitle( badActor );
337
338   DALI_TEST_CHECK( !popup.GetTitle() );
339
340   END_TEST;
341 }
342
343 int UtcDaliPopupSetContentP(void)
344 {
345   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
346   tet_infoline( " UtcDaliPopupSetContentP" );
347
348   // Create the Popup actor
349   Popup popup = Popup::New();
350   Stage::GetCurrent().Add( popup );
351   popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
352
353   // Put in show state so it's layer is connected to popup (for ancestor check).
354   popup.SetDisplayState( Popup::SHOWN );
355
356   PushButton button = PushButton::New();
357   DALI_TEST_CHECK( !HasAncestor( button, popup ) );
358   popup.SetFooter( button );
359   // Hide and then re-show popup to cause button to be rearranged and added to popup.
360   popup.SetDisplayState( Popup::HIDDEN );
361   popup.SetDisplayState( Popup::SHOWN );
362   DALI_TEST_CHECK( HasAncestor( button, popup ) );
363   END_TEST;
364 }
365
366 int UtcDaliPopupSetContentN(void)
367 {
368   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
369   tet_infoline( " UtcDaliPopupSetContentN" );
370
371   // Create the Popup actor
372   Popup popup = Popup::New();
373
374   TextLabel content = TextLabel::New( "text" );
375   popup.SetContent( content );
376
377   DALI_TEST_CHECK( popup.GetContent() );
378
379   // Set a bad title value.
380   Actor badActor;
381   popup.SetContent( badActor );
382
383   DALI_TEST_CHECK( !popup.GetContent() );
384
385   END_TEST;
386 }
387
388 int UtcDaliPopupSetFooterP(void)
389 {
390   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
391   tet_infoline(" UtcDaliPopupSetFooterP");
392
393   // Create the Popup actor
394   Popup popup = Popup::New();
395   Stage::GetCurrent().Add( popup );
396   popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
397   // Put in show state so it's layer is connected to popup (for ancestor check).
398   popup.SetDisplayState( Popup::SHOWN );
399
400   PushButton button = PushButton::New();
401   DALI_TEST_CHECK( !HasAncestor(button, popup) );
402   popup.SetFooter( button );
403   // Hide and then re-show popup to cause button to be rearranged and added to popup.
404   popup.SetDisplayState( Popup::HIDDEN );
405   popup.SetDisplayState( Popup::SHOWN );
406   DALI_TEST_CHECK( HasAncestor( button, popup ) );
407   END_TEST;
408 }
409
410 int UtcDaliPopupSetFooterN(void)
411 {
412   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
413   tet_infoline(" UtcDaliPopupSetFooterN");
414
415   // Create the Popup actor
416   Popup popup = Popup::New();
417
418   PushButton button = PushButton::New();
419   popup.SetFooter( button );
420
421   DALI_TEST_CHECK( popup.GetFooter() );
422
423   // Set a bad title value.
424   Actor badActor;
425   popup.SetFooter( badActor );
426
427   DALI_TEST_CHECK( !popup.GetFooter() );
428
429   END_TEST;
430 }
431
432 int UtcDaliPopupSetControlFooterMultiple(void)
433 {
434   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
435   tet_infoline(" UtcDaliPopupSetControlFooterMultiple");
436
437   // Create the Popup actor
438   Popup popup = Popup::New();
439   Stage::GetCurrent().Add( popup );
440   popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
441   // Put in show state so it's layer is connected to popup (for ancestor check).
442   popup.SetDisplayState( Popup::SHOWN );
443
444   Actor container = Actor::New();
445   PushButton button1 = PushButton::New();
446   PushButton button2 = PushButton::New();
447   DALI_TEST_CHECK( !HasAncestor( button1, popup ) );
448   DALI_TEST_CHECK( !HasAncestor( button2, popup ) );
449   container.Add( button1 );
450   container.Add( button2 );
451   popup.SetFooter( container );
452
453   // Hide and then re-show popup to cause button to be rearranged and added to popup.
454   popup.SetDisplayState( Popup::HIDDEN );
455   popup.SetDisplayState( Popup::SHOWN );
456   DALI_TEST_CHECK( HasAncestor( button1, popup ) );
457   DALI_TEST_CHECK( HasAncestor( button2, popup ) );
458   END_TEST;
459 }
460
461 int UtcDaliPopupSetStateP(void)
462 {
463   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
464   tet_infoline(" UtcDaliPopupSetStateP");
465
466   // Create the Popup actor
467   Popup popup = Popup::New();
468
469   popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
470
471   DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION );
472
473   popup.SetDisplayState( Popup::SHOWN );
474   DALI_TEST_EQUALS( Popup::SHOWN, popup.GetDisplayState(), TEST_LOCATION );
475
476   popup.SetDisplayState( Popup::HIDDEN );
477   DALI_TEST_EQUALS( Popup::HIDDEN, popup.GetDisplayState(), TEST_LOCATION );
478   END_TEST;
479 }
480
481 int UtcDaliPopupSetStateN(void)
482 {
483   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
484   tet_infoline(" UtcDaliPopupSetStateN");
485
486   // Create the Popup actor
487   Popup popup = Popup::New();
488
489   popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 1.0f );
490
491   DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION );
492
493   popup.SetDisplayState( Popup::SHOWN );
494   DALI_TEST_EQUALS( Popup::SHOWING, popup.GetDisplayState(), TEST_LOCATION );
495
496   // Test cancelling a show before it has finished.
497   popup.SetDisplayState( Popup::HIDDEN );
498   DALI_TEST_EQUALS( Popup::HIDING, popup.GetDisplayState(), TEST_LOCATION );
499   END_TEST;
500 }
501
502 int UtcDaliPopupDisplayStateSignal(void)
503 {
504   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
505   tet_infoline( " UtcDaliPopupDisplayStateSignal" );
506
507   // Create the Popup actor
508   Popup popup = Popup::New();
509   ConnectStateSignals( popup );
510
511   popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 1.0f );
512   popup.SetDisplayState( Popup::SHOWN );
513   DALI_TEST_EQUALS( Popup::SHOWING, popup.GetDisplayState(), TEST_LOCATION );
514   DALI_TEST_EQUALS( gPopupState, Popup::SHOWING, TEST_LOCATION );
515
516   // Wait for a while (allow animation to complete), and then check state.
517   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
518   {
519     application.SendNotification();
520     application.Render( RENDER_FRAME_INTERVAL );
521   }
522
523   DALI_TEST_EQUALS( Popup::SHOWN, popup.GetDisplayState(), TEST_LOCATION );
524   DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
525
526   // Hide slowly
527   popup.SetDisplayState( Popup::HIDDEN );
528   DALI_TEST_EQUALS( Popup::HIDING, popup.GetDisplayState(), TEST_LOCATION );
529   DALI_TEST_EQUALS( gPopupState, Popup::HIDING, TEST_LOCATION );
530
531   // Wait for a while (allow animation to complete), and then check state.
532   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
533   {
534     application.SendNotification();
535     application.Render( RENDER_FRAME_INTERVAL );
536   }
537
538   DALI_TEST_EQUALS( Popup::HIDDEN, popup.GetDisplayState(), TEST_LOCATION );
539   DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
540
541   END_TEST;
542 }
543
544 int UtcDaliPopupShowHide(void)
545 {
546   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
547   tet_infoline(" UtcDaliPopupShowHide");
548
549   // Create the Popup actor
550   Popup popup = Popup::New();
551   ConnectStateSignals( popup );
552
553   Actor container = Actor::New();
554   PushButton button1 = PushButton::New();
555   PushButton button2 = PushButton::New();
556   button1.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() );
557   button2.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() );
558   container.Add( button1 );
559   container.Add( button2 );
560   popup.SetFooter( container );
561
562   // Show
563   // Note: in most popup animation implementations show would result in
564   // popup being onstage immediately following Show(). However we can't
565   // assume for all. e.g. If one creates a animation with a delay.
566   popup.SetDisplayState( Popup::SHOWN );
567
568   // Wait for a while (allow animation to complete), and then check state.
569   for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
570   {
571     application.SendNotification();
572     application.Render( RENDER_FRAME_INTERVAL );
573   }
574
575   // Hide
576   popup.SetDisplayState( Popup::HIDDEN );
577
578   // Wait for a while (allow animation to complete), and then check state.
579   for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
580   {
581     application.SendNotification();
582     application.Render(RENDER_FRAME_INTERVAL);
583   }
584
585   DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
586   END_TEST;
587 }
588
589 int UtcDaliPopupPropertyTailVisibility(void)
590 {
591   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
592   tet_infoline(" UtcDaliPopupShowHideTail");
593
594   // Create the Popup actor
595   Popup popup = Popup::New();
596   Stage::GetCurrent().Add( popup );
597
598   popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false );
599   popup.SetDisplayState( Popup::SHOWN );
600
601   int withoutTailCount = DescendentCount( popup );
602
603   popup.SetDisplayState( Popup::HIDDEN );
604
605   popup.SetProperty( Popup::Property::TAIL_POSITION, "BOTTOM_CENTER" );
606   popup.SetProperty( Popup::Property::TAIL_VISIBILITY, true );
607   popup.SetDisplayState( Popup::SHOWN );
608
609   int withTailCount = DescendentCount( popup );
610
611   // There should be more actors if the Tail has been added.
612   DALI_TEST_CHECK( withTailCount > withoutTailCount );
613
614   // Hide again
615   popup.SetDisplayState( Popup::HIDDEN );
616   popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false );
617   popup.SetDisplayState( Popup::SHOWN );
618   int withoutTailCount2 = DescendentCount(popup);
619
620   DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
621   END_TEST;
622 }
623
624 int UtcDaliPopupOnTouchedOutsideSignal(void)
625 {
626   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
627   tet_infoline(" UtcDaliPopupOnTouchedOutside");
628
629   // Create the Popup actor
630   Popup popup = Popup::New();
631   popup.SetParentOrigin( ParentOrigin::CENTER );
632   popup.SetAnchorPoint( ParentOrigin::CENTER );
633   popup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
634   popup.SetSize( 50.0f, 50.0f );
635   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
636   Stage::GetCurrent().Add( popup );
637   popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
638   popup.SetDisplayState( Popup::SHOWN );
639
640   application.SendNotification();
641   application.Render();
642
643   gTouchedOutside = false;
644   Dali::Integration::TouchEvent event;
645
646   event = Dali::Integration::TouchEvent();
647   event.AddPoint( GetPointDown() );
648   application.ProcessEvent( event );
649
650   application.SendNotification();
651   application.Render();
652
653   event = Dali::Integration::TouchEvent();
654   event.AddPoint( GetPointUp() );
655   application.ProcessEvent( event );
656
657   application.SendNotification();
658   application.Render();
659
660   // Confirm the signal is ignored if touch_transparent.
661   gTouchedOutside = false;
662   popup.SetProperty( Popup::Property::TOUCH_TRANSPARENT, true );
663
664   event = Dali::Integration::TouchEvent();
665   event.AddPoint( GetPointDown() );
666   application.ProcessEvent( event );
667
668   application.SendNotification();
669   application.Render();
670
671   event = Dali::Integration::TouchEvent();
672   event.AddPoint( GetPointUp() );
673   application.ProcessEvent( event );
674
675   application.SendNotification();
676   application.Render();
677
678   DALI_TEST_CHECK( !gTouchedOutside );
679
680   END_TEST;
681 }
682
683 int UtcDaliPopupPropertyAutoHide(void)
684 {
685   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
686   tet_infoline( " UtcDaliPopupPropertyAutoHide" );
687
688   // Create the Popup actor
689   Popup popup = Popup::New();
690   ConnectStateSignals( popup );
691
692   Actor container = Actor::New();
693   PushButton button1 = PushButton::New();
694   button1.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() );
695   container.Add( button1 );
696   popup.SetFooter( container );
697
698   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
699   float getAnimationDuration = 0.0f;
700   DALI_TEST_CHECK( popup.GetProperty( Popup::Property::ANIMATION_DURATION ).Get( getAnimationDuration ) );
701   DALI_TEST_EQUALS( getAnimationDuration, 0.0f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
702
703   popup.SetProperty( Popup::Property::AUTO_HIDE_DELAY, 200 );
704   int getAutoHideDelay = 0;
705   DALI_TEST_CHECK( popup.GetProperty( Popup::Property::AUTO_HIDE_DELAY ).Get( getAutoHideDelay ) );
706   DALI_TEST_EQUALS( getAutoHideDelay, 200, TEST_LOCATION );
707
708   Stage::GetCurrent().Add( popup );
709
710   DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
711
712   // Show
713   // Note: in most popup animation implementations show would result in
714   // popup being onstage immediately following Show(). However we can't
715   // assume for all. e.g. If one creates a animation with a delay.
716   popup.SetDisplayState( Popup::SHOWN );
717
718   DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
719
720   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
721   {
722     application.SendNotification();
723     application.Render( RENDER_FRAME_INTERVAL );
724   }
725
726   // Force the timer used by the popup to expire,
727   // this will cause the popup to hide automatically.
728   Dali::Timer timer = Timer::New( 0 );
729   timer.MockEmitSignal();
730
731   DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
732
733   END_TEST;
734 }
735
736 /*
737  * This test checks all animation modes to confirm they all trigger all display states at the expected times.
738  */
739 int UtcDaliPopupPropertyAnimationMode(void)
740 {
741   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
742   tet_infoline( " UtcDaliPopupPropertyAnimationMode" );
743
744   // Create the Popup actor
745   Popup popup = Popup::New();
746   ConnectStateSignals( popup );
747   popup.SetTitle( TextLabel::New( "Title" ) );
748   Stage::GetCurrent().Add( popup );
749
750   std::string animationModes[] = { "NONE", "ZOOM", "FADE", "CUSTOM" };
751
752   // Try both default and zero animation duration, as zero has a special case for some animation types.
753   for( int j = 0; j <= 1; j++ )
754   {
755     // On the second loop, set duration to zero.
756     if( j == 1 )
757     {
758       popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
759     }
760
761     // Loop through 4 animation modes.
762     for( int i = 0; i < 4; i++ )
763     {
764       popup.SetProperty( Popup::Property::ANIMATION_MODE, animationModes[i] );
765
766       std::string checkMode;
767       DALI_TEST_CHECK( popup.GetProperty( Popup::Property::ANIMATION_MODE ).Get( checkMode ) )
768
769       DALI_TEST_EQUALS( checkMode, animationModes[i], TEST_LOCATION );
770
771       popup.SetProperty( Toolkit::Popup::Property::DISPLAY_STATE, "SHOWN" );
772       std::string resultState;
773
774       // Only wait for animation if it isn't instant.
775       if( j == 0 )
776       {
777         DALI_TEST_EQUALS( gPopupState, Popup::SHOWING, TEST_LOCATION );
778         DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::DISPLAY_STATE ).Get( resultState ) );
779         DALI_TEST_EQUALS( resultState, "SHOWING", TEST_LOCATION );
780         WaitAnimation( application );
781       }
782
783       DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
784       DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::DISPLAY_STATE ).Get( resultState ) );
785       DALI_TEST_EQUALS( resultState, "SHOWN", TEST_LOCATION );
786       popup.SetDisplayState( Popup::HIDDEN );
787
788       if( j == 0 )
789       {
790         DALI_TEST_EQUALS( gPopupState, Popup::HIDING, TEST_LOCATION );
791         DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::DISPLAY_STATE ).Get( resultState ) );
792         DALI_TEST_EQUALS( resultState, "HIDING", TEST_LOCATION );
793         WaitAnimation( application );
794       }
795
796       DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
797       DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::DISPLAY_STATE ).Get( resultState ) );
798       DALI_TEST_EQUALS( resultState, "HIDDEN", TEST_LOCATION );
799     }
800   }
801
802   END_TEST;
803 }
804
805 int UtcDaliPopupPropertyTitle(void)
806 {
807   ToolkitTestApplication application;
808   tet_infoline( " UtcDaliPopupPropertyTitle" );
809
810   // Create the Popup actor
811   Popup popup = Popup::New();
812
813   std::string testLabelText = "TitleTest";
814   TextLabel titleLabel = TextLabel::New();
815   titleLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, testLabelText );
816   Actor title = titleLabel;
817   Property::Map map;
818   Scripting::CreatePropertyMap( title, map );
819   popup.SetProperty( Toolkit::Popup::Property::TITLE, map );
820
821   Property::Map resultMap;
822   DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::TITLE ).Get( resultMap ) );
823
824   Property::Value* resultProperty = resultMap.Find( "text" );
825   DALI_TEST_CHECK( resultProperty );
826
827   std::string resultText;
828   DALI_TEST_CHECK( resultProperty->Get( resultText ) );
829
830   DALI_TEST_EQUALS( resultText, testLabelText, TEST_LOCATION );
831
832   END_TEST;
833 }
834
835 int UtcDaliPopupPropertyContent(void)
836 {
837   ToolkitTestApplication application;
838   tet_infoline( " UtcDaliPopupPropertyContent" );
839
840   // Create the Popup actor
841   Popup popup = Popup::New();
842
843   std::string testLabelText = "ContentTest";
844   TextLabel contentLabel = TextLabel::New();
845   contentLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, testLabelText );
846   Actor content = contentLabel;
847   Property::Map map;
848   Scripting::CreatePropertyMap( content, map );
849   popup.SetProperty( Toolkit::Popup::Property::CONTENT, map );
850
851   Property::Map resultMap;
852   DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::CONTENT ).Get( resultMap ) );
853
854   Property::Value* resultProperty = resultMap.Find( "text" );
855   DALI_TEST_CHECK( resultProperty );
856
857   std::string resultText;
858   DALI_TEST_CHECK( resultProperty->Get( resultText ) );
859
860   DALI_TEST_EQUALS( resultText, testLabelText, TEST_LOCATION );
861
862   END_TEST;
863 }
864
865 int UtcDaliPopupPropertyFooter(void)
866 {
867   ToolkitTestApplication application;
868   tet_infoline( " UtcDaliPopupPropertyFooter" );
869
870   // Create the Popup actor
871   Popup popup = Popup::New();
872
873   std::string testLabelText = "FooterTest";
874   TextLabel footerLabel = TextLabel::New();
875   footerLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, testLabelText );
876   Actor footer = footerLabel;
877   Property::Map map;
878   Scripting::CreatePropertyMap( footer, map );
879   popup.SetProperty( Toolkit::Popup::Property::FOOTER, map );
880
881   Property::Map resultMap;
882   DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::FOOTER ).Get( resultMap ) );
883
884   Property::Value* resultProperty = resultMap.Find( "text" );
885   DALI_TEST_CHECK( resultProperty );
886
887   std::string resultText;
888   DALI_TEST_CHECK( resultProperty->Get( resultText ) );
889
890   DALI_TEST_EQUALS( resultText, testLabelText, TEST_LOCATION );
891
892   END_TEST;
893 }
894
895 int UtcDaliPopupPropertyContextualMode(void)
896 {
897   ToolkitTestApplication application;
898   tet_infoline( " UtcDaliPopupPropertyContextualMode" );
899
900   // Create the Popup actor
901   Popup popup = Popup::New();
902   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
903   std::string testLabelText = "ContentTest";
904
905   TextLabel contentLabel = TextLabel::New();
906
907   popup.SetContent( contentLabel );
908
909   // Placement actor to parent the popup from so the popup's contextual position can be relative to it.
910   Actor placement = Actor::New();
911   placement.SetParentOrigin( ParentOrigin::CENTER );
912   placement.SetAnchorPoint( AnchorPoint::CENTER );
913   placement.SetSize( 1.0f, 1.0f );
914   placement.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
915   Stage::GetCurrent().Add( placement );
916
917   placement.Add( popup );
918
919   // Test all contextual modes.
920   const char* mode[5] = { "NON_CONTEXTUAL", "ABOVE", "RIGHT", "BELOW", "LEFT" };
921   Vector2 offsetValues[5];
922   offsetValues[0] = Vector2( 0.375f, 0.0f );
923   offsetValues[1] = Vector2( -0.125f, -10.5f );
924   offsetValues[2] = Vector2( 10.875f, -0.5f );
925   offsetValues[3] = Vector2( -0.125f, 10.5f );
926   offsetValues[4] = Vector2( -10.875f, -0.5f );
927
928   for( int i = 0; i < 5; ++i )
929   {
930     popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, mode[i] );
931
932     std::string propertyResult;
933     DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE ).Get( propertyResult ) );
934     DALI_TEST_EQUALS( propertyResult, std::string( mode[i] ), TEST_LOCATION );
935
936     popup.SetDisplayState( Popup::SHOWN );
937     application.SendNotification();
938     application.Render();
939
940     // Check the position of the label within the popup.
941     DALI_TEST_EQUALS( contentLabel.GetCurrentWorldPosition().GetVectorXY(), offsetValues[i], TEST_LOCATION );
942
943     popup.SetDisplayState( Popup::HIDDEN );
944     application.SendNotification();
945     application.Render();
946   }
947
948   END_TEST;
949 }
950
951 int UtcDaliPopupPropertyBacking(void)
952 {
953   ToolkitTestApplication application;
954   tet_infoline( " UtcDaliPopupPropertyBacking" );
955
956   // Create the Popup actor
957   Popup popup = Popup::New();
958   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
959   Stage::GetCurrent().Add( popup );
960
961   Actor backing = popup.FindChildByName( "popupBacking" );
962   DALI_TEST_CHECK( backing );
963
964   DALI_TEST_EQUALS( backing.GetCurrentOpacity(), 1.0f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
965
966   // Check enabled property.
967   popup.SetDisplayState( Popup::SHOWN );
968   application.SendNotification();
969   application.Render();
970
971   DALI_TEST_EQUALS( backing.GetCurrentOpacity(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
972
973   popup.SetDisplayState( Popup::HIDDEN );
974   application.SendNotification();
975   application.Render();
976
977   DALI_TEST_EQUALS( backing.GetCurrentOpacity(), 0.0f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
978
979   popup.SetProperty( Popup::Property::BACKING_ENABLED, false );
980   bool propertyResult;
981   DALI_TEST_CHECK( popup.GetProperty( Popup::Property::BACKING_ENABLED ).Get( propertyResult ) );
982   DALI_TEST_EQUALS( propertyResult, false, TEST_LOCATION );
983
984   popup.SetDisplayState( Popup::SHOWN );
985   application.SendNotification();
986   application.Render();
987
988   DALI_TEST_EQUALS( backing.GetCurrentOpacity(), 0.0f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
989
990   popup.SetDisplayState( Popup::HIDDEN );
991   application.SendNotification();
992   application.Render();
993
994   DALI_TEST_EQUALS( backing.GetCurrentOpacity(), 0.0f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
995
996   // Check color property.
997   popup.SetProperty( Popup::Property::BACKING_ENABLED, true );
998   popup.SetProperty( Popup::Property::BACKING_COLOR, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
999
1000   popup.SetDisplayState( Popup::SHOWN );
1001   application.SendNotification();
1002   application.Render();
1003
1004   Vector4 resultColor;
1005   popup.GetProperty( Popup::Property::BACKING_COLOR ).Get( resultColor );
1006   DALI_TEST_EQUALS( resultColor, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
1007
1008   END_TEST;
1009 }
1010
1011 int UtcDaliPopupPropertyBackgroundImage(void)
1012 {
1013   ToolkitTestApplication application;
1014   tet_infoline( " UtcDaliPopupPropertyBackgroundImage" );
1015
1016   // Create the Popup actor
1017   Popup popup = Popup::New();
1018   Stage::GetCurrent().Add( popup );
1019
1020   // Check setting an image
1021   popup.SetProperty( Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE, "invalid-image.png" );
1022   std::string resultString;
1023   popup.GetProperty( Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE ).Get( resultString );
1024   DALI_TEST_EQUALS( resultString, "invalid-image.png", TEST_LOCATION );
1025
1026   END_TEST;
1027 }
1028
1029 int UtcDaliPopupPropertyCustomAnimation(void)
1030 {
1031   ToolkitTestApplication application;
1032   tet_infoline( " UtcDaliPopupPropertyCustomAnimation" );
1033
1034   // Create the Popup actor
1035   Popup popup = Popup::New();
1036   TextLabel content = TextLabel::New( "text" );
1037   popup.SetContent( content );
1038
1039   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 1.0f );
1040   popup.SetProperty( Popup::Property::ANIMATION_MODE, "CUSTOM" );
1041
1042   Actor popupContainer = popup.FindChildByName( "popupContainer" );
1043   DALI_TEST_CHECK( popupContainer );
1044
1045   Vector3 entryAnimationDestination( 300.0f, 200.0f, 0.0f );
1046   Vector3 exitAnimationDestination( -300.0f, -200.0f, 0.0f );
1047
1048   Property::Map animationMapEntry;
1049   animationMapEntry.Insert( "actor", "customAnimationPopup" );
1050   animationMapEntry.Insert( "property", "position" );
1051   animationMapEntry.Insert( "value", entryAnimationDestination );
1052   animationMapEntry.Insert( "alphaFunction",  "EASE_OUT" );
1053
1054   Property::Array timePeriodMapEntry;
1055   timePeriodMapEntry.PushBack( 0.0f );
1056   timePeriodMapEntry.PushBack( 1.0f );
1057
1058   animationMapEntry.Insert( "timePeriod",  timePeriodMapEntry );
1059
1060   Property::Map animationMapExit;
1061   animationMapExit.Insert( "actor", "customAnimationPopup" );
1062   animationMapExit.Insert( "property", "position" );
1063   animationMapExit.Insert( "value", exitAnimationDestination );
1064   animationMapExit.Insert( "alphaFunction",  "EASE_IN" );
1065
1066   Property::Array timePeriodMapExit;
1067   timePeriodMapExit.PushBack( 0.0f );
1068   timePeriodMapExit.PushBack( 1.0f );
1069
1070   animationMapExit.Insert( "timePeriod",  timePeriodMapExit );
1071
1072   popup.SetProperty( Toolkit::Popup::Property::ENTRY_ANIMATION, animationMapEntry );
1073   popup.SetProperty( Toolkit::Popup::Property::EXIT_ANIMATION, animationMapExit );
1074
1075   Property::Map resultMap;
1076   DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::ENTRY_ANIMATION ).Get( resultMap ) );
1077   DALI_TEST_EQUALS( resultMap.Count(), 0u, TEST_LOCATION );
1078   DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::EXIT_ANIMATION ).Get( resultMap ) );
1079   DALI_TEST_EQUALS( resultMap.Count(), 0u, TEST_LOCATION );
1080
1081   Stage::GetCurrent().Add( popup );
1082   popup.SetDisplayState( Popup::SHOWN );
1083
1084   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1085   {
1086     application.SendNotification();
1087     application.Render( RENDER_FRAME_INTERVAL );
1088   }
1089
1090   // Test the popup has animated to it's entry-transition destination.
1091   DALI_TEST_EQUALS( popupContainer.GetCurrentWorldPosition(), entryAnimationDestination, 0.1f, TEST_LOCATION );
1092
1093   popup.SetDisplayState( Popup::HIDDEN );
1094
1095   for( int j = 0; j < RENDER_ANIMATION_TEST_DURATION_FRAMES; j++ )
1096   {
1097     application.SendNotification();
1098     application.Render( RENDER_FRAME_INTERVAL );
1099   }
1100
1101   DALI_TEST_EQUALS( popupContainer.GetCurrentWorldPosition(), exitAnimationDestination, 0.1f, TEST_LOCATION );
1102
1103   END_TEST;
1104 }
1105
1106 static bool gPushButtonClicked;
1107 static bool PushButtonClicked( Button button )
1108 {
1109   gPushButtonClicked = true;
1110   return true;
1111 }
1112
1113 int UtcDaliPopupPropertyTouchTransparent(void)
1114 {
1115   ToolkitTestApplication application;
1116   tet_infoline( " UtcDaliPopupPropertyTouchTransparent" );
1117
1118   // Create the Popup actor
1119   Popup popup = Popup::New();
1120   TextLabel content = TextLabel::New( "text" );
1121   popup.SetContent( content );
1122   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
1123   popup.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1124   popup.SetParentOrigin( ParentOrigin::TOP_LEFT );
1125   popup.SetSize( 100, 100 );
1126   popup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
1127
1128   // Create a button (to go underneath the popup).
1129   PushButton button = Toolkit::PushButton::New();
1130   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1131   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
1132   button.SetSize( 100, 100 );
1133   button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
1134
1135   button.ClickedSignal().Connect( &PushButtonClicked );
1136
1137   Stage::GetCurrent().Add( button );
1138
1139   button.Add( popup );
1140
1141   popup.SetDisplayState( Popup::SHOWN );
1142   application.SendNotification();
1143   application.Render();
1144
1145   gPushButtonClicked = false;
1146   Dali::Integration::TouchEvent event;
1147
1148   // Perform a click, the popup should block the click from hitting the button.
1149   event = Dali::Integration::TouchEvent();
1150   event.AddPoint( GetPointDown() );
1151   application.ProcessEvent( event );
1152   application.SendNotification();
1153   application.Render();
1154
1155   event = Dali::Integration::TouchEvent();
1156   event.AddPoint( GetPointUp() );
1157   application.ProcessEvent( event );
1158   application.SendNotification();
1159   application.Render();
1160
1161   DALI_TEST_CHECK( !gPushButtonClicked );
1162
1163   // Enable touch transparency.
1164   popup.SetProperty( Popup::Property::TOUCH_TRANSPARENT, true );
1165   bool propertyResult;
1166   DALI_TEST_CHECK( popup.GetProperty( Popup::Property::TOUCH_TRANSPARENT ).Get( propertyResult ) );
1167   DALI_TEST_EQUALS( propertyResult, true, TEST_LOCATION );
1168
1169   // Perform a click, the popup should allow the click to travel through to the button.
1170   event = Dali::Integration::TouchEvent();
1171   event.AddPoint( GetPointDown() );
1172   application.ProcessEvent( event );
1173   application.SendNotification();
1174   application.Render();
1175
1176   event = Dali::Integration::TouchEvent();
1177   event.AddPoint( GetPointUp() );
1178   application.ProcessEvent( event );
1179   application.SendNotification();
1180   application.Render();
1181
1182   DALI_TEST_CHECK( gPushButtonClicked );
1183
1184   END_TEST;
1185 }
1186
1187 int UtcDaliPopupPropertyTail(void)
1188 {
1189   ToolkitTestApplication application;
1190   tet_infoline( " UtcDaliPopupPropertyTail" );
1191
1192   // Create the Popup actor
1193   Popup popup = Popup::New();
1194   popup.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1195   popup.SetParentOrigin( ParentOrigin::TOP_LEFT );
1196   popup.SetSize( 100, 100 );
1197   popup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
1198   TextLabel content = TextLabel::New( "text" );
1199   popup.SetContent( content );
1200
1201   std::string imageFilename = "invalid-image.jpg";
1202   popup.SetProperty( Popup::Property::TAIL_DOWN_IMAGE, imageFilename );
1203   popup.SetProperty( Popup::Property::TAIL_UP_IMAGE, imageFilename );
1204   popup.SetProperty( Popup::Property::TAIL_RIGHT_IMAGE, imageFilename );
1205   popup.SetProperty( Popup::Property::TAIL_LEFT_IMAGE, imageFilename );
1206
1207   std::string resultString;
1208   popup.GetProperty( Toolkit::Popup::Property::TAIL_DOWN_IMAGE ).Get( resultString );
1209   DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1210   popup.GetProperty( Toolkit::Popup::Property::TAIL_UP_IMAGE ).Get( resultString );
1211   DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1212   popup.GetProperty( Toolkit::Popup::Property::TAIL_RIGHT_IMAGE ).Get( resultString );
1213   DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1214   popup.GetProperty( Toolkit::Popup::Property::TAIL_LEFT_IMAGE ).Get( resultString );
1215   DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1216
1217   popup.SetProperty( Popup::Property::TAIL_VISIBILITY, true );
1218   bool boolResult;
1219   DALI_TEST_CHECK( popup.GetProperty( Popup::Property::TAIL_VISIBILITY ).Get( boolResult ) );
1220   DALI_TEST_EQUALS( boolResult, true, TEST_LOCATION );
1221
1222   Actor tailActor;
1223   Vector3 tailPosition( ParentOrigin::TOP_CENTER );
1224
1225   popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1226   Vector3 vectorResult;
1227   DALI_TEST_CHECK( popup.GetProperty( Popup::Property::TAIL_POSITION ).Get( vectorResult ) );
1228   DALI_TEST_EQUALS( vectorResult, tailPosition, TEST_LOCATION );
1229
1230   Stage::GetCurrent().Add( popup );
1231
1232   popup.SetDisplayState( Popup::SHOWN );
1233   application.SendNotification();
1234   application.Render();
1235   tailActor = popup.FindChildByName( "tailImage" );
1236   DALI_TEST_CHECK( tailActor );
1237
1238   float baseValX = tailActor.GetCurrentWorldPosition().x;
1239
1240   DALI_TEST_GREATER( baseValX, tailActor.GetCurrentWorldPosition().y, TEST_LOCATION );
1241
1242   popup.SetDisplayState( Popup::HIDDEN );
1243   application.SendNotification();
1244   application.Render();
1245
1246   tailPosition = ParentOrigin::CENTER_LEFT;
1247   popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1248
1249   popup.SetDisplayState( Popup::SHOWN );
1250   application.SendNotification();
1251   application.Render();
1252   tailActor = popup.FindChildByName( "tailImage" );
1253   DALI_TEST_CHECK( tailActor );
1254
1255   float baseValY = tailActor.GetCurrentWorldPosition().y;
1256   DALI_TEST_GREATER( baseValX, tailActor.GetCurrentWorldPosition().x, TEST_LOCATION );
1257
1258   popup.SetDisplayState( Popup::HIDDEN );
1259   application.SendNotification();
1260   application.Render();
1261
1262   tailPosition = ParentOrigin::BOTTOM_CENTER;
1263   popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1264
1265   popup.SetDisplayState( Popup::SHOWN );
1266   application.SendNotification();
1267   application.Render();
1268   tailActor = popup.FindChildByName( "tailImage" );
1269   DALI_TEST_CHECK( tailActor );
1270   DALI_TEST_EQUALS( tailActor.GetCurrentWorldPosition().x, baseValX, TEST_LOCATION );
1271   DALI_TEST_GREATER( tailActor.GetCurrentWorldPosition().y, baseValY, TEST_LOCATION );
1272
1273   popup.SetDisplayState( Popup::HIDDEN );
1274   application.SendNotification();
1275   application.Render();
1276
1277   tailPosition = ParentOrigin::CENTER_RIGHT;
1278   popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1279
1280   popup.SetDisplayState( Popup::SHOWN );
1281   application.SendNotification();
1282   application.Render();
1283   tailActor = popup.FindChildByName( "tailImage" );
1284   DALI_TEST_CHECK( tailActor );
1285   DALI_TEST_GREATER( tailActor.GetCurrentWorldPosition().x, baseValX, TEST_LOCATION );
1286   DALI_TEST_EQUALS( tailActor.GetCurrentWorldPosition().y, baseValY, TEST_LOCATION );
1287
1288   popup.SetDisplayState( Popup::HIDDEN );
1289   application.SendNotification();
1290   application.Render();
1291
1292   END_TEST;
1293 }
1294
1295 int UtcDaliPopupTypeToast(void)
1296 {
1297   ToolkitTestApplication application;
1298   tet_infoline( " UtcDaliPopupTypeToast" );
1299
1300   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
1301   DALI_TEST_CHECK( typeInfo )
1302
1303   BaseHandle baseHandle = typeInfo.CreateInstance();
1304   DALI_TEST_CHECK( baseHandle )
1305
1306   Toolkit::Popup popup = Toolkit::Popup::DownCast( baseHandle );
1307   gPopupState = Toolkit::Popup::HIDDEN;
1308   ConnectStateSignals( popup );
1309   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 1.0f );
1310
1311   popup.SetTitle( Toolkit::TextLabel::New( "This is a Toast Popup.\nIt will auto-hide itself" ) );
1312   Stage::GetCurrent().Add( popup );
1313   popup.SetDisplayState( Toolkit::Popup::SHOWN );
1314
1315   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1316   {
1317     application.SendNotification();
1318     application.Render( RENDER_FRAME_INTERVAL );
1319   }
1320
1321   // Check the toast popup is shown.
1322   DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
1323
1324   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1325   {
1326     application.SendNotification();
1327     application.Render( RENDER_FRAME_INTERVAL );
1328   }
1329
1330   // Check the toast popup hides.
1331   Dali::Timer timer = Timer::New( 0 );
1332   timer.MockEmitSignal();
1333
1334   for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1335   {
1336     application.SendNotification();
1337     application.Render( RENDER_FRAME_INTERVAL );
1338   }
1339
1340   DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
1341
1342   END_TEST;
1343 }
1344
1345 int UtcDaliPopupTypeRegistryCreation(void)
1346 {
1347   ToolkitTestApplication application;
1348   tet_infoline( " UtcDaliPopupTypeRegistryCreation" );
1349
1350   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "Popup" );
1351   DALI_TEST_CHECK( typeInfo )
1352
1353   BaseHandle baseHandle = typeInfo.CreateInstance();
1354   DALI_TEST_CHECK( baseHandle )
1355
1356   Toolkit::Popup popup = Toolkit::Popup::DownCast( baseHandle );
1357   gPopupState = Toolkit::Popup::HIDDEN;
1358   ConnectStateSignals( popup );
1359   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
1360
1361   Stage::GetCurrent().Add( popup );
1362   popup.SetDisplayState( Toolkit::Popup::SHOWN );
1363
1364   application.SendNotification();
1365   application.Render();
1366
1367   // Check the popup is shown.
1368   DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
1369
1370   END_TEST;
1371 }
1372
1373 int UtcDaliPopupPropertyTypeRegistryConnectSignal(void)
1374 {
1375   ToolkitTestApplication application;
1376   tet_infoline( " UtcDaliPopupPropertyTypeRegistryConnectSignal" );
1377
1378   // Create the Popup actor
1379   Popup popup = Popup::New();
1380
1381   TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
1382   // Note: The emmision of this signals has already been tested in other tests.
1383   DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "touchedOutside",  PopupTestFunctor() ) );
1384   DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "showing", PopupTestFunctor() ) );
1385   DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "shown", PopupTestFunctor() ) );
1386   DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "hiding", PopupTestFunctor() ) );
1387   DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "hidden", PopupTestFunctor() ) );
1388
1389   // Test connecting to an invalid signal does not work.
1390   DALI_TEST_CHECK( !popup.ConnectSignal( testTracker, "invalid", PopupTestFunctor() ) );
1391
1392   END_TEST;
1393 }
1394
1395 int UtcDaliPopupOnControlChildAdd(void)
1396 {
1397   ToolkitTestApplication application;
1398   tet_infoline( " UtcDaliPopupOnControlChildAdd" );
1399
1400   // Create the Popup actor
1401   Popup popup = Popup::New();
1402   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
1403   std::string testLabelText = "ContentTest";
1404   TextLabel contentLabel = TextLabel::New( testLabelText );
1405
1406   popup.Add( contentLabel );
1407
1408   DALI_TEST_CHECK( HasAncestor( contentLabel, popup ) );
1409
1410   END_TEST;
1411 }
1412
1413 int UtcDaliPopupOnKeyEvent(void)
1414 {
1415   ToolkitTestApplication application;
1416   tet_infoline( " UtcDaliPopupOnKeyEvent" );
1417
1418   // Create the Popup actor
1419   Popup popup = Popup::New();
1420   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
1421   Stage::GetCurrent().Add( popup );
1422
1423   popup.SetDisplayState( Popup::SHOWN );
1424   application.SendNotification();
1425   application.Render();
1426
1427   DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::SHOWN, TEST_LOCATION );
1428
1429   popup.SetKeyInputFocus();
1430
1431   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "" ) );
1432   application.SendNotification();
1433   application.Render();
1434
1435   DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION );
1436
1437   END_TEST;
1438 }
1439
1440 int UtcDaliPopupSetPopupBackgroundBorderProperty(void)
1441 {
1442   ToolkitTestApplication application;
1443
1444   tet_infoline( "Set the background border property of a popup & retrieve it" );
1445   Popup popup = Popup::New();
1446
1447   Rect< int > rect( 40, 30, 20, 10 );
1448   tet_infoline( "Ensure value we want to set is different from what is already set" );
1449   DALI_TEST_CHECK( rect != popup.GetProperty( Popup::Property::POPUP_BACKGROUND_BORDER ).Get< Rect< int > >() );
1450
1451   tet_infoline( "Set the property and retrieve it to make sure it's the value we set" );
1452   popup.SetProperty( Popup::Property::POPUP_BACKGROUND_BORDER, rect );
1453   DALI_TEST_EQUALS( rect, popup.GetProperty( Popup::Property::POPUP_BACKGROUND_BORDER ).Get< Rect< int > >(), TEST_LOCATION );
1454
1455   tet_infoline( "Set a vector4 as well which should also work" );
1456   Vector4 vectorValue( 10.0f, 20.0f, 30.0f, 40.0f );
1457   popup.SetProperty( Popup::Property::POPUP_BACKGROUND_BORDER, vectorValue );
1458   DALI_TEST_EQUALS( Rect< int >( 10, 20, 30, 40 ), popup.GetProperty( Popup::Property::POPUP_BACKGROUND_BORDER ).Get< Rect< int > >(), TEST_LOCATION );
1459
1460   END_TEST;
1461 }