Merge remote-tracking branch 'widget-control/tizen'
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / AccessibilityTest.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.Linq;
19 using ElmSharp;
20 using ElmSharp.Accessible;
21
22 namespace ElmSharp.Test
23 {
24     class AccessibilityTest : TestCaseBase
25     {
26         public override string TestName => "AccessibilityTest";
27         public override string TestDescription => "Accessibility API test";
28
29         int sequence = 0;
30         Naviframe navi;
31
32         Array accessRoleValues;
33
34         public override void Run(Window window)
35         {
36             accessRoleValues = Enum.GetValues(typeof(AccessRole));
37
38             Conformant conformant = new Conformant(window);
39             conformant.Show();
40
41             navi = new Naviframe(window)
42             {
43                 PreserveContentOnPop = true,
44                 DefaultBackButtonEnabled = true
45             };
46
47             navi.Push(CreatePage(window, "Main page"), "first page");
48             navi.Show();
49             conformant.SetContent(navi);
50         }
51
52         static string StatusStr(ReadingStatus status)
53         {
54             if (status == ReadingStatus.Unknown)
55             {
56                 return "Unknown";
57             }
58             else if (status == ReadingStatus.Cancelled)
59             {
60                 return "Cancelled";
61             }
62             else if (status == ReadingStatus.Stoppped)
63             {
64                 return "Stopped";
65             }
66             else if (status == ReadingStatus.Skipped)
67             {
68                 return "Skipped";
69             }
70             else
71             {
72                 return "invalid";
73             }
74         }
75
76         Widget CreatePage(Window win, string pageName)
77         {
78             Box box = new Box(win);
79             ((IAccessibleObject)box).Name = pageName;
80
81             box.Show();
82
83             Button abutton = new Button(win)
84             {
85                 Text = "Accessibility-normal",
86                 WeightX = 1,
87                 AlignmentX = -1
88             };
89             ((IAccessibleObject)abutton).TranslationDomain = "kr";
90             ((IAccessibleObject)abutton).Name = "Accessibility";
91             ((IAccessibleObject)abutton).Description = "Description for Accessibility";
92
93             Label abutton_label = new Label(win)
94             {
95                 WeightX = 1,
96                 AlignmentX = -1
97             };
98             abutton_label.Text =
99                 "domain : " + ((IAccessibleObject)abutton).TranslationDomain +
100                 ", name : " + ((IAccessibleObject)abutton).Name +
101                 ", desc : " + ((IAccessibleObject)abutton).Description;
102
103             Button bbutton = new Button(win)
104             {
105                 Text = "Accessibility-provider",
106                 WeightX = 1,
107                 AlignmentX = -1
108             };
109             ((IAccessibleObject)bbutton).NameProvider = (obj) => "Name-provider";
110             ((IAccessibleObject)bbutton).DescriptionProvider = (obj) => "Description-provider";
111
112             Label bbutton_label = new Label(win)
113             {
114                 WeightX = 1,
115                 AlignmentX = -1
116             };
117             bbutton_label.Text =
118                 "name : " + ((IAccessibleObject)bbutton).Name +
119                 ", desc : " + ((IAccessibleObject)bbutton).Description;
120
121             Button cbutton = new Button(win)
122             {
123                 Text = "Readingtype,CanHighlight",
124                 WeightX = 1,
125                 AlignmentX = -1
126             };
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)
133             {
134                 Text = "ReadingInfoType.Name : " +
135                     ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.Name) != 0 ? "on" : "off"),
136                 WeightX = 1,
137                 AlignmentX = -1
138             };
139             Label role_onoff_label = new Label(win)
140             {
141                 Text = "ReadingInfoType.Role : " +
142                     ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.Role) != 0 ? "on" : "off"),
143                 WeightX = 1,
144                 AlignmentX = -1
145             };
146             Label description_onoff_label = new Label(win)
147             {
148                 Text = "ReadingInfoType.Description : " +
149                     ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.Description) != 0 ? "on" : "off"),
150                 WeightX = 1,
151                 AlignmentX = -1
152             };
153             Label state_onoff_label = new Label(win)
154             {
155                 Text = "ReadingInfoType.State : " +
156                     ((((IAccessibleObject)cbutton).ReadingInfoType & ReadingInfoType.State) != 0 ? "on" : "off"),
157                 WeightX = 1,
158                 AlignmentX = -1
159             };
160
161             Button saybutton = new Button(win)
162             {
163                 Text = "HHGG with false",
164                 WeightX = 1,
165                 AlignmentX = -1
166             };
167
168             Button saybutton2 = new Button(win)
169             {
170                 Text = "HHGG with true",
171                 WeightX = 1,
172                 AlignmentX = -1
173             };
174
175             int labelIndex = 0;
176             Button roleButton = new Button(win)
177             {
178                 WeightX = 1,
179                 AlignmentX = -1
180             };
181
182             roleButton.Clicked += (s, e) =>
183             {
184                 if (labelIndex >= accessRoleValues.Length)
185                 {
186                     labelIndex = 0;
187                 }
188
189                 IAccessibleObject obj = roleButton as IAccessibleObject;
190                 AccessRole role = (AccessRole) accessRoleValues.GetValue(labelIndex);
191                 obj.Role = role;
192                 roleButton.Text = Enum.GetName(typeof(AccessRole), obj.Role);
193
194                 labelIndex++;
195             };
196
197             Label label = new Label(win)
198             {
199                 Text = string.Format("{0} Apple", sequence++),
200                 WeightX = 1,
201                 AlignmentX = -1
202             };
203             ((IAccessibleObject)label).Name = "Apple";
204
205             Button push = new Button(win)
206             {
207                 Text = "Push",
208                 WeightX = 1,
209                 AlignmentX = -1
210             };
211             ((IAccessibleObject)push).Name = "PushButton";
212
213             Button pop = new Button(win)
214             {
215                 Text = "pop",
216                 WeightX = 1,
217                 AlignmentX = -1,
218             };
219             ((IAccessibleObject)pop).Name = "PopButton";
220
221             abutton.Show();
222             abutton_label.Show();
223             bbutton.Show();
224             bbutton_label.Show();
225             cbutton.Show();
226             name_onoff_label.Show();
227             role_onoff_label.Show();
228             description_onoff_label.Show();
229             state_onoff_label.Show();
230             saybutton.Show();
231             saybutton2.Show();
232             roleButton.Show();
233             label.Show();
234             push.Show();
235             pop.Show();
236
237             push.Clicked += (s, e) =>
238             {
239                 NaviItem item = navi.Push(CreatePage(win, string.Format("Apple {0}", sequence -1)), string.Format("Page {0}", sequence -1));
240             };
241
242             Label statusLog = new Label(win)
243             {
244                 WeightX = 1,
245                 AlignmentX = -1
246             };
247             statusLog.Show();
248
249             saybutton.Clicked += (s, e) =>
250             {
251                     AccessibleUtil.Say("The Hitchhiker's Guide to the Galaxy", false)
252                         .ContinueWith(status => { statusLog.Text = StatusStr(status.Result); });
253             };
254             saybutton2.Clicked += (s, e) =>
255             {
256                     AccessibleUtil.Say("The Hitchhiker's Guide to the Galaxy", true)
257                         .ContinueWith(status => { statusLog.Text = StatusStr(status.Result); });
258             };
259
260             pop.Clicked += (s, e) =>
261             {
262                 var item = navi.NavigationStack.LastOrDefault();
263                 navi.Pop();
264             };
265
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);
278             box.PackEnd(label);
279             box.PackEnd(push);
280             box.PackEnd(pop);
281             box.PackEnd(statusLog);
282
283             return box;
284         }
285     }
286 }