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