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