test_domWindowUtils_scrollbarSize.html (2225B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>nsIDOMWindowUtils::getScrollbarSize test</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 7 </head> 8 9 <body id="body"> 10 <script type="application/javascript"> 11 function doTests() { 12 let iframe = document.getElementById("iframe"); 13 let cwindow = iframe.contentWindow; 14 let utils = SpecialPowers.getDOMWindowUtils(cwindow); 15 let doc = cwindow.document; 16 17 function haveNonFloatingScrollbars() { 18 return doc.getElementById("float").offsetWidth > 200; 19 } 20 21 checkScrollbarSizeFlush(utils, (w, h) => w == 0 && h == 0, 22 "[overflow=hidden] corrrect scrollbar size after flushing"); 23 24 // Some platforms (esp. mobile) may have floating scrollbars that don't 25 // affect layout. Thus getScrollbarSize() would always return zeros. 26 if (haveNonFloatingScrollbars()) { 27 let body = doc.querySelector("body"); 28 body.style.overflowY = "scroll"; 29 30 checkScrollbarSize(utils, (w, h) => w == 0 && h == 0, 31 "[overflowY=scroll] correct scrollbar size w/o flushing"); 32 33 checkScrollbarSizeFlush(utils, (w, h) => w > 0 && h == 0, 34 "[overflowY=scroll] correct scrollbar size after flushing"); 35 36 body.style.overflowX = "scroll"; 37 checkScrollbarSize(utils, (w, h) => w > 0 && h == 0, 38 "[overflowXY=scroll] correct scrollbar size w/o flushing"); 39 40 checkScrollbarSizeFlush(utils, (w, h) => w > 0 && h > 0, 41 "[overflowXY=scroll] correct scrollbar size after flushing"); 42 } 43 44 SimpleTest.finish(); 45 } 46 47 function checkScrollbarSize(utils, check, msg, flush = false) { 48 let width = {}, height = {}; 49 utils.getScrollbarSize(flush, width, height); 50 ok(check(width.value, height.value), msg); 51 } 52 53 function checkScrollbarSizeFlush(utils, check, msg) { 54 checkScrollbarSize(utils, check, msg, true); 55 } 56 57 SimpleTest.waitForExplicitFinish(); 58 </script> 59 60 <iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_domWindowUtils_scrollbarSize.html" 61 id="iframe" onload="doTests();"> 62 </iframe> 63 64 </body> 65 </html>