Index: chrome/test/data/webui/a11y_audit_browsertest.js |
diff --git a/chrome/test/data/webui/a11y_audit_browsertest.js b/chrome/test/data/webui/a11y_audit_browsertest.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cbebb5caba27a168554a6bb303adfc20aa7bbe00 |
--- /dev/null |
+++ b/chrome/test/data/webui/a11y_audit_browsertest.js |
@@ -0,0 +1,144 @@ |
+// 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. |
+ |
+function WebUIA11yAuditBrowserTest() {} |
+ |
+WebUIA11yAuditBrowserTest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ |
+ browsePreload: 'chrome://terms', |
+ |
+ runA11yChecks: true, |
+ a11yIssuesAreErrors: true, |
+ |
+ 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.
|
+ expectedA11yErrors: null, |
+ |
+ tearDown: function() { |
+ if (this.expectedA11yErrors != null) |
+ expectEquals(this.expectedA11yErrors, getA11yErrors().length); |
+ if (this.expectedA11yWarnings != null) |
+ assertEquals(this.expectedA11yWarnings, getA11yWarnings().length); |
+ testing.Test.prototype.tearDown.call(this); |
+ } |
+}; |
+ |
+function addAuditFailures() { |
+ // Contrast ratio |
+ var style = document.createElement('style'); |
+ style.innerText = 'p { color: #ffffff }'; |
+ document.head.appendChild(style); |
+ |
+ // Bad ARIA role |
+ var div = document.createElement('div'); |
+ div.setAttribute('role', 'not-a-role'); |
+ document.body.appendChild(div); |
+ |
+ // Unlabelled control |
+ var input = document.createElement('input'); |
+ input.type = 'text'; |
+ document.body.appendChild(input); |
+} |
+ |
+function mockAudit() { |
dmazzoni
2012/12/14 18:45:41
How about createMockAudit?
aboxhall
2012/12/14 23:26:44
Done.
|
+ function StubAudit() {}; |
+ StubAudit.prototype.run = function() {}; |
+ return mock(StubAudit); |
+} |
+ |
+function expectAuditWillNotRun() { |
+ var audit = mockAudit(); |
+ audit.expects(never()).run(); |
+ axs.Audit = audit.proxy(); |
+} |
+ |
+function expectAuditWillRun(times) { |
+ var audit = mockAudit(); |
+ var realAudit = axs.Audit; |
+ var expectedInvocation = audit.expects(exactly(times)).run(); |
+ var willArgs = []; |
+ for (var i = 0; i < times; i++) |
+ willArgs.push(callFunction(realAudit.run)); |
+ ExpectedInvocation.prototype.will.apply(expectedInvocation, willArgs); |
+ axs.Audit = audit.proxy(); |
+} |
+ |
+TEST_F('WebUIA11yAuditBrowserTest', 'testWithAuditFailures_shouldFail', |
+ function() { |
+ expectAuditWillRun(1); |
+ addAuditFailures(); |
+}); |
+ |
+TEST_F('WebUIA11yAuditBrowserTest', |
+ 'testWithAuditFailures_a11yChecksDisabled', |
+ function() { |
+ expectAuditWillNotRun(); |
+ disableA11yChecks(); |
+ addAuditFailures(); |
+}); |
+ |
+function WebUIA11yAuditBrowserTest_TestsDisabledInFixture() {} |
+ |
+WebUIA11yAuditBrowserTest_TestsDisabledInFixture.prototype = { |
+ __proto__: WebUIA11yAuditBrowserTest.prototype, |
+ |
+ runA11yChecks: false, |
+ a11yIssuesAreErrors: true, |
+}; |
+ |
+TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture', |
+ 'testWithAuditFailures_shouldFail', |
+ function() { |
+ expectAuditWillRun(1); |
+ enableA11yChecks(); |
+ addAuditFailures(); |
+}); |
+ |
+TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture', |
+ 'testWithAuditFailures_a11yChecksNotEnabled', |
+ function() { |
+ expectAuditWillNotRun(); |
+ addAuditFailures(); |
+}); |
+ |
+TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture', |
+ 'testRunningAuditManually_noErrors', |
+ function() { |
+ expectAuditWillRun(1); |
+ expectAccessibilityOk(); |
+}); |
+ |
+TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture', |
+ 'testRunningAuditManually_withErrors_shouldFail', |
+ function() { |
+ expectAuditWillRun(1); |
+ addAuditFailures(); |
+ expectAccessibilityOk(); |
+}); |
+ |
+TEST_F('WebUIA11yAuditBrowserTest_TestsDisabledInFixture', |
+ 'testRunningAuditManuallySeveralTimes', function() { |
+ expectAuditWillRun(2); |
+ expectAccessibilityOk(); |
+ expectAccessibilityOk(); |
+}); |
+ |
+function WebUIA11yAuditBrowserTest_IssuesAreWarnings() {} |
+ |
+WebUIA11yAuditBrowserTest_IssuesAreWarnings.prototype = { |
+ __proto__: WebUIA11yAuditBrowserTest.prototype, |
+ |
+ a11yIssuesAreErrors: false, |
+}; |
+ |
+TEST_F('WebUIA11yAuditBrowserTest_IssuesAreWarnings', |
+ 'testWithAuditFailures', |
+ function() { |
+ expectAuditWillRun(1); |
+ this.expectedA11yWarnings = 1; |
+ this.expectedA11yErrors = 2; |
+ enableA11yChecks(); |
+ addAuditFailures(); |
+}); |
+ |