tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

containing-block.html (2103B)


      1 <!DOCTYPE html>
      2 <meta name="viewport" content="width=device-width,initial-scale=1">
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="./resources/intersection-observer-test-utils.js"></script>
      6 
      7 <style>
      8 pre, #log {
      9  position: absolute;
     10  top: 0;
     11  left: 200px;
     12 }
     13 #root {
     14  width: 170px;
     15  height: 200px;
     16  overflow-y: scroll;
     17 }
     18 #target {
     19  width: 100px;
     20  height: 100px;
     21  background-color: green;
     22  position: absolute;
     23 }
     24 </style>
     25 
     26 <div id="root" style="position: absolute">
     27  <div id="target" style="left: 50px; top: 250px"></div>
     28 </div>
     29 
     30 <script>
     31 var entries = [];
     32 var root, target;
     33 
     34 runTestCycle(function() {
     35  root = document.getElementById("root");
     36  assert_true(!!root, "root element exists.");
     37  target = document.getElementById("target");
     38  assert_true(!!target, "target element exists.");
     39  var observer = new IntersectionObserver(function(changes) {
     40    entries = entries.concat(changes);
     41  }, { root: root });
     42  observer.observe(target);
     43  entries = entries.concat(observer.takeRecords());
     44  assert_equals(entries.length, 0, "No initial notifications.");
     45  target.style.top = "10px";
     46  runTestCycle(test1, "In containing block and intersecting.");
     47 }, "IntersectionObserver should only report intersections if root is a containing block ancestor of target.");
     48 
     49 function test1() {
     50  runTestCycle(test2, "In containing block and not intersecting.");
     51  var rootBounds = contentBounds(root);
     52  checkLastEntry(entries, 0, [58, 158, 18, 118, 58, 158, 18, 118].concat(rootBounds));
     53  target.style.top = "250px";
     54 }
     55 
     56 function test2() {
     57  runTestCycle(test3, "Not in containing block and intersecting.");
     58  var rootBounds = contentBounds(root);
     59  checkLastEntry(entries, 1, [58, 158, 258, 358, 0, 0, 0, 0].concat(rootBounds));
     60  root.style.position = "static";
     61  target.style.top = "10px";
     62 }
     63 
     64 function test3() {
     65  runTestCycle(test4, "Not in containing block and not intersecting.");
     66  checkLastEntry(entries, 1);
     67  target.style.top = "250px";
     68 }
     69 
     70 function test4() {
     71  checkLastEntry(entries, 1);
     72  target.style.top = "0";
     73 }
     74 </script>