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