Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2390)

Side by Side Diff: chrome/test/data/webui/accessibility_audit_browsertest.js

Issue 11664011: Add a mechanism to ignore certain elements for accessibility audit on a per-test basis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update use of gypv8sh in js_unittest_rules.gypi to point to axs_testing.js Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/js_unittest_vars.gypi ('k') | chrome/test/data/webui/test_api.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 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 */
11 11
(...skipping 19 matching lines...) Expand all
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
41 tearDown: function() { 43 tearDown: function() {
42 if (this.expectedErrors != null) 44 if (this.expectedErrors != null)
43 expectEquals(this.expectedErrors, this.getAccessibilityErrors().length); 45 expectEquals(this.expectedErrors, this.getAccessibilityErrors().length);
44 if (this.expectedWarnings != null) { 46 if (this.expectedWarnings != null) {
45 expectEquals(this.expectedWarnings, 47 expectEquals(this.expectedWarnings,
46 this.getAccessibilityWarnings().length); 48 this.getAccessibilityWarnings().length);
47 } 49 }
48 testing.Test.prototype.tearDown.call(this); 50 testing.Test.prototype.tearDown.call(this);
49 } 51 }
50 }; 52 };
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 /** 126 /**
125 * Creates an expectation that the global axs.Audit object will have its run() 127 * Creates an expectation that the global axs.Audit object will have its run()
126 * method called |times| times. 128 * method called |times| times.
127 * This creates an interstitial mock axs.Audit object with the expectation, and 129 * This creates an interstitial mock axs.Audit object with the expectation, and
128 * delegates to the real axs.Audit object to run the actual audit. 130 * delegates to the real axs.Audit object to run the actual audit.
129 * @param {number} times The number of times the audit is expected to run. 131 * @param {number} times The number of times the audit is expected to run.
130 */ 132 */
131 function expectAuditWillRun(times) { 133 function expectAuditWillRun(times) {
132 var audit = createMockAudit(); 134 var audit = createMockAudit();
133 var realAudit = axs.Audit; 135 var realAudit = axs.Audit;
134 var expectedInvocation = audit.expects(exactly(times)).run(); 136 var expectedInvocation = audit.expects(exactly(times)).run(ANYTHING);
135 var willArgs = []; 137 var willArgs = [];
136 for (var i = 0; i < times; i++) 138 for (var i = 0; i < times; i++)
137 willArgs.push(callFunction(realAudit.run)); 139 willArgs.push(callFunction(realAudit.run));
138 expectedInvocation.will.apply(expectedInvocation, willArgs); 140 expectedInvocation.will.apply(expectedInvocation, willArgs);
139 axs.Audit = audit.proxy(); 141 axs.Audit = audit.proxy();
140 } 142 }
141 143
142 // Tests that an audit failure causes a test failure, if both 144 // Test that an audit failure causes a test failure, if both
143 // |runAccessibilityChecks| and |accessibilityIssuesAreErrors| are true. 145 // |runAccessibilityChecks| and |accessibilityIssuesAreErrors| are true.
144 TEST_F('WebUIAccessibilityAuditBrowserTest_ShouldFail', 'testWithAuditFailures', 146 TEST_F('WebUIAccessibilityAuditBrowserTest_ShouldFail', 'testWithAuditFailures',
145 function() { 147 function() {
146 expectAuditWillRun(1); 148 expectAuditWillRun(1);
147 addAuditFailures(); 149 addAuditFailures();
148 }); 150 });
149 151
150 // Tests that the accessibility audit does not run if |runAccessibilityChecks| 152 // Test that the accessibility audit does not run if |runAccessibilityChecks|
151 // is false. 153 // is false.
152 TEST_F('WebUIAccessibilityAuditBrowserTest', 154 TEST_F('WebUIAccessibilityAuditBrowserTest',
153 'testWithAuditFailures_a11yChecksDisabled', 155 'testWithAuditFailures_a11yChecksDisabled',
154 function() { 156 function() {
155 expectAuditWillNotRun(); 157 expectAuditWillNotRun();
156 this.disableAccessibilityChecks(); 158 this.disableAccessibilityChecks();
157 addAuditFailures(); 159 addAuditFailures();
158 }); 160 });
159 161
160 // Tests that the accessibility audit will run but not cause a test failure when 162 // Tests that the accessibility audit will run but not cause a test failure when
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail.prototype = 200 WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail.prototype =
199 { 201 {
200 __proto__: 202 __proto__:
201 WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture.prototype, 203 WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture.prototype,
202 204
203 testShouldFail: true 205 testShouldFail: true
204 }; 206 };
205 207
206 208
207 209
208 // Tests that the accessibility audit does not run when |runAccessibilityChecks| 210 // Test that the accessibility audit does not run when |runAccessibilityChecks|
209 // is set to false in the test fixture. 211 // is set to false in the test fixture.
210 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', 212 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
211 'testWithAuditFailures_a11yChecksNotEnabled', 213 'testWithAuditFailures_a11yChecksNotEnabled',
212 function() { 214 function() {
213 expectAuditWillNotRun(); 215 expectAuditWillNotRun();
214 addAuditFailures(); 216 addAuditFailures();
215 }); 217 });
216 218
217 // Tests that the accessibility audit does run if the 219 // Test that the accessibility audit does run if the enableAccessibilityChecks()
218 // enableAccessibilityChecks() method is called in the test function. 220 // method is called in the test function.
219 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail', 221 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail',
220 'testWithAuditFailures', 222 'testWithAuditFailures',
221 function() { 223 function() {
222 console.log(axs.Audit);
223 expectAuditWillRun(1); 224 expectAuditWillRun(1);
224 this.enableAccessibilityChecks(); 225 this.enableAccessibilityChecks();
225 addAuditFailures(); 226 addAuditFailures();
226 }); 227 });
227 228
228 // Tests that the accessibility audit runs when the expectAccessibilityOk() 229 // Test that the accessibility audit runs when the expectAccessibilityOk()
229 // method is called. 230 // method is called.
230 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', 231 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
231 'testRunningAuditManually_noErrors', 232 'testRunningAuditManually_noErrors',
232 function() { 233 function() {
233 expectAuditWillRun(1); 234 expectAuditWillRun(1);
234 expectAccessibilityOk(); 235 expectAccessibilityOk();
235 }); 236 });
236 237
237 // Tests that calling expectAccessibilityOk() when there are accessibility 238 // Test that calling expectAccessibilityOk() when there are accessibility issues
238 // issues on the page causes the test to fail. 239 // on the page causes the test to fail.
239 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail', 240 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture_ShouldFail',
240 'testRunningAuditManually_withErrors', 241 'testRunningAuditManually_withErrors',
241 function() { 242 function() {
242 expectAuditWillRun(1); 243 expectAuditWillRun(1);
243 addAuditFailures(); 244 addAuditFailures();
244 expectAccessibilityOk(); 245 expectAccessibilityOk();
245 }); 246 });
246 247
247 // Tests that calling expectAccessibilityOk() multiple times will cause the 248 // Test that calling expectAccessibilityOk() multiple times will cause the
248 // accessibility audit to run multiple times. 249 // accessibility audit to run multiple times.
249 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', 250 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
250 'testRunningAuditManuallySeveralTimes', function() { 251 'testRunningAuditManuallySeveralTimes', function() {
251 expectAuditWillRun(2); 252 expectAuditWillRun(2);
252 expectAccessibilityOk(); 253 expectAccessibilityOk();
253 expectAccessibilityOk(); 254 expectAccessibilityOk();
254 }); 255 });
255 256
256 /** 257 /**
257 * Test fixture with |accessibilityIssuesAreErrors| set to false. 258 * Test fixture with |accessibilityIssuesAreErrors| set to false.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 expectAccessibilityOk(); 322 expectAccessibilityOk();
322 323
323 this.expectedWarnings = 1; 324 this.expectedWarnings = 1;
324 this.expectedErrors = 2; 325 this.expectedErrors = 2;
325 expectReportConsoleWarning(); 326 expectReportConsoleWarning();
326 327
327 this.enableAccessibilityChecks(); 328 this.enableAccessibilityChecks();
328 329
329 addAuditFailures(); 330 addAuditFailures();
330 }); 331 });
332
333 // Tests that parts of the page can be ignored on a per-audit rule basis.
334 TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings',
335 'testCanIgnoreSelectors',
336 function() {
337 this.disableAccessibilityChecks();
338
339 addAuditFailures();
340 var accessibilityErrors = [];
341 var accessibilityWarnings = [];
342 try {
343 assertAccessibilityOk(accessibilityErrors, accessibilityWarnings);
344 } catch (e) {
345 // Expected error from assertion
346 }
347 expectEquals(2, accessibilityErrors.length);
348 expectEquals(1, accessibilityWarnings.length);
349
350 accessibilityErrors.length = 0;
351 accessibilityWarnings.length = 0;
352
353 this.accessibilityAuditConfig.ignoreSelectors('lowContrastElements', 'P');
354 try {
355 assertAccessibilityOk(accessibilityErrors, accessibilityWarnings);
356 } catch (e) {
357 // Expected error from assertion
358 }
359 expectEquals(2, accessibilityErrors.length);
360 // lowContrastElements should pass as the failing element is ignored.
361 expectEquals(0, accessibilityWarnings.length);
362 });
OLDNEW
« no previous file with comments | « chrome/js_unittest_vars.gypi ('k') | chrome/test/data/webui/test_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698