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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/remove-element.html

Issue 2560253004: IntersectionObserver: convert tests to testharness.js (Closed)
Patch Set: Address comments Created 3 years, 11 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 <div id="root" style="display: inline-block; overflow-y: scroll; height: 200px; border: 3px solid black"> 4 <script src="./resources/intersection-observer-test-utils.js"></script>
5 <div style="width:100px; height: 300px;"></div> 5
6 <div id="target" style="background-color: green; width:100px; height:100px"></ div> 6 <style>
7 <div id="afterTarget" style="width:100px; height: 300px;"></div> 7 pre, #log {
8 position: absolute;
9 top: 0;
10 left: 200px;
11 }
12 #root {
13 display: inline-block;
14 overflow-y: scroll;
15 height: 200px;
16 border: 3px solid black;
17 }
18 #target {
19 width: 100px;
20 height: 100px;
21 background-color: green;
22 }
23 .spacer {
24 height: 300px;
25 }
26 </style>
27
28 <div id="root">
29 <div id="leading-space" class="spacer"></div>
30 <div id="target"></div>
31 <div id="trailing-space" class="spacer"</div>
8 </div> 32 </div>
9 33
10 <script> 34 <script>
11 description("Test that notifications are sent correctly when root and/or target are removed from the DOM tree.");
12 var target = document.getElementById("target");
13 var afterTarget = document.getElementById("afterTarget");
14 var root = document.getElementById("root");
15 var entries = []; 35 var entries = [];
16 var observer = new IntersectionObserver( 36 var root, target, trailingSpace;
17 changes => { entries = entries.concat(changes) },
18 { root: document.getElementById("root") }
19 );
20 37
21 onload = function() { 38 runTestCycle(function() {
39 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
40 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
41
42 target = document.getElementById("target");
43 assert_true(!!target, "Target exists");
44 trailingSpace = document.getElementById("trailing-space");
45 assert_true(!!trailingSpace, "TrailingSpace exists");
46 root = document.getElementById("root");
47 assert_true(!!root, "Root exists");
48 var observer = new IntersectionObserver(function(changes) {
49 entries = entries.concat(changes)
50 }, {root: root});
22 observer.observe(target); 51 observer.observe(target);
23 entries = entries.concat(observer.takeRecords()); 52 entries = entries.concat(observer.takeRecords());
24 shouldBeEqualToNumber("entries.length", 0); 53 assert_equals(entries.length, 0, "No initial notifications.");
54 runTestCycle(step0, "First rAF");
55 }, "Verify that not-intersecting notifications are sent when a target is removed from the DOM tree.");
56
57 function step0() {
25 root.scrollTop = 150; 58 root.scrollTop = 150;
26 waitForNotification(step1); 59 runTestCycle(step1, "root.scrollTop = 150");
60 assert_equals(entries.length, 0, "No notifications after first rAF.");
27 } 61 }
28 62
29 function step1() { 63 function step1() {
30 shouldBeEqualToNumber("entries.length", 1);
31 if (entries.length > 0) {
32 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 11);
33 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 111);
34 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 161);
35 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 261);
36 shouldBeEqualToNumber("entries[0].intersectionRect.left", 11);
37 shouldBeEqualToNumber("entries[0].intersectionRect.right", 111);
38 shouldBeEqualToNumber("entries[0].intersectionRect.top", 161);
39 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 211);
40 shouldBeEqualToNumber("entries[0].rootBounds.left", 11);
41 shouldBeEqualToNumber("entries[0].rootBounds.right", 111);
42 shouldBeEqualToNumber("entries[0].rootBounds.top", 11);
43 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 211);
44 shouldEvaluateToSameObject("entries[0].target", target);
45 }
46 root.removeChild(target); 64 root.removeChild(target);
47 waitForNotification(step2); 65 runTestCycle(step2, "root.removeChild(target).");
66 checkLastEntry(entries, 0, [11, 111, 161, 261, 11, 111, 161, 211, 11, 111, 11, 211, target]);
48 } 67 }
49 68
50 function step2() { 69 function step2() {
51 shouldBeEqualToNumber("entries.length", 2);
52 if (entries.length > 1) {
53 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 0);
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 }
67 root.scrollTop = 0; 70 root.scrollTop = 0;
68 root.insertBefore(target, afterTarget); 71 root.insertBefore(target, trailingSpace);
69 waitForNotification(step3); 72 runTestCycle(step3, "root.insertBefore(target, trailingSpace).");
73 checkLastEntry(entries, 1, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, target]);
70 } 74 }
71 75
72 function step3() { 76 function step3() {
73 shouldBeEqualToNumber("entries.length", 2);
74 root.scrollTop = 150; 77 root.scrollTop = 150;
75 waitForNotification(step4); 78 runTestCycle(step4, "root.scrollTop = 150 after reinserting target.");
79 checkLastEntry(entries, 1);
76 } 80 }
77 81
78 function step4() { 82 function step4() {
79 shouldBeEqualToNumber("entries.length", 3); 83 checkLastEntry(entries, 2, [11, 111, 161, 261, 11, 111, 161, 211, 11, 111, 11, 211, target]);
80 if (entries.length > 2) {
81 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 11);
82 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 111);
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 }
95 finishJSTest();
96 } 84 }
97 </script> 85 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698