Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Include body as part of background color checks when element does not intersect #1520

Merged
merged 3 commits into from
May 28, 2019

Conversation

scurker
Copy link
Member

@scurker scurker commented Apr 25, 2019

sortPageBackground did not account for instances where an element did not visually intersect with document.body but should inherit the background color from the canvas background (<html>).

According to the CSS3 Background Spec, the document canvas should propagate the background color of the <body> element when all of the following are true:

  • The <html> element has background-image: none
  • The <html> element has background-color: transparent

The following CodePen provides a case where axe shows a false positive due to the above missing check.

  • Added: Include body as part of the element stack when element does not intersect with body
  • Moved #fixture element in test template as it was interfering with the layout of elements due to to the Mocha results being dynamic.
  • When moving #fixture, the static display of #mocha-stats was interfering with a few tests.
  • Included more verbose browser information when running with WebDriver for easier debugging.

I opted to go the route of moving the #fixture and resolving the breaking tests, as the alternatives I explored seemed dirty and hacky.

Closes issue: #1456

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Has documentation updated, a DU ticket, or requires no documentation change
  • Includes new tests, or was unnecessary
  • Code is reviewed for security by: @WilcoFiers

@scurker scurker requested a review from a team as a code owner April 25, 2019 17:18
@scurker scurker requested a review from a team April 25, 2019 17:19
Copy link
Contributor

@straker straker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the code changes in a sandbox. The changes fix the false positive error. However when changing the color of the link to have a color-contrast problem (such as color: #333) an error is not reported.

<html>
  <head>
    <style>
    body {
      /* If 0px - 8px, color contrast problem identified; no problem when >= 9px */
      height: 5px;
      background: #161616;
    }

    a {
      color: #333;
    }
    </style>
  </head>
  <body>
    <a href="https://link/">This is a link - test 38</a>
  </body>
</html>

@straker straker dismissed their stale review April 25, 2019 21:13

I had an older version of the code that didn't work. works with most up-to-date version

@straker
Copy link
Contributor

straker commented Apr 25, 2019

Should we add a test to verify that we don't break the check in either direction? So works when there is a color-contrast problem (test we don't have) and when there isn't (test we have now).

@scurker
Copy link
Member Author

scurker commented Apr 25, 2019

I believe in this case, I'm just testing that an element returns the correct background stack. An element that visually intersects with body should have [element, ... , body, html] as its stack while an element that does not should have [element, ... , body] when the html element does not have an image or opaque background.

I suppose we could have a test for the scenario of when an element does not intersect with the body and <html> does have a background image and/or opaqueness. It's seems like a super edge case. Thoughts?


if (
// Check that the body background is the page's background
bodyIndex > 1 && // only if there are negative z-index elements
sortBodyElement &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be bodyIndex !== 0, since bodyIndex can never be less than -1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bodyIndex can be -1 in some specific scenarios. See https://jsfiddle.net/o3hjdsy8/1/

lib/commons/color/get-background-color.js Outdated Show resolved Hide resolved
assert.closeTo(actual.red, 0, 0);
assert.closeTo(actual.green, 0, 0);
assert.closeTo(actual.blue, 0, 0);
assert.closeTo(actual.alpha, 1, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should end up black (see my comment above). It looks to me like even with the body height changed, the background color is still the background color of the body.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand here. See above comments for clarification.

@scurker scurker requested a review from WilcoFiers April 26, 2019 17:10
@scurker scurker dismissed WilcoFiers’s stale review May 6, 2019 17:34

@WilcoFiers Added some comments, so this will likely need a re-review.

lib/commons/color/get-background-color.js Outdated Show resolved Hide resolved
@scurker scurker dismissed WilcoFiers’s stale review May 24, 2019 18:28

@wilco Swapped around the logic and added some general comments. Hopefully that will help give context for future viewers.

@WilcoFiers WilcoFiers changed the title fix: include body as part of background color checks when element does not intersect fix: Include body as part of background color checks when element does not intersect May 28, 2019
@WilcoFiers WilcoFiers merged commit 55820cf into develop May 28, 2019
@WilcoFiers WilcoFiers deleted the body-bg-color branch May 28, 2019 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants