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

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

Issue 11363170: Add an accessibility audit test for WebUI pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years 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/test/base/js2gtest.js ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 function WebUIAccessibilityAuditBrowserTest() {}
6
7 /**
8 * @fileoverview Tests to ensure that the accessibility audit and mechanisms
9 * to enable/disable it work as expected.
scr 2012/12/18 23:13:44 Indent 4 spaces http://google-styleguide.googlecod
10 * @author aboxhall@google.com (Alice Boxhall)
11 * @see test_api.js
12 */
13 WebUIAccessibilityAuditBrowserTest.prototype = {
14 __proto__: testing.Test.prototype,
15
16 browsePreload: 'chrome://terms',
17
18 runAccessibilityChecks: true,
19 accessibilityIssuesAreErrors: true,
20
21 /**
22 * Number of expected accessibility errors, if it should be checked, otherwise
23 * null. Note: 'a11y' is short for 'accessibility'
24 * @type {?number}
25 */
26 expectedWarnings: null,
27
28 /**
29 * Number of expected accessibility warnings, if it should be checked,
30 * otherwise null.
31 * @type {?number}
32 */
33 expectedErrors: null,
34
35 tearDown: function() {
36 if (this.expectedErrors != null)
37 expectEquals(this.expectedErrors, getAccessibilityErrors().length);
38 if (this.expectedWarnings != null)
39 expectEquals(this.expectedWarnings, getAccessibilityWarnings().length);
40 testing.Test.prototype.tearDown.call(this);
41 }
42 };
43
44 /**
45 * Adds some canned audit failures to the page being tested:
46 * - A low-contrast (white on white) element
47 * - An element with a non-existent ARIA role
48 * - A control without a label
49 */
50 function addAuditFailures() {
51 // Contrast ratio
52 var style = document.createElement('style');
53 style.innerText = 'p { color: #ffffff }';
54 document.head.appendChild(style);
55
56 // Bad ARIA role
57 var div = document.createElement('div');
58 div.setAttribute('role', 'not-a-role');
59 document.body.appendChild(div);
60
61 // Unlabelled control
62 var input = document.createElement('input');
63 input.type = 'text';
64 document.body.appendChild(input);
65 }
66
67 /**
68 * Creates a mock axs.Audit object.
69 * @return {object} a mock object with a run() method.
70 */
71 function createMockAudit() {
72 function StubAudit() {};
73 StubAudit.prototype.run = function() {};
74 return mock(StubAudit);
75 }
76
77 /**
78 * Creates an expectation that the global axs.Audit object will never have its
79 * run() method called.
80 */
81 function expectAuditWillNotRun() {
82 var audit = createMockAudit();
83 audit.expects(never()).run();
84 axs.Audit = audit.proxy();
85 }
86
87 /**
88 * Creates an expectation that the global axs.Audit object will have its run()
89 * method called |times| times.
90 * This creates an interstitial mock axs.Audit object with the expectation, and
91 * delegates to the real axs.Audit object to run the actual audit.
92 * @param {number} times The number of times the audit is expected to run.
93 */
94 function expectAuditWillRun(times) {
95 var audit = createMockAudit();
96 var realAudit = axs.Audit;
97 var expectedInvocation = audit.expects(exactly(times)).run();
98 var willArgs = [];
99 for (var i = 0; i < times; i++)
100 willArgs.push(callFunction(realAudit.run));
101 ExpectedInvocation.prototype.will.apply(expectedInvocation, willArgs);
102 axs.Audit = audit.proxy();
103 }
104
105 // Test that an audit failure causes a test failure, if both
106 // |runAccessibilityChecks| and |accessibilityIssuesAreErrors| are true.
107 TEST_F('WebUIAccessibilityAuditBrowserTest', 'testWithAuditFailures_shouldFail',
108 function() {
109 expectAuditWillRun(1);
110 addAuditFailures();
111 });
112
113 // Test that the accessibility audit does not run if |runAccessibilityChecks|
114 // is false.
115 TEST_F('WebUIAccessibilityAuditBrowserTest',
116 'testWithAuditFailures_a11yChecksDisabled',
117 function() {
118 expectAuditWillNotRun();
119 disableAccessibilityChecks();
120 addAuditFailures();
121 });
122
123 // Tests that the accessibility audit will run but not cause a test failure when
124 // accessibilityIssuesAreErrors(false) is called in the test function
125 TEST_F('WebUIAccessibilityAuditBrowserTest',
126 'testWithAuditFailures_a11yIssuesAreWarnings',
127 function() {
128 accessibilityIssuesAreErrors(false);
129 expectAuditWillRun(1);
130 this.expectedWarnings = 1;
131 this.expectedErrors = 2;
132 enableAccessibilityChecks();
133 addAuditFailures();
134 });
135
136 /**
137 * Test fixture with |runAccessibilityChecks| set to false.
138 */
139 function WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture() {}
140
141 WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture.prototype = {
142 __proto__: WebUIAccessibilityAuditBrowserTest.prototype,
143
144 runAccessibilityChecks: false,
145 accessibilityIssuesAreErrors: true,
146 };
147
148 // Test that the accessibility audit does not run when |runAccessibilityChecks|
149 // is set to false in the test fixture.
150 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
151 'testWithAuditFailures_a11yChecksNotEnabled',
152 function() {
153 expectAuditWillNotRun();
154 addAuditFailures();
155 });
156
157 // Test that the accessibility audit does run if the enableAccessibilityChecks()
158 // method is called in the test function.
159 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
160 'testWithAuditFailures_shouldFail',
161 function() {
162 expectAuditWillRun(1);
163 enableAccessibilityChecks();
164 addAuditFailures();
165 });
166
167 // Test that the accessibility audit runs when the expectAccessibilityOk()
168 // method is called.
169 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
170 'testRunningAuditManually_noErrors',
171 function() {
172 expectAuditWillRun(1);
173 expectAccessibilityOk();
174 });
175
176 // Test that calling expectAccessibilityOk() when there are accessibility issues
177 // on the page causes the test to fail.
178 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
179 'testRunningAuditManually_withErrors_shouldFail',
180 function() {
181 expectAuditWillRun(1);
182 addAuditFailures();
183 expectAccessibilityOk();
184 });
185
186 // Test that calling expectAccessibilityOk() multiple times will cause the
187 // accessibility audit to run multiple times.
188 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture',
189 'testRunningAuditManuallySeveralTimes', function() {
190 expectAuditWillRun(2);
191 expectAccessibilityOk();
192 expectAccessibilityOk();
193 });
194
195 /**
196 * Test fixture with |accessibilityIssuesAreErrors| set to false.
197 */
198 function WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings() {}
199
200 WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings.prototype = {
201 __proto__: WebUIAccessibilityAuditBrowserTest.prototype,
202
203 accessibilityIssuesAreErrors: false,
204 };
205
206 // Tests that the accessibility audit will run but not cause a test failure when
207 // |accessibilityIssuesAreErrors| is false in the test fixture.
208 TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings',
209 'testWithAuditFailures',
210 function() {
211 expectAuditWillRun(1);
212 this.expectedWarnings = 1;
213 this.expectedErrors = 2;
214
215 enableAccessibilityChecks();
216 addAuditFailures();
217 });
218
219 // Tests that the accessibility audit will run and call a test failure when
220 // accessibilityIssuesAreErrors(true) is called in the test function.
221 TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings',
222 'testWithAuditFailuresAndIssuesAreErrors_shouldFail',
223 function() {
224 expectAuditWillRun(1);
225 this.expectedWarnings = 1;
226 this.expectedErrors = 2;
227
228 accessibilityIssuesAreErrors(true)
229 enableAccessibilityChecks();
230
231 addAuditFailures();
232 });
233
234 // Tests that the accessibility audit will run twice if expectAccessibilityOk()
235 // is called during the test function and |runAccessibilityChecks| is true in
236 // the test fixture.
237 TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings',
238 'testWithAuditFailuresAndExpectA11yOk',
239 function() {
240 expectAuditWillRun(2);
241
242 expectAccessibilityOk();
243
244 this.expectedWarnings = 1;
245 this.expectedErrors = 2;
246
247 enableAccessibilityChecks();
248
249 addAuditFailures();
250 });
OLDNEW
« no previous file with comments | « chrome/test/base/js2gtest.js ('k') | chrome/test/data/webui/test_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698