Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/layout/scroll-anchoring/onscroll-bouncing.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/layout/scroll-anchoring/onscroll-bouncing.html b/third_party/WebKit/LayoutTests/fast/layout/scroll-anchoring/onscroll-bouncing.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..564de3dd2e275820608b4e66912cd8001faa03ef |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/layout/scroll-anchoring/onscroll-bouncing.html |
| @@ -0,0 +1,91 @@ |
| +<!DOCTYPE html> |
| +<script src="../../../resources/js-test.js"></script> |
|
ymalik
2016/05/16 17:34:40
I think we want to write tests using testharness.j
skobes
2016/05/18 01:24:30
Done.
|
| +<style> |
| + |
| +body { margin: 80px 0; height: 5000px; } |
| +#a, #b { height: 200px; width: 200px; } |
| +#c { height: 400px; } |
| +#left, #c { display: inline-block; width: 200px; vertical-align: top; } |
| +#a.f { position: fixed; top: 30px; left: 150px; } |
| +#a { background-color: #fcc; } |
| +#b { background-color: #cfc; } |
| +#c { background-color: #ccf; } |
| + |
| +</style> |
| +<div id="left"> |
| + <div id="a"></div> |
| + <div id="b"></div> |
| +</div><div id="c"></div> |
| +<div id="console"></div> |
| +<script> |
| + |
| +var jsTestIsAsync = true; |
| +description("Tests if scroll anchoring plays nicely with scroll event handlers."); |
| + |
| +internals.runtimeFlags.scrollAnchoringEnabled = true; |
| + |
| +// The scroll handler marks #a as position: fixed when scroll offset > 300px. |
| +// This triggers layout during which we anchor to #b, which has moved up 200px. |
| +// After our anchoring adjustment, the scroll offset is < 300px again, so the |
| +// scroll handler removes position: fixed from #a, triggering a second layout, |
| +// during which #b "bounces" back to its original location. |
| +// |
| +// The desired behavior here is for ScrollAnchor to follow #b back the first |
| +// time it bounces, but not follow a second bounce. |
| +// |
| +// There are two failure modes we are concerned about: |
| +// |
| +// - If ScrollAnchor doesn't follow #b back to its original position during the |
| +// FIRST bounce, we've "trapped" the user above 300px. Every time they try to |
| +// scroll past this point we will push them back up. |
| +// |
| +// - If ScrollAnchor follows #b religiously, we get stuck in an infinite cycle |
| +// of continuous bouncing, which looks hilariously broken. |
| + |
| +var a = document.querySelector('#a'); |
| +var fixed = false; |
| +onscroll = function() { |
| + var y = scrollY; |
| + if (fixed == (y > 300)) |
| + return; |
| + if (y < 130) { |
| + // Clear the scroll anchor. |
| + scrollBy(0, 10); |
| + scrollBy(0, -10); |
| + } |
| + a.className = (fixed = !fixed) ? "f" : ""; |
| +}; |
| + |
| +shouldSettleAt = function(expectedScrollY, completion) { |
| + expectedScrollY = String(expectedScrollY); |
| + shouldBecomeEqual("scrollY", expectedScrollY, function() { |
| + var waitFrames = function(frames, check, then) { |
| + if (check) |
| + shouldBe("scrollY", expectedScrollY); |
|
ymalik
2016/05/16 17:34:40
Do we want to check intermediate values as well?
skobes
2016/05/18 01:24:30
I'm not sure we are guaranteed to get raf calls in
|
| + if (!frames) |
| + then(); |
| + else |
| + requestAnimationFrame(function() { |
| + waitFrames(frames - 1, check, then); |
| + }); |
| + }; |
| + waitFrames(3, false, function() { |
| + waitFrames(3, true, completion); |
| + }); |
| + }); |
| +}; |
| + |
| +onload = function() { |
| + // The 320px offset tests for the first failure mode. |
| + eventSender.mouseScrollBy(0, -8); |
|
ymalik
2016/05/16 17:34:40
Nit: continuousMouseScrollBy to make the pixel cou
skobes
2016/05/18 01:24:30
Done.
|
| + shouldSettleAt(320, function() { |
| + scrollTo(0, 0); |
| + requestAnimationFrame(function() { |
| + // The 360px offset tests for the second failure mode. |
| + eventSender.mouseScrollBy(0, -9); |
| + shouldSettleAt(360, finishJSTest); |
| + }); |
| + }); |
| +} |
| + |
| +</script> |