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