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 Tests to ensure that the accessibility audit and mechanisms | 6 * @fileoverview Tests to ensure that the accessibility audit and mechanisms |
7 * to enable/disable it work as expected. | 7 * to enable/disable it work as expected. |
8 * @author aboxhall@google.com (Alice Boxhall) | 8 * @author aboxhall@google.com (Alice Boxhall) |
9 * @see test_api.js | 9 * @see test_api.js |
10 */ | 10 */ |
(...skipping 20 matching lines...) Expand all Loading... | |
31 */ | 31 */ |
32 expectedWarnings: null, | 32 expectedWarnings: null, |
33 | 33 |
34 /** | 34 /** |
35 * Number of expected accessibility warnings, if it should be checked, | 35 * Number of expected accessibility warnings, if it should be checked, |
36 * otherwise null. | 36 * otherwise null. |
37 * @type {?number} | 37 * @type {?number} |
38 */ | 38 */ |
39 expectedErrors: null, | 39 expectedErrors: null, |
40 | 40 |
41 isAsync: false, | |
42 accessibilityAuditConfig: new axs.AuditConfiguration(), | |
43 | |
41 tearDown: function() { | 44 tearDown: function() { |
42 if (this.expectedErrors != null) | 45 if (this.expectedErrors != null) |
43 expectEquals(this.expectedErrors, this.getAccessibilityErrors().length); | 46 expectEquals(this.expectedErrors, this.getAccessibilityErrors().length); |
44 if (this.expectedWarnings != null) | 47 if (this.expectedWarnings != null) |
45 expectEquals(this.expectedWarnings, | 48 expectEquals(this.expectedWarnings, |
46 this.getAccessibilityWarnings().length); | 49 this.getAccessibilityWarnings().length); |
47 testing.Test.prototype.tearDown.call(this); | 50 testing.Test.prototype.tearDown.call(this); |
48 } | 51 } |
49 }; | 52 }; |
50 | 53 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 /** | 115 /** |
113 * Creates an expectation that the global axs.Audit object will have its run() | 116 * Creates an expectation that the global axs.Audit object will have its run() |
114 * method called |times| times. | 117 * method called |times| times. |
115 * This creates an interstitial mock axs.Audit object with the expectation, and | 118 * This creates an interstitial mock axs.Audit object with the expectation, and |
116 * delegates to the real axs.Audit object to run the actual audit. | 119 * delegates to the real axs.Audit object to run the actual audit. |
117 * @param {number} times The number of times the audit is expected to run. | 120 * @param {number} times The number of times the audit is expected to run. |
118 */ | 121 */ |
119 function expectAuditWillRun(times) { | 122 function expectAuditWillRun(times) { |
120 var audit = createMockAudit(); | 123 var audit = createMockAudit(); |
121 var realAudit = axs.Audit; | 124 var realAudit = axs.Audit; |
122 var expectedInvocation = audit.expects(exactly(times)).run(); | 125 var expectedInvocation = audit.expects(exactly(times)).run(ANYTHING); |
123 var willArgs = []; | 126 var willArgs = []; |
124 for (var i = 0; i < times; i++) | 127 for (var i = 0; i < times; i++) |
125 willArgs.push(callFunction(realAudit.run)); | 128 willArgs.push(callFunction(realAudit.run)); |
126 expectedInvocation.will.apply(expectedInvocation, willArgs); | 129 expectedInvocation.will.apply(expectedInvocation, willArgs); |
127 axs.Audit = audit.proxy(); | 130 axs.Audit = audit.proxy(); |
128 } | 131 } |
129 | 132 |
130 // Test that an audit failure causes a test failure, if both | 133 // Test that an audit failure causes a test failure, if both |
131 // |runAccessibilityChecks| and |accessibilityIssuesAreErrors| are true. | 134 // |runAccessibilityChecks| and |accessibilityIssuesAreErrors| are true. |
132 TEST_F('WebUIAccessibilityAuditBrowserTest', 'testWithAuditFailures_shouldFail', | 135 TEST_F('WebUIAccessibilityAuditBrowserTest', 'testWithAuditFailures_shouldFail', |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 function() { | 184 function() { |
182 expectAuditWillNotRun(); | 185 expectAuditWillNotRun(); |
183 addAuditFailures(); | 186 addAuditFailures(); |
184 }); | 187 }); |
185 | 188 |
186 // Test that the accessibility audit does run if the enableAccessibilityChecks() | 189 // Test that the accessibility audit does run if the enableAccessibilityChecks() |
187 // method is called in the test function. | 190 // method is called in the test function. |
188 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | 191 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', |
189 'testWithAuditFailures_shouldFail', | 192 'testWithAuditFailures_shouldFail', |
190 function() { | 193 function() { |
191 console.log(axs.Audit); | |
192 expectAuditWillRun(1); | 194 expectAuditWillRun(1); |
193 this.enableAccessibilityChecks(); | 195 this.enableAccessibilityChecks(); |
194 addAuditFailures(); | 196 addAuditFailures(); |
195 }); | 197 }); |
196 | 198 |
197 // Test that the accessibility audit runs when the expectAccessibilityOk() | 199 // Test that the accessibility audit runs when the expectAccessibilityOk() |
198 // method is called. | 200 // method is called. |
199 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | 201 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', |
200 'testRunningAuditManually_noErrors', | 202 'testRunningAuditManually_noErrors', |
201 function() { | 203 function() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 expectAccessibilityOk(); | 277 expectAccessibilityOk(); |
276 | 278 |
277 this.expectedWarnings = 1; | 279 this.expectedWarnings = 1; |
278 this.expectedErrors = 2; | 280 this.expectedErrors = 2; |
279 expectReportConsoleWarning(); | 281 expectReportConsoleWarning(); |
280 | 282 |
281 this.enableAccessibilityChecks(); | 283 this.enableAccessibilityChecks(); |
282 | 284 |
283 addAuditFailures(); | 285 addAuditFailures(); |
284 }); | 286 }); |
287 | |
288 // Tests that the accessibility audit will run twice if expectAccessibilityOk() | |
dmazzoni
2012/12/21 20:00:35
Update this comment
aboxhall
2012/12/21 23:12:04
Done.
| |
289 // is called during the test function and |runAccessibilityChecks| is true in | |
290 // the test fixture. | |
291 TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings', | |
292 'testCanIgnoreSelectors', | |
293 function() { | |
294 expectAuditWillRun(1); | |
295 // lowContrastElements should pass as the failing element is ignored. | |
dmazzoni
2012/12/21 20:00:35
Would it be possible to make this test self-contai
aboxhall
2012/12/21 23:12:04
Done.
| |
296 this.expectedWarnings = 0; | |
297 this.expectedErrors = 2; | |
298 expectReportConsoleWarning(); | |
299 | |
300 this.enableAccessibilityChecks(); | |
301 | |
302 this.accessibilityAuditConfig.ignoreSelectors('lowContrastElements', 'P'); | |
303 | |
304 addAuditFailures(); | |
305 }); | |
OLD | NEW |