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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/root-margin.html

Issue 1776493002: IntersectionObserver: use an idle callback to send notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: syntax error Created 4 years, 9 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/js-test.js"></script> 2 <script src="../resources/js-test.js"></script>
3 <script src="helper-functions.js"></script> 3 <script src="helper-functions.js"></script>
4 <div style="width:100%; height:700px;"></div> 4 <div style="width:100%; height:700px;"></div>
5 <div style="white-space: nowrap;"> 5 <div style="white-space: nowrap;">
6 <div style="display: inline-block; width: 1000px; height: 100px"></div> 6 <div style="display: inline-block; width: 1000px; height: 100px"></div>
7 <div id="target" style="display: inline-block; background-color: green; width: 100px; height:100px"></div> 7 <div id="target" style="display: inline-block; background-color: green; width: 100px; height:100px"></div>
8 <div style="display: inline-block; width: 1000px; height: 100px"></div> 8 <div style="display: inline-block; width: 1000px; height: 100px"></div>
9 </div> 9 </div>
10 <div style="width:100%; height:700px;"></div> 10 <div style="width:100%; height:700px;"></div>
11 11
12 <script> 12 <script>
13 description("Intersection observer test with root margin and implicit root."); 13 description("Intersection observer test with root margin and implicit root.");
14 var target = document.getElementById("target"); 14 var target = document.getElementById("target");
15 var entries = []; 15 var entries = [];
16 var observer = new IntersectionObserver(
17 changes => { entries = entries.concat(changes) },
18 { rootMargin: "10px 20% 40% 30px" }
19 );
16 20
17 function observer_callback(changes) { 21 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px' })");
18 for (var i in changes) 22 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px' })") ;
19 entries.push(changes[i]); 23 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3%' } )");
24 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3% 40 px junk junk junk' })");
25
26 onload = function() {
27 observer.observe(target);
28 entries = entries.concat(observer.takeRecords());
29 shouldBeEqualToNumber("entries.length", 0);
30 // See README for explanation of double RAF.
31 requestAnimationFrame(() => { requestAnimationFrame(step0) });
32 }
33
34 function step0() {
35 entries = entries.concat(observer.takeRecords());
36 shouldBeEqualToNumber("entries.length", 0);
37 document.scrollingElement.scrollLeft = 100;
38 requestAnimationFrame(step1);
39 }
40
41 function step1() {
42 entries = entries.concat(observer.takeRecords());
43 shouldBeEqualToNumber("entries.length", 1);
44 if (entries.length > 0) {
45 shouldBeEqualToNumber("entries.length", 1);
46 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912);
47 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012);
48 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708);
49 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808);
50 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912);
51 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942);
52 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708);
53 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808);
54 shouldBeEqualToNumber("entries[0].rootBounds.left", -30);
55 shouldBeEqualToNumber("entries[0].rootBounds.right", 942);
56 shouldBeEqualToNumber("entries[0].rootBounds.top", -10);
57 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819);
58 shouldEvaluateToSameObject("entries[0].target", target);
20 } 59 }
60 document.scrollingElement.scrollTop = 800;
61 requestAnimationFrame(step2);
62 }
21 63
22 var observer = new IntersectionObserver(observer_callback, { 64 function step2() {
23 rootMargin: "10px 20% 40% 30px" 65 entries = entries.concat(observer.takeRecords());
24 }); 66 shouldBeEqualToNumber("entries.length", 1);
25 observer.observe(target); 67 document.scrollingElement.scrollTop = 900;
68 requestAnimationFrame(step3);
69 }
26 70
27 function step0() { 71 function step3() {
28 setTimeout(function() { 72 entries = entries.concat(observer.takeRecords());
29 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1.4px' })"); 73 shouldBeEqualToNumber("entries.length", 2);
30 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1.4px 2px' })"); 74 if (entries.length > 1) {
31 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1.4px 2px 3%' })"); 75 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912);
32 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1.4px 2px 3% 40px junk junk junk' })"); 76 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012);
33 shouldBeEqualToNumber("entries.length", 0); 77 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192);
34 document.scrollingElement.scrollLeft = 100; 78 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92);
35 requestAnimationFrame(step1); 79 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
36 }); 80 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
81 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
82 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
83 shouldBeEqualToNumber("entries[1].rootBounds.left", -30);
84 shouldBeEqualToNumber("entries[1].rootBounds.right", 942);
85 shouldBeEqualToNumber("entries[1].rootBounds.top", -10);
86 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819);
87 shouldEvaluateToSameObject("entries[1].target", target);
37 } 88 }
38 89 finishJSTest();
39 function step1() { 90 document.scrollingElement.scrollLeft = 0;
40 setTimeout(function() { 91 document.scrollingElement.scrollTop = 0;
41 shouldBeEqualToNumber("entries.length", 1); 92 }
42 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912);
43 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012);
44 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708);
45 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808);
46 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912);
47 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942);
48 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708);
49 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808);
50 shouldBeEqualToNumber("entries[0].rootBounds.left", -30);
51 shouldBeEqualToNumber("entries[0].rootBounds.right", 942);
52 shouldBeEqualToNumber("entries[0].rootBounds.top", -10);
53 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819);
54 shouldEvaluateToSameObject("entries[0].target", target);
55 document.scrollingElement.scrollTop = 800;
56 requestAnimationFrame(step2);
57 });
58 }
59
60 function step2() {
61 setTimeout(function() {
62 shouldBeEqualToNumber("entries.length", 1);
63 document.scrollingElement.scrollTop = 900;
64 requestAnimationFrame(step3);
65 });
66 }
67
68 function step3() {
69 setTimeout(function() {
70 shouldBeEqualToNumber("entries.length", 2);
71 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912);
72 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012);
73 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192);
74 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92);
75 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
76 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
77 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
78 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
79 shouldBeEqualToNumber("entries[1].rootBounds.left", -30);
80 shouldBeEqualToNumber("entries[1].rootBounds.right", 942);
81 shouldBeEqualToNumber("entries[1].rootBounds.top", -10);
82 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819);
83 shouldEvaluateToSameObject("entries[1].target", target);
84
85 finishJSTest();
86 document.scrollingElement.scrollLeft = 0;
87 document.scrollingElement.scrollTop = 0;
88 });
89 }
90
91 step0();
92 </script> 93 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698