diff options
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/js_unittest_rules.gypi | 3 | ||||
-rw-r--r-- | chrome/js_unittest_vars.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/webui/accessibility_audit_browsertest.js | 56 | ||||
-rw-r--r-- | chrome/test/data/webui/test_api.js | 31 | ||||
-rwxr-xr-x | tools/gypv8sh.py | 8 |
7 files changed, 76 insertions, 27 deletions
@@ -323,7 +323,7 @@ deps = { "/trunk/deps/third_party/opus@173498", "src/third_party/accessibility-developer-tools": - Var("chromium_git") + "/external/accessibility-developer-tools.git@d694593cc87d18ccb7e2cb94d447354f5fc6c059", + Var("chromium_git") + "/external/accessibility-developer-tools.git@e2a7557c79da617d0c06d6e96ada803b8b4b3ece", "src/webkit/media/crypto/ppapi/cdm": "/trunk/deps/cdm@173055", diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 1e7df96..9d85950 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1362,6 +1362,7 @@ '<(gypv8sh)', '<(PRODUCT_DIR)/v8_shell<(EXECUTABLE_SUFFIX)', '<(mock_js)', + '<(accessibility_audit_js)', '<(test_api_js)', '<(js2gtest)', ], @@ -1713,6 +1714,7 @@ '<(gypv8sh)', '<(PRODUCT_DIR)/v8_shell<(EXECUTABLE_SUFFIX)', '<(mock_js)', + '<(accessibility_audit_js)', '<(test_api_js)', '<(js2gtest)', ], diff --git a/chrome/js_unittest_rules.gypi b/chrome/js_unittest_rules.gypi index d650f627db..0370eee 100644 --- a/chrome/js_unittest_rules.gypi +++ b/chrome/js_unittest_rules.gypi @@ -14,7 +14,7 @@ # ], # # Then include this rule file in each of your unittest targets: -# +# # { # 'target_name': 'my_unittests', # ... @@ -56,6 +56,7 @@ '<(gypv8sh)', '<(PRODUCT_DIR)/v8_shell<(EXECUTABLE_SUFFIX)', '<(mock_js)', + '<(accessibility_audit_js)', '<(test_api_js)', '<(js2gtest)', ], diff --git a/chrome/js_unittest_vars.gypi b/chrome/js_unittest_vars.gypi index 7c4bebd..8146ea2 100644 --- a/chrome/js_unittest_vars.gypi +++ b/chrome/js_unittest_vars.gypi @@ -8,5 +8,6 @@ 'js2gtest': '<(DEPTH)/chrome/test/base/js2gtest.js', 'mock_js': '<(DEPTH)/chrome/third_party/mock4js/mock4js.js', 'test_api_js': '<(DEPTH)/chrome/test/data/webui/test_api.js', + 'accessibility_audit_js': '<(DEPTH)/third_party/accessibility-developer-tools/gen/axs_testing.js', }, } diff --git a/chrome/test/data/webui/accessibility_audit_browsertest.js b/chrome/test/data/webui/accessibility_audit_browsertest.js index 7651dc1..6e5c046 100644 --- a/chrome/test/data/webui/accessibility_audit_browsertest.js +++ b/chrome/test/data/webui/accessibility_audit_browsertest.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -38,6 +38,8 @@ WebUIAccessibilityAuditBrowserTest.prototype = { */ expectedErrors: null, + isAsync: false, + tearDown: function() { if (this.expectedErrors != null) expectEquals(this.expectedErrors, this.getAccessibilityErrors().length); @@ -131,7 +133,7 @@ function expectAuditWillNotRun() { function expectAuditWillRun(times) { var audit = createMockAudit(); var realAudit = axs.Audit; - var expectedInvocation = audit.expects(exactly(times)).run(); + var expectedInvocation = audit.expects(exactly(times)).run(ANYTHING); var willArgs = []; for (var i = 0; i < times; i++) willArgs.push(callFunction(realAudit.run)); @@ -139,7 +141,7 @@ function expectAuditWillRun(times) { axs.Audit = audit.proxy(); } -// Tests that an audit failure causes a test failure, if both +// Test that an audit failure causes a test failure, if both // |runAccessibilityChecks| and |accessibilityIssuesAreErrors| are true. TEST_F('WebUIAccessibilityAuditBrowserTest_ShouldFail', 'testWithAuditFailures', function() { @@ -147,7 +149,7 @@ TEST_F('WebUIAccessibilityAuditBrowserTest_ShouldFail', 'testWithAuditFailures', addAuditFailures(); }); -// Tests that the accessibility audit does not run if |runAccessibilityChecks| +// Test that the accessibility audit does not run if |runAccessibilityChecks| // is false. TEST_F('WebUIAccessibilityAuditBrowserTest', 'testWithAuditFailures_a11yChecksDisabled', @@ -205,7 +207,7 @@ WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail.prototype = -// Tests that the accessibility audit does not run when |runAccessibilityChecks| +// Test that the accessibility audit does not run when |runAccessibilityChecks| // is set to false in the test fixture. TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', 'testWithAuditFailures_a11yChecksNotEnabled', @@ -214,18 +216,17 @@ TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', addAuditFailures(); }); -// Tests that the accessibility audit does run if the -// enableAccessibilityChecks() method is called in the test function. +// Test that the accessibility audit does run if the enableAccessibilityChecks() +// method is called in the test function. TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail', 'testWithAuditFailures', function() { - console.log(axs.Audit); expectAuditWillRun(1); this.enableAccessibilityChecks(); addAuditFailures(); }); -// Tests that the accessibility audit runs when the expectAccessibilityOk() +// Test that the accessibility audit runs when the expectAccessibilityOk() // method is called. TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', 'testRunningAuditManually_noErrors', @@ -234,8 +235,8 @@ TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', expectAccessibilityOk(); }); -// Tests that calling expectAccessibilityOk() when there are accessibility -// issues on the page causes the test to fail. +// Test that calling expectAccessibilityOk() when there are accessibility issues +// on the page causes the test to fail. TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail', 'testRunningAuditManually_withErrors', function() { @@ -244,7 +245,7 @@ TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail', expectAccessibilityOk(); }); -// Tests that calling expectAccessibilityOk() multiple times will cause the +// Test that calling expectAccessibilityOk() multiple times will cause the // accessibility audit to run multiple times. TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', 'testRunningAuditManuallySeveralTimes', function() { @@ -328,3 +329,34 @@ TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings', addAuditFailures(); }); + +// Tests that parts of the page can be ignored on a per-audit rule basis. +TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings', + 'testCanIgnoreSelectors', + function() { + this.disableAccessibilityChecks(); + + addAuditFailures(); + var accessibilityErrors = []; + var accessibilityWarnings = []; + try { + assertAccessibilityOk(accessibilityErrors, accessibilityWarnings); + } catch (e) { + // Expected error from assertion + } + expectEquals(2, accessibilityErrors.length); + expectEquals(1, accessibilityWarnings.length); + + accessibilityErrors.length = 0; + accessibilityWarnings.length = 0; + + this.accessibilityAuditConfig.ignoreSelectors('lowContrastElements', 'P'); + try { + assertAccessibilityOk(accessibilityErrors, accessibilityWarnings); + } catch (e) { + // Expected error from assertion + } + expectEquals(2, accessibilityErrors.length); + // lowContrastElements should pass as the failing element is ignored. + expectEquals(0, accessibilityWarnings.length); +}); diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js index 61d459a..d2068e7 100644 --- a/chrome/test/data/webui/test_api.js +++ b/chrome/test/data/webui/test_api.js @@ -42,7 +42,7 @@ var testing = {}; * mimic the gtest's class names. * @constructor */ - function Test() {} + function Test() {}; Test.prototype = { /** @@ -125,7 +125,13 @@ var testing = {}; * Whether to run the accessibility checks. * @type {boolean} */ - runAccessibilityChecks : true, + runAccessibilityChecks: true, + + /** + * Configuration for the accessibility audit. + * @type {axs.AuditConfiguration} + */ + accessibilityAuditConfig: new axs.AuditConfiguration(), /** * Whether to treat accessibility issues (errors or warnings) as test @@ -245,7 +251,8 @@ var testing = {}; if (!this.runAccessibilityChecks || typeof document === 'undefined') return; - if (!runAccessibilityAudit(this.a11yErrors_, this.a11yWarnings_)) { + if (!runAccessibilityAudit(this.a11yErrors_, this.a11yWarnings_, + this.accessibilityAuditConfig)) { var report = accessibilityAuditReport(this.a11yErrors_, this.a11yWarnings_); if (this.accessibilityIssuesAreErrors) @@ -883,11 +890,14 @@ var testing = {}; /** * Run an accessibility audit on the current page state. * @type {Function} + * @param {Array} a11yErrors + * @param {Array} a11yWarnings + * @param {axs.AuditConfigutarion=} opt_config * @return {boolean} Whether there were any errors or warnings * @private */ - function runAccessibilityAudit(a11yErrors, a11yWarnings) { - var auditResults = axs.Audit.run(); + function runAccessibilityAudit(a11yErrors, a11yWarnings, opt_config) { + var auditResults = axs.Audit.run(opt_config); for (var i = 0; i < auditResults.length; i++) { var auditResult = auditResults[i]; if (auditResult.result == axs.constants.AuditResult.FAIL) { @@ -975,12 +985,15 @@ var testing = {}; /** * Asserts that the current page state passes the accessibility audit. + * @param {Array=} opt_errors Array to fill with errors, if desired. + * @param {Array=} opt_warnings Array to fill with warnings, if desired. */ - function assertAccessibilityOk() { + function assertAccessibilityOk(opt_errors, opt_warnings) { helper.registerCall(); - var a11yErrors = []; - var a11yWarnings = []; - if (!runAccessibilityAudit(a11yErrors, a11yWarnings)) + var a11yErrors = opt_errors || []; + var a11yWarnings = opt_warnings || []; + var auditConfig = currentTestCase.fixture.accessibilityAuditConfig; + if (!runAccessibilityAudit(a11yErrors, a11yWarnings, auditConfig)) throw new Error(accessibilityAuditReport(a11yErrors, a11yWarnings)); } diff --git a/tools/gypv8sh.py b/tools/gypv8sh.py index c45dbfd..918368c 100755 --- a/tools/gypv8sh.py +++ b/tools/gypv8sh.py @@ -22,20 +22,20 @@ import shutil def main (): parser = optparse.OptionParser() parser.set_usage( - "%prog v8_shell mock.js test_api.js js2webui.js " + "%prog v8_shell mock.js axs_testing.js test_api.js js2webui.js " "testtype inputfile inputrelfile cxxoutfile jsoutfile") parser.add_option('-v', '--verbose', action='store_true') parser.add_option('-n', '--impotent', action='store_true', help="don't execute; just print (as if verbose)") (opts, args) = parser.parse_args() - if len(args) != 9: + if len(args) != 10: parser.error('all arguments are required.') - (v8_shell, mock_js, test_api, js2webui, test_type, + (v8_shell, mock_js, axs_testing_js, test_api, js2webui, test_type, inputfile, inputrelfile, cxxoutfile, jsoutfile) = args arguments = [js2webui, inputfile, inputrelfile, cxxoutfile, test_type] cmd = [v8_shell, '-e', "arguments=" + json.dumps(arguments), mock_js, - test_api, js2webui] + axs_testing_js, test_api, js2webui] if opts.verbose or opts.impotent: print cmd if not opts.impotent: |