dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>nsIDOMWindowUtils::elementFromPoint test</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
    1.10 +  <style>
    1.11 +    body {
    1.12 +      /* Make room for scrolling */
    1.13 +    }
    1.14 +  </style>
    1.15 +</head>
    1.16 +
    1.17 +<body id="body">
    1.18 +  <script type="application/javascript;version=1.8">
    1.19 +    /*
    1.20 +      void getScrollXY(in boolean aFlushLayout, out long aScrollX, out long aScrollY);
    1.21 +    */
    1.22 +    function doTests() {
    1.23 +      testScrollXY();
    1.24 +      testHiddenIframe();
    1.25 +
    1.26 +      SimpleTest.finish();
    1.27 +    }
    1.28 +
    1.29 +    function testScrollXY() {
    1.30 +      let iframe = document.getElementById("iframe");
    1.31 +      let cwindow = iframe.contentWindow;
    1.32 +      let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
    1.33 +
    1.34 +      function checkGetScrollXYState(flush, vals, testName) {
    1.35 +        let scrollX = {}, scrollY = {};
    1.36 +        domWindowUtils.getScrollXY(flush, scrollX, scrollY);
    1.37 +        is(scrollX.value, vals[0], "getScrollXY x for test: " + testName);
    1.38 +        is(scrollY.value, vals[1], "getScrollXY y for test: " + testName);
    1.39 +      }
    1.40 +
    1.41 +      function checkWindowScrollState(vals, testName) {
    1.42 +        is(cwindow.scrollX, vals[0], "scrollX for test: " + testName);
    1.43 +        is(cwindow.scrollY, vals[1], "scrollY for test: " + testName);
    1.44 +      }
    1.45 +
    1.46 +      // Check initial state (0, 0)
    1.47 +      checkGetScrollXYState(false, [0, 0], "initial getScrollXY state");
    1.48 +      checkGetScrollXYState(true, [0, 0], "initial getScrollXY state+flush");
    1.49 +      checkWindowScrollState([0, 0], "initial window.scroll* state");
    1.50 +
    1.51 +      // scroll
    1.52 +      cwindow.scrollTo(900, 1000);
    1.53 +      checkGetScrollXYState(false, [900, 1000], "after scroll getScrollXY state");
    1.54 +      checkGetScrollXYState(true, [900, 1000], "after scroll getScrollXY state+flush");
    1.55 +      checkWindowScrollState([900, 1000], "after scroll window.scroll* state");
    1.56 +
    1.57 +      // ensure flush=false works
    1.58 +      cwindow.document.body.style.width = 'auto';
    1.59 +      cwindow.document.body.style.height = 'auto';
    1.60 +      checkGetScrollXYState(false, [900, 1000], "didn't flush layout for getScrollXY");
    1.61 +      checkGetScrollXYState(true, [0, 0], "flushed layout for getScrollXY");
    1.62 +    }
    1.63 +
    1.64 +    function testHiddenIframe() {
    1.65 +      let iframe = document.getElementById("hidden-iframe");
    1.66 +      let cwindow = iframe.contentWindow;
    1.67 +      let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
    1.68 +
    1.69 +      // make sure getScrollXY doesn't throw
    1.70 +      let scrollX = {}, scrollY = {};
    1.71 +      domWindowUtils.getScrollXY(false, scrollX, scrollY);
    1.72 +
    1.73 +      is(scrollX.value, 0, "scrollX is zero for display:none iframe");
    1.74 +      is(scrollY.value, 0, "scrollY is zero for display:none iframe");
    1.75 +    }
    1.76 +
    1.77 +    SimpleTest.waitForExplicitFinish();
    1.78 +  </script>
    1.79 +
    1.80 +  <!-- can't run this in the test document, since it potentially runs in a
    1.81 +       scrolling="no" test harness iframe, and that causes a failure for some
    1.82 +       reason -->
    1.83 +  <iframe src="data:text/html,<body style='width: 100000px; height: 100000px;'><p>top</p></body>"
    1.84 +          id="iframe"
    1.85 +          onload="doTests();">
    1.86 +  </iframe>
    1.87 +
    1.88 +  <iframe id="hidden-iframe" style="display: none;"></iframe>
    1.89 +
    1.90 +  <p id="display"></p>
    1.91 +
    1.92 +</body>
    1.93 +</html>

mercurial