diff --git a/lib/checks/color/color-contrast.js b/lib/checks/color/color-contrast.js
index 96f336cd3d..b59a49103d 100644
--- a/lib/checks/color/color-contrast.js
+++ b/lib/checks/color/color-contrast.js
@@ -23,6 +23,12 @@ var missing;
if (bgColor === null) {
missing = axe.commons.color.incompleteData.get('bgColor');
}
+
+let equalRatio = false;
+if (truncatedResult === 1) {
+ equalRatio = true;
+ missing = axe.commons.color.incompleteData.set('bgColor', 'equalRatio');
+}
// need both independently in case both are missing
var data = {
fgColor: fgColor ? fgColor.toHexString() : undefined,
@@ -35,12 +41,12 @@ var data = {
this.data(data);
-if (!cr.isValid) {
+if (!cr.isValid || equalRatio) {
this.relatedNodes(bgNodes);
}
//We don't know, so we'll put it into Can't Tell
-if (fgColor === null || bgColor === null) {
+if (fgColor === null || bgColor === null || equalRatio) {
missing = null;
axe.commons.color.incompleteData.clear();
return undefined;
diff --git a/lib/checks/color/color-contrast.json b/lib/checks/color/color-contrast.json
index 561213c39b..09dc0acc3b 100644
--- a/lib/checks/color/color-contrast.json
+++ b/lib/checks/color/color-contrast.json
@@ -13,6 +13,7 @@
"bgOverlap": "Element's background color could not be determined because it is overlapped by another element",
"fgAlpha" : "Element's foreground color could not be determined because of alpha transparency",
"elmPartiallyObscured": "Element's background color could not be determined because it's partially obscured by another element",
+ "equalRatio": "Element has a 1:1 contrast ratio with the background",
"default": "Unable to determine contrast ratio"
}
}
diff --git a/lib/commons/color/incomplete-data.js b/lib/commons/color/incomplete-data.js
index b12a2737c4..288f61457d 100644
--- a/lib/commons/color/incomplete-data.js
+++ b/lib/commons/color/incomplete-data.js
@@ -15,9 +15,10 @@ color.incompleteData = (function() {
if (typeof key !== 'string') {
throw new Error('Incomplete data: key must be a string');
}
- if (reason){
+ if (reason) {
data[key] = reason;
}
+ return data[key];
},
/**
* Get incomplete data by key
diff --git a/test/checks/color/color-contrast.js b/test/checks/color/color-contrast.js
index 0bcb63bb29..82b9ab56e2 100644
--- a/test/checks/color/color-contrast.js
+++ b/test/checks/color/color-contrast.js
@@ -201,4 +201,15 @@ describe('color-contrast', function () {
assert.equal(checkContext._data.missingData, 'bgOverlap');
assert.equal(checkContext._data.contrastRatio, 0);
});
+
+ it('should return undefined if element has same color as background', function () {
+ fixture.innerHTML = '