Эх сурвалжийг харах

Fixed Cursor URI Support Detection

There was a bug in cursor URI support detection due to the way
set_defaults now works -- the code was checking for `null`, whereas
when not set, options default to `undefined` unless otherwise
specified.  The code now checks for either `null` or `undefined`.
Tests have been added to ensure that this works properly.
Solly Ross 11 жил өмнө
parent
commit
53762c31fe

+ 2 - 2
include/display.js

@@ -89,12 +89,12 @@ var Display;
             var curSave = this._target.style.cursor;
             Display.changeCursor(this._target, curDat, curDat, 2, 2, 8, 8);
             if (this._target.style.cursor) {
-                if (this._cursor_uri === null) {
+                if (this._cursor_uri === null || this._cursor_uri === undefined) {
                     this._cursor_uri = true;
                 }
                 Util.Info("Data URI scheme cursor supported");
             } else {
-                if (this._cursor_uri === null) {
+                if (this._cursor_uri === null || this._cursor_uri === undefined) {
                     this._cursor_uri = false;
                 }
                 Util.Warn("Data URI scheme cursor not supported");

+ 34 - 0
tests/test.display.js

@@ -26,6 +26,40 @@ describe('Display/Canvas Helper', function () {
         return canvas;
     }
 
+    describe('checking for cursor uri support', function () {
+        beforeEach(function () {
+            this._old_change_cursor = Display.changeCursor;
+        });
+
+        it('should disable cursor URIs if there is no support', function () {
+            Display.changeCursor = function(target) {
+                target.style.cursor = undefined;
+            };
+            var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false });
+            expect(display._cursor_uri).to.be.false;
+        });
+
+        it('should enable cursor URIs if there is support', function () {
+            Display.changeCursor = function(target) {
+                target.style.cursor = 'pointer';
+            };
+            var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false });
+            expect(display._cursor_uri).to.be.true;
+        });
+
+        it('respect the cursor_uri option if there is support', function () {
+            Display.changeCursor = function(target) {
+                target.style.cursor = 'pointer';
+            };
+            var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false, cursor_uri: false });
+            expect(display._cursor_uri).to.be.false;
+        });
+
+        afterEach(function () {
+            Display.changeCursor = this._old_change_cursor;
+        });
+    });
+
     describe('viewport handling', function () {
         var display;
         beforeEach(function () {