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

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/same-document-zero-size-target.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 style="width:100%; height:700px;"></div> 4 <script src="./resources/intersection-observer-test-utils.js"></script>
5 <div id="target" style="background-color: green; width:0px; height:0px"></div> 5
6 <div style="width:100%; height:700px;"></div> 6 <style>
7 pre, #log {
8 position: absolute;
9 top: 0;
10 left: 200px;
11 }
12 .spacer {
13 height: 700px;
14 }
15 #target {
16 width: 0px;
17 height: 0px;
18 background-color: green;
19 }
20 </style>
21
22 <div class="spacer"></div>
23 <div id="target"></div>
24 <div class="spacer"></div>
7 25
8 <script> 26 <script>
9 description("Intersection observer test with zero-size target element.");
10 var target = document.getElementById("target");
11 var entries = []; 27 var entries = [];
12 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch anges) }, {}); 28 var target;
13 29
14 onload = function() { 30 runTestCycle(function() {
31 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
32 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
33
34 target = document.getElementById("target");
35 assert_true(!!target, "Target exists");
36 var observer = new IntersectionObserver(function(changes) {
37 entries = entries.concat(changes)
38 });
15 observer.observe(target); 39 observer.observe(target);
16 entries.push(...observer.takeRecords()); 40 entries = entries.concat(observer.takeRecords());
17 shouldBeEqualToNumber("entries.length", 0); 41 assert_equals(entries.length, 0, "No initial notifications.");
42 runTestCycle(step0, "First rAF");
43 }, "Observing a zero-area target.");
44
45 function step0() {
18 document.scrollingElement.scrollTop = 300; 46 document.scrollingElement.scrollTop = 300;
19 waitForNotification(step1); 47 runTestCycle(step1, "document.scrollingElement.scrollTop = 300");
20 }; 48 assert_equals(entries.length, 0, "No notifications after first rAF.");
49 }
21 50
22 function step1() { 51 function step1() {
23 shouldBeEqualToNumber("entries.length", 1);
24 if (entries.length > 0) {
25 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8);
26 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 8);
27 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408);
28 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 408);
29 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8);
30 shouldBeEqualToNumber("entries[0].intersectionRect.right", 8);
31 shouldBeEqualToNumber("entries[0].intersectionRect.top", 408);
32 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 408);
33 shouldBeEqualToNumber("entries[0].rootBounds.left", 0);
34 shouldBeEqualToNumber("entries[0].rootBounds.right", 785);
35 shouldBeEqualToNumber("entries[0].rootBounds.top", 0);
36 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600);
37 shouldEvaluateToSameObject("entries[0].target", target);
38
39 // ClientRect members of IntersectionObserverEntry should be stable.
40 shouldEvaluateToSameObject("entries[0].boundingClientRect", entries[0].bound ingClientRect);
41 shouldEvaluateToSameObject("entries[0].intersectionRect", entries[0].interse ctionRect);
42 shouldEvaluateToSameObject("entries[0].rootBounds", entries[0].rootBounds);
43 }
44 document.scrollingElement.scrollTop = 100; 52 document.scrollingElement.scrollTop = 100;
45 waitForNotification(step2); 53 runTestCycle(step2, "document.scrollingElement.scrollTop = 100");
54 checkLastEntry(entries, 0, [8, 8, 408, 408, 8, 8, 408, 408, 0, 785, 0, 600, ta rget]);
46 } 55 }
47 56
48 function step2() { 57 function step2() {
49 shouldBeEqualToNumber("entries.length", 2);
50 if (entries.length > 1) {
51 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8);
52 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 8);
53 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 608);
54 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 608);
55 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
56 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
57 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
58 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
59 shouldBeEqualToNumber("entries[1].rootBounds.left", 0);
60 shouldBeEqualToNumber("entries[1].rootBounds.right", 785);
61 shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
62 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600);
63 shouldEvaluateToSameObject("entries[1].target", target);
64 }
65 finishJSTest();
66 document.scrollingElement.scrollTop = 0; 58 document.scrollingElement.scrollTop = 0;
59 checkLastEntry(entries, 1, [8, 8, 608, 608, 0, 0, 0, 0, 0, 785, 0, 600, target ]);
67 } 60 }
68 </script> 61 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698