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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/root-margin.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 <div style="width:100%; height:700px;"></div> 4
5 <div style="white-space: nowrap;"> 5 <div id="leading-space" style="width:100%; height:700px;"></div>
6 <div style="white-space:nowrap;">
6 <div style="display: inline-block; width: 1000px; height: 100px"></div> 7 <div style="display: inline-block; width: 1000px; height: 100px"></div>
7 <div id="target" style="display: inline-block; background-color: green; width: 100px; height:100px"></div> 8 <div id="target" style="display: inline-block; background-color: green; width: 100px; height:100px"></div>
8 <div style="display: inline-block; width: 1000px; height: 100px"></div> 9 <div style="display: inline-block; width: 1000px; height: 100px"></div>
9 </div> 10 </div>
10 <div style="width:100%; height:700px;"></div> 11 <div id="trailing-space" style="width:100%; height:700px;"></div>
11 12
12 <script> 13 <script>
13 description("Intersection observer test with root margin and implicit root."); 14 function waitForNotification(f) {
14 var target = document.getElementById("target"); 15 requestAnimationFrame(() => {
15 var entries = []; 16 setTimeout(() => {
16 var observer = new IntersectionObserver( 17 setTimeout(f);
17 changes => { entries = entries.concat(changes) }, 18 });
18 { rootMargin: "10px 20% 40% 30px" } 19 });
19 ); 20 }
20
21 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px' })");
22 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px' })") ;
23 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3%' } )");
24 21
25 onload = function() { 22 onload = function() {
23 var t = async_test("Intersection observer test with root margin and implicit r oot.");
24
25 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800 pixels wide.");
26 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60 0 pixels high.");
27
28 var target = document.getElementById("target");
29 var entries = [];
30 var observer = new IntersectionObserver(function(changes) {
31 entries = entries.concat(changes)
32 }, { rootMargin: "10px 20% 40% 30px" });
26 observer.observe(target); 33 observer.observe(target);
27 entries = entries.concat(observer.takeRecords()); 34 entries = entries.concat(observer.takeRecords());
28 shouldBeEqualToNumber("entries.length", 0); 35 test(function() { assert_equals(entries.length, 0) }, "No initial notification s.");
29 waitForNotification(step0); 36 waitForNotification(step0);
30 }
31 37
32 function step0() { 38 function checkEntry(i, expected) {
33 shouldBeEqualToNumber("entries.length", 0); 39 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti fication(s).");
34 document.scrollingElement.scrollLeft = 100; 40 if (expected && entries.length > i) {
35 waitForNotification(step1); 41 test(function() { assert_equals(entries[i].boundingClientRect.left, expect ed[0]) },
36 } 42 "entries[" + i + "].boundingClientRect.left == " + expected[0]);
43 test(function() { assert_equals(entries[i].boundingClientRect.right, expec ted[1]) },
44 "entries[" + i + "].boundingClientRect.right == " + expected[1]);
45 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte d[2]) },
46 "entries[" + i + "].boundingClientRect.top == " + expected[2]);
47 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe cted[3]) },
48 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]);
49 test(function() { assert_equals(entries[i].intersectionRect.left, expected [4]) },
50 "entries[" + i + "].intersectionRect.left == " + expected[4]);
51 test(function() { assert_equals(entries[i].intersectionRect.right, expecte d[5]) },
52 "entries[" + i + "].intersectionRect.right == " + expected[5]);
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 }
68 }
37 69
38 function step1() { 70 function step0() {
39 shouldBeEqualToNumber("entries.length", 1); 71 test(function() { assert_equals(entries.length, 0) }, "No notifications afte r first rAF.");
40 if (entries.length > 0) { 72 document.scrollingElement.scrollLeft = 100;
41 shouldBeEqualToNumber("entries.length", 1); 73 waitForNotification(step1);
42 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912);
43 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012);
44 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708);
45 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808);
46 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912);
47 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942);
48 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708);
49 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808);
50 shouldBeEqualToNumber("entries[0].rootBounds.left", -30);
51 shouldBeEqualToNumber("entries[0].rootBounds.right", 942);
52 shouldBeEqualToNumber("entries[0].rootBounds.top", -10);
53 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819);
54 shouldEvaluateToSameObject("entries[0].target", target);
55 } 74 }
56 document.scrollingElement.scrollTop = 800;
57 waitForNotification(step2);
58 }
59 75
60 function step2() { 76 function step1() {
61 shouldBeEqualToNumber("entries.length", 1); 77 checkEntry(0, [912, 1012, 708, 808, 912, 942, 708, 808, -30, 942, -10, 819, target]);
62 document.scrollingElement.scrollTop = 900; 78 document.scrollingElement.scrollTop = 800;
63 waitForNotification(step3); 79 waitForNotification(step2);
64 } 80 }
65 81
66 function step3() { 82 function step2() {
67 shouldBeEqualToNumber("entries.length", 2); 83 checkEntry(0);
68 if (entries.length > 1) { 84 document.scrollingElement.scrollTop = 900;
69 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912); 85 waitForNotification(step3);
70 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012);
71 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192);
72 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92);
73 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
74 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
75 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
76 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
77 shouldBeEqualToNumber("entries[1].rootBounds.left", -30);
78 shouldBeEqualToNumber("entries[1].rootBounds.right", 942);
79 shouldBeEqualToNumber("entries[1].rootBounds.top", -10);
80 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819);
81 shouldEvaluateToSameObject("entries[1].target", target);
82 } 86 }
83 finishJSTest(); 87
84 document.scrollingElement.scrollLeft = 0; 88 function step3() {
85 document.scrollingElement.scrollTop = 0; 89 checkEntry(1, [912, 1012, -192, -92, 0, 0, 0, 0, -30, 942, -10, 819, target] );
86 } 90 document.getElementById("leading-space").style.height = "";
91 document.getElementById("trailing-space").style.height = "";
92 document.scrollingElement.scrollLeft = 0;
93 document.scrollingElement.scrollTop = 0;
94 t.done();
95 }
96 };
87 </script> 97 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698