Index: third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/iframe-no-root.html b/third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
similarity index 50% |
copy from third_party/WebKit/LayoutTests/intersection-observer/iframe-no-root.html |
copy to third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
index 0685994bc299138ca6690ab413c955ade13973d0..f7db8fb8ee8d9878185571d268a8c5056a4582ad 100644 |
--- a/third_party/WebKit/LayoutTests/intersection-observer/iframe-no-root.html |
+++ b/third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
@@ -1,59 +1,81 @@ |
<!DOCTYPE html> |
<script src="../resources/js-test.js"></script> |
<script src="helper-functions.js"></script> |
-<div style="width:100%; height:700px;"></div> |
-<iframe id="target-iframe" src="../resources/intersection-observer-subframe.html" style="height: 100px; overflow-y: scroll"></iframe> |
-<div style="width:100%; height:700px;"></div> |
+<style> |
+#root { |
+ width: 200px; |
+ height: 200px; |
+ overflow-y: scroll; |
+} |
+#target { |
+ width: 100px; |
+ height: 100px; |
+ background-color: green; |
+ position: absolute; |
+} |
+</style> |
+<div id="root" style="position: absolute"> |
+ <div id="target" style="left: 50px; top: 250px"></div> |
+</div> |
<script> |
-description("Simple intersection observer test with no explicit root and target in an iframe."); |
-var entries = []; |
-var targetIframe = document.getElementById("target-iframe"); |
+ description("Test that no notifications are generated when root is not in the containing block chain of target."); |
+ var root = document.getElementById("root"); |
+ var target = document.getElementById("target"); |
+ var entries = []; |
-targetIframe.onload = function() { |
- var target = targetIframe.contentDocument.getElementById("target"); |
- var iframeScroller = targetIframe.contentDocument.scrollingElement; |
- |
- observer_callback = function(changes) { |
- for (var i in changes) |
- entries.push(changes[i]); |
- }; |
- var observer = new IntersectionObserver(observer_callback, {}); |
- observer.observe(target); |
+ function observer_callback(changes) { |
+ changes.forEach(function(e) { entries.push(e) }); |
+ } |
+ new IntersectionObserver(observer_callback, {root: root}).observe(target); |
function step0() { |
setTimeout(function() { |
shouldBeEqualToNumber("entries.length", 0); |
- document.scrollingElement.scrollTop = 200; |
+ target.style.top = "10px"; |
requestAnimationFrame(step1); |
}); |
} |
function step1() { |
setTimeout(function() { |
- shouldBeEqualToNumber("entries.length", 0); |
- iframeScroller.scrollTop = 250; |
+ shouldBeEqualToNumber("entries.length", 1); |
+ shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); |
+ shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158); |
+ shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18); |
+ shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118); |
+ shouldBeEqualToNumber("entries[0].intersectionRect.left", 58); |
+ shouldBeEqualToNumber("entries[0].intersectionRect.right", 158); |
+ shouldBeEqualToNumber("entries[0].intersectionRect.top", 18); |
+ shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118); |
+ shouldBeEqualToNumber("entries[0].rootBounds.left", 8); |
+ shouldBeEqualToNumber("entries[0].rootBounds.right", 193); |
+ shouldBeEqualToNumber("entries[0].rootBounds.top", 8); |
+ shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208); |
+ shouldEvaluateToSameObject("entries[0].target", target); |
+ target.style.top = "250px"; |
requestAnimationFrame(step2); |
}); |
} |
function step2() { |
setTimeout(function() { |
- shouldBeEqualToNumber("entries.length", 1); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.left", 18); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.right", 118); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.top", 468); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 568); |
- shouldBeEqualToNumber("entries[0].intersectionRect.left", 18); |
- shouldBeEqualToNumber("entries[0].intersectionRect.right", 118); |
- shouldBeEqualToNumber("entries[0].intersectionRect.top", 510); |
- shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 568); |
- shouldBeEqualToNumber("entries[0].rootBounds.left", 0); |
- shouldBeEqualToNumber("entries[0].rootBounds.right", 785); |
- shouldBeEqualToNumber("entries[0].rootBounds.top", 0); |
- shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); |
- shouldEvaluateToSameObject("entries[0].target", target); |
- document.scrollingElement.scrollTop = 100; |
+ shouldBeEqualToNumber("entries.length", 2); |
+ shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); |
+ shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158); |
+ shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258); |
+ shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358); |
+ shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
+ shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
+ shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
+ shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
+ shouldBeEqualToNumber("entries[1].rootBounds.left", 8); |
+ shouldBeEqualToNumber("entries[1].rootBounds.right", 193); |
+ shouldBeEqualToNumber("entries[1].rootBounds.top", 8); |
+ shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208); |
+ shouldEvaluateToSameObject("entries[1].target", target); |
+ root.style.position = "static"; |
+ target.style.top = "10px"; |
requestAnimationFrame(step3); |
}); |
} |
@@ -61,24 +83,17 @@ targetIframe.onload = function() { |
function step3() { |
setTimeout(function() { |
shouldBeEqualToNumber("entries.length", 2); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.left", 18); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.right", 118); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.top", 568); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 668); |
- shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
- shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
- shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
- shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
- shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
- shouldBeEqualToNumber("entries[1].rootBounds.right", 785); |
- shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
- shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); |
- shouldEvaluateToSameObject("entries[1].target", target); |
+ target.style.top = "250px"; |
+ requestAnimationFrame(step4); |
+ }); |
+ } |
+ |
+ function step4() { |
+ setTimeout(function() { |
+ shouldBeEqualToNumber("entries.length", 2); |
finishJSTest(); |
- document.scrollingElement.scrollTop = 0; |
}); |
} |
step0(); |
-} |
</script> |