From: Dan Vanderkam Date: Wed, 21 Dec 2011 20:43:26 +0000 (-0500) Subject: Fix some tests that started failing in OS X Lion. X-Git-Tag: v1.0.0~396 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=27561e51dd6cc693ace32b7d2e3a2c3b2994a09f;p=dygraphs.git Fix some tests that started failing in OS X Lion. --- diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index 3c0ad7c..6fc54e5 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -30,11 +30,21 @@ function getXLabels() { return ary; } +function makeNumbers(ary) { + var ret = []; + for (var i = 0; i < ary.length; i++) { + ret.push(parseFloat(ary[i])); + } + return ret; +} + function getLegend() { var legend = document.getElementsByClassName("dygraph-legend")[0]; return legend.textContent; } +AxisLabelsTestCase.prototype.kCloseFloat = 1.0e-10; + AxisLabelsTestCase.prototype.testMinusOneToOne = function() { var opts = { width: 480, @@ -87,16 +97,18 @@ AxisLabelsTestCase.prototype.testSmallRangeNearZero = function() { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); - assertEquals(["-0.1","-0.08","-0.06","-0.04","-0.02","0","0.02","0.04","0.06","0.08"], getYLabels()); + assertEqualsDelta(makeNumbers(["-0.1","-0.08","-0.06","-0.04","-0.02","0","0.02","0.04","0.06","0.08"]), + makeNumbers(getYLabels()), this.kCloseFloat); opts.valueRange = [-0.05, 0.05]; g.updateOptions(opts); // TODO(danvk): why '1.00e-2' and not '0.01'? - assertEquals(["-0.05","-0.04","-0.03","-0.02","-0.01","0","1.00e-2","0.02","0.03","0.04"], getYLabels()); + assertEquals(makeNumbers(["-0.05","-0.04","-0.03","-0.02","-0.01","0","1.00e-2","0.02","0.03","0.04"]), + makeNumbers(getYLabels())); opts.valueRange = [-0.01, 0.01]; g.updateOptions(opts); - assertEquals(["-0.01","-8.00e-3","-6.00e-3","-4.00e-3","-2.00e-3","0","2.00e-3","4.00e-3","6.00e-3","8.00e-3"], getYLabels()); + assertEquals(makeNumbers(["-0.01","-8.00e-3","-6.00e-3","-4.00e-3","-2.00e-3","0","2.00e-3","4.00e-3","6.00e-3","8.00e-3"]), makeNumbers(getYLabels())); g.setSelection(1); assertEquals('1: Y:0', getLegend()); diff --git a/auto_tests/tests/scrolling_div.js b/auto_tests/tests/scrolling_div.js index 527f046..8fa950e 100644 --- a/auto_tests/tests/scrolling_div.js +++ b/auto_tests/tests/scrolling_div.js @@ -43,6 +43,9 @@ var LOREM_IPSUM = drawPoints : true, highlightCircleSize : 6, pointClickCallback : function(evt, point) { + // chrome sez: 243 30 248 124, scroller.offsetLeft/Top = 8/8 + // ff sez: 245 17 249 126, " " + console.log(evt.clientX, evt.clientY, evt.screenX, evt.screenY); self.point = point; } } @@ -50,6 +53,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() { }; @@ -83,7 +109,7 @@ ScrollingDivTestCase.prototype.testScrolledDiv = function() { var clickOn4_40 = { clientX: 244, - clientY: 20, + clientY: 30 - this.detectScrollbarWidth(), screenX: 416, screenY: 160 };