dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial