Chromium Code Reviews| OLD | NEW |
|---|---|
| (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() {} | |
|
Sheridan Rawlins
2012/12/18 01:43:35
JSDoc this class/constructor
aboxhall
2012/12/18 19:21:35
Done.
| |
| 6 | |
| 7 WebUIAccessibilityAuditBrowserTest.prototype = { | |
| 8 __proto__: testing.Test.prototype, | |
| 9 | |
| 10 browsePreload: 'chrome://terms', | |
| 11 | |
| 12 runAccessibilityChecks: true, | |
| 13 accessibilityIssuesAreErrors: true, | |
| 14 | |
| 15 // 'a11y' is short for 'accessibility' | |
| 16 expectedWarnings: null, | |
|
Sheridan Rawlins
2012/12/18 01:43:35
Should these be true/false?
aboxhall
2012/12/18 19:21:35
They are numerical values. Added JSDoc.
| |
| 17 expectedErrors: null, | |
| 18 | |
| 19 tearDown: function() { | |
| 20 if (this.expectedErrors != null) | |
| 21 expectEquals(this.expectedErrors, getAccessibilityErrors().length); | |
| 22 if (this.expectedWarnings != null) | |
| 23 assertEquals(this.expectedWarnings, getAccessibilityWarnings().length); | |
|
Sheridan Rawlins
2012/12/18 01:43:35
expect? Otherwise, it'll skip the call to supercl
aboxhall
2012/12/18 19:21:35
Ah yes, I was having trouble with expect initially
| |
| 24 testing.Test.prototype.tearDown.call(this); | |
| 25 } | |
| 26 }; | |
| 27 | |
| 28 function addAuditFailures() { | |
|
Sheridan Rawlins
2012/12/18 01:43:35
jsdoc
aboxhall
2012/12/18 19:21:35
Done.
| |
| 29 // Contrast ratio | |
| 30 var style = document.createElement('style'); | |
| 31 style.innerText = 'p { color: #ffffff }'; | |
| 32 document.head.appendChild(style); | |
| 33 | |
| 34 // Bad ARIA role | |
| 35 var div = document.createElement('div'); | |
| 36 div.setAttribute('role', 'not-a-role'); | |
| 37 document.body.appendChild(div); | |
| 38 | |
| 39 // Unlabelled control | |
| 40 var input = document.createElement('input'); | |
| 41 input.type = 'text'; | |
| 42 document.body.appendChild(input); | |
| 43 } | |
| 44 | |
| 45 function createMockAudit() { | |
|
Sheridan Rawlins
2012/12/18 01:43:35
jsdoc
aboxhall
2012/12/18 19:21:35
Done.
| |
| 46 function StubAudit() {}; | |
| 47 StubAudit.prototype.run = function() {}; | |
| 48 return mock(StubAudit); | |
| 49 } | |
| 50 | |
| 51 function expectAuditWillNotRun() { | |
|
Sheridan Rawlins
2012/12/18 01:43:35
jsdoc
aboxhall
2012/12/18 19:21:35
Done.
| |
| 52 var audit = createMockAudit(); | |
| 53 audit.expects(never()).run(); | |
| 54 axs.Audit = audit.proxy(); | |
| 55 } | |
| 56 | |
| 57 function expectAuditWillRun(times) { | |
|
Sheridan Rawlins
2012/12/18 01:43:35
jsdoc
aboxhall
2012/12/18 19:21:35
Done.
| |
| 58 var audit = createMockAudit(); | |
| 59 var realAudit = axs.Audit; | |
| 60 var expectedInvocation = audit.expects(exactly(times)).run(); | |
| 61 var willArgs = []; | |
| 62 for (var i = 0; i < times; i++) | |
| 63 willArgs.push(callFunction(realAudit.run)); | |
| 64 ExpectedInvocation.prototype.will.apply(expectedInvocation, willArgs); | |
|
Sheridan Rawlins
2012/12/18 01:43:35
I'm a bit confused by this… couldn't you just do s
aboxhall
2012/12/18 19:21:35
Unfortunately, no: will() can only be called once;
scr
2012/12/18 23:13:44
Ok, so how 'bout this after the for loop instead o
aboxhall
2012/12/19 19:10:05
will() only takes varargs, not an array - hence th
| |
| 65 axs.Audit = audit.proxy(); | |
| 66 } | |
| 67 | |
| 68 TEST_F('WebUIAccessibilityAuditBrowserTest', 'testWithAuditFailures_shouldFail', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
regular comment ( // ) what the test intention is.
aboxhall
2012/12/18 19:21:35
Done.
| |
| 69 function() { | |
| 70 expectAuditWillRun(1); | |
| 71 addAuditFailures(); | |
| 72 }); | |
| 73 | |
| 74 TEST_F('WebUIAccessibilityAuditBrowserTest', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
aboxhall
2012/12/18 19:21:35
Done.
| |
| 75 'testWithAuditFailures_a11yChecksDisabled', | |
| 76 function() { | |
| 77 expectAuditWillNotRun(); | |
| 78 disableAccessibilityChecks(); | |
| 79 addAuditFailures(); | |
| 80 }); | |
| 81 | |
| 82 function WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture() {} | |
|
Sheridan Rawlins
2012/12/18 01:43:35
jsdoc this class/constructor
aboxhall
2012/12/18 19:21:35
Done.
| |
| 83 | |
| 84 WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture.prototype = { | |
| 85 __proto__: WebUIAccessibilityAuditBrowserTest.prototype, | |
| 86 | |
| 87 runAccessibilityChecks: false, | |
| 88 accessibilityIssuesAreErrors: true, | |
| 89 }; | |
| 90 | |
| 91 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
| |
| 92 'testWithAuditFailures_shouldFail', | |
| 93 function() { | |
| 94 expectAuditWillRun(1); | |
| 95 enableAccessibilityChecks(); | |
| 96 addAuditFailures(); | |
| 97 }); | |
|
Sheridan Rawlins
2012/12/18 01:43:35
For kicks, could we add a version of this that doe
aboxhall
2012/12/18 19:21:35
Added at the end, in the fixture with |accessibili
| |
| 98 | |
| 99 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
aboxhall
2012/12/18 19:21:35
Done.
| |
| 100 'testWithAuditFailures_a11yChecksNotEnabled', | |
| 101 function() { | |
| 102 expectAuditWillNotRun(); | |
| 103 addAuditFailures(); | |
| 104 }); | |
| 105 | |
| 106 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
aboxhall
2012/12/18 19:21:35
Done.
| |
| 107 'testRunningAuditManually_noErrors', | |
| 108 function() { | |
| 109 expectAuditWillRun(1); | |
| 110 expectAccessibilityOk(); | |
| 111 }); | |
| 112 | |
| 113 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
aboxhall
2012/12/18 19:21:35
Done.
| |
| 114 'testRunningAuditManually_withErrors_shouldFail', | |
| 115 function() { | |
| 116 expectAuditWillRun(1); | |
| 117 addAuditFailures(); | |
| 118 expectAccessibilityOk(); | |
| 119 }); | |
| 120 | |
| 121 TEST_F('WebUIAccessibilityAuditBrowserTest_TestsDisabledInFixture', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
aboxhall
2012/12/18 19:21:35
Done.
| |
| 122 'testRunningAuditManuallySeveralTimes', function() { | |
| 123 expectAuditWillRun(2); | |
| 124 expectAccessibilityOk(); | |
| 125 expectAccessibilityOk(); | |
| 126 }); | |
| 127 | |
| 128 function WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings() {} | |
|
Sheridan Rawlins
2012/12/18 01:43:35
jsdoc class/constructor
aboxhall
2012/12/18 19:21:35
Done.
| |
| 129 | |
| 130 WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings.prototype = { | |
| 131 __proto__: WebUIAccessibilityAuditBrowserTest.prototype, | |
| 132 | |
| 133 accessibilityIssuesAreErrors: false, | |
| 134 }; | |
| 135 | |
| 136 TEST_F('WebUIAccessibilityAuditBrowserTest_IssuesAreWarnings', | |
|
Sheridan Rawlins
2012/12/18 01:43:35
// regular comment
aboxhall
2012/12/18 19:21:35
Done.
| |
| 137 'testWithAuditFailures', | |
| 138 function() { | |
| 139 expectAuditWillRun(1); | |
| 140 this.expectedWarnings = 1; | |
| 141 this.expectedErrors = 2; | |
| 142 enableAccessibilityChecks(); | |
| 143 addAuditFailures(); | |
| 144 }); | |
| 145 | |
|
Sheridan Rawlins
2012/12/18 01:43:35
Any way to test for warnings being logged? Maybe
aboxhall
2012/12/18 19:21:35
Would it be sufficient to mock out console.warn si
scr
2012/12/18 23:13:44
Sure, that seems reasonable.
On 2012/12/18 19:21:
aboxhall
2012/12/19 19:10:05
Done.
| |
| OLD | NEW |