tor-browser

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

helper_hittest_spam.html (3045B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test doing lots of hit-testing on a rapidly changing page</title>
      5  <script type="application/javascript" src="apz_test_utils.js"></script>
      6  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
      7  <script src="/tests/SimpleTest/paint_listener.js"></script>
      8  <meta name="viewport" content="width=device-width"/>
      9 </head>
     10 <style>
     11 #spamdiv {
     12    overflow: scroll;
     13    width: 400px;
     14    height: 400px;
     15 }
     16 #spamdiv div {
     17    width: 1000px;
     18    height: 1000px;
     19 }
     20 </style>
     21 <body>
     22 <script type="application/javascript">
     23 
     24 var SPAM_LIMIT = 200; // bigger numbers make the test run longer
     25 
     26 // This function adds and removes a scrollable div very rapidly (via
     27 // setTimeout(0) self-scheduling). This causes very frequent layer
     28 // transactions with a new APZ hit-testing tree from the main thread to APZ.
     29 // The div is created afresh every time so that the scroll identifier in
     30 // Gecko is continually increasing, and hit results from a stale tree will
     31 // not be valid on the new tree.
     32 var spamCount = 0;
     33 var spamPoint = null;
     34 function divSpammer() {
     35  spamCount++;
     36  if (spamCount >= SPAM_LIMIT) {
     37    return;
     38  }
     39  setTimeout(divSpammer, 0);
     40 
     41  // Remove the div if it exists...
     42  var spamdiv = document.getElementById('spamdiv');
     43  if (spamdiv) {
     44    spamdiv.remove();
     45    return;
     46  }
     47  // ... and add it if it doesn't exist.
     48  spamdiv = document.createElement('div');
     49  spamdiv.id = 'spamdiv';
     50  spamdiv.appendChild(document.createElement('div'));
     51  document.body.appendChild(spamdiv);
     52  if (spamPoint == null) {
     53    spamPoint = centerOf(spamdiv);
     54  }
     55 }
     56 
     57 // This function does continuous hit-testing by scheduling itself over and
     58 // over with setTimeout(0). It hit-tests the same spot and expects to hit
     59 // either the root scrollframe (if the spamdiv is not present in that
     60 // instant) or the spamdiv (if it is present). If the spamdiv is hit, it
     61 // expects the scrollid to be non-decreasing.
     62 var rootScrollId = null;
     63 var lastScrollId = -1;
     64 function hitTestSpammer() {
     65  if (spamCount >= SPAM_LIMIT) {
     66    subtestDone();
     67    return;
     68  }
     69  setTimeout(hitTestSpammer, 0);
     70 
     71  if (spamPoint == null) {
     72    // The very first invocation of this function will have spamPoint as null,
     73    // and we use that to pick up the rootScrollId.
     74    ok(rootScrollId == null, "This codepath shouldn't get hit twice");
     75    rootScrollId = hitTest(centerOf(document.body)).scrollId;
     76    ok(true, "Root scroll id detected as " + rootScrollId);
     77    return;
     78  }
     79 
     80  var scrollId = hitTest(spamPoint).scrollId;
     81  if (scrollId == rootScrollId) {
     82    ok(true, "Hit test hit the root scroller, spamdiv is not in compositor");
     83  } else {
     84    is(scrollId >= lastScrollId, true, "spamdiv's scroll id is now " + scrollId);
     85    lastScrollId = scrollId;
     86  }
     87 }
     88 
     89 function startTest() {
     90  // Make sure to run hitTestSpammer first so the first iteration is while
     91  // spamPoint is still null.
     92  setTimeout(hitTestSpammer, 0);
     93  setTimeout(divSpammer, 0);
     94 }
     95 
     96 waitUntilApzStable().then(startTest);
     97 
     98 </script>
     99 </body>
    100 </html>