Put the time in TestGenerateTap()
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
index 3e8b0de..f762e8d 100644 (file)
 #include <unistd.h>
 #include <iostream>
 
-#include <dali/integration-api/events/key-event-integ.h>
-#include <dali/integration-api/events/touch-event-integ.h>
-#include <dali/public-api/rendering/renderer.h>
-#include <dali/devel-api/actors/actor-devel.h>
 
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
 #include <dali-toolkit/devel-api/text/rendering-backend.h>
 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/adaptor-framework/key-devel.h>
+#include <dali/devel-api/events/pan-gesture-devel.h>
 #include <dali/devel-api/text-abstraction/font-client.h>
+#include <dali/integration-api/events/key-event-integ.h>
+#include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/public-api/rendering/renderer.h>
 #include "test-text-geometry-utils.h"
 #include "toolkit-clipboard.h"
 
@@ -72,6 +74,7 @@ const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHand
 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
+const char* const PROPERTY_NAME_SELECTION_POPUP_STYLE                = "selectionPopupStyle";
 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
@@ -403,6 +406,56 @@ bool DaliTestCheckMaps(const Property::Map& fontStyleMapGet, const Property::Map
   return true;
 }
 
+
+// Stores data that is populated in the callback and will be read by the test cases
+struct SignalData
+{
+  SignalData()
+  : functorCalled(false),
+    voidFunctorCalled(false),
+    receivedGesture()
+  {
+  }
+
+  void Reset()
+  {
+    functorCalled     = false;
+    voidFunctorCalled = false;
+
+    receivedGesture.Reset();
+
+    pannedActor.Reset();
+  }
+
+  bool       functorCalled;
+  bool       voidFunctorCalled;
+  PanGesture receivedGesture;
+  Actor      pannedActor;
+};
+
+// Functor that sets the data when called
+struct GestureReceivedFunctor
+{
+  GestureReceivedFunctor(SignalData& data)
+  : signalData(data)
+  {
+  }
+
+  void operator()(Actor actor, const PanGesture& pan)
+  {
+    signalData.functorCalled   = true;
+    signalData.receivedGesture = pan;
+    signalData.pannedActor     = actor;
+  }
+
+  void operator()()
+  {
+    signalData.voidFunctorCalled = true;
+  }
+
+  SignalData& signalData;
+};
+
 } // namespace
 
 int UtcDaliToolkitTextFieldConstructorP(void)
@@ -591,6 +644,7 @@ int UtcDaliTextFieldGetPropertyP(void)
   DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_INPUT_FILTER) == DevelTextField::Property::INPUT_FILTER);
   DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_STRIKETHROUGH) == DevelTextField::Property::STRIKETHROUGH);
   DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_INPUT_STRIKETHROUGH) == DevelTextField::Property::INPUT_STRIKETHROUGH);
+  DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_SELECTION_POPUP_STYLE) == DevelTextField::Property::SELECTION_POPUP_STYLE);
 
   END_TEST;
 }
@@ -765,6 +819,64 @@ int UtcDaliTextFieldSetPropertyP(void)
   DALI_TEST_CHECK(SetPropertyMapRetrieved(field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage"));
   DALI_TEST_CHECK(SetPropertyMapRetrieved(field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage"));
 
+  // Check the selection popup style
+  const Vector2 popupMaxSize(200.0f, 300.0f);
+  const Vector2 optionDividerSize(30.0f, 5.0f);
+  const Vector4 optionDividerPadding(20.0f, 20.0f, 10.0f, 10.0f);
+  const Vector4 labelPadding(5.0f, 5.0f, 50.0f, 25.0f);
+
+  Property::Map selectionPopupStyle;
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::POPUP_MAX_SIZE, popupMaxSize);
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE, optionDividerSize);
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING, optionDividerPadding);
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::LABEL_PADDING, labelPadding);
+
+  field.SetProperty(DevelTextField::Property::SELECTION_POPUP_STYLE, selectionPopupStyle);
+
+  Property::Map selectionPopupStyleGet;
+  selectionPopupStyleGet = field.GetProperty<Property::Map>(DevelTextField::Property::SELECTION_POPUP_STYLE);
+
+  Property::Value* popupValue;
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::POPUP_MAX_SIZE);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector2 popupMaxSizeGet;
+    popupValue->Get(popupMaxSizeGet);
+    DALI_TEST_EQUALS(popupMaxSizeGet, popupMaxSize, TEST_LOCATION);
+  }
+
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector2 optionDividerSizeGet;
+    popupValue->Get(optionDividerSizeGet);
+    DALI_TEST_EQUALS(optionDividerSizeGet, optionDividerSize, TEST_LOCATION);
+  }
+
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector4 optionDividerPaddingGet;
+    popupValue->Get(optionDividerPaddingGet);
+    DALI_TEST_EQUALS(optionDividerPaddingGet, optionDividerPadding, TEST_LOCATION);
+  }
+
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::LABEL_PADDING);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector4 labelPaddingGet;
+    popupValue->Get(labelPaddingGet);
+    DALI_TEST_EQUALS(labelPaddingGet, labelPadding, TEST_LOCATION);
+  }
+
+  // Reset selection popup style
+  selectionPopupStyle.Clear();
+  field.SetProperty(DevelTextField::Property::SELECTION_POPUP_STYLE, selectionPopupStyle);
+
   // Check the highlight color
   field.SetProperty(TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN);
   DALI_TEST_EQUALS(field.GetProperty<Vector4>(TextField::Property::SELECTION_HIGHLIGHT_COLOR), Color::GREEN, TEST_LOCATION);
@@ -2589,14 +2701,14 @@ int utcDaliTextFieldEvent03(void)
   application.Render();
 
   // Tap first to get the focus.
-  TestGenerateTap(application, 3.0f, 25.0f);
+  TestGenerateTap(application, 3.0f, 25.0f, 100);
 
   // Render and notify
   application.SendNotification();
   application.Render();
 
   // Double tap to select a word.
-  TestGenerateTap(application, 3.0f, 25.0f);
+  TestGenerateTap(application, 3.0f, 25.0f, 200);
 
   // Render and notify
   application.SendNotification();
@@ -3225,6 +3337,14 @@ int utcDaliTextFieldSomeSpecialKeys(void)
   application.SendNotification();
   application.Render();
 
+  // Generate a Back key event. Nothing happens to the text field.
+  application.ProcessEvent(GenerateKey("XF86Back", "", "XF86Back", DALI_KEY_BACK, 0, 0, Integration::KeyEvent::DOWN, "XF86Back", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+  application.ProcessEvent(GenerateKey("XF86Back", "", "XF86Back", DALI_KEY_BACK, 0, 0, Integration::KeyEvent::UP, "XF86Back", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
   // The text shouldn't be deleted.
   DALI_TEST_EQUALS(field.GetProperty<std::string>(TextField::Property::TEXT), longText, TEST_LOCATION);
 
@@ -5497,4 +5617,76 @@ int utcDaliTextFieldClusteredEmojiDeletionDeleteKey(void)
   application.Render();
 
   END_TEST;
-}
\ No newline at end of file
+}
+
+int utcDaliTextFieldPanGesturePropagation(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextFieldPanGesturePropagation");
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  application.GetScene().Add(actor);
+
+  TextField field = TextField::New();
+  DALI_TEST_CHECK(field);
+
+  field.SetProperty(TextField::Property::TEXT, "This is a long text for the size of the text-field.");
+  field.SetProperty(TextField::Property::POINT_SIZE, 10.f);
+
+  field.SetProperty(Actor::Property::SIZE, Vector2(50.f, 100.f));
+  field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  actor.Add(field);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  SignalData             data;
+  GestureReceivedFunctor functor(data);
+
+  PanGestureDetector detector = PanGestureDetector::New();
+  detector.Attach(actor);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  // Tap first to get the focus.
+  TestGenerateTap(application, 3.0f, 25.0f, 100);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Pan the text field
+  uint32_t time = 100;
+  TestStartPan(application, Vector2(40.0f, 50.0f), Vector2(40.0f, 50.0f), time);
+  TestMovePan(application, Vector2(10.0f, 50.0f), time);
+  TestEndPan(application, Vector2(40.0f, 50.0f), time);
+  application.SendNotification();
+  application.Render();
+
+  // The text scrolls because there is text that is scrolling.
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+  data.Reset();
+
+  // Set the size large enough to prevent scrolling.
+  field.SetProperty(Actor::Property::SIZE, Vector2(700.f, 100.f));
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  time = 200;
+  TestStartPan(application, Vector2(40.0f, 50.0f), Vector2(40.0f, 50.0f), time);
+  TestMovePan(application, Vector2(10.0f, 50.0f), time);
+  TestEndPan(application, Vector2(40.0f, 50.0f), time);
+
+  // Because scrolling is not possible, the pan gesture is propagated.
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  data.Reset();
+
+
+  END_TEST;
+}