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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/remove-element.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
4 <div id="root" style="display: inline-block; overflow-y: scroll; height: 200px; border: 3px solid black"> 5 <div id="root" style="display: inline-block; overflow-y: scroll; height: 200px; border: 3px solid black">
5 <div style="width:100px; height: 300px;"></div> 6 <div style="width:100px; height: 300px;"></div>
6 <div id="target" style="background-color: green; width:100px; height:100px"></ div> 7 <div id="target" style="background-color: green; width:100px; height:100px"></ div>
7 <div id="afterTarget" style="width:100px; height: 300px;"></div> 8 <div id="afterTarget" style="width:100px; height: 300px;"></div>
8 </div> 9 </div>
9 10
10 <script> 11 <script>
11 description("Test that notifications are sent correctly when root and/or target are removed from the DOM tree."); 12 function waitForNotification(f) {
12 var target = document.getElementById("target"); 13 requestAnimationFrame(() => {
13 var afterTarget = document.getElementById("afterTarget"); 14 setTimeout(() => {
14 var root = document.getElementById("root"); 15 setTimeout(f);
15 var entries = []; 16 });
16 var observer = new IntersectionObserver( 17 });
17 changes => { entries = entries.concat(changes) }, 18 }
18 { root: document.getElementById("root") }
19 );
20 19
21 onload = function() { 20 onload = function() {
21 var t = async_test("Test that notifications are sent correctly when root and/o r target are removed from the DOM tree.");
22
23 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800 pixels wide.");
24 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60 0 pixels high.");
25
26 var target = document.getElementById("target");
27 var afterTarget = document.getElementById("afterTarget");
28 var root = document.getElementById("root");
29 var entries = [];
30 var observer = new IntersectionObserver(function(changes) {
31 entries = entries.concat(changes)
32 }, {root: root});
22 observer.observe(target); 33 observer.observe(target);
23 entries = entries.concat(observer.takeRecords()); 34 entries = entries.concat(observer.takeRecords());
24 shouldBeEqualToNumber("entries.length", 0); 35 test(function() { assert_equals(entries.length, 0) }, "No initial notification s.");
25 root.scrollTop = 150; 36 waitForNotification(step0);
26 waitForNotification(step1);
27 }
28 37
29 function step1() { 38 function checkEntry(i, expected) {
30 shouldBeEqualToNumber("entries.length", 1); 39 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti fication(s).");
31 if (entries.length > 0) { 40 if (expected && entries.length > i) {
32 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 11); 41 test(function() { assert_equals(entries[i].boundingClientRect.left, expect ed[0]) },
33 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 111); 42 "entries[" + i + "].boundingClientRect.left == " + expected[0]);
34 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 161); 43 test(function() { assert_equals(entries[i].boundingClientRect.right, expec ted[1]) },
35 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 261); 44 "entries[" + i + "].boundingClientRect.right == " + expected[1]);
36 shouldBeEqualToNumber("entries[0].intersectionRect.left", 11); 45 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte d[2]) },
37 shouldBeEqualToNumber("entries[0].intersectionRect.right", 111); 46 "entries[" + i + "].boundingClientRect.top == " + expected[2]);
38 shouldBeEqualToNumber("entries[0].intersectionRect.top", 161); 47 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe cted[3]) },
39 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 211); 48 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]);
40 shouldBeEqualToNumber("entries[0].rootBounds.left", 11); 49 test(function() { assert_equals(entries[i].intersectionRect.left, expected [4]) },
41 shouldBeEqualToNumber("entries[0].rootBounds.right", 111); 50 "entries[" + i + "].intersectionRect.left == " + expected[4]);
42 shouldBeEqualToNumber("entries[0].rootBounds.top", 11); 51 test(function() { assert_equals(entries[i].intersectionRect.right, expecte d[5]) },
43 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 211); 52 "entries[" + i + "].intersectionRect.right == " + expected[5]);
44 shouldEvaluateToSameObject("entries[0].target", target); 53 test(function() { assert_equals(entries[i].intersectionRect.top, expected[ 6]) },
54 "entries[" + i + "].intersectionRect.top == " + expected[6]);
55 test(function() { assert_equals(entries[i].intersectionRect.bottom, expect ed[7]) },
56 "entries[" + i + "].intersectionRect.bottom == " + expected[7]);
57 test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) } ,
58 "entries[" + i + "].rootBounds.left == " + expected[8]);
59 test(function() { assert_equals(entries[i].rootBounds.right, expected[9]) },
60 "entries[" + i + "].rootBounds.right == " + expected[9]);
61 test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) } ,
62 "entries[" + i + "].rootBounds.top == " + expected[10]);
63 test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11] ) },
64 "entries[" + i + "].rootBounds.bottom == " + expected[11]);
65 test(function() { assert_true(entries[i].target === expected[12]) },
66 "entries[" + i + "].target === " + expected[12]);
67 }
45 } 68 }
46 root.removeChild(target);
47 waitForNotification(step2);
48 }
49 69
50 function step2() { 70 function step0() {
51 shouldBeEqualToNumber("entries.length", 2); 71 test(function() { assert_equals(entries.length, 0) }, "No notifications afte r first rAF.");
52 if (entries.length > 1) { 72 root.scrollTop = 150;
53 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 0); 73 waitForNotification(step1);
54 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 0);
55 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 0);
56 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 0)
57 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
58 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
59 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
60 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
61 shouldBeEqualToNumber("entries[1].rootBounds.left", 0);
62 shouldBeEqualToNumber("entries[1].rootBounds.right", 0);
63 shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
64 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 0);
65 shouldEvaluateToSameObject("entries[1].target", target);
66 } 74 }
67 root.scrollTop = 0;
68 root.insertBefore(target, afterTarget);
69 waitForNotification(step3);
70 }
71 75
72 function step3() { 76 function step1() {
73 shouldBeEqualToNumber("entries.length", 2); 77 checkEntry(0, [11, 111, 161, 261, 11, 111, 161, 211, 11, 111, 11, 211, targe t]);
74 root.scrollTop = 150; 78 root.removeChild(target);
75 waitForNotification(step4); 79 waitForNotification(step2);
76 } 80 }
77 81
78 function step4() { 82 function step2() {
79 shouldBeEqualToNumber("entries.length", 3); 83 checkEntry(1, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, target]);
80 if (entries.length > 2) { 84 root.scrollTop = 0;
81 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 11); 85 root.insertBefore(target, afterTarget);
82 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 111); 86 waitForNotification(step3);
83 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 161);
84 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 261);
85 shouldBeEqualToNumber("entries[2].intersectionRect.left", 11);
86 shouldBeEqualToNumber("entries[2].intersectionRect.right", 111);
87 shouldBeEqualToNumber("entries[2].intersectionRect.top", 161);
88 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 211);
89 shouldBeEqualToNumber("entries[2].rootBounds.left", 11);
90 shouldBeEqualToNumber("entries[2].rootBounds.right", 111);
91 shouldBeEqualToNumber("entries[2].rootBounds.top", 11);
92 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 211);
93 shouldEvaluateToSameObject("entries[2].target", target);
94 } 87 }
95 finishJSTest(); 88
96 } 89 function step3() {
90 checkEntry(1);
91 root.scrollTop = 150;
92 waitForNotification(step4);
93 }
94
95 function step4() {
96 checkEntry(2, [11, 111, 161, 261, 11, 111, 161, 211, 11, 111, 11, 211, targe t]);
97 t.done();
98 }
99 };
97 </script> 100 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698