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

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

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

Powered by Google App Engine
This is Rietveld 408576698