Skip to content

Commit

Permalink
Fixes issue GoogleChrome#182 and adds a unit test to check this condi…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
ricksbrown committed Jul 25, 2015
1 parent a0fe269 commit 56df2ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug fixes:

* Fix `badAriaAttributeValue` not correctly handling decimal values (#182).
* Work around null pointer exception caused by closure compiler issue (#183).

## 2.8.0 - 2015-07-24
Expand Down
13 changes: 7 additions & 6 deletions src/js/AccessibilityUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ axs.utils.getRoles = function(element, implicit) {
roleObject.valid = result.valid = true;
} else {
roleObject.valid = false;

}
result.roles.push(roleObject);
}
Expand Down Expand Up @@ -705,26 +705,27 @@ axs.utils.getAriaPropertyValue = function(propertyName, value, element) {
}
return result;
case "integer":
case "decimal":
var validNumber = axs.utils.isValidNumber(value);
if (!validNumber.valid) {
result.valid = false;
result.reason = validNumber.reason;
return result;
}
if (Math.floor(validNumber.value) != validNumber.value) {
if (Math.floor(validNumber.value) !== validNumber.value) {
result.valid = false;
result.reason = '' + value + ' is not a whole integer';
} else {
result.valid = true;
result.value = validNumber.value;
}
return result;
case "decimal":
case "number":
var validNumber = axs.utils.isValidNumber(value);
if (validNumber.valid) {
result.valid = true;
result.value = validNumber.value;
if (!validNumber.valid) {
result.valid = false;
result.reason = validNumber.reason;
return result;
}
case "string":
result.valid = true;
Expand Down
22 changes: 22 additions & 0 deletions test/audits/bad-aria-attribute-value-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,25 @@ test('Good number value is good', function() {
{ elements: [], result: axs.constants.AuditResult.PASS }
);
});

test('Good decimal number value is good', function() {
var fixture = document.getElementById('qunit-fixture');
var div = document.createElement('div');
fixture.appendChild(div);
div.setAttribute('aria-valuenow', '0.5');
deepEqual(
axs.AuditRules.getRule('badAriaAttributeValue').run({ scope: fixture }),
{ elements: [], result: axs.constants.AuditResult.PASS }
);
});

test('Good negative number value is good', function() {
var fixture = document.getElementById('qunit-fixture');
var div = document.createElement('div');
fixture.appendChild(div);
div.setAttribute('aria-valuenow', '-10');
deepEqual(
axs.AuditRules.getRule('badAriaAttributeValue').run({ scope: fixture }),
{ elements: [], result: axs.constants.AuditResult.PASS }
);
});

0 comments on commit 56df2ac

Please sign in to comment.