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