OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Library providing basic test framework functionality. | 6 * @fileoverview Library providing basic test framework functionality. |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * Namespace for |Test|. | 10 * Namespace for |Test|. |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 throw new Error(helper.getCallMessage(message)); | 881 throw new Error(helper.getCallMessage(message)); |
882 } | 882 } |
883 | 883 |
884 /** | 884 /** |
885 * Run an accessibility audit on the current page state. | 885 * Run an accessibility audit on the current page state. |
886 * @type {Function} | 886 * @type {Function} |
887 * @return {boolean} Whether there were any errors or warnings | 887 * @return {boolean} Whether there were any errors or warnings |
888 * @private | 888 * @private |
889 */ | 889 */ |
890 function runAccessibilityAudit(a11yErrors, a11yWarnings) { | 890 function runAccessibilityAudit(a11yErrors, a11yWarnings) { |
891 var auditResults = axs.Audit.run(); | 891 var auditResults = axs.Audit.run(this.auditConfig); |
892 for (var i = 0; i < auditResults.length; i++) { | 892 for (var i = 0; i < auditResults.length; i++) { |
893 var auditResult = auditResults[i]; | 893 var auditResult = auditResults[i]; |
894 if (auditResult.result == axs.constants.AuditResult.FAIL) { | 894 if (auditResult.result == axs.constants.AuditResult.FAIL) { |
895 var auditRule = auditResult.rule; | 895 var auditRule = auditResult.rule; |
896 // TODO(aboxhall): more useful error messages (sadly non-trivial) | 896 // TODO(aboxhall): more useful error messages (sadly non-trivial) |
897 if (auditRule.severity == axs.constants.Severity.Severe) | 897 if (auditRule.severity == axs.constants.Severity.Severe) |
898 a11yErrors.push(accessibilityErrorMessage(auditRule, auditResult)); | 898 a11yErrors.push(accessibilityErrorMessage(auditRule, auditResult)); |
899 else | 899 else |
900 a11yWarnings.push(accessibilityErrorMessage(auditRule, auditResult)); | 900 a11yWarnings.push(accessibilityErrorMessage(auditRule, auditResult)); |
901 } | 901 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 ' of ' + result.elements.length + '):'; | 968 ' of ' + result.elements.length + '):'; |
969 | 969 |
970 var maxElements = Math.min(result.elements.length, 5); | 970 var maxElements = Math.min(result.elements.length, 5); |
971 for (var i = 0; i < maxElements; i++) | 971 for (var i = 0; i < maxElements; i++) |
972 message += '\n' + axs.utils.getQuerySelectorText(result.elements[i]); | 972 message += '\n' + axs.utils.getQuerySelectorText(result.elements[i]); |
973 return message; | 973 return message; |
974 } | 974 } |
975 | 975 |
976 /** | 976 /** |
977 * Asserts that the current page state passes the accessibility audit. | 977 * Asserts that the current page state passes the accessibility audit. |
| 978 * @param {Array=} opt_errors Array to fill with errors, if desired. |
| 979 * @param {Array=} opt_warnings Array to fill with warnings, if desired. |
978 */ | 980 */ |
979 function assertAccessibilityOk() { | 981 function assertAccessibilityOk(opt_errors, opt_warnings) { |
980 helper.registerCall(); | 982 helper.registerCall(); |
981 var a11yErrors = []; | 983 var a11yErrors = opt_errors || []; |
982 var a11yWarnings = []; | 984 var a11yWarnings = opt_warnings || []; |
983 if (!runAccessibilityAudit(a11yErrors, a11yWarnings)) | 985 if (!runAccessibilityAudit(a11yErrors, a11yWarnings)) |
984 throw new Error(accessibilityAuditReport(a11yErrors, a11yWarnings)); | 986 throw new Error(accessibilityAuditReport(a11yErrors, a11yWarnings)); |
985 } | 987 } |
986 | 988 |
987 /** | 989 /** |
988 * Creates a function based upon a function that thows an exception on | 990 * Creates a function based upon a function that thows an exception on |
989 * failure. The new function stuffs any errors into the |errors| array for | 991 * failure. The new function stuffs any errors into the |errors| array for |
990 * checking by runTest. This allows tests to continue running other checks, | 992 * checking by runTest. This allows tests to continue running other checks, |
991 * while failing the overall test if any errors occurrred. | 993 * while failing the overall test if any errors occurrred. |
992 * @param {Function} assertFunc The function which may throw an Error. | 994 * @param {Function} assertFunc The function which may throw an Error. |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 exports.TEST = TEST; | 1600 exports.TEST = TEST; |
1599 exports.TEST_F = TEST_F; | 1601 exports.TEST_F = TEST_F; |
1600 exports.RUNTIME_TEST_F = TEST_F; | 1602 exports.RUNTIME_TEST_F = TEST_F; |
1601 exports.GEN = GEN; | 1603 exports.GEN = GEN; |
1602 exports.GEN_INCLUDE = GEN_INCLUDE; | 1604 exports.GEN_INCLUDE = GEN_INCLUDE; |
1603 exports.WhenTestDone = WhenTestDone; | 1605 exports.WhenTestDone = WhenTestDone; |
1604 | 1606 |
1605 // Import the Mock4JS helpers. | 1607 // Import the Mock4JS helpers. |
1606 Mock4JS.addMockSupport(exports); | 1608 Mock4JS.addMockSupport(exports); |
1607 })(this); | 1609 })(this); |
OLD | NEW |