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