diff --git a/package.json b/package.json
index 3caafd20e6..9b5575fb9a 100644
--- a/package.json
+++ b/package.json
@@ -66,7 +66,7 @@
}
},
"scripts": {
- "start": "http-server -p 9876 --silent",
+ "start": "http-server -a \"\" -p 9876 --silent",
"develop": "grunt dev --force",
"api-docs": "jsdoc --configure .jsdoc.json",
"build": "grunt",
diff --git a/test/commons/color/get-background-color.js b/test/commons/color/get-background-color.js
index fb76e89328..e20abb6d43 100644
--- a/test/commons/color/get-background-color.js
+++ b/test/commons/color/get-background-color.js
@@ -4,18 +4,34 @@ describe('color.getBackgroundColor', function () {
var fixture = document.getElementById('fixture');
var shadowSupported = axe.testUtils.shadowSupport.v1;
- var origBodyBg;
- var origHtmlBg;
- before(function () {
- origBodyBg = document.body.style.background;
- origHtmlBg = document.documentElement.style.background;
+ /**
+ * Assert that two Colors are close-to-equal.
+ * @param {axe.commons.color.Color[]} actual
+ * @param {axe.commons.color.Color[]} expected
+ * @param {number} threshold How much each RGB value may differ by
+ * @param {number} alphaThreshold How much the alpha channel may differ by
+ */
+ function assertColorsClose(
+ actual,
+ expected,
+ threshold = 0.5,
+ alphaThreshold = 0.1
+ ) {
+ assert.closeTo(actual.red, expected.red, threshold, 'red');
+ assert.closeTo(actual.green, expected.green, threshold, 'green');
+ assert.closeTo(actual.blue, expected.blue, threshold, 'blue');
+ assert.closeTo(actual.alpha, expected.alpha, alphaThreshold, 'alpha');
+ }
+
+ beforeEach(function () {
+ // This normalizes the default mocha behavior of setting a different background
+ // based on prefers-color-scheme settings.
+ document.body.style.background = '#fff';
+ document.documentElement.style.background = 'unset';
});
afterEach(function () {
- document.body.style.background = origBodyBg;
- document.documentElement.style.background = origHtmlBg;
-
axe.commons.color.incompleteData.clear();
axe._tree = undefined;
});
@@ -31,10 +47,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(128, 0, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -55,11 +68,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(64, 64, 0, 1);
-
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [target, pos]);
});
@@ -75,10 +84,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(64, 64, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [target, under]);
});
@@ -101,11 +107,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(64, 64, 0, 1);
-
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [target, under]);
});
@@ -120,10 +122,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(64, 64, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [target, parent]);
});
@@ -138,10 +137,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(64, 64, 0, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [target, parent]);
});
@@ -155,10 +151,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(102, 153, 51, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
});
it('should apply opacity from an ancestor not in the element stack', function () {
@@ -173,10 +166,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(102, 153, 51, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
});
it('should return null if containing parent has a background image and is non-opaque', function () {
@@ -195,16 +185,13 @@ describe('color.getBackgroundColor', function () {
assert.equal(axe.commons.color.incompleteData.get('bgColor'), 'bgImage');
});
- it('should return white if transparency goes all the way up to document', function () {
+ it('should return body color if transparency goes all the way up to document', function () {
fixture.innerHTML = '
';
var target = fixture.querySelector('#target');
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target);
var expected = new axe.commons.color.Color(255, 255, 255, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
});
it('should return null if there is a background image', function () {
@@ -272,10 +259,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(0, 128, 0, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [target]);
});
@@ -324,9 +308,8 @@ describe('color.getBackgroundColor', function () {
document.getElementById('target'),
[]
);
- assert.equal(Math.round(actual.blue), 255);
- assert.equal(Math.round(actual.red), 255);
- assert.equal(Math.round(actual.green), 255);
+ var expected = new axe.commons.color.Color(255, 255, 255);
+ assertColorsClose(actual, expected);
});
it('should return null if an absolutely positioned element partially obsures background', function () {
@@ -362,10 +345,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -384,10 +364,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -406,10 +383,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -428,10 +402,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -450,10 +421,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -472,10 +440,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -491,10 +456,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(255, 255, 255, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.notEqual(bgNodes, [parent]);
});
@@ -508,10 +470,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(0, 0, 0, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
});
it('handles nested inline elements in the middle of a text', function () {
@@ -527,10 +486,8 @@ describe('color.getBackgroundColor', function () {
var bgNodes = [];
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
- assert.equal(actual.red, 0);
- assert.equal(actual.green, 255);
- assert.equal(actual.blue, 255);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(0, 255, 255, 1);
+ assert.deepEqual(actual, expected);
});
it('should return null for inline elements with position:absolute', function () {
@@ -560,10 +517,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(255, 255, 255, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.notEqual(bgNodes, [parent]);
});
@@ -586,10 +540,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(243, 243, 243, 1);
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -609,10 +560,7 @@ describe('color.getBackgroundColor', function () {
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(255, 255, 255, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -630,10 +578,7 @@ describe('color.getBackgroundColor', function () {
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
var expected = new axe.commons.color.Color(255, 255, 255, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -655,10 +600,7 @@ describe('color.getBackgroundColor', function () {
assert.deepEqual(bgNodes, [shifted]);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('should return null when encountering background images during visual traversal', function () {
@@ -715,10 +657,7 @@ describe('color.getBackgroundColor', function () {
var expected = new axe.commons.color.Color(0, 0, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('returns negative z-index elements when body has a background', function () {
@@ -736,10 +675,7 @@ describe('color.getBackgroundColor', function () {
var expected = new axe.commons.color.Color(0, 0, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('should return null for negative z-index element when html and body have a background', function () {
@@ -768,11 +704,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(fixture, []);
var expected = new axe.commons.color.Color(255, 255, 255, 1);
-
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('should return the body bgColor when content does not overlap', function () {
@@ -783,11 +715,8 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var target = fixture.querySelector('#target');
var actual = axe.commons.color.getBackgroundColor(target, []);
-
- assert.closeTo(actual.red, 255, 0);
- assert.closeTo(actual.green, 255, 0);
- assert.closeTo(actual.blue, 255, 0);
- assert.closeTo(actual.alpha, 1, 0);
+ var expected = new axe.commons.color.Color(255, 255, 255, 1);
+ assert.deepEqual(actual, expected);
});
it('should return the html canvas inherited from body bgColor when element content does not overlap with body', function () {
@@ -801,17 +730,16 @@ describe('color.getBackgroundColor', function () {
document.body.style.background = '#000';
document.body.style.margin = 0;
- axe.testUtils.flatTreeSetup(fixture);
- var target = fixture.querySelector('#target');
- var actual = axe.commons.color.getBackgroundColor(target, []);
-
- assert.closeTo(actual.red, 0, 0);
- assert.closeTo(actual.green, 0, 0);
- assert.closeTo(actual.blue, 0, 0);
- assert.closeTo(actual.alpha, 1, 0);
-
- document.body.style.height = originalHeight;
- document.body.style.margin = originalMargin;
+ try {
+ axe.testUtils.flatTreeSetup(fixture);
+ var target = fixture.querySelector('#target');
+ var actual = axe.commons.color.getBackgroundColor(target, []);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
+ } finally {
+ document.body.style.height = originalHeight;
+ document.body.style.margin = originalMargin;
+ }
});
it('should return the html canvas bgColor when element content does not overlap with body', function () {
@@ -824,16 +752,15 @@ describe('color.getBackgroundColor', function () {
document.body.style.background = '#0f0';
document.documentElement.style.background = '#f00';
- axe.testUtils.flatTreeSetup(fixture);
- var target = fixture.querySelector('#target');
- var actual = axe.commons.color.getBackgroundColor(target, []);
-
- assert.closeTo(actual.red, 255, 0);
- assert.closeTo(actual.green, 0, 0);
- assert.closeTo(actual.blue, 0, 0);
- assert.closeTo(actual.alpha, 1, 0);
-
- document.body.style.height = originalHeight;
+ try {
+ axe.testUtils.flatTreeSetup(fixture);
+ var target = fixture.querySelector('#target');
+ var actual = axe.commons.color.getBackgroundColor(target, []);
+ var expected = new axe.commons.color.Color(255, 0, 0, 1);
+ assert.deepEqual(actual, expected);
+ } finally {
+ document.body.style.height = originalHeight;
+ }
});
it('should apply mix-blend-mode', function () {
@@ -870,10 +797,8 @@ describe('color.getBackgroundColor', function () {
var target = shadow.querySelector('#shadowTarget');
var actual = axe.commons.color.getBackgroundColor(target, []);
- assert.closeTo(actual.red, 0, 0);
- assert.closeTo(actual.green, 0, 0);
- assert.closeTo(actual.blue, 0, 0);
- assert.closeTo(actual.alpha, 1, 0);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
}
);
@@ -890,11 +815,8 @@ describe('color.getBackgroundColor', function () {
var target = shadow.querySelector('#shadowTarget');
var actual = axe.commons.color.getBackgroundColor(target, [], false);
-
- assert.equal(actual.red, 0);
- assert.equal(actual.green, 0);
- assert.equal(actual.blue, 0);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
}
);
@@ -911,11 +833,7 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, []);
var expected = new axe.commons.color.Color(0, 0, 0, 1);
-
- assert.equal(actual.red, expected.red);
- assert.equal(actual.green, expected.green);
- assert.equal(actual.blue, expected.blue);
- assert.equal(actual.alpha, expected.alpha);
+ assert.deepEqual(actual, expected);
}
);
@@ -933,10 +851,8 @@ describe('color.getBackgroundColor', function () {
var target = shadow.querySelector('#shadowTarget');
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, []);
- assert.equal(actual.red, 255);
- assert.equal(actual.green, 255);
- assert.equal(actual.blue, 255);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(255, 255, 255, 1);
+ assert.deepEqual(actual, expected);
}
);
@@ -954,10 +870,8 @@ describe('color.getBackgroundColor', function () {
var elm2 = document.querySelector('#elm2');
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(elm2, []);
- assert.equal(actual.red, 0);
- assert.equal(actual.blue, 0);
- assert.equal(actual.green, 0);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
}
);
@@ -983,10 +897,8 @@ describe('color.getBackgroundColor', function () {
var elm3 = shadow2.querySelector('#elm3');
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(elm3, []);
- assert.closeTo(actual.red, 128, 2);
- assert.closeTo(actual.blue, 128, 2);
- assert.closeTo(actual.green, 128, 2);
- assert.closeTo(actual.alpha, 1, 0);
+ var expected = new axe.commons.color.Color(128, 128, 128, 1);
+ assertColorsClose(actual, expected, 2, 0);
}
);
@@ -1002,10 +914,8 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var target = shadow.querySelector('#shadowTarget');
var actual = axe.commons.color.getBackgroundColor(target, []);
- assert.equal(actual.red, 0);
- assert.equal(actual.green, 0);
- assert.equal(actual.blue, 0);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
}
);
@@ -1036,10 +946,8 @@ describe('color.getBackgroundColor', function () {
axe.testUtils.flatTreeSetup(fixture);
var linkElm = div.querySelector('a');
var actual = axe.commons.color.getBackgroundColor(linkElm, []);
- assert.equal(actual.red, 0);
- assert.equal(actual.green, 0);
- assert.equal(actual.blue, 0);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
}
);
@@ -1056,10 +964,7 @@ describe('color.getBackgroundColor', function () {
// is 128 without the shadow
var expected = new axe.commons.color.Color(145, 0, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
assert.deepEqual(bgNodes, [parent]);
});
@@ -1072,11 +977,8 @@ describe('color.getBackgroundColor', function () {
var bgNodes = [];
axe.testUtils.flatTreeSetup(fixture);
var actual = axe.commons.color.getBackgroundColor(target, bgNodes);
-
- assert.equal(actual.red, 0);
- assert.equal(actual.green, 0);
- assert.equal(actual.blue, 0);
- assert.equal(actual.alpha, 1);
+ var expected = new axe.commons.color.Color(0, 0, 0, 1);
+ assert.deepEqual(actual, expected);
});
it('ignores text-shadows thinner than shadowOutlineEmMax', function () {
@@ -1091,10 +993,7 @@ describe('color.getBackgroundColor', function () {
// is 128 without the shadow
var expected = new axe.commons.color.Color(145, 0, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
describe('body and document', function () {
@@ -1108,11 +1007,7 @@ describe('color.getBackgroundColor', function () {
[]
);
var expected = new axe.commons.color.Color(255, 0, 0, 1);
-
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('returns the body background even when the body is MUCH larger than the screen', function () {
@@ -1126,10 +1021,7 @@ describe('color.getBackgroundColor', function () {
);
var expected = new axe.commons.color.Color(255, 0, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('returns the html background', function () {
@@ -1145,10 +1037,7 @@ describe('color.getBackgroundColor', function () {
document.body.removeAttribute('style');
var expected = new axe.commons.color.Color(0, 255, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('returns the html background when body does not cover the element', function () {
@@ -1164,10 +1053,7 @@ describe('color.getBackgroundColor', function () {
);
var expected = new axe.commons.color.Color(0, 255, 0, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('returns the body background when body does cover the element', function () {
@@ -1182,10 +1068,7 @@ describe('color.getBackgroundColor', function () {
);
var expected = new axe.commons.color.Color(0, 0, 255, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
it('returns both the html and body background if the body has alpha', function () {
@@ -1200,10 +1083,7 @@ describe('color.getBackgroundColor', function () {
);
var expected = new axe.commons.color.Color(0, 128, 128, 1);
- assert.closeTo(actual.red, expected.red, 0.5);
- assert.closeTo(actual.green, expected.green, 0.5);
- assert.closeTo(actual.blue, expected.blue, 0.5);
- assert.closeTo(actual.alpha, expected.alpha, 0.1);
+ assertColorsClose(actual, expected);
});
});
});
diff --git a/test/commons/color/get-foreground-color.js b/test/commons/color/get-foreground-color.js
index 50b7ea5526..06b31cc752 100644
--- a/test/commons/color/get-foreground-color.js
+++ b/test/commons/color/get-foreground-color.js
@@ -10,6 +10,12 @@ describe('color.getForegroundColor', () => {
assert.closeTo(actual.alpha, expected.alpha, margin / 255);
}
+ beforeEach(() => {
+ // This normalizes the default mocha behavior of setting a different background
+ // based on prefers-color-scheme settings.
+ document.body.style.background = '#fff';
+ });
+
afterEach(() => {
axe.commons.color.incompleteData.clear();
document.body.scrollTop = 0;
diff --git a/test/commons/dom/get-visible-child-text-rects.js b/test/commons/dom/get-visible-child-text-rects.js
index 242e9453be..126e79d037 100644
--- a/test/commons/dom/get-visible-child-text-rects.js
+++ b/test/commons/dom/get-visible-child-text-rects.js
@@ -14,20 +14,20 @@ describe('dom.getVisibleChildTextRects', () => {
}
/**
- * Asset that two DOMRect arrays are equal.
- * @param {DOMRect[]} rectAs
- * @param {DOMRect[]} rectBs
+ * Assert that two DOMRect arrays are equal.
+ * @param {DOMRect[]} actualRects
+ * @param {DOMRect[]} expectedRects
*/
- function assertRectsEqual(rectAs, rectBs) {
- assert.equal(rectAs.length, rectBs.length);
- rectAs.forEach((rect, index) => {
- const rectA = rectAs[index];
- const rectB = rectBs[index];
-
- assert.approximately(rectA.left, rectB.left, 1);
- assert.approximately(rectA.top, rectB.top, 1);
- assert.approximately(rectA.width, rectB.width, 1);
- assert.approximately(rectA.height, rectB.height, 1);
+ function assertRectsEqual(actualRects, expectedRects) {
+ assert.equal(actualRects.length, expectedRects.length);
+ actualRects.forEach((rect, index) => {
+ const actual = actualRects[index];
+ const expected = expectedRects[index];
+
+ assert.approximately(actual.left, expected.left, 1, 'left');
+ assert.approximately(actual.top, expected.top, 1, 'top');
+ assert.approximately(actual.width, expected.width, 1, 'width');
+ assert.approximately(actual.height, expected.height, 1, 'height');
});
}
diff --git a/test/integration/full/dialog/dialog.html b/test/integration/full/dialog/dialog.html
index e1168db4cf..07847f14d3 100644
--- a/test/integration/full/dialog/dialog.html
+++ b/test/integration/full/dialog/dialog.html
@@ -22,12 +22,12 @@
-
+
Contrast failure