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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/display-none.html

Issue 2560253004: IntersectionObserver: convert tests to testharness.js (Closed)
Patch Set: Address comments Created 3 years, 10 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/testharness.js"></script>
3 <script src="../resources/intersection-observer-helper-functions.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="./resources/intersection-observer-test-utils.js"></script>
5
4 <style> 6 <style>
5 #root { 7 pre, #log {
6 display: inline-block; 8 position: absolute;
7 overflow-y: scroll; 9 top: 0;
8 height: 200px; 10 left: 200px;
9 border: 3px solid black;
10 } 11 }
11 #target { 12 #target {
12 background-color: green; 13 background-color: green;
13 width: 100px; 14 width: 100px;
14 height: 100px; 15 height: 100px;
15 } 16 }
16 </style> 17 </style>
17 <div style="width:100%; height:700px;"></div> 18
18 <div id="root"> 19 <div id="target"></div>
19 <div style="width:100px; height: 300px;"></div>
20 <div id="target"></div>
21 <div style="width:100%;height:700px;"></div>
22 </div>
23 <div style="width:100%;height:700px;"></div>
24 20
25 <script> 21 <script>
26 description("Test that setting display:none will send a not-intersecting notific ation.");
27 var target = document.getElementById("target");
28 var root = document.getElementById("root");
29 var entries = []; 22 var entries = [];
30 var observer = new IntersectionObserver(
31 changes => { entries = entries.concat(changes) },
32 { root: document.getElementById("root") }
33 );
34 23
35 onload = function() { 24 runTestCycle(function() {
25 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
26 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
27
28 var target = document.getElementById("target");
29 var root = document.getElementById("root");
30 var observer = new IntersectionObserver(function(changes) {
31 entries = entries.concat(changes)
32 });
36 observer.observe(target); 33 observer.observe(target);
37 entries = entries.concat(observer.takeRecords()); 34 entries = entries.concat(observer.takeRecords());
38 shouldBeEqualToNumber("entries.length", 0); 35 assert_equals(entries.length, 0, "No initial notifications.");
39 waitForNotification(step0); 36 runTestCycle(step0, "Intersecting notification after first rAF.");
40 } 37 }, "IntersectionObserver should send a not-intersecting notification for a targe t that gets display:none.");
41 38
42 function step0() { 39 function step0() {
43 shouldBeEqualToNumber("entries.length", 0); 40 runTestCycle(step1, "Not-intersecting notification after setting display:none on target.");
44 document.scrollingElement.scrollTop = 600; 41 checkLastEntry(entries, 0, [8, 108, 8, 108, 8, 108, 8, 108, 0, 800, 0, 600, ta rget]);
45 waitForNotification(step1); 42 target.style.display = "none";
46 } 43 }
47 44
48 function step1() { 45 function step1() {
49 shouldBeEqualToNumber("entries.length", 0); 46 runTestCycle(step2, "Intersecting notification after removing display:none on target.");
50 root.scrollTop = 150; 47 checkLastEntry(entries, 1, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, target]);
51 waitForNotification(step2); 48 target.style.display = "";
52 } 49 }
53 50
54 function step2() { 51 function step2() {
55 shouldBeEqualToNumber("entries.length", 1); 52 checkLastEntry(entries, 2, [8, 108, 8, 108, 8, 108, 8, 108, 0, 800, 0, 600, ta rget]);
56 if (entries.length > 0) {
57 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 11);
58 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 111);
59 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 261);
60 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 361);
61 shouldBeEqualToNumber("entries[0].intersectionRect.left", 11);
62 shouldBeEqualToNumber("entries[0].intersectionRect.right", 111);
63 shouldBeEqualToNumber("entries[0].intersectionRect.top", 261);
64 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 311);
65 shouldBeEqualToNumber("entries[0].rootBounds.left", 11);
66 shouldBeEqualToNumber("entries[0].rootBounds.right", 111);
67 shouldBeEqualToNumber("entries[0].rootBounds.top", 111);
68 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 311);
69 shouldEvaluateToSameObject("entries[0].target", target);
70 }
71 target.style.display = "none";
72 waitForNotification(step3);
73 }
74
75 function step3() {
76 shouldBeEqualToNumber("entries.length", 2);
77 if (entries.length > 1) {
78 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 0);
79 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 0);
80 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 0);
81 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 0);
82 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
83 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
84 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
85 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
86 shouldBeEqualToNumber("entries[1].rootBounds.left", 0);
87 shouldBeEqualToNumber("entries[1].rootBounds.right", 0);
88 shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
89 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 0);
90 shouldEvaluateToSameObject("entries[1].target", target);
91 }
92 target.style.display = "";
93 waitForNotification(step4);
94 }
95
96 function step4() {
97 shouldBeEqualToNumber("entries.length", 3);
98 if (entries.length > 2) {
99 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 11);
100 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 111);
101 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 261);
102 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 361);
103 shouldBeEqualToNumber("entries[2].intersectionRect.left", 11);
104 shouldBeEqualToNumber("entries[2].intersectionRect.right", 111);
105 shouldBeEqualToNumber("entries[2].intersectionRect.top", 261);
106 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 311);
107 shouldBeEqualToNumber("entries[2].rootBounds.left", 11);
108 shouldBeEqualToNumber("entries[2].rootBounds.right", 111);
109 shouldBeEqualToNumber("entries[2].rootBounds.top", 111);
110 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 311);
111 shouldEvaluateToSameObject("entries[2].target", target);
112 }
113
114 finishJSTest();
115 } 53 }
116 </script> 54 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698