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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/cssom-view/scrollIntoView-smooth.html

Issue 2936283003: Update CSSOM SmoothScroll Web Platform Test (Closed)
Patch Set: Update the tests and idl Created 3 years, 6 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 <title>Check End Position of smooth scrollIntoView</title>
5 <div id="container" style="height: 2500px; width: 2500px;">
6 <div id="content" style="height: 500px; width: 500px;margin-left: 1000px; marg in-right: 1000px; margin-top: 1000px;margin-bottom: 1000px;background-color: red ">
7 </div>
8 <div id="shadow"></div>
9 </div>
10 <script>
11 var content_height = 500;
12 var content_width = 500;
13 var window_height = document.documentElement.clientHeight;
14 var window_width = document.documentElement.clientWidth;
15 var content = document.getElementById("content");
16 add_completion_callback(() => document.getElementById("container").remove());
17
18 function waitForScrollEnd() {
19 var last_changed_frame = 0;
20 var last_x = window.scrollX;
21 var last_y = window.scrollY;
22 return new Promise((resolve, reject) => {
23 function tick(frames) {
24 // We requestAnimationFrame either for 500 frames or until 20 frames with
25 // no change have been observed.
26 if (frames >= 500 || frames - last_changed_frame > 20) {
27 resolve();
28 } else {
29 if (window.scrollX != last_x || window.scrollY != last_y) {
30 last_changed_frame = frames;
31 last_x = window.scrollX;
32 last_y = window.scrollY;
33 }
34 requestAnimationFrame(tick.bind(null, frames + 1));
35 }
36 }
37 tick(0);
38 });
39 }
40
41 // When testing manually, we need an additional frame at beginning
42 // to trigger the effect.
43 requestAnimationFrame(() => {
44 promise_test(t => {
45 window.scrollTo(0, 0);
46 var expected_x = content.offsetLeft + content_width - window_width;
47 var expected_y = content.offsetTop + content_height - window_height;
48 assert_not_equals(window.scrollX, expected_x);
49 assert_not_equals(window.scrollY, expected_y);
50 content.scrollIntoView({behavior: "smooth", block: "nearest", inlinePosition:
51 "nearest"});
52 return waitForScrollEnd().then(() => {
53 assert_approx_equals(window.scrollX, expected_x, 1);
54 assert_approx_equals(window.scrollY, expected_y, 1);
55 });
56 }, "Smooth scrollIntoView should scroll the element to the 'nearest' position");
57
58 promise_test(t => {
59 window.scrollTo(0, 0);
60 var expected_x = content.offsetLeft;
61 var expected_y = content.offsetTop;
62 assert_not_equals(window.scrollX, expected_x);
63 assert_not_equals(window.scrollY, expected_y);
64 content.scrollIntoView({behavior: "smooth", block: "start", inlinePosition:
65 "start"});
66 return waitForScrollEnd().then(() => {
67 assert_approx_equals(window.scrollX, expected_x, 1);
68 assert_approx_equals(window.scrollY, expected_y, 1);
69 });
70 }, "Smooth scrollIntoView should scroll the element to the 'start' position");
71
72 promise_test(t => {
73 window.scrollTo(0, 0);
74 var expected_x = content.offsetLeft + (content_width - window_width) / 2;
75 var expected_y = content.offsetTop + (content_height - window_height) / 2;
76 assert_not_equals(window.scrollX, expected_x);
77 assert_not_equals(window.scrollY, expected_y);
78 content.scrollIntoView({behavior: "smooth", block: "center", inlinePosition:
79 "center"});
80 return waitForScrollEnd().then(() => {
81 assert_approx_equals(window.scrollX, expected_x, 1);
82 assert_approx_equals(window.scrollY, expected_y, 1);
83 });
84 }, "Smooth scrollIntoView should scroll the element to the 'center' position");
85
86 promise_test(t => {
87 window.scrollTo(0, 0);
88 var expected_x = content.offsetLeft + content_width - window_width;
89 var expected_y = content.offsetTop + content_height - window_height;
90 assert_not_equals(window.scrollX, expected_x);
91 assert_not_equals(window.scrollY, expected_y);
92 content.scrollIntoView({behavior: "smooth", block: "end", inlinePosition:
93 "end"});
94 return waitForScrollEnd().then(() => {
95 assert_approx_equals(window.scrollX, expected_x, 1);
96 assert_approx_equals(window.scrollY, expected_y, 1);
97 });
98 }, "Smooth scrollIntoView should scroll the element to the 'end' position");
99
100 });
101 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698