X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fscrolling_div.js;h=ceb2a3d9be8407c161bb5dbf8811e3281549e5f4;hb=f1ec8cf5aedd62613b954803cb48aaa0a065dc32;hp=a97874b7a8e1e255e3ab91ee461a1787a42cc542;hpb=22bce4f209d99203fcb3c3892ddf5ddb6d359b93;p=dygraphs.git diff --git a/auto_tests/tests/scrolling_div.js b/auto_tests/tests/scrolling_div.js index a97874b..ceb2a3d 100644 --- a/auto_tests/tests/scrolling_div.js +++ b/auto_tests/tests/scrolling_div.js @@ -17,11 +17,10 @@ var LOREM_IPSUM = "laborum.

"; document.body.innerHTML = - "
" + - "
" + + "
" + + "
" + "
" + LOREM_IPSUM + "
" + "
" + LOREM_IPSUM + "
" + - "" + "
"; var data = [ @@ -51,6 +50,29 @@ var LOREM_IPSUM = }; +// This is usually something like 15, but for OS X Lion and its auto-hiding +// scrollbars, it's 0. This is a large enough difference that we need to +// consider it when synthesizing clicks. +// Adapted from http://davidwalsh.name/detect-scrollbar-width +ScrollingDivTestCase.prototype.detectScrollbarWidth = function() { + // Create the measurement node + var scrollDiv = document.createElement("div"); + scrollDiv.style.width = "100px"; + scrollDiv.style.height = "100px"; + scrollDiv.style.overflow = "scroll"; + scrollDiv.style.position = "absolute"; + scrollDiv.style.top = "-9999px"; + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the DIV + document.body.removeChild(scrollDiv); + + return scrollbarWidth; +}; + ScrollingDivTestCase.prototype.tearDown = function() { }; @@ -59,7 +81,7 @@ ScrollingDivTestCase.prototype.tearDown = function() { */ ScrollingDivTestCase.prototype.testUnscrolledDiv = function() { - window.location.href="#TOP"; + document.getElementById('scroller').scrollTop = 0; var clickOn4_40 = { clientX: 244, @@ -80,11 +102,11 @@ ScrollingDivTestCase.prototype.testUnscrolledDiv = function() { * This tests that when the nested div is scrolled, things work normally. */ ScrollingDivTestCase.prototype.testScrolledDiv = function() { - window.location.href="#BOTTOM"; + document.getElementById('scroller').scrollTop = 117; var clickOn4_40 = { clientX: 244, - clientY: 20, + clientY: 30 - this.detectScrollbarWidth(), screenX: 416, screenY: 160 };