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

Side by Side Diff: chrome/test/data/webui/a11y_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: Working test for a11y audit 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
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 WebUIA11yAuditBrowserTest() {}
6
7 WebUIA11yAuditBrowserTest.prototype = {
8 __proto__: testing.Test.prototype,
9
10 browsePreload: 'chrome://terms',
11
12 runA11yChecks: true,
13 a11yIssuesAreErrors: true,
14
15 expectedA11yWarnings: null,
dmazzoni 2012/12/14 18:45:41 It should be fine to use A11y here, for variables
aboxhall 2012/12/14 23:26:44 SGTM.
16 expectedA11yErrors: null,
17
18 tearDown: function() {
19 if (this.expectedA11yErrors != null)
20 expectEquals(this.expectedA11yErrors, getA11yErrors().length);
21 if (this.expectedA11yWarnings != null)
22 assertEquals(this.expectedA11yWarnings, getA11yWarnings().length);
23 testing.Test.prototype.tearDown.call(this);
24 }
25 };
26
27 function addAuditFailures() {
28 // Contrast ratio
29 var style = document.createElement('style');
30 style.innerText = 'p { color: #ffffff }';
31 document.head.appendChild(style);
32
33 // Bad ARIA role
34 var div = document.createElement('div');
35 div.setAttribute('role', 'not-a-role');
36 document.body.appendChild(div);
37
38 // Unlabelled control
39 var input = document.createElement('input');
40 input.type = 'text';
41 document.body.appendChild(input);
42 }
43
44 function mockAudit() {
dmazzoni 2012/12/14 18:45:41 How about createMockAudit?
aboxhall 2012/12/14 23:26:44 Done.
45 function StubAudit() {};
46 StubAudit.prototype.run = function() {};
47 return mock(StubAudit);
48 }
49
50 function expectAuditWillNotRun() {
51 var audit = mockAudit();
52 audit.expects(never()).run();
53 axs.Audit = audit.proxy();
54 }
55
56 function expectAuditWillRun(times) {
57 var audit = mockAudit();
58 var realAudit = axs.Audit;
59 var expectedInvocation = audit.expects(exactly(times)).run();
60 var willArgs = [];
61 for (var i = 0; i < times; i++)
62 willArgs.push(callFunction(realAudit.run));
63 ExpectedInvocation.prototype.will.apply(expectedInvocation, willArgs);
64 axs.Audit = audit.proxy();
65 }
66
67 TEST_F('WebUIA11yAuditBrowserTest', 'testWithAuditFailures_shouldFail',
68 function() {
69 expectAuditWillRun(1);
70 addAuditFailures();
71 });
72
73 TEST_F('WebUIA11yAuditBrowserTest',
74 'testWithAuditFailures_a11yChecksDisabled',
75 function() {
76 expectAuditWillNotRun();
77 disableA11yChecks();
78 addAuditFailures();
79 });
80
81 function WebUIA11yAuditBrowserTest_TestsDisabledInFixture() {}
82
83 WebUIA11yAuditBrowserTest_TestsDisabledInFixture.prototype = {
84 __proto__: WebUIA11yAuditBrowserTest.prototype,
85
86 runA11yChecks: false,
87 a11yIssuesAreErrors: true,
88 };
89
90 TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture',
91 'testWithAuditFailures_shouldFail',
92 function() {
93 expectAuditWillRun(1);
94 enableA11yChecks();
95 addAuditFailures();
96 });
97
98 TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture',
99 'testWithAuditFailures_a11yChecksNotEnabled',
100 function() {
101 expectAuditWillNotRun();
102 addAuditFailures();
103 });
104
105 TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture',
106 'testRunningAuditManually_noErrors',
107 function() {
108 expectAuditWillRun(1);
109 expectAccessibilityOk();
110 });
111
112 TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture',
113 'testRunningAuditManually_withErrors_shouldFail',
114 function() {
115 expectAuditWillRun(1);
116 addAuditFailures();
117 expectAccessibilityOk();
118 });
119
120 TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture',
121 'testRunningAuditManuallySeveralTimes', function() {
122 expectAuditWillRun(2);
123 expectAccessibilityOk();
124 expectAccessibilityOk();
125 });
126
127 function WebUIA11yAuditBrowserTest_IssuesAreWarnings() {}
128
129 WebUIA11yAuditBrowserTest_IssuesAreWarnings.prototype = {
130 __proto__: WebUIA11yAuditBrowserTest.prototype,
131
132 a11yIssuesAreErrors: false,
133 };
134
135 TEST_F('WebUIA11yAuditBrowserTest_IssuesAreWarnings',
136 'testWithAuditFailures',
137 function() {
138 expectAuditWillRun(1);
139 this.expectedA11yWarnings = 1;
140 this.expectedA11yErrors = 2;
141 enableA11yChecks();
142 addAuditFailures();
143 });
144
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698