OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <script src="/resources/testharness.js"></script> | 2 <script src="/resources/testharness.js"></script> |
3 <script src="/resources/testharnessreport.js"></script> | 3 <script src="/resources/testharnessreport.js"></script> |
4 <title>Check End Position of smooth scrollIntoView</title> | 4 <title>Check End Position of smooth scrollIntoView</title> |
5 <div id="container" style="height: 2500px; width: 2500px;"> | 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
"> | 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> | 7 </div> |
8 <div id="shadow"></div> | 8 <div id="shadow"></div> |
9 </div> | 9 </div> |
10 <script> | 10 <script> |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // When testing manually, we need an additional frame at beginning | 41 // When testing manually, we need an additional frame at beginning |
42 // to trigger the effect. | 42 // to trigger the effect. |
43 requestAnimationFrame(() => { | 43 requestAnimationFrame(() => { |
44 promise_test(t => { | 44 promise_test(t => { |
45 window.scrollTo(0, 0); | 45 window.scrollTo(0, 0); |
46 var expected_x = content.offsetLeft + content_width - window_width; | 46 var expected_x = content.offsetLeft + content_width - window_width; |
47 var expected_y = content.offsetTop + content_height - window_height; | 47 var expected_y = content.offsetTop + content_height - window_height; |
48 assert_not_equals(window.scrollX, expected_x); | 48 assert_not_equals(window.scrollX, expected_x); |
49 assert_not_equals(window.scrollY, expected_y); | 49 assert_not_equals(window.scrollY, expected_y); |
50 content.scrollIntoView({behavior: "smooth", block: "nearest", inlinePosition: | 50 content.scrollIntoView({behavior: "smooth", block: "nearest", inline: |
51 "nearest"}); | 51 "nearest"}); |
52 return waitForScrollEnd().then(() => { | 52 return waitForScrollEnd().then(() => { |
53 assert_approx_equals(window.scrollX, expected_x, 1); | 53 assert_approx_equals(window.scrollX, expected_x, 1); |
54 assert_approx_equals(window.scrollY, expected_y, 1); | 54 assert_approx_equals(window.scrollY, expected_y, 1); |
55 }); | 55 }); |
56 }, "Smooth scrollIntoView should scroll the element to the 'nearest' position"); | 56 }, "Smooth scrollIntoView should scroll the element to the 'nearest' position"); |
57 | 57 |
58 promise_test(t => { | 58 promise_test(t => { |
59 window.scrollTo(0, 0); | 59 window.scrollTo(0, 0); |
60 var expected_x = content.offsetLeft; | 60 var expected_x = content.offsetLeft; |
61 var expected_y = content.offsetTop; | 61 var expected_y = content.offsetTop; |
62 assert_not_equals(window.scrollX, expected_x); | 62 assert_not_equals(window.scrollX, expected_x); |
63 assert_not_equals(window.scrollY, expected_y); | 63 assert_not_equals(window.scrollY, expected_y); |
64 content.scrollIntoView({behavior: "smooth", block: "start", inlinePosition: | 64 content.scrollIntoView({behavior: "smooth", block: "start", inline: |
65 "start"}); | 65 "start"}); |
66 return waitForScrollEnd().then(() => { | 66 return waitForScrollEnd().then(() => { |
67 assert_approx_equals(window.scrollX, expected_x, 1); | 67 assert_approx_equals(window.scrollX, expected_x, 1); |
68 assert_approx_equals(window.scrollY, expected_y, 1); | 68 assert_approx_equals(window.scrollY, expected_y, 1); |
69 }); | 69 }); |
70 }, "Smooth scrollIntoView should scroll the element to the 'start' position"); | 70 }, "Smooth scrollIntoView should scroll the element to the 'start' position"); |
71 | 71 |
72 promise_test(t => { | 72 promise_test(t => { |
73 window.scrollTo(0, 0); | 73 window.scrollTo(0, 0); |
74 var expected_x = content.offsetLeft + (content_width - window_width) / 2; | 74 var expected_x = content.offsetLeft + (content_width - window_width) / 2; |
75 var expected_y = content.offsetTop + (content_height - window_height) / 2; | 75 var expected_y = content.offsetTop + (content_height - window_height) / 2; |
76 assert_not_equals(window.scrollX, expected_x); | 76 assert_not_equals(window.scrollX, expected_x); |
77 assert_not_equals(window.scrollY, expected_y); | 77 assert_not_equals(window.scrollY, expected_y); |
78 content.scrollIntoView({behavior: "smooth", block: "center", inlinePosition: | 78 content.scrollIntoView({behavior: "smooth", block: "center", inline: |
79 "center"}); | 79 "center"}); |
80 return waitForScrollEnd().then(() => { | 80 return waitForScrollEnd().then(() => { |
81 assert_approx_equals(window.scrollX, expected_x, 1); | 81 assert_approx_equals(window.scrollX, expected_x, 1); |
82 assert_approx_equals(window.scrollY, expected_y, 1); | 82 assert_approx_equals(window.scrollY, expected_y, 1); |
83 }); | 83 }); |
84 }, "Smooth scrollIntoView should scroll the element to the 'center' position"); | 84 }, "Smooth scrollIntoView should scroll the element to the 'center' position"); |
85 | 85 |
86 promise_test(t => { | 86 promise_test(t => { |
87 window.scrollTo(0, 0); | 87 window.scrollTo(0, 0); |
88 var expected_x = content.offsetLeft + content_width - window_width; | 88 var expected_x = content.offsetLeft + content_width - window_width; |
89 var expected_y = content.offsetTop + content_height - window_height; | 89 var expected_y = content.offsetTop + content_height - window_height; |
90 assert_not_equals(window.scrollX, expected_x); | 90 assert_not_equals(window.scrollX, expected_x); |
91 assert_not_equals(window.scrollY, expected_y); | 91 assert_not_equals(window.scrollY, expected_y); |
92 content.scrollIntoView({behavior: "smooth", block: "end", inlinePosition: | 92 content.scrollIntoView({behavior: "smooth", block: "end", inline: |
93 "end"}); | 93 "end"}); |
94 return waitForScrollEnd().then(() => { | 94 return waitForScrollEnd().then(() => { |
95 assert_approx_equals(window.scrollX, expected_x, 1); | 95 assert_approx_equals(window.scrollX, expected_x, 1); |
96 assert_approx_equals(window.scrollY, expected_y, 1); | 96 assert_approx_equals(window.scrollY, expected_y, 1); |
97 }); | 97 }); |
98 }, "Smooth scrollIntoView should scroll the element to the 'end' position"); | 98 }, "Smooth scrollIntoView should scroll the element to the 'end' position"); |
99 | 99 |
100 }); | 100 }); |
101 </script> | 101 </script> |
OLD | NEW |