Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/layout/scroll-anchoring/onscroll-bouncing.html

Issue 1971423002: Implement bounce suppression in ScrollAnchor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <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.
3 <style>
4
5 body { margin: 80px 0; height: 5000px; }
6 #a, #b { height: 200px; width: 200px; }
7 #c { height: 400px; }
8 #left, #c { display: inline-block; width: 200px; vertical-align: top; }
9 #a.f { position: fixed; top: 30px; left: 150px; }
10 #a { background-color: #fcc; }
11 #b { background-color: #cfc; }
12 #c { background-color: #ccf; }
13
14 </style>
15 <div id="left">
16 <div id="a"></div>
17 <div id="b"></div>
18 </div><div id="c"></div>
19 <div id="console"></div>
20 <script>
21
22 var jsTestIsAsync = true;
23 description("Tests if scroll anchoring plays nicely with scroll event handlers." );
24
25 internals.runtimeFlags.scrollAnchoringEnabled = true;
26
27 // The scroll handler marks #a as position: fixed when scroll offset > 300px.
28 // This triggers layout during which we anchor to #b, which has moved up 200px.
29 // After our anchoring adjustment, the scroll offset is < 300px again, so the
30 // scroll handler removes position: fixed from #a, triggering a second layout,
31 // during which #b "bounces" back to its original location.
32 //
33 // The desired behavior here is for ScrollAnchor to follow #b back the first
34 // time it bounces, but not follow a second bounce.
35 //
36 // There are two failure modes we are concerned about:
37 //
38 // - If ScrollAnchor doesn't follow #b back to its original position during the
39 // FIRST bounce, we've "trapped" the user above 300px. Every time they try to
40 // scroll past this point we will push them back up.
41 //
42 // - If ScrollAnchor follows #b religiously, we get stuck in an infinite cycle
43 // of continuous bouncing, which looks hilariously broken.
44
45 var a = document.querySelector('#a');
46 var fixed = false;
47 onscroll = function() {
48 var y = scrollY;
49 if (fixed == (y > 300))
50 return;
51 if (y < 130) {
52 // Clear the scroll anchor.
53 scrollBy(0, 10);
54 scrollBy(0, -10);
55 }
56 a.className = (fixed = !fixed) ? "f" : "";
57 };
58
59 shouldSettleAt = function(expectedScrollY, completion) {
60 expectedScrollY = String(expectedScrollY);
61 shouldBecomeEqual("scrollY", expectedScrollY, function() {
62 var waitFrames = function(frames, check, then) {
63 if (check)
64 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
65 if (!frames)
66 then();
67 else
68 requestAnimationFrame(function() {
69 waitFrames(frames - 1, check, then);
70 });
71 };
72 waitFrames(3, false, function() {
73 waitFrames(3, true, completion);
74 });
75 });
76 };
77
78 onload = function() {
79 // The 320px offset tests for the first failure mode.
80 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.
81 shouldSettleAt(320, function() {
82 scrollTo(0, 0);
83 requestAnimationFrame(function() {
84 // The 360px offset tests for the second failure mode.
85 eventSender.mouseScrollBy(0, -9);
86 shouldSettleAt(360, finishJSTest);
87 });
88 });
89 }
90
91 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698