tor-browser

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

test_domWindowUtils_scrollXY.html (3215B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>nsIDOMWindowUtils::elementFromPoint test</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
      7  <style>
      8    body {
      9      /* Make room for scrolling */
     10    }
     11  </style>
     12 </head>
     13 
     14 <body id="body">
     15  <script type="application/javascript">
     16    /*
     17      void getScrollXY(in boolean aFlushLayout, out long aScrollX, out long aScrollY);
     18    */
     19    function doTests() {
     20      testScrollXY();
     21      testHiddenIframe();
     22 
     23      SimpleTest.finish();
     24    }
     25 
     26    function testScrollXY() {
     27      let iframe = document.getElementById("iframe");
     28      let cwindow = iframe.contentWindow;
     29      let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
     30 
     31      function checkGetScrollXYState(flush, vals, testName) {
     32        let scrollX = {}, scrollY = {};
     33        domWindowUtils.getScrollXY(flush, scrollX, scrollY);
     34        is(Math.round(scrollX.value), vals[0], "getScrollXY x for test: " + testName);
     35        is(Math.round(scrollY.value), vals[1], "getScrollXY y for test: " + testName);
     36      }
     37 
     38      function checkWindowScrollState(vals, testName) {
     39        is(Math.round(cwindow.scrollX), vals[0], "scrollX for test: " + testName);
     40        is(Math.round(cwindow.scrollY), vals[1], "scrollY for test: " + testName);
     41      }
     42 
     43      // Check initial state (0, 0)
     44      checkGetScrollXYState(false, [0, 0], "initial getScrollXY state");
     45      checkGetScrollXYState(true, [0, 0], "initial getScrollXY state+flush");
     46      checkWindowScrollState([0, 0], "initial window.scroll* state");
     47 
     48      // scroll
     49      cwindow.scrollTo(900, 1000);
     50      checkGetScrollXYState(false, [900, 1000], "after scroll getScrollXY state");
     51      checkGetScrollXYState(true, [900, 1000], "after scroll getScrollXY state+flush");
     52      checkWindowScrollState([900, 1000], "after scroll window.scroll* state");
     53 
     54      // ensure flush=false works
     55      cwindow.document.body.style.width = 'auto';
     56      cwindow.document.body.style.height = 'auto';
     57      checkGetScrollXYState(false, [900, 1000], "didn't flush layout for getScrollXY");
     58      checkGetScrollXYState(true, [0, 0], "flushed layout for getScrollXY");
     59    }
     60 
     61    function testHiddenIframe() {
     62      let iframe = document.getElementById("hidden-iframe");
     63      let cwindow = iframe.contentWindow;
     64      let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
     65 
     66      // make sure getScrollXY doesn't throw
     67      let scrollX = {}, scrollY = {};
     68      domWindowUtils.getScrollXY(false, scrollX, scrollY);
     69 
     70      is(Math.round(scrollX.value), 0, "scrollX is zero for display:none iframe");
     71      is(Math.round(scrollY.value), 0, "scrollY is zero for display:none iframe");
     72    }
     73 
     74    SimpleTest.waitForExplicitFinish();
     75  </script>
     76 
     77  <!-- can't run this in the test document, since it potentially runs in a
     78       scrolling="no" test harness iframe, and that causes a failure for some
     79       reason -->
     80  <iframe srcdoc="<body style='width: 100000px; height: 100000px;'><p>top</p></body>"
     81          id="iframe"
     82          onload="doTests();">
     83  </iframe>
     84 
     85  <iframe id="hidden-iframe" style="display: none;"></iframe>
     86 
     87  <p id="display"></p>
     88 
     89 </body>
     90 </html>