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