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