-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathindex.ts
More file actions
380 lines (361 loc) · 14.3 KB
/
index.ts
File metadata and controls
380 lines (361 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
import { ACBrowserManager } from "./lib/ACBrowserManager.js";
import { ACEngineManager } from "./lib/ACEngineManager.js";
import { getComplianceHelper } from "./lib/ACHelper.js";
import { eAssertResult, ICheckerReport, ICheckerResult, ReportResult } from "./lib/api/IChecker.js";
import { ACConfigManager } from "./lib/common/config/ACConfigManager.js";
import { IConfig, IConfigInternal } from "./lib/common/config/IConfig.js";
import { IBaselineReport } from "./lib/common/engine/IReport.js";
import { BaselineManager } from "./lib/common/report/BaselineManager.js";
import { ReporterManager } from "./lib/common/report/ReporterManager.js";
/**
* This function is responsible performing a scan based on the context that is provided, following are
* the supported context type:
* Single node (HTMLElement)
* Local file path (String)
* URL (String)
* document node
* data stream for html content (String)
*
* Future Items
* Multiple node (Array of HTMLElements) ---> FUTURE
*
* @param {(String|HTMLElement|DocumentNode|Puppeteer Page |)} content - Provide the context to scan, which includes the items from above.
* @param {String} label - Provide a label for the scan that is being performed
* @param {Function} callback - (optional) Provide callback function which will be executed once the results are extracted.
* @return Promise with the ICheckerResult
*/
export function getCompliance(content: any,
label: string,
callback?: (report: ReportResult, webdriver) => void) : Promise<ICheckerResult>
{
if (callback) {
getComplianceHelper(content, label)
.then((result) => {
callback(result.report, result.webdriver);
});
} else {
return getComplianceHelper(content, label);
}
}
/**
* This function is responsible for comparing the scan results with baseline or checking that there are
* no violations which fall into the failsLevels levels. In the case a baseline is found then baseline will
* be used to perform the check, in the case no baseline is provided then we comply with only failing if
* there is a sinble violation which falls into failLevels.
*
* @param {ReportResult} actual - the actual results object provided by the user, this object should follow the
* same format as outlined in the return of aChecker.buildReport function.
*
* @return {int} - return 0 in the case actual matches baseline or no violations fall into failsLevels,
* return 1 in the case actual results does not match baseline results,
* return 2 in the case that there is a failure based on failLevels (this means no baseline found).
* return -1 in the case that there is an exception that occured in the results object which came from the scan engine.
*/
export function assertCompliance(report: IBaselineReport) : eAssertResult {
return BaselineManager.assertCompliance(report)
}
/**
* This function is responsible for printing the scan results to console.
*
* @param {Object} results - Provide the results from the scan.
*
* @return {String} resultsString - String representation of the results/violations.
*
* PUBLIC API
*
* @memberOf this
*/
export function stringifyResults(report: ICheckerReport) : string {
return ReporterManager.stringifyResults(report)
}
export function getConfig() : Promise<IConfig> {
return ACConfigManager.getConfig();
}
export function getConfigUnsupported() : Promise<IConfigInternal> {
return ACConfigManager.getConfigUnsupported();
}
export function close() {
return ACBrowserManager.close();
}
/**
* This function is responsible for getting the diff results based on label for a scan that was already performed.
*
* @param {String} label - Provide a lable for which to get the diff results for.
*
* @return {Object} - return the diff results object from global space based on label provided, the object will be
* in the same format as outlined in the return of aChecker.diffResultsWithExpected function.
*/
export function getDiffResults(label: string) {
return BaselineManager.getDiffResults(label);
}
/**
* This function is responsible for getting the baseline object for a label that was provided.
*
* @param {String} label - Provide a lable for which to get the baseline for.
*
* @return {Object} - return the baseline object from global space based on label provided, the object will be
* in the same format as outlined in the return of aChecker.buildReport function.
*/
export function getBaseline(label: string) {
return BaselineManager.getBaseline(label);
}
/**
* This function is responsible for comparing actual with expected and returning all the differences as an array.
*
* @param {Object} actual - Provide the actual object to be used for compare
* @param {Object} expected - Provide the expected object to be used for compare
* @param {boolean} clean - Provide a boolean if both the actual and expected objects need to be cleaned
* cleaning refers to converting the objects to match with a basic compliance
* compare of xpath and ruleId.
*
* @return {Object} differences - return an array of diff objects that were found, following is the format of the object:
* [
* {
* "kind": "E",
* "path": [
* "reports",
* 0,
* "issues",
* 10,
* "xpath"
* ],
* "lhs": "/html[1]/body[1]/div[2]/table[5]",
* "rhs": "/html[1]/body[1]/div[2]/table[5]d",
* },
* {
* "kind": "E",
* "path": [
* "label"
* ],
* "lhs": "Table-layoutMultiple",
* "rhs": "dependencies/tools-rules-html/v2/a11y/test/g471/Table-layoutMultiple.html",
* }
* ]
*/
export function diffResultsWithExpected(actual, expected, clean) {
return BaselineManager.diffResultsWithExpected(actual, expected, clean);
}
/**
* This function is responsible for cleaning up the compliance baseline or actual results, based on
* a pre-defined set of criterias, such as the following:
* 1. No need to compare summary object
* 2. Only need to compare the ruleId and xpath in for each of the issues
*
* @param {Object} objectToClean - Provide either an baseline or actual results object which would be in the
* the same format as outlined in the return of aChecker.buildReport function.
*
* @return {Object} objectToClean - return an object that was cleaned to only contain the information that is
* needed for compare. Following is a sample of how the cleaned object will look like:
* {
* "label": "unitTestContent",
* "reports": [
* {
* "frameIdx": "0",
* "frameTitle": "Frame 0",
* "issues": [
* {
* "ruleId": "1",
* "xpath": "/html[1]/head[1]/style[1]"
* }
* ....
* ]
* },
* {
* "frameIdx": "1",
* "frameTitle": "Frame 1",
* "issues": [
* {
* "ruleId": "471",
* "xpath": "/html[1]/body[1]/div[2]/table[3]"
* }
* ....
* ]
* }
* ]
* }
*/
export function cleanComplianceObjectBeforeCompare(objectToClean) {
return BaselineManager.cleanComplianceObjectBeforeCompare(objectToClean);
}
export function addRuleset(ruleset) {
ACEngineManager.addRuleset(ruleset);
}
export async function getRuleset(rsId) {
return ACEngineManager.getRuleset(rsId);
};
export async function getRulesets() {
return ACEngineManager.getRulesets();
};
export async function getRules() {
return ACEngineManager.getRules();
}
export const ruleIdToLegacyId = {
"list_structure_proper": "3",
"marquee_elem_avoid": "5",
"heading_markup_misuse": "7",
"imagebutton_alt_exists": "10",
"img_ismap_misuse": "11",
"object_text_exists": "20",
"applet_alt_exists": "21",
"media_audio_transcribed": "24",
"blockquote_cite_exists": "25",
"meta_refresh_delay": "33",
"frame_title_exists": "39",
"input_label_exists": "41",
"media_alt_brief": "99",
"a_target_warning": "112",
"area_alt_exists": "240",
"RPT_Media_ImgColorUsage": "245",
"meta_redirect_optional": "254",
"element_attribute_deprecated": "256",
"text_quoted_correctly": "263",
"element_mouseevent_keyboard": "269",
"page_title_exists": "273",
"text_block_heading": "322",
"form_submit_button_exists": "324",
"element_id_unique": "377",
"form_font_color": "394",
"form_label_unique": "398",
"img_alt_misuse": "453",
"img_longdesc_misuse": "454",
"img_alt_valid": "455",
"style_background_decorative": "456",
"asciiart_alt_exists": "458",
"media_track_available": "511",
"media_alt_exists": "460",
"style_color_misuse": "466",
"select_options_grouped": "467",
"list_markup_review": "468",
"script_onclick_misuse": "470",
"table_structure_misuse": "471",
"WCAG20_Img_AltTriggerNonDecorative": "473",
"blink_elem_deprecated": "478",
"blink_css_review": "479",
"html_skipnav_exists": "481",
"page_title_valid": "484",
"heading_content_exists": "488",
"html_lang_exists": "490",
"form_interaction_review": "491",
"a_text_purpose": "495",
"fieldset_legend_valid": "497",
"media_live_captioned": "501",
"text_sensory_misuse": "502",
"media_autostart_controllable": "503",
"style_focus_visible": "506",
"img_alt_redundant": "1000",
"RPT_Style_ExternalStyleSheet": "1073",
// "RPT_Header_Trigger": "1002",
"script_onclick_avoid": "1007",
"table_summary_redundant": "1011",
"input_label_before": "1017",
"input_label_after": "1018",
"embed_noembed_exists": "1020",
"table_scope_valid": "1025",
"img_alt_null": "1027",
"input_fields_grouped": "1028",
"input_checkboxes_grouped": "1029",
"script_select_review": "1035",
"input_onchange_review": "1050",
"embed_alt_exists": "1051",
"noembed_content_exists": "1052",
"table_caption_empty": "1053",
"table_caption_nested": "1054",
"label_content_exists": "1055",
"dir_attribute_valid": "1056",
"frame_src_valid": "1057",
"table_headers_related": "1059",
"table_layout_linearized": "1060",
"table_headers_exists": "1061",
"label_ref_valid": "1062",
"element_accesskey_unique": "1063",
"script_focus_blur_review": "1064",
"imagemap_alt_exists": "1067",
"emoticons_alt_exists": "1068",
"style_before_after_review": "1069",
"text_whitespace_valid": "1070",
"aria_role_allowed": "1074",
"aria_attribute_value_valid": "1076",
"aria_id_unique": "1077",
"aria_attribute_required": "1079",
"aria_attribute_exists": "1082",
"aria_attribute_allowed": "1083",
"aria_activedescendant_tabindex_valid": "1084",
"aria_child_tabbable": "1086",
"aria_keyboard_handler_exists": "1087",
"img_alt_decorative": "1090",
"aria_search_label_unique": "1097",
"aria_application_label_unique": "1099",
"aria_application_labelled": "1100",
"aria_document_label_unique": "1101",
"WCAG20_Label_TargetInvisible": "1112",
"caption_track_exists": "1117",
"media_keyboard_controllable": "1119",
"HAAC_Input_HasRequired": "1124",
"aria_img_labelled": "1128",
"img_alt_background": "1132",
"element_accesskey_labelled": "1140",
"aria_attribute_conflict": "1141",
"canvas_content_described": "1143",
"figure_label_exists": "1144",
"input_placeholder_label_visible": "1145",
"form_submit_review": "1147",
"text_contrast_sufficient": "1148",
"text_contrast_sufficient_PV": "1149",
"skip_main_exists": "1150",
"skip_main_described": "1151",
"aria_child_valid": "1152",
"aria_parent_required": "1153",
"aria_eventhandler_role_valid": "1154",
"aria_widget_labelled": "1156",
"aria_content_in_landmark": "1157",
"aria_region_labelled": "1158",
"aria_main_label_visible": "1159",
"aria_banner_label_unique": "1160",
"aria_complementary_label_unique": "1161",
"aria_contentinfo_label_unique": "1162",
"aria_form_label_unique": "1163",
"aria_navigation_label_unique": "1164",
"aria_complementary_label_visible": "1165",
"aria_article_label_unique": "1166",
"Rpt_Aria_ArticleRoleLabel_Implicit": "1167",
"Rpt_Aria_MultipleGroupRoles_Implicit": "1168",
"Rpt_Aria_GroupRoleLabel_Implicit": "1169",
"aria_contentinfo_single": "1170",
"aria_banner_single": "1172",
"aria_contentinfo_misuse": "1173",
"aria_complementary_labelled": "1174",
"aria_region_label_unique": "1176",
"widget_tabbable_exists": "1177",
"widget_tabbable_single": "1178",
"style_highcontrast_visible": "1180",
"aria_main_label_unique": "1182",
"download_keyboard_controllable": "1183",
"error_message_exists": "1184",
"list_children_valid": "1185",
"aria_activedescendant_valid": "1186",
"application_content_accessible": "1187",
"aria_toolbar_label_unique": "1188",
"HAAC_Combobox_ARIA_11_Guideline": "1193",
"HAAC_Combobox_Must_Have_Text_Input": "1194",
"HAAC_Combobox_DOM_Focus": "1195",
"HAAC_Combobox_Autocomplete": "1196",
"HAAC_Combobox_Autocomplete_Invalid": "1197",
"HAAC_Combobox_Expanded": "1198",
"HAAC_Combobox_Popup": "1199",
"style_viewport_resizable": "1200",
"label_name_visible": "1202",
"input_autocomplete_valid": "1203",
"input_label_visible": "1204"
}