Skip to content

Commit

Permalink
[css-scroll-snap] Add tests for scroll-into-view operations (#8575)
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasai authored and gsnedders committed Apr 29, 2019
1 parent c626cbb commit ba85e61
Show file tree
Hide file tree
Showing 17 changed files with 732 additions and 0 deletions.
23 changes: 23 additions & 0 deletions css/css-scroll-snap/scroll-target-001-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<title>Reference</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<style type='text/css'>
.container {
border: solid blue 4px;
height: 4em;
overflow: auto;
font: 20px/1 sans-serif;
}
.container > div {
height: 1em;
margin: 1em 0;
background: green;
}
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<div class="container">
<div></div>
</div>
23 changes: 23 additions & 0 deletions css/css-scroll-snap/scroll-target-align-001.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<title>#target and snap position with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#choosing'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name="flags" content="may">
<meta name='assert'
content="Test passes if scroll snapping is honored
on a scroll container with 'scroll-snap-type: none'
when navigating to an element with the target fragment ID.">

<style type='text/css'>
iframe {
border: solid blue 4px;
height: 80px;
width: calc(100% - 8px);
}
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<iframe class="container" src="support/scroll-target-align-001-iframe.html#target">This UA doesn't support iframes; please request a custom version of this test!</iframe>
57 changes: 57 additions & 0 deletions css/css-scroll-snap/scroll-target-align-002.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<title>scrollIntoView() and snap position with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#choosing'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name="flags" content="may">
<meta name='assert'
content="Test passes if scroll snapping is honored
on a scroll container with 'scroll-snap-type: none'
when scrolling an element into view
explicitly by script.">

<style type='text/css'>
.container {
border: solid blue 4px;
height: 4em;
overflow: auto;

/* to make failing more obvious */
background: 0 1em / 100% 1em linear-gradient(red, red) repeat-x;
/* avoid anti-aliasing issues */
font: 20px/1 sans-serif;
scrollbar-width: none;
}
.container > div {
height: 1em;
}
.container { scroll-padding: .5em 0 0; } /* set up a snap position */
#target { scroll-margin: .5em 0 0;
scroll-snap-align: center; }
#stripe { background: green; } /* color part of the snap area */
.fail { color: red; } /* make failing more obvious */
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div id="stripe"></div>
<div id="target"></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<script>
document.getElementById('target').scrollIntoView();
</script>
58 changes: 58 additions & 0 deletions css/css-scroll-snap/scroll-target-align-003.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<title>focus() and snap position with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#choosing'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name="flags" content="may">
<meta name='assert'
content="Test passes if scroll snapping is honored
on a scroll container with 'scroll-snap-type: none'
when scrolling an element into view
even if that operation is implied (in this case, by .focus()).">
<style type='text/css'>
.container {
border: solid blue 4px;
height: 4em;
overflow: auto;

/* to make failing more obvious */
background: 0 1em / 100% 1em linear-gradient(red, red) repeat-x;
/* avoid anti-aliasing issues */
font: 20px/1 sans-serif;
scrollbar-width: none;
}
.container > div, a {
height: 1em;
display: block;
outline: none;
}
.container { scroll-padding: .5em 0 0; } /* set up a snap position */
#target { scroll-margin: .5em 0 0;
scroll-snap-align: center; }
#stripe { background: green; } /* color part of the snap area */
.fail { color: red; } /* make failing more obvious */
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div id="stripe"></div>
<a href="" id="target"></a>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<script>
document.getElementById('target').focus();
</script>
23 changes: 23 additions & 0 deletions css/css-scroll-snap/scroll-target-margin-001.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<title>#target and scroll-margin with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#scroll-margin'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name="flags" content="should">
<meta name='assert'
content="Test passes if scroll-margin is honored
on a scroll container with 'scroll-snap-type: none'
when navigating to an element with the target fragment ID.">

<style type='text/css'>
iframe {
border: solid blue 4px;
height: 80px;
width: calc(100% - 8px);
}
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<iframe class="container" src="support/scroll-target-margin-001-iframe.html#target">This UA doesn't support iframes; please request a custom version of this test!</iframe>
54 changes: 54 additions & 0 deletions css/css-scroll-snap/scroll-target-margin-002.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<title>scrollIntoView() and scroll-margin with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#scroll-margin'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name="flags" content="should">
<meta name='assert'
content="Test passes if scroll-margin is honored
on a scroll container with 'scroll-snap-type: none'
when scrolling an element into view
explicitly by script.">
<style type='text/css'>
.container {
border: solid blue 4px;
height: 4em;
overflow: auto;

/* to make failing more obvious */
background: 0 1em / 100% 1em linear-gradient(red, red) repeat-x;
/* avoid anti-aliasing issues */
font: 20px/1 sans-serif;
scrollbar-width: none;
}
.container > div {
height: 1em;
}
#target { scroll-margin: 2em 0 1em; } /* snap area is exact fit for snapport */
#stripe { background: green; } /* color part of the snap area */
.fail { color: red; } /* make failing more obvious */
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div id="stripe"></div>
<div id="target"></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<script>
document.getElementById('target').scrollIntoView();
</script>
56 changes: 56 additions & 0 deletions css/css-scroll-snap/scroll-target-margin-003.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<title>focus() and scroll-margin with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#scroll-margin'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name="flags" content="should">
<meta name='assert'
content="Test passes if scroll-margin is honored
on a scroll container with 'scroll-snap-type: none'
when scrolling an element into view
even if that operation is implied (in this case, by .focus()).">
<style type='text/css'>
.container {
border: solid blue 4px;
height: 4em;
overflow: auto;

/* to make failing more obvious */
background: 0 1em / 100% 1em linear-gradient(red, red) repeat-x;
/* avoid anti-aliasing issues */
font: 20px/1 sans-serif;
scrollbar-width: none;
}
.container > div, a {
height: 1em;
display: block;
outline: none;
}
#target { scroll-margin: 2em 0 1em; } /* snap area is exact fit for snapport */
#stripe { background: green; } /* color part of the snap area */
.fail { color: red; } /* make failing more obvious */
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div id="stripe"></div>
<a href="" id="target"></a>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<script>
document.getElementById('target').focus();
</script>
21 changes: 21 additions & 0 deletions css/css-scroll-snap/scroll-target-padding-001.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<title>#target and scroll-padding with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#scroll-padding'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name='assert'
content="Test passes if scroll-padding is honored
on a scroll container with 'scroll-snap-type: none'
when navigating to an element with the target fragment ID.">
<style type='text/css'>
iframe {
border: solid blue 4px;
height: 80px;
width: calc(100% - 8px);
}
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<iframe class="container" src="support/scroll-target-padding-001-iframe.html#target">This UA doesn't support iframes; please request a custom version of this test!</iframe>
53 changes: 53 additions & 0 deletions css/css-scroll-snap/scroll-target-padding-002.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<title>scrollIntoView() and scroll-padding with snapping off (y-axis)</title>
<link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'>
<link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#scroll-padding'>
<link rel='match' href='scroll-target-001-ref.html'>
<meta name='assert'
content="Test passes if scroll-padding is honored
on a scroll container with 'scroll-snap-type: none'
when scrolling an element into view
explicitly by script.">
<style type='text/css'>
.container {
border: solid blue 4px;
height: 4em;
overflow: auto;

/* to make failing more obvious */
background: 0 1em / 100% 1em linear-gradient(red, red) repeat-x;
/* avoid anti-aliasing issues */
font: 20px/1 sans-serif;
scrollbar-width: none;
}
.container > div {
height: 1em;
}
.container { scroll-padding: 2em 0 1em; } /* snap area is exact fit for snapport */
#stripe { background: green; } /* color part of the snap area */
.fail { color: red; } /* make failing more obvious */
</style>

<div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div>

<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div id="stripe"></div>
<div id="target"></div>
<div></div>
<div class="fail">FAIL</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<script>
document.getElementById('target').scrollIntoView();
</script>
Loading

0 comments on commit ba85e61

Please sign in to comment.