Add DevelControl::Property::AUTOMATION_ID
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Accessibility-Accessible.cpp
index 9b103e8..60e1892 100644 (file)
 
 #include <dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 
 #include <dali/devel-api/adaptor-framework/accessibility.h>
-#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
+#include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
+#include <dali/devel-api/atspi-interfaces/accessible.h>
 
 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
 
@@ -64,3 +66,143 @@ int utcDaliAccessibilityCheckLabelText(void)
 
   END_TEST;
 }
+
+int UtcDaliAccessibilityCheckShowingState(void)
+{
+  ToolkitTestApplication application;
+
+  auto parentButton = Toolkit::PushButton::New();
+  parentButton.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
+  parentButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  parentButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  parentButton.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
+  parentButton.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
+  application.GetScene().Add( parentButton );
+
+  // Toatally inside of parent
+  auto buttonA = Toolkit::PushButton::New();
+  buttonA.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  buttonA.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  buttonA.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
+  buttonA.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
+  parentButton.Add(buttonA);
+
+  // Toatally outside of parent
+  auto buttonB = Toolkit::PushButton::New();
+  buttonB.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  buttonB.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  buttonB.SetProperty(Actor::Property::POSITION, Dali::Vector2(300.0f, 300.0f));
+  buttonB.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
+  parentButton.Add(buttonB);
+
+  // Partially inside of parent
+  auto buttonC = Toolkit::PushButton::New();
+  buttonC.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  buttonC.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  buttonC.SetProperty(Actor::Property::POSITION, Dali::Vector2(100.0f,100.0f));
+  buttonC.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
+  parentButton.Add(buttonC);
+
+  application.SendNotification();
+  application.Render(16);
+
+  auto q = Dali::Accessibility::Accessible::Get(buttonA);
+  DALI_TEST_CHECK(q);
+  auto states = q->GetStates();
+  DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) true, TEST_LOCATION);
+
+  q = Dali::Accessibility::Accessible::Get(buttonB);
+  DALI_TEST_CHECK(q);
+  states = q->GetStates();
+  DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
+
+  q = Dali::Accessibility::Accessible::Get(buttonC);
+  DALI_TEST_CHECK(q);
+  states = q->GetStates();
+  DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) true, TEST_LOCATION);
+
+  // Make SHOWING object invisible
+  buttonC.SetProperty(Actor::Property::VISIBLE, false);
+
+  application.SendNotification();
+  application.Render(16);
+
+  states = q->GetStates();
+  DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
+
+  // Make SHOWING parent invisible
+  parentButton.SetProperty(Actor::Property::VISIBLE, false);
+
+  application.SendNotification();
+  application.Render(16);
+
+  q = Dali::Accessibility::Accessible::Get(buttonA);
+  DALI_TEST_CHECK(q);
+  states = q->GetStates();
+  DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int utcDaliAccessibilityHidden(void)
+{
+  ToolkitTestApplication application;
+
+  auto  parent            = Toolkit::Control::New();
+  auto* parentAccessible  = Accessibility::Accessible::Get(parent);
+  auto  control           = Toolkit::Control::New();
+  auto* controlAccessible = Accessibility::Accessible::Get(control);
+
+  parent.Add(control);
+
+  // Check not hidden
+  DALI_TEST_CHECK(parentAccessible && controlAccessible);
+  DALI_TEST_CHECK(!controlAccessible->IsHidden());
+  DALI_TEST_CHECK(!control.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN));
+  DALI_TEST_EQUALS(parentAccessible->GetChildCount(), 1u, TEST_LOCATION);
+  DALI_TEST_EQUALS(parentAccessible->GetChildAtIndex(0), controlAccessible, TEST_LOCATION);
+
+  control.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
+
+  // Check hidden
+  DALI_TEST_CHECK(controlAccessible->IsHidden());
+  DALI_TEST_CHECK(control.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN));
+  DALI_TEST_EQUALS(parentAccessible->GetChildCount(), 0u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int utcDaliAutomationId(void)
+{
+  ToolkitTestApplication application;
+  Dali::Property::Index  automationIdIndex = Toolkit::DevelControl::Property::AUTOMATION_ID;
+  std::string            automationIdKey   = "automationId";
+  std::string            automationIdValue = "test123";
+
+  auto  control           = Toolkit::Control::New();
+  auto* controlAccessible = Accessibility::Accessible::Get(control);
+
+  // Check that there is no automationId initially
+  DALI_TEST_CHECK(control.GetProperty<std::string>(automationIdIndex).empty());
+  auto attributes = controlAccessible->GetAttributes();
+  DALI_TEST_CHECK(attributes.find(automationIdKey) == attributes.end());
+
+  // Set automationId
+  control.SetProperty(automationIdIndex, automationIdValue);
+
+  // Check that automationId is set
+  DALI_TEST_EQUALS(control.GetProperty<std::string>(automationIdIndex), automationIdValue, TEST_LOCATION);
+  attributes = controlAccessible->GetAttributes();
+  DALI_TEST_CHECK(attributes.find(automationIdKey) != attributes.end());
+  DALI_TEST_EQUALS(attributes[automationIdKey], automationIdValue, TEST_LOCATION);
+
+  // Unset automationId
+  control.SetProperty(automationIdIndex, "");
+
+  // Check that there is no automationId
+  DALI_TEST_CHECK(control.GetProperty<std::string>(automationIdIndex).empty());
+  attributes = controlAccessible->GetAttributes();
+  DALI_TEST_CHECK(attributes.find(automationIdKey) == attributes.end());
+
+  END_TEST;
+}