tor-browser

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

multiple-thresholds.html (3202B)


      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 .spacer {
     14  height: calc(100vh + 100px);
     15 }
     16 #target {
     17  width: 100px;
     18  height: 100px;
     19  background-color: green;
     20 }
     21 </style>
     22 
     23 <div class="spacer"></div>
     24 <div id="target"></div>
     25 <div class="spacer"></div>
     26 
     27 <script>
     28 var vw = document.documentElement.clientWidth;
     29 var vh = document.documentElement.clientHeight;
     30 
     31 var entries = [];
     32 var target;
     33 
     34 runTestCycle(function() {
     35  target = document.getElementById("target");
     36  var observer = new IntersectionObserver(function(changes) {
     37    entries = entries.concat(changes)
     38  }, { threshold: [0, 0.25, 0.5, 0.75, 1] });
     39  observer.observe(target);
     40  entries = entries.concat(observer.takeRecords());
     41  assert_equals(entries.length, 0, "No initial notifications.");
     42  runTestCycle(step0, "First rAF.");
     43 }, "Observer with multiple thresholds.");
     44 
     45 function step0() {
     46  document.scrollingElement.scrollTop = 120;
     47  runTestCycle(step1, "document.scrollingElement.scrollTop = 120");
     48  checkLastEntry(entries, 0, [8, 108, vh + 108, vh + 208, 0, 0, 0, 0, 0, vw, 0, vh, false]);
     49 }
     50 
     51 function step1() {
     52  document.scrollingElement.scrollTop = 160;
     53  runTestCycle(step2, "document.scrollingElement.scrollTop = 160");
     54  checkLastEntry(entries, 1, [8, 108, vh - 12, vh + 88, 8, 108, vh - 12, vh, 0, vw, 0, vh, true]);
     55 }
     56 
     57 function step2() {
     58  document.scrollingElement.scrollTop = 200;
     59  runTestCycle(step3, "document.scrollingElement.scrollTop = 200");
     60  checkLastEntry(entries, 2, [8, 108, vh - 52, vh + 48, 8, 108, vh - 52, vh, 0, vw, 0, vh, true]);
     61 }
     62 
     63 function step3() {
     64  document.scrollingElement.scrollTop = 240;
     65  runTestCycle(step4, "document.scrollingElement.scrollTop = 240");
     66  checkLastEntry(entries, 3, [8, 108, vh - 92, vh + 8, 8, 108, vh - 92, vh, 0, vw, 0, vh, true]);
     67 }
     68 
     69 function step4() {
     70  document.scrollingElement.scrollTop = vh + 140;
     71  runTestCycle(step5, "document.scrollingElement.scrollTop = window.innerHeight + 140");
     72  checkLastEntry(entries, 4, [8, 108, vh - 132, vh - 32, 8, 108, vh - 132, vh - 32, 0, vw, 0, vh, true]);
     73 }
     74 
     75 function step5() {
     76  document.scrollingElement.scrollTop = vh + 160;
     77  runTestCycle(step6, "document.scrollingElement.scrollTop = window.innerHeight + 160");
     78  checkLastEntry(entries, 5, [8, 108, -32, 68, 8, 108, 0, 68, 0, vw, 0, vh, true]);
     79 }
     80 
     81 function step6() {
     82  document.scrollingElement.scrollTop = vh + 200;
     83  runTestCycle(step7, "document.scrollingElement.scrollTop = window.innerHeight + 200");
     84  checkLastEntry(entries, 6, [8, 108, -52, 48, 8, 108, 0, 48, 0, vw, 0, vh, true]);
     85 }
     86 
     87 function step7() {
     88  checkLastEntry(entries, 7, [8, 108, -92, 8, 8, 108, 0, 8, 0, vw, 0, vh, true]);
     89  document.scrollingElement.scrollTop = vh + 220;
     90  runTestCycle(step8, "document.scrollingElement.scrollTop = window.innerHeight + 220");
     91 }
     92 
     93 function step8() {
     94  checkLastEntry(entries, 8, [8, 108, -112, -12, 0, 0, 0, 0, 0, vw, 0, vh, false]);
     95  document.scrollingElement.scrollTop = 0;
     96 }
     97 </script>