Merge "fix issue in negative line spacing with key arrow down" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Popup.cpp
1 /*
2  * Copyright (c) 2022 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-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/controls/popup/popup.h>
27 #include <dali.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/devel-api/scripting/scripting.h>
30 #include <dali/integration-api/events/key-event-integ.h>
31 #include <dali/integration-api/events/touch-event-integ.h>
32 #include <dali/integration-api/events/wheel-event-integ.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   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 = application.GetCore().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   application.GetScene().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   application.GetScene().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   application.GetScene().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   application.GetScene().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   application.GetScene().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   application.GetScene().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   application.GetScene().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   application.GetScene().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   application.GetScene().Add(popup);
1007
1008   Actor backing = popup.FindChildByName("popupBacking");
1009   DALI_TEST_CHECK(backing);
1010
1011   DALI_TEST_EQUALS(backing.GetCurrentProperty<float>(Actor::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>(Actor::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>(Actor::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>(Actor::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>(Actor::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   application.GetScene().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   application.GetScene().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   application.GetScene().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   // Perform a wheel event
1211   Dali::Integration::WheelEvent wheelEvent(Dali::Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, Vector2(10.0f, 10.0f), 1, 1000u);
1212   application.ProcessEvent(wheelEvent);
1213   application.SendNotification();
1214   application.Render();
1215
1216   // Enable touch transparency.
1217   popup.SetProperty(Popup::Property::TOUCH_TRANSPARENT, true);
1218   bool propertyResult;
1219   DALI_TEST_CHECK(popup.GetProperty(Popup::Property::TOUCH_TRANSPARENT).Get(propertyResult));
1220   DALI_TEST_EQUALS(propertyResult, true, TEST_LOCATION);
1221
1222   // Perform a click, the popup should allow the click to travel through to the button.
1223   event = Dali::Integration::TouchEvent();
1224   event.AddPoint(GetPointDown());
1225   application.ProcessEvent(event);
1226   application.SendNotification();
1227   application.Render();
1228
1229   event = Dali::Integration::TouchEvent();
1230   event.AddPoint(GetPointUp());
1231   application.ProcessEvent(event);
1232   application.SendNotification();
1233   application.Render();
1234
1235   DALI_TEST_CHECK(gPushButtonClicked);
1236
1237   END_TEST;
1238 }
1239
1240 int UtcDaliPopupPropertyTail(void)
1241 {
1242   ToolkitTestApplication application;
1243   tet_infoline(" UtcDaliPopupPropertyTail");
1244
1245   // Create the Popup actor
1246   Popup popup = Popup::New();
1247   popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1248   popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1249   popup.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1250   popup.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1251   TextLabel content = TextLabel::New("text");
1252   popup.SetContent(content);
1253
1254   std::string imageFilename = "invalid-image.jpg";
1255   popup.SetProperty(Popup::Property::TAIL_DOWN_IMAGE, imageFilename);
1256   popup.SetProperty(Popup::Property::TAIL_UP_IMAGE, imageFilename);
1257   popup.SetProperty(Popup::Property::TAIL_RIGHT_IMAGE, imageFilename);
1258   popup.SetProperty(Popup::Property::TAIL_LEFT_IMAGE, imageFilename);
1259
1260   std::string resultString;
1261   popup.GetProperty(Toolkit::Popup::Property::TAIL_DOWN_IMAGE).Get(resultString);
1262   DALI_TEST_EQUALS(resultString, imageFilename, TEST_LOCATION);
1263   popup.GetProperty(Toolkit::Popup::Property::TAIL_UP_IMAGE).Get(resultString);
1264   DALI_TEST_EQUALS(resultString, imageFilename, TEST_LOCATION);
1265   popup.GetProperty(Toolkit::Popup::Property::TAIL_RIGHT_IMAGE).Get(resultString);
1266   DALI_TEST_EQUALS(resultString, imageFilename, TEST_LOCATION);
1267   popup.GetProperty(Toolkit::Popup::Property::TAIL_LEFT_IMAGE).Get(resultString);
1268   DALI_TEST_EQUALS(resultString, imageFilename, TEST_LOCATION);
1269
1270   popup.SetProperty(Popup::Property::TAIL_VISIBILITY, true);
1271   bool boolResult;
1272   DALI_TEST_CHECK(popup.GetProperty(Popup::Property::TAIL_VISIBILITY).Get(boolResult));
1273   DALI_TEST_EQUALS(boolResult, true, TEST_LOCATION);
1274
1275   Actor   tailActor;
1276   Vector3 tailPosition(ParentOrigin::TOP_CENTER);
1277
1278   popup.SetProperty(Popup::Property::TAIL_POSITION, tailPosition);
1279   Vector3 vectorResult;
1280   DALI_TEST_CHECK(popup.GetProperty(Popup::Property::TAIL_POSITION).Get(vectorResult));
1281   DALI_TEST_EQUALS(vectorResult, tailPosition, TEST_LOCATION);
1282
1283   application.GetScene().Add(popup);
1284
1285   popup.SetDisplayState(Popup::SHOWN);
1286   application.SendNotification();
1287   application.Render();
1288   tailActor = popup.FindChildByName("tailImage");
1289   DALI_TEST_CHECK(tailActor);
1290
1291   float baseValX = tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).x;
1292
1293   DALI_TEST_GREATER(baseValX, tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).y, TEST_LOCATION);
1294
1295   popup.SetDisplayState(Popup::HIDDEN);
1296   application.SendNotification();
1297   application.Render();
1298
1299   tailPosition = ParentOrigin::CENTER_LEFT;
1300   popup.SetProperty(Popup::Property::TAIL_POSITION, tailPosition);
1301
1302   popup.SetDisplayState(Popup::SHOWN);
1303   application.SendNotification();
1304   application.Render();
1305   tailActor = popup.FindChildByName("tailImage");
1306   DALI_TEST_CHECK(tailActor);
1307
1308   float baseValY = tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).y;
1309   DALI_TEST_GREATER(baseValX, tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).x, TEST_LOCATION);
1310
1311   popup.SetDisplayState(Popup::HIDDEN);
1312   application.SendNotification();
1313   application.Render();
1314
1315   tailPosition = ParentOrigin::BOTTOM_CENTER;
1316   popup.SetProperty(Popup::Property::TAIL_POSITION, tailPosition);
1317
1318   popup.SetDisplayState(Popup::SHOWN);
1319   application.SendNotification();
1320   application.Render();
1321   tailActor = popup.FindChildByName("tailImage");
1322   DALI_TEST_CHECK(tailActor);
1323   DALI_TEST_EQUALS(tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).x, baseValX, TEST_LOCATION);
1324   DALI_TEST_GREATER(tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).y, baseValY, TEST_LOCATION);
1325
1326   popup.SetDisplayState(Popup::HIDDEN);
1327   application.SendNotification();
1328   application.Render();
1329
1330   tailPosition = ParentOrigin::CENTER_RIGHT;
1331   popup.SetProperty(Popup::Property::TAIL_POSITION, tailPosition);
1332
1333   popup.SetDisplayState(Popup::SHOWN);
1334   application.SendNotification();
1335   application.Render();
1336   tailActor = popup.FindChildByName("tailImage");
1337   DALI_TEST_CHECK(tailActor);
1338   DALI_TEST_GREATER(tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).x, baseValX, TEST_LOCATION);
1339   DALI_TEST_EQUALS(tailActor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION).y, baseValY, TEST_LOCATION);
1340
1341   popup.SetDisplayState(Popup::HIDDEN);
1342   application.SendNotification();
1343   application.Render();
1344
1345   END_TEST;
1346 }
1347
1348 int UtcDaliPopupTypeToast(void)
1349 {
1350   ToolkitTestApplication application;
1351   tet_infoline(" UtcDaliPopupTypeToast");
1352
1353   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("PopupToast");
1354   DALI_TEST_CHECK(typeInfo)
1355
1356   BaseHandle baseHandle = typeInfo.CreateInstance();
1357   DALI_TEST_CHECK(baseHandle)
1358
1359   Toolkit::Popup popup = Toolkit::Popup::DownCast(baseHandle);
1360   gPopupState          = Toolkit::Popup::HIDDEN;
1361   ConnectStateSignals(popup);
1362   popup.SetProperty(Popup::Property::ANIMATION_DURATION, 1.0f);
1363
1364   popup.SetTitle(Toolkit::TextLabel::New("This is a Toast Popup.\nIt will auto-hide itself"));
1365   application.GetScene().Add(popup);
1366   popup.SetDisplayState(Toolkit::Popup::SHOWN);
1367
1368   for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
1369   {
1370     application.SendNotification();
1371     application.Render(RENDER_FRAME_INTERVAL);
1372   }
1373
1374   // Check the toast popup is shown.
1375   DALI_TEST_EQUALS(gPopupState, Popup::SHOWN, TEST_LOCATION);
1376
1377   for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
1378   {
1379     application.SendNotification();
1380     application.Render(RENDER_FRAME_INTERVAL);
1381   }
1382
1383   // Check the toast popup hides.
1384   Dali::Timer timer = Timer::New(0);
1385   timer.MockEmitSignal();
1386
1387   for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
1388   {
1389     application.SendNotification();
1390     application.Render(RENDER_FRAME_INTERVAL);
1391   }
1392
1393   DALI_TEST_EQUALS(gPopupState, Popup::HIDDEN, TEST_LOCATION);
1394
1395   END_TEST;
1396 }
1397
1398 int UtcDaliPopupTypeRegistryCreation(void)
1399 {
1400   ToolkitTestApplication application;
1401   tet_infoline(" UtcDaliPopupTypeRegistryCreation");
1402
1403   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("Popup");
1404   DALI_TEST_CHECK(typeInfo)
1405
1406   BaseHandle baseHandle = typeInfo.CreateInstance();
1407   DALI_TEST_CHECK(baseHandle)
1408
1409   Toolkit::Popup popup = Toolkit::Popup::DownCast(baseHandle);
1410   gPopupState          = Toolkit::Popup::HIDDEN;
1411   ConnectStateSignals(popup);
1412   popup.SetProperty(Popup::Property::ANIMATION_DURATION, 0.0f);
1413
1414   application.GetScene().Add(popup);
1415   popup.SetDisplayState(Toolkit::Popup::SHOWN);
1416
1417   application.SendNotification();
1418   application.Render();
1419
1420   // Check the popup is shown.
1421   DALI_TEST_EQUALS(gPopupState, Popup::SHOWN, TEST_LOCATION);
1422
1423   END_TEST;
1424 }
1425
1426 int UtcDaliPopupPropertyTypeRegistryConnectSignal(void)
1427 {
1428   ToolkitTestApplication application;
1429   tet_infoline(" UtcDaliPopupPropertyTypeRegistryConnectSignal");
1430
1431   // Create the Popup actor
1432   Popup popup = Popup::New();
1433
1434   TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
1435   // Note: The emmision of this signals has already been tested in other tests.
1436   DALI_TEST_CHECK(popup.ConnectSignal(testTracker, "touchedOutside", PopupTestFunctor()));
1437   DALI_TEST_CHECK(popup.ConnectSignal(testTracker, "showing", PopupTestFunctor()));
1438   DALI_TEST_CHECK(popup.ConnectSignal(testTracker, "shown", PopupTestFunctor()));
1439   DALI_TEST_CHECK(popup.ConnectSignal(testTracker, "hiding", PopupTestFunctor()));
1440   DALI_TEST_CHECK(popup.ConnectSignal(testTracker, "hidden", PopupTestFunctor()));
1441
1442   // Test connecting to an invalid signal does not work.
1443   DALI_TEST_CHECK(!popup.ConnectSignal(testTracker, "invalid", PopupTestFunctor()));
1444
1445   END_TEST;
1446 }
1447
1448 int UtcDaliPopupOnChildAdd(void)
1449 {
1450   ToolkitTestApplication application;
1451   tet_infoline(" UtcDaliPopupOnChildAdd");
1452
1453   // Create the Popup actor
1454   Popup popup = Popup::New();
1455   popup.SetProperty(Popup::Property::ANIMATION_DURATION, 0.0f);
1456   std::string testLabelText = "ContentTest";
1457   TextLabel   contentLabel  = TextLabel::New(testLabelText);
1458
1459   popup.Add(contentLabel);
1460
1461   DALI_TEST_CHECK(HasAncestor(contentLabel, popup));
1462
1463   END_TEST;
1464 }
1465
1466 int UtcDaliPopupOnKeyEvent(void)
1467 {
1468   ToolkitTestApplication application;
1469   tet_infoline(" UtcDaliPopupOnKeyEvent");
1470
1471   // Create the Popup actor
1472   Popup popup = Popup::New();
1473   popup.SetProperty(Popup::Property::ANIMATION_DURATION, 0.0f);
1474   application.GetScene().Add(popup);
1475
1476   popup.SetDisplayState(Popup::SHOWN);
1477   application.SendNotification();
1478   application.Render();
1479
1480   DALI_TEST_EQUALS(popup.GetDisplayState(), Popup::SHOWN, TEST_LOCATION);
1481
1482   popup.SetKeyInputFocus();
1483
1484   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", "", Device::Class::TOUCH, Device::Subclass::NONE));
1485   application.SendNotification();
1486   application.Render();
1487
1488   DALI_TEST_EQUALS(popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION);
1489
1490   END_TEST;
1491 }
1492
1493 int UtcDaliPopupSetPopupBackgroundBorderProperty(void)
1494 {
1495   ToolkitTestApplication application;
1496
1497   tet_infoline("Set the background border property of a popup & retrieve it");
1498   Popup popup = Popup::New();
1499
1500   Rect<int> rect(40, 30, 20, 10);
1501   tet_infoline("Ensure value we want to set is different from what is already set");
1502   DALI_TEST_CHECK(rect != popup.GetProperty(Popup::Property::POPUP_BACKGROUND_BORDER).Get<Rect<int> >());
1503
1504   tet_infoline("Set the property and retrieve it to make sure it's the value we set");
1505   popup.SetProperty(Popup::Property::POPUP_BACKGROUND_BORDER, rect);
1506   DALI_TEST_EQUALS(rect, popup.GetProperty(Popup::Property::POPUP_BACKGROUND_BORDER).Get<Rect<int> >(), TEST_LOCATION);
1507
1508   tet_infoline("Set a vector4 as well which should also work");
1509   Vector4 vectorValue(10.0f, 20.0f, 30.0f, 40.0f);
1510   popup.SetProperty(Popup::Property::POPUP_BACKGROUND_BORDER, vectorValue);
1511   DALI_TEST_EQUALS(Rect<int>(10, 20, 30, 40), popup.GetProperty(Popup::Property::POPUP_BACKGROUND_BORDER).Get<Rect<int> >(), TEST_LOCATION);
1512
1513   END_TEST;
1514 }