From: Robert Konigsberg Date: Fri, 8 Feb 2013 23:54:34 +0000 (-0500) Subject: Fix bug 428, add test which catches exception. What an annoying little bug. X-Git-Tag: v1.0.0~91^2^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=4c10c8d21b6858ea9029bdb789f487d9103d72f9;p=dygraphs.git Fix bug 428, add test which catches exception. What an annoying little bug. --- diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index 0e6b4fa..601aceb 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -8,12 +8,14 @@ var CallbackTestCase = TestCase("callback"); CallbackTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; + this.xhr = XMLHttpRequest; this.styleSheet = document.createElement("style"); this.styleSheet.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(this.styleSheet); }; CallbackTestCase.prototype.tearDown = function() { + XMLHttpRequest = this.xhr; }; var data = "X,a\,b,c\n" + @@ -487,3 +489,35 @@ CallbackTestCase.prototype.testGapHighlight = function() { assertEquals(8, h_pts[0].yval); assertEquals('A', h_pts[0].name); }; + +CallbackTestCase.prototype.testFailedResponse = function() { + + // Fake out the XMLHttpRequest so it doesn't do anything. + XMLHttpRequest = function () {}; + XMLHttpRequest.prototype.open = function () {}; + XMLHttpRequest.prototype.send = function () {}; + + var highlightCallback = function(e, x, pts, row) { + fail("should not reach here"); + }; + + var graph = document.getElementById("graph"); + graph.style.border = "2px solid black"; + var g = new Dygraph(graph, "data.csv", { // fake name + width: 400, + height: 300, + highlightCallback : highlightCallback + }); + + DygraphOps.dispatchMouseOver_Point(g, 800, 800); + DygraphOps.dispatchMouseMove_Point(g, 100, 100); + DygraphOps.dispatchMouseMove_Point(g, 800, 800); + + var oldOnerror = window.onerror; + var failed = false; + window.onerror = function() { failed = true; return false; } + + DygraphOps.dispatchMouseOut_Point(g, 800, 800); // This call should not throw an exception. + + assertFalse("exception thrown during mouseout", failed); +}; diff --git a/dygraph.js b/dygraph.js index eba57db..8e06ba2 100644 --- a/dygraph.js +++ b/dygraph.js @@ -3500,9 +3500,12 @@ Dygraph.prototype.annotations = function() { /** * Get the list of label names for this graph. The first column is the * x-axis, so the data series names start at index 1. + * + * Returns null when labels have not yet been defined. */ Dygraph.prototype.getLabels = function() { - return this.attr_("labels").slice(); + var labels = this.attr_("labels"); + return labels ? labels.slice() : null; }; /**