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

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

Issue 1983383002: Convert IntersectionObserver tests to use testRunner.runIdleTasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: rebase Created 4 years, 7 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="../resources/intersection-observer-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( 16 var observer = new IntersectionObserver(
17 changes => { entries = entries.concat(changes) }, 17 changes => { entries = entries.concat(changes) },
18 { rootMargin: "10px 20% 40% 30px" } 18 { rootMargin: "10px 20% 40% 30px" }
19 ); 19 );
20 20
21 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px' })"); 21 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px' })");
22 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px' })") ; 22 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px' })") ;
23 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3%' } )"); 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' })"); 24 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3% 40 px junk junk junk' })");
25 25
26 onload = function() { 26 onload = function() {
27 observer.observe(target); 27 observer.observe(target);
28 entries = entries.concat(observer.takeRecords()); 28 entries = entries.concat(observer.takeRecords());
29 shouldBeEqualToNumber("entries.length", 0); 29 shouldBeEqualToNumber("entries.length", 0);
30 // See README for explanation of double RAF. 30 waitForNotification(step0);
31 requestAnimationFrame(() => { requestAnimationFrame(step0) });
32 } 31 }
33 32
34 function step0() { 33 function step0() {
35 entries = entries.concat(observer.takeRecords());
36 shouldBeEqualToNumber("entries.length", 0); 34 shouldBeEqualToNumber("entries.length", 0);
37 document.scrollingElement.scrollLeft = 100; 35 document.scrollingElement.scrollLeft = 100;
38 requestAnimationFrame(step1); 36 waitForNotification(step1);
39 } 37 }
40 38
41 function step1() { 39 function step1() {
42 entries = entries.concat(observer.takeRecords());
43 shouldBeEqualToNumber("entries.length", 1); 40 shouldBeEqualToNumber("entries.length", 1);
44 if (entries.length > 0) { 41 if (entries.length > 0) {
45 shouldBeEqualToNumber("entries.length", 1); 42 shouldBeEqualToNumber("entries.length", 1);
46 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912); 43 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912);
47 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012); 44 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012);
48 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708); 45 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708);
49 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808); 46 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808);
50 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912); 47 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912);
51 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942); 48 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942);
52 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708); 49 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708);
53 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808); 50 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808);
54 shouldBeEqualToNumber("entries[0].rootBounds.left", -30); 51 shouldBeEqualToNumber("entries[0].rootBounds.left", -30);
55 shouldBeEqualToNumber("entries[0].rootBounds.right", 942); 52 shouldBeEqualToNumber("entries[0].rootBounds.right", 942);
56 shouldBeEqualToNumber("entries[0].rootBounds.top", -10); 53 shouldBeEqualToNumber("entries[0].rootBounds.top", -10);
57 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819); 54 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819);
58 shouldEvaluateToSameObject("entries[0].target", target); 55 shouldEvaluateToSameObject("entries[0].target", target);
59 } 56 }
60 document.scrollingElement.scrollTop = 800; 57 document.scrollingElement.scrollTop = 800;
61 requestAnimationFrame(step2); 58 waitForNotification(step2);
62 } 59 }
63 60
64 function step2() { 61 function step2() {
65 entries = entries.concat(observer.takeRecords());
66 shouldBeEqualToNumber("entries.length", 1); 62 shouldBeEqualToNumber("entries.length", 1);
67 document.scrollingElement.scrollTop = 900; 63 document.scrollingElement.scrollTop = 900;
68 requestAnimationFrame(step3); 64 waitForNotification(step3);
69 } 65 }
70 66
71 function step3() { 67 function step3() {
72 entries = entries.concat(observer.takeRecords());
73 shouldBeEqualToNumber("entries.length", 2); 68 shouldBeEqualToNumber("entries.length", 2);
74 if (entries.length > 1) { 69 if (entries.length > 1) {
75 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912); 70 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912);
76 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012); 71 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012);
77 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192); 72 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192);
78 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92); 73 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92);
79 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); 74 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
80 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); 75 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
81 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); 76 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
82 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); 77 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
83 shouldBeEqualToNumber("entries[1].rootBounds.left", -30); 78 shouldBeEqualToNumber("entries[1].rootBounds.left", -30);
84 shouldBeEqualToNumber("entries[1].rootBounds.right", 942); 79 shouldBeEqualToNumber("entries[1].rootBounds.right", 942);
85 shouldBeEqualToNumber("entries[1].rootBounds.top", -10); 80 shouldBeEqualToNumber("entries[1].rootBounds.top", -10);
86 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819); 81 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819);
87 shouldEvaluateToSameObject("entries[1].target", target); 82 shouldEvaluateToSameObject("entries[1].target", target);
88 } 83 }
89 finishJSTest(); 84 finishJSTest();
90 document.scrollingElement.scrollLeft = 0; 85 document.scrollingElement.scrollLeft = 0;
91 document.scrollingElement.scrollTop = 0; 86 document.scrollingElement.scrollTop = 0;
92 } 87 }
93 </script> 88 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698