Index: chrome/test/data/webui/test_api.js |
diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js |
index 03c6721d51d55bf0baf4641caa2e6d9955c31802..5315213496cb072f1f26ba0a57030d43f4c7f107 100644 |
--- a/chrome/test/data/webui/test_api.js |
+++ b/chrome/test/data/webui/test_api.js |
@@ -122,6 +122,11 @@ var testing = {}; |
extraLibraries: [], |
/** |
+ * FIXME(aboxhall) |
+ */ |
+ runA11yChecks: true, |
+ |
+ /** |
* Create a new class to handle |messageNames|, assign it to |
* |this.mockHandler|, register its messages and return it. |
* @return {Mock} Mock handler class assigned to |this.mockHandler|. |
@@ -234,6 +239,7 @@ var testing = {}; |
function TestCase(name, fixture, body) { |
this.name = name; |
this.fixture = fixture; |
+ this.runA11yChecks = fixture.runA11yChecks; |
this.body = body; |
} |
@@ -264,6 +270,11 @@ var testing = {}; |
deferred_: false, |
/** |
+ * FIXME(aboxhall) |
+ */ |
+ runA11yChecks: true, |
+ |
+ /** |
* Called at preload time, proxies to the fixture. |
* @type {Function} |
*/ |
@@ -585,6 +596,13 @@ var testing = {}; |
var errors = []; |
/** |
+ * Hold the accessibility warnings and errors, respectively. |
+ * Like errors, cleared when results are reported. |
+ */ |
+ var a11y_warnings = []; |
+ var a11y_errors = []; |
+ |
+ /** |
* URL to dummy WebUI page for testing framework. |
* @type {string} |
*/ |
@@ -605,6 +623,9 @@ var testing = {}; |
*/ |
function testDone(result) { |
if (!testIsDone) { |
+ // FIXME(aboxhall): run a11y check if not disabled; combine with result. |
+ var accessibilityOk = runAccessibilityAudit_(a11y_errors, a11y_warnings); |
+ |
testIsDone = true; |
if (currentTestCase) { |
try { |
@@ -618,7 +639,12 @@ var testing = {}; |
} |
currentTestCase = null; |
} |
- chrome.send('testResult', result ? result : testResult()); |
+ if (!result) |
+ result = testResult(); |
+ if (!accessibilityOk) |
+ result.push(createAccessibilityErrorMessage(a11y_errors, |
+ a11y_warnings)); |
+ chrome.send('testResult', result); |
errors.splice(0, errors.length); |
} else { |
console.warn('testIsDone already'); |
@@ -793,6 +819,66 @@ var testing = {}; |
} |
/** |
+ * FIXME(aboxhall) documentation |
+ */ |
+ function createAccessibilityErrorMessage(a11y_errors, a11y_warnings) { |
+ var errorMessage = 'Accessibility '; |
+ if (a11y_errors.length > 0) |
+ errorMessage += 'Errors '; |
+ else |
+ errorMessage += 'Warnings '; |
+ errorMessage += 'found:\n'; |
+ for (var i = 0; i < a11y_errors.length; i++) |
+ errorMessage += 'Error: ' + a11y_errors[i] + '\n'; |
+ for (var i = 0; i < a11y_warnings.length; i++) |
+ errorMessage += 'Warning: ' + a11y_warnings[i] + '\n'; |
+ return errorMessage; |
+ } |
+ |
+ /** |
+ * FIXME(aboxhall) documentation |
+ */ |
+ function assertAccessibilityOk() { |
+ helper.registerCall(); |
+ var a11y_errors = []; |
+ var a11y_warnings = []; |
+ if (!runAccessibilityAudit_(a11y_errors, a11y_warnings)) |
+ throw new Error(createAccessibilityErrorMessage(a11y_errors, |
+ a11y_warnings)); |
+ } |
+ |
+ /** |
+ * Run an accessibility audit on the current page state. |
+ * FIXME(aboxhall) documentation |
+ * @type {Function} |
+ * @return {boolean} Whether there were any errors or warnings |
+ * @private |
+ */ |
+ function runAccessibilityAudit_(errors, warnings) { |
+ for (var auditRuleName in axs.AuditRule.specs) { |
+ var auditRule = axs.AuditRules.getRule(auditRuleName); |
+ if (!auditRule) |
+ continue; // Shouldn't happen, but fail silently if it does. |
+ if (!auditRule.disabled && !auditRule.requiresConsoleAPI) { |
+ var result = auditRule.run(); |
+ if (result.result == axs.constants.AuditResult.FAIL) { |
+ // TODO(aboxhall): more useful error messages (sadly non-trivial) |
+ if (auditRule.severity == axs.constants.Severity.Severe) |
+ errors.push("Accessibility audit rule " + auditRule.name + |
+ " failed"); |
+ else |
+ warnings.push("Accessibility audit rule " + auditRule.name + |
+ " failed"); |
+ } |
+ } |
+ } |
+ // TODO(aboxhall): have strict (no errors or warnings) vs non-strict |
+ // (warnings ok) |
+ // TODO(aboxhall): some kind of info logging for warnings only?? |
+ return (errors.length == 0 && warnings.length == 0); |
+ } |
+ |
+ /** |
* Creates a function based upon a function that thows an exception on |
* failure. The new function stuffs any errors into the |errors| array for |
* checking by runTest. This allows tests to continue running other checks, |
@@ -834,6 +920,7 @@ var testing = {}; |
* @see runTestFunction |
*/ |
function runTest(isAsync, testFunction, testArguments) { |
+ // FIXME(aboxhall): modify to add a11y phase |
// Avoid eval() if at all possible, since it will not work on pages |
// that have enabled content-security-policy. |
var testBody = this[testFunction]; // global object -- not a method. |
@@ -1389,6 +1476,7 @@ var testing = {}; |
exports.expectLT = createExpect(assertLT); |
exports.expectNotEquals = createExpect(assertNotEquals); |
exports.expectNotReached = createExpect(assertNotReached); |
+ exports.expectAccessibilityOk = createExpect(assertAccessibilityOk); |
exports.preloadJavascriptLibraries = preloadJavascriptLibraries; |
exports.registerMessageCallback = registerMessageCallback; |
exports.registerMockGlobals = registerMockGlobals; |