2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.
20 using ElmSharp.Accessible;
22 namespace ElmSharp.Test
24 class AccessibilityTest : TestCaseBase
26 public override string TestName => "AccessibilityTest";
27 public override string TestDescription => "Accessibility API test";
32 Array accessRoleValues;
34 public override void Run(Window window)
36 accessRoleValues = Enum.GetValues(typeof(AccessRole));
38 Conformant conformant = new Conformant(window);
41 navi = new Naviframe(window)
43 PreserveContentOnPop = true,
44 DefaultBackButtonEnabled = true
47 navi.Push(CreatePage(window, "Main page"), "first page");
49 conformant.SetContent(navi);
52 static string StatusStr(ReadingStatus status)
54 if (status == ReadingStatus.Unknown)
58 else if (status == ReadingStatus.Cancelled)
62 else if (status == ReadingStatus.Stoppped)
66 else if (status == ReadingStatus.Skipped)
76 Widget CreatePage(Window win, string pageName)
78 Box box = new Box(win);
79 ((IAccessibleObject)box).Name = pageName;
83 Button abutton = new Button(win)
85 Text = "Accessibility-normal",
89 ((IAccessibleObject)abutton).TranslationDomain = "kr";
90 ((IAccessibleObject)abutton).Name = "Accessibility";
91 ((IAccessibleObject)abutton).Description = "Description for Accessibility";
93 Label abutton_label = new Label(win)
99 "domain : " + ((IAccessibleObject)abutton).TranslationDomain +
100 ", name : " + ((IAccessibleObject)abutton).Name +
101 ", desc : " + ((IAccessibleObject)abutton).Description;
103 Button bbutton = new Button(win)
105 Text = "Accessibility-provider",
109 ((IAccessibleObject)bbutton).NameProvider = (obj) => "Name-provider";
110 ((IAccessibleObject)bbutton).DescriptionProvider = (obj) => "Description-provider";
112 Label bbutton_label = new Label(win)
118 "name : " + ((IAccessibleObject)bbutton).Name +
119 ", desc : " + ((IAccessibleObject)bbutton).Description;
121 Button cbutton = new Button(win)
123 Text = "Readingtype,CanHighlight",
127 ((IAccessibleObject)cbutton).ReadingInfoType =
128 ReadingInfoType.Name | ReadingInfoType.Role | ReadingInfoType.Description;
129 ((IAccessibleObject)cbutton).Name = "FooFoo";
130 ((IAccessibleObject)cbutton).Role = AccessRole.Text;
131 ((IAccessibleObject)cbutton).Description = "FooFooButton";
132 Label name_onoff_label = new Label(win)
134 Text = "ReadingInfoType.Name : " +
135 ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.Name) != 0 ? "on" : "off"),
139 Label role_onoff_label = new Label(win)
141 Text = "ReadingInfoType.Role : " +
142 ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.Role) != 0 ? "on" : "off"),
146 Label description_onoff_label = new Label(win)
148 Text = "ReadingInfoType.Description : " +
149 ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.Description) != 0 ? "on" : "off"),
153 Label state_onoff_label = new Label(win)
155 Text = "ReadingInfoType.State : " +
156 ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.State) != 0 ? "on" : "off"),
161 Button saybutton = new Button(win)
163 Text = "HHGG with false",
168 Button saybutton2 = new Button(win)
170 Text = "HHGG with true",
176 Button roleButton = new Button(win)
182 roleButton.Clicked += (s, e) =>
184 if (labelIndex >= accessRoleValues.Length)
189 IAccessibleObject obj = roleButton as IAccessibleObject;
190 AccessRole role = (AccessRole) accessRoleValues.GetValue(labelIndex);
192 roleButton.Text = Enum.GetName(typeof(AccessRole), obj.Role);
197 Label label = new Label(win)
199 Text = string.Format("{0} Apple", sequence++),
203 ((IAccessibleObject)label).Name = "Apple";
205 Button push = new Button(win)
211 ((IAccessibleObject)push).Name = "PushButton";
213 Button pop = new Button(win)
219 ((IAccessibleObject)pop).Name = "PopButton";
222 abutton_label.Show();
224 bbutton_label.Show();
226 name_onoff_label.Show();
227 role_onoff_label.Show();
228 description_onoff_label.Show();
229 state_onoff_label.Show();
237 push.Clicked += (s, e) =>
239 NaviItem item = navi.Push(CreatePage(win, string.Format("Apple {0}", sequence -1)), string.Format("Page {0}", sequence -1));
242 Label statusLog = new Label(win)
249 saybutton.Clicked += (s, e) =>
251 AccessibleUtil.Say("The Hitchhiker's Guide to the Galaxy", false)
252 .ContinueWith(status => { statusLog.Text = StatusStr(status.Result); });
254 saybutton2.Clicked += (s, e) =>
256 AccessibleUtil.Say("The Hitchhiker's Guide to the Galaxy", true)
257 .ContinueWith(status => { statusLog.Text = StatusStr(status.Result); });
260 pop.Clicked += (s, e) =>
262 var item = navi.NavigationStack.LastOrDefault();
266 box.PackEnd(abutton);
267 box.PackEnd(abutton_label);
268 box.PackEnd(bbutton);
269 box.PackEnd(bbutton_label);
270 box.PackEnd(cbutton);
271 box.PackEnd(name_onoff_label);
272 box.PackEnd(role_onoff_label);
273 box.PackEnd(description_onoff_label);
274 box.PackEnd(state_onoff_label);
275 box.PackEnd(saybutton);
276 box.PackEnd(saybutton2);
277 box.PackEnd(roleButton);
281 box.PackEnd(statusLog);