testing/web-platform/tests/intersection-observer/client-rect.html
author Hiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 18 May 2019 23:43:54 +0000
changeset 536344 a6e9e91432d4c224cef1ea0b8c232ccd4c57dd13
parent 486740 8c74b0e7a64a6d00cdf7ab5ff5613617b51fe391
permissions -rw-r--r--
Bug 1552134 - Add width=device-width,initial-scale=1 to avoid auto shrink the contents to intersection-observer tests. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D31580

<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/intersection-observer-test-utils.js"></script>

<style>
pre, #log {
  position: absolute;
  top: 0;
  left: 200px;
}
iframe {
  width: 180px;
  height: 100px;
}
</style>

<iframe id="iframe" srcdoc="<div id='target' style='margin:0.5px;width:1000px;height:1000px;'></div>"></iframe>

<script>
var target;
var entries = [];
var observer;
var iframe = document.getElementById("iframe");

iframe.onload = function() {
  runTestCycle(function() {
    target = iframe.contentDocument.getElementById("target");
    assert_true(!!target, "Target element exists.");
    observer = new IntersectionObserver(function(changes) {
      entries = entries.concat(changes);
    });
    observer.observe(target);
    entries = entries.concat(observer.takeRecords());
    assert_equals(entries.length, 0, "No initial notifications.");
    runTestCycle(test0, "First rAF should generate notification.");
  }, "IntersectionObserverEntry.boundingClientRect should match target.boundingClientRect()");
};

function test0() {
  assert_equals(entries.length, 1, "One notification.");
  var bcr = target.getBoundingClientRect();
  checkLastEntry(entries, 0, [bcr.left, bcr.right, bcr.top, bcr.bottom]);
}
</script>