[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Accessibility-Accessible.cpp
1 /**
2  * Copyright (c) 2017 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 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
25 #include <dali.h>
26
27 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
28 #include <dali/devel-api/adaptor-framework/accessibility.h>
29 #include <dali/devel-api/atspi-interfaces/accessible.h>
30
31 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
32
33 void utc_dali_toolkit_accessibility_accessible_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36   DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
37 }
38
39 void utc_dali_toolkit_accessibility_accessible_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 int utcDaliAccessibilityCheckBoxButtonGetStates(void)
45 {
46   ToolkitTestApplication application;
47
48   auto check_box_button = Toolkit::CheckBoxButton::New();
49   auto q                = Dali::Accessibility::Accessible::Get(check_box_button);
50   DALI_TEST_CHECK(q);
51   auto states = q->GetStates();
52   DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SELECTABLE], (int)true, TEST_LOCATION);
53
54   END_TEST;
55 }
56
57 int utcDaliAccessibilityCheckLabelText(void)
58 {
59   ToolkitTestApplication application;
60
61   auto check_box_button = Toolkit::CheckBoxButton::New();
62   //check_box_button.SetLabelText( "button" );
63   check_box_button.SetProperty(Toolkit::Button::Property::LABEL, "button");
64   auto q = Dali::Accessibility::Accessible::Get(check_box_button);
65   DALI_TEST_CHECK(q);
66   DALI_TEST_EQUALS(q->GetName(), "button", TEST_LOCATION);
67
68   END_TEST;
69 }
70
71 int UtcDaliAccessibilityCheckShowingState(void)
72 {
73   ToolkitTestApplication application;
74
75   auto parentButton = Toolkit::PushButton::New();
76   parentButton.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
77   parentButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
78   parentButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
79   parentButton.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
80   parentButton.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
81   application.GetScene().Add(parentButton);
82
83   // Toatally inside of parent
84   auto buttonA = Toolkit::PushButton::New();
85   buttonA.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
86   buttonA.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
87   buttonA.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
88   buttonA.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
89   parentButton.Add(buttonA);
90
91   // Toatally outside of parent
92   auto buttonB = Toolkit::PushButton::New();
93   buttonB.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
94   buttonB.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
95   buttonB.SetProperty(Actor::Property::POSITION, Dali::Vector2(300.0f, 300.0f));
96   buttonB.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
97   parentButton.Add(buttonB);
98
99   // Partially inside of parent
100   auto buttonC = Toolkit::PushButton::New();
101   buttonC.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
102   buttonC.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
103   buttonC.SetProperty(Actor::Property::POSITION, Dali::Vector2(100.0f, 100.0f));
104   buttonC.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
105   parentButton.Add(buttonC);
106
107   application.SendNotification();
108   application.Render(16);
109
110   auto q = Dali::Accessibility::Accessible::Get(buttonA);
111   DALI_TEST_CHECK(q);
112   auto states = q->GetStates();
113   DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)true, TEST_LOCATION);
114
115   q = Dali::Accessibility::Accessible::Get(buttonB);
116   DALI_TEST_CHECK(q);
117   states = q->GetStates();
118   DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)true, TEST_LOCATION);
119
120   q = Dali::Accessibility::Accessible::Get(buttonC);
121   DALI_TEST_CHECK(q);
122   states = q->GetStates();
123   DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)true, TEST_LOCATION);
124
125   // Make SHOWING object invisible
126   buttonC.SetProperty(Actor::Property::VISIBLE, false);
127
128   application.SendNotification();
129   application.Render(16);
130
131   states = q->GetStates();
132   DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)false, TEST_LOCATION);
133
134   // Make SHOWING parent invisible
135   parentButton.SetProperty(Actor::Property::VISIBLE, false);
136
137   application.SendNotification();
138   application.Render(16);
139
140   q = Dali::Accessibility::Accessible::Get(buttonA);
141   DALI_TEST_CHECK(q);
142   states = q->GetStates();
143   DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)false, TEST_LOCATION);
144
145   END_TEST;
146 }
147
148 int utcDaliAccessibilityHidden(void)
149 {
150   ToolkitTestApplication application;
151
152   auto  parent            = Toolkit::Control::New();
153   auto* parentAccessible  = Accessibility::Accessible::Get(parent);
154   auto  control           = Toolkit::Control::New();
155   auto* controlAccessible = Accessibility::Accessible::Get(control);
156
157   parent.Add(control);
158
159   // Check not hidden
160   DALI_TEST_CHECK(parentAccessible && controlAccessible);
161   DALI_TEST_CHECK(!controlAccessible->IsHidden());
162   DALI_TEST_CHECK(!control.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN));
163   DALI_TEST_EQUALS(parentAccessible->GetChildCount(), 1u, TEST_LOCATION);
164   DALI_TEST_EQUALS(parentAccessible->GetChildAtIndex(0), controlAccessible, TEST_LOCATION);
165
166   control.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
167
168   // Check hidden
169   DALI_TEST_CHECK(controlAccessible->IsHidden());
170   DALI_TEST_CHECK(control.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN));
171   DALI_TEST_EQUALS(parentAccessible->GetChildCount(), 0u, TEST_LOCATION);
172
173   END_TEST;
174 }
175
176 int utcDaliAutomationId(void)
177 {
178   ToolkitTestApplication application;
179   Dali::Property::Index  automationIdIndex = Toolkit::DevelControl::Property::AUTOMATION_ID;
180   std::string            automationIdKey   = "automationId";
181   std::string            automationIdValue = "test123";
182
183   auto  control           = Toolkit::Control::New();
184   auto* controlAccessible = Accessibility::Accessible::Get(control);
185
186   // Check that there is no automationId initially
187   DALI_TEST_CHECK(control.GetProperty<std::string>(automationIdIndex).empty());
188   auto attributes = controlAccessible->GetAttributes();
189   DALI_TEST_CHECK(attributes.find(automationIdKey) == attributes.end());
190
191   // Set automationId
192   control.SetProperty(automationIdIndex, automationIdValue);
193
194   // Check that automationId is set
195   DALI_TEST_EQUALS(control.GetProperty<std::string>(automationIdIndex), automationIdValue, TEST_LOCATION);
196   attributes = controlAccessible->GetAttributes();
197   DALI_TEST_CHECK(attributes.find(automationIdKey) != attributes.end());
198   DALI_TEST_EQUALS(attributes[automationIdKey], automationIdValue, TEST_LOCATION);
199
200   // Unset automationId
201   control.SetProperty(automationIdIndex, "");
202
203   // Check that there is no automationId
204   DALI_TEST_CHECK(control.GetProperty<std::string>(automationIdIndex).empty());
205   attributes = controlAccessible->GetAttributes();
206   DALI_TEST_CHECK(attributes.find(automationIdKey) == attributes.end());
207
208   END_TEST;
209 }
210
211 int utcDaliImgSrc(void)
212 {
213   ToolkitTestApplication application;
214   const std::string      imageSrcKey = "imgSrc";
215   // Check that imgSrc is NOT added for non-image view w/ no additional property
216   {
217     const auto checkBoxButton    = Toolkit::CheckBoxButton::New();
218     const auto controlAccessible = Dali::Accessibility::Accessible::Get(checkBoxButton);
219     auto       attributes        = controlAccessible->GetAttributes();
220     DALI_TEST_CHECK(attributes.find(imageSrcKey) == attributes.end());
221   }
222
223   // Check that imgSrc is NOT added for non-image view w/ additional properties
224   {
225     const auto textLabel         = Toolkit::TextLabel::New("Hello");
226     const auto controlAccessible = Dali::Accessibility::Accessible::Get(textLabel);
227     auto       attributes        = controlAccessible->GetAttributes();
228     DALI_TEST_CHECK(attributes.find(imageSrcKey) == attributes.end());
229   }
230
231   // Check that imgSrc is added for image view w/ Url
232   {
233     const std::string imagePath         = "gallery-small-1.jpg";
234     const auto        imageView         = Toolkit::ImageView::New(imagePath);
235     const auto        controlAccessible = Dali::Accessibility::Accessible::Get(imageView);
236     auto              attributes        = controlAccessible->GetAttributes();
237     DALI_TEST_CHECK(attributes.find(imageSrcKey) != attributes.end());
238     DALI_TEST_EQUALS(attributes[imageSrcKey], imagePath, TEST_LOCATION);
239   }
240
241   // Check that imgSrc is added for image view w/ imageMap; single url case
242   {
243     const std::string imagePathForImageMap = "icon-edit.png";
244     Property::Map     imageMap;
245     imageMap[Toolkit::ImageVisual::Property::URL]            = imagePathForImageMap;
246     imageMap[Toolkit::ImageVisual::Property::RELEASE_POLICY] = Toolkit::ImageVisual::ReleasePolicy::DETACHED;
247
248     auto imageView = Toolkit::ImageView::New();
249     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
250
251     const auto controlAccessible = Dali::Accessibility::Accessible::Get(imageView);
252     auto       attributes        = controlAccessible->GetAttributes();
253     DALI_TEST_CHECK(attributes.find(imageSrcKey) != attributes.end());
254     DALI_TEST_EQUALS(attributes[imageSrcKey], imagePathForImageMap, TEST_LOCATION);
255   }
256
257   // Check that imgSrc is added for image view w/ imageMap; url array returns first element
258   {
259     const std::string image1 = "application-icon-20.png";
260     const std::string image2 = "application-icon-21.png";
261     Property::Map     imageMap;
262     Property::Array   urls{image1, image2};
263     imageMap[Toolkit::ImageVisual::Property::URL]            = urls;
264     imageMap[Toolkit::ImageVisual::Property::RELEASE_POLICY] = Toolkit::ImageVisual::ReleasePolicy::DETACHED;
265
266     auto imageView = Toolkit::ImageView::New();
267     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
268
269     const auto controlAccessible = Dali::Accessibility::Accessible::Get(imageView);
270     auto       attributes        = controlAccessible->GetAttributes();
271     DALI_TEST_CHECK(attributes.find(imageSrcKey) != attributes.end());
272     DALI_TEST_EQUALS(attributes[imageSrcKey], image1, TEST_LOCATION);
273   }
274
275   END_TEST;
276 }