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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/layout/scroll-anchoring/feedback-loop.html

Issue 2118683002: Limit ScrollAnchor to 20 adjustments between user scrolls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/testharness.js"></script>
3 <script src="../../../resources/testharnessreport.js"></script>
4 <style>
5
6 body { margin: 0; height: 5000px; }
7 #evil { height: 200px; width: 200px; background-color: #fcc; }
8
9 </style>
10 <div id="evil"></div>
11 <script>
12
13 internals.runtimeFlags.scrollAnchoringEnabled = true;
14
15 var kMaxAdjustments = 20; // Keep in sync with kMaxAdjustments in ScrollAnchor.c pp
16
17 var evil = document.querySelector('#evil');
18 onscroll = () => { evil.style.marginTop = scrollY + "px"; };
19
20 var frame = () => new Promise((resolve) => { requestAnimationFrame(resolve); });
21
22 var waitFor = function(condition, failmsg, deadline) {
23 if (!deadline) deadline = Date.now() + 1000;
24 if (condition()) return Promise.resolve();
25 else if (Date.now() > deadline) return Promise.reject(failmsg);
26 else return frame().then(() => waitFor(condition, failmsg, deadline));
27 };
28
29 var waitFrames = function(n, condition, failmsg) {
30 var p = Promise.resolve();
31 var check = () => (!condition || condition() ?
32 Promise.resolve() : Promise.reject(failmsg));
33 while (n--)
34 p = p.then(check).then(frame);
35 return p.then(check);
36 };
37
38 var scrollSettlesAt = function(expectedY) {
39 return waitFor(() => (scrollY == expectedY),
40 "scroll did not reach " + expectedY)
41 .then(() => waitFrames(3))
42 .then(() => waitFrames(3, () => (scrollY == expectedY),
43 "scroll did not stay at " + expectedY));
44 };
45
46 promise_test(function() {
47 var y = 10;
48 return Promise.resolve()
49 .then(() => { scrollTo(0, y); })
50 .then(() => scrollSettlesAt(y + kMaxAdjustments * y));
51 }, "Scroll anchoring with scroll event handler feedback loop");
52
53 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698