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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/containing-block.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>
7 pre, #log {
8 position: absolute;
9 top: 0;
10 left: 200px;
11 }
5 #root { 12 #root {
6 width: 200px; 13 width: 170px;
7 height: 200px; 14 height: 200px;
8 overflow-y: scroll; 15 overflow-y: scroll;
9 } 16 }
10 #target { 17 #target {
11 width: 100px; 18 width: 100px;
12 height: 100px; 19 height: 100px;
13 background-color: green; 20 background-color: green;
14 position: absolute; 21 position: absolute;
15 } 22 }
16 </style> 23 </style>
24
17 <div id="root" style="position: absolute"> 25 <div id="root" style="position: absolute">
18 <div id="target" style="left: 50px; top: 250px"></div> 26 <div id="target" style="left: 50px; top: 250px"></div>
19 </div> 27 </div>
20 28
21 <script> 29 <script>
22 description("Test that no notifications are generated when root is not in the co ntaining block chain of target.");
23 var root = document.getElementById("root");
24 var target = document.getElementById("target");
25 var entries = []; 30 var entries = [];
31 var root, target;
26 32
27 var observer = new IntersectionObserver( 33 runTestCycle(function() {
28 changes => { entries.push(...changes) }, 34 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
29 { root: root } 35 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
30 );
31 36
32 onload = function() { 37 root = document.getElementById("root");
38 assert_true(!!root, "root element exists.");
39 target = document.getElementById("target");
40 assert_true(!!target, "target element exists.");
41 var observer = new IntersectionObserver(function(changes) {
42 entries = entries.concat(changes);
43 }, { root: root });
33 observer.observe(target); 44 observer.observe(target);
34 shouldBeEqualToNumber("entries.length", 0); 45 entries = entries.concat(observer.takeRecords());
46 assert_equals(entries.length, 0, "No initial notifications.");
35 target.style.top = "10px"; 47 target.style.top = "10px";
36 waitForNotification(step1); 48 runTestCycle(test1, "In containing block and intersecting.");
37 }; 49 }, "IntersectionObserver should only report intersections if root is a containin g block ancestor of target.");
38 50
39 function step1() { 51 function test1() {
40 shouldBeEqualToNumber("entries.length", 1); 52 runTestCycle(test2, "In containing block and not intersecting.");
41 if (entries.length > 0) { 53 var rootBounds = contentBounds(root);
42 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); 54 checkLastEntry(entries, 0, [58, 158, 18, 118, 58, 158, 18, 118].concat(rootBou nds));
43 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158);
44 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18);
45 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118);
46 shouldBeEqualToNumber("entries[0].intersectionRect.left", 58);
47 shouldBeEqualToNumber("entries[0].intersectionRect.right", 158);
48 shouldBeEqualToNumber("entries[0].intersectionRect.top", 18);
49 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118);
50 shouldBeEqualToNumber("entries[0].rootBounds.left", 8);
51 shouldBeEqualToNumber("entries[0].rootBounds.right", 193);
52 shouldBeEqualToNumber("entries[0].rootBounds.top", 8);
53 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208);
54 shouldEvaluateToSameObject("entries[0].target", target);
55 }
56 target.style.top = "250px"; 55 target.style.top = "250px";
57 waitForNotification(step2);
58 } 56 }
59 57
60 function step2() { 58 function test2() {
61 shouldBeEqualToNumber("entries.length", 2); 59 runTestCycle(test3, "Not in containing block and intersecting.");
62 if (entries.length > 1) { 60 var rootBounds = contentBounds(root);
63 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); 61 checkLastEntry(entries, 1, [58, 158, 258, 358, 0, 0, 0, 0].concat(rootBounds)) ;
64 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158);
65 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258);
66 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358);
67 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
68 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
69 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
70 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
71 shouldBeEqualToNumber("entries[1].rootBounds.left", 8);
72 shouldBeEqualToNumber("entries[1].rootBounds.right", 193);
73 shouldBeEqualToNumber("entries[1].rootBounds.top", 8);
74 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208);
75 shouldEvaluateToSameObject("entries[1].target", target);
76 }
77 root.style.position = "static"; 62 root.style.position = "static";
78 target.style.top = "10px"; 63 target.style.top = "10px";
79 waitForNotification(step3);
80 } 64 }
81 65
82 function step3() { 66 function test3() {
83 shouldBeEqualToNumber("entries.length", 2); 67 runTestCycle(test4, "Not in containing block and not intersecting.");
68 checkLastEntry(entries, 1);
84 target.style.top = "250px"; 69 target.style.top = "250px";
85 waitForNotification(step4);
86 } 70 }
87 71
88 function step4() { 72 function test4() {
89 shouldBeEqualToNumber("entries.length", 2); 73 checkLastEntry(entries, 1);
90 finishJSTest(); 74 target.style.top = "0";
91 } 75 }
92 </script> 76 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698