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

Side by Side Diff: LayoutTests/fast/scroll-behavior/resources/scroll-behavior-test.js

Issue 872433002: Fix flake in threaded CSSOM smooth scroll layout tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // A ScrollBehaviorTest runs a set of ScrollBehaviorTestCases. The only 1 // A ScrollBehaviorTest runs a set of ScrollBehaviorTestCases. The only
2 // ScrollBehaviorTest method that should be called by external code is run(). 2 // ScrollBehaviorTest method that should be called by external code is run().
3 3
4 // Creates a ScrollBehaviorTest with arguments: 4 // Creates a ScrollBehaviorTest with arguments:
5 // scrollElement - Element being scrolled. 5 // scrollElement - Element being scrolled.
6 // scrollEventTarget - Target for scroll events for |scrollElement|. 6 // scrollEventTarget - Target for scroll events for |scrollElement|.
7 // testsCases - Array of ScrollBehaviorTestCases. 7 // testsCases - Array of ScrollBehaviorTestCases.
8 // getEndPosition - Callback that takes a test case and start position, and 8 // getEndPosition - Callback that takes a test case and start position, and
9 // returns the corresponding end position (where positions 9 // returns the corresponding end position (where positions
10 // are dictionaries with x and y fields). 10 // are dictionaries with x and y fields).
11 // jsScroll - Callback that takes a test case and executes the corresponding 11 // jsScroll - Callback that takes a test case and executes the corresponding
12 // js-driven scroll (e.g. by setting scrollLeft/scrollTop or by 12 // js-driven scroll (e.g. by setting scrollLeft/scrollTop or by
13 // calling scroll, scrollTo, or scrollBy). This should assume that 13 // calling scroll, scrollTo, or scrollBy). This should assume that
14 // scrollElement's scroll-behavior CSS property has already been 14 // scrollElement's scroll-behavior CSS property has already been
15 // set appropriately. 15 // set appropriately.
16 function ScrollBehaviorTest(scrollElement, 16 function ScrollBehaviorTest(scrollElement,
17 scrollEventTarget, 17 scrollEventTarget,
18 testCases, 18 testCases,
19 getEndPosition, 19 getEndPosition,
20 jsScroll) { 20 jsScroll) {
21 this.scrollElement = scrollElement; 21 this.scrollElement = scrollElement;
22 this.scrollEventTarget = scrollEventTarget; 22 this.scrollEventTarget = scrollEventTarget;
23 this.testCases = testCases; 23 this.testCases = testCases;
24 this.currentTestCase = 0; 24 this.currentTestCase = 0;
25 this.getEndPosition = getEndPosition; 25 this.getEndPosition = getEndPosition;
26 this.jsScroll = jsScroll; 26 this.jsScroll = jsScroll;
27 } 27 }
28 28
29 ScrollBehaviorTest.prototype.scrollListener = function(testCase) { 29 ScrollBehaviorTest.prototype.scrollListener = function(testCase) {
30 if (testCase.waitForEnd) { 30 var endReached = (this.scrollElement.scrollLeft == testCase.endX && this.scr ollElement.scrollTop == testCase.endY);
31 if (this.scrollElement.scrollLeft == testCase.endX && this.scrollElement .scrollTop == testCase.endY) 31 if (endReached) {
32 this.testCaseComplete(); 32 this.testCaseComplete();
33 return; 33 return;
34 } 34 }
35 35
36 // Wait for an intermediate frame, then instant-scroll to the end state. 36 if (testCase.waitForEnd)
37 if ((this.scrollElement.scrollLeft != testCase.startX || this.scrollElement. scrollTop != testCase.startY) && 37 return;
38 (this.scrollElement.scrollLeft != testCase.endX || this.scrollElement.sc rollTop != testCase.endY)) { 38
39 // Wait for the animation to start, then instant-scroll to the end state.
40 if (this.scrollElement.scrollLeft != testCase.startX || this.scrollElement.s crollTop != testCase.startY) {
39 // Instant scroll, and then wait for the next scroll event. This allows 41 // Instant scroll, and then wait for the next scroll event. This allows
40 // the instant scroll to propagate to the compositor (when using 42 // the instant scroll to propagate to the compositor (when using
41 // composited scrolling) so that the next smooth scroll starts at this 43 // composited scrolling) so that the next smooth scroll starts at this
42 // position (the compositor always starts smooth scrolls at the current 44 // position (the compositor always starts smooth scrolls at the current
43 // scroll position on the compositor thread). 45 // scroll position on the compositor thread).
44 this.scrollElement.scrollTo({left: testCase.endX, top: testCase.endY, be havior: "instant"}); 46 this.scrollElement.scrollTo({left: testCase.endX, top: testCase.endY, be havior: "instant"});
45 testCase.waitForEnd = true; 47 testCase.waitForEnd = true;
46 } 48 }
47 }; 49 };
48 50
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 130
129 ScrollBehaviorTestCase.prototype.setStartPosition = function(startPosition) { 131 ScrollBehaviorTestCase.prototype.setStartPosition = function(startPosition) {
130 this.startX = startPosition.x; 132 this.startX = startPosition.x;
131 this.startY = startPosition.y; 133 this.startY = startPosition.y;
132 } 134 }
133 135
134 ScrollBehaviorTestCase.prototype.setEndPosition = function(endPosition) { 136 ScrollBehaviorTestCase.prototype.setEndPosition = function(endPosition) {
135 this.endX = endPosition.x; 137 this.endX = endPosition.x;
136 this.endY = endPosition.y; 138 this.endY = endPosition.y;
137 } 139 }
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/scroll-behavior/resources/scroll-interruption-test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698