2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
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>
31 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
33 void utc_dali_toolkit_accessibility_accessible_startup(void)
35 test_return_value = TET_UNDEF;
36 DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
39 void utc_dali_toolkit_accessibility_accessible_cleanup(void)
41 test_return_value = TET_PASS;
44 int utcDaliAccessibilityCheckBoxButtonGetStates(void)
46 ToolkitTestApplication application;
48 auto check_box_button = Toolkit::CheckBoxButton::New();
49 auto q = Dali::Accessibility::Accessible::Get(check_box_button);
51 auto states = q->GetStates();
52 DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SELECTABLE], (int)true, TEST_LOCATION);
57 int utcDaliAccessibilityCheckLabelText(void)
59 ToolkitTestApplication application;
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);
66 DALI_TEST_EQUALS(q->GetName(), "button", TEST_LOCATION);
71 int UtcDaliAccessibilityCheckShowingState(void)
73 ToolkitTestApplication application;
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);
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);
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);
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);
107 application.SendNotification();
108 application.Render(16);
110 auto q = Dali::Accessibility::Accessible::Get(buttonA);
112 auto states = q->GetStates();
113 DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)true, TEST_LOCATION);
115 q = Dali::Accessibility::Accessible::Get(buttonB);
117 states = q->GetStates();
118 DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)true, TEST_LOCATION);
120 q = Dali::Accessibility::Accessible::Get(buttonC);
122 states = q->GetStates();
123 DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)true, TEST_LOCATION);
125 // Make SHOWING object invisible
126 buttonC.SetProperty(Actor::Property::VISIBLE, false);
128 application.SendNotification();
129 application.Render(16);
131 states = q->GetStates();
132 DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)false, TEST_LOCATION);
134 // Make SHOWING parent invisible
135 parentButton.SetProperty(Actor::Property::VISIBLE, false);
137 application.SendNotification();
138 application.Render(16);
140 q = Dali::Accessibility::Accessible::Get(buttonA);
142 states = q->GetStates();
143 DALI_TEST_EQUALS((int)states[Dali::Accessibility::State::SHOWING], (int)false, TEST_LOCATION);
148 int utcDaliAccessibilityHidden(void)
150 ToolkitTestApplication application;
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);
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);
166 control.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
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);
176 int utcDaliAutomationId(void)
178 ToolkitTestApplication application;
179 Dali::Property::Index automationIdIndex = Toolkit::DevelControl::Property::AUTOMATION_ID;
180 std::string automationIdKey = "automationId";
181 std::string automationIdValue = "test123";
183 auto control = Toolkit::Control::New();
184 auto* controlAccessible = Accessibility::Accessible::Get(control);
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());
192 control.SetProperty(automationIdIndex, automationIdValue);
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);
200 // Unset automationId
201 control.SetProperty(automationIdIndex, "");
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());
211 int utcDaliImgSrc(void)
213 ToolkitTestApplication application;
214 const std::string imageSrcKey = "imgSrc";
215 // Check that imgSrc is NOT added for non-image view w/ no additional property
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());
223 // Check that imgSrc is NOT added for non-image view w/ additional properties
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());
231 // Check that imgSrc is added for image view w/ Url
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);
241 // Check that imgSrc is added for image view w/ imageMap; single url case
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;
248 auto imageView = Toolkit::ImageView::New();
249 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
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);
257 // Check that imgSrc is added for image view w/ imageMap; url array returns first element
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;
266 auto imageView = Toolkit::ImageView::New();
267 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
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);