diff options
author | wout <wout@impinc.co.uk> | 2014-09-03 12:15:16 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-09-03 12:15:16 +0200 |
commit | 69da2d385450daa158d75ebe59449cc044ec8022 (patch) | |
tree | 94d13794806978d4a8ca4d50ac0323b7d93475b7 /spec | |
parent | 826649995f1aae806fb9bf8464a4259c4290c4fb (diff) | |
download | svg.js-69da2d385450daa158d75ebe59449cc044ec8022.tar.gz svg.js-69da2d385450daa158d75ebe59449cc044ec8022.zip |
Firefox fixes and event specs
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/index.html | 1 | ||||
-rw-r--r-- | spec/spec/event.js | 246 | ||||
-rwxr-xr-x | spec/spec/helper.js | 23 |
3 files changed, 270 insertions, 0 deletions
diff --git a/spec/index.html b/spec/index.html index 21b3ba5..ccd8e4a 100755 --- a/spec/index.html +++ b/spec/index.html @@ -56,6 +56,7 @@ <script src="spec/element.js"></script> <script src="spec/memory.js"></script> <script src="spec/arrange.js"></script> +<script src="spec/event.js"></script> <script src="spec/bbox.js"></script> <script src="spec/matrix.js"></script> <script src="spec/rect.js"></script> diff --git a/spec/spec/event.js b/spec/spec/event.js new file mode 100644 index 0000000..f6c271e --- /dev/null +++ b/spec/spec/event.js @@ -0,0 +1,246 @@ +describe('Event', function() { + var rect, toast, context + , action = function() { + toast = 'ready' + context = this + } + + beforeEach(function() { + rect = draw.rect(100, 100) + }) + + afterEach(function() { + toast = context = null + }) + + if (!window.isTouchDevice) { + + describe('click()', function() { + it('attaches an onclick event to the node of the element', function() { + expect(typeof rect.node.onclick).not.toBe('function') + rect.click(action) + expect(typeof rect.node.onclick).toBe('function') + }) + it('fires the event on click', function() { + dispatchEvent(rect.click(action), 'click') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.click(action), 'click') + expect(context).toBe(rect) + }) + }) + + describe('dblclick()', function() { + it('attaches an ondblclick event to the node of the element', function() { + expect(typeof rect.node.ondblclick).not.toBe('function') + rect.dblclick(action) + expect(typeof rect.node.ondblclick).toBe('function') + }) + it('fires the event on dblclick', function() { + dispatchEvent(rect.dblclick(action), 'dblclick') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.dblclick(action), 'dblclick') + expect(context).toBe(rect) + }) + }) + + describe('mousedown()', function() { + it('attaches an onmousedown event to the node of the element', function() { + expect(typeof rect.node.onmousedown).not.toBe('function') + rect.mousedown(action) + expect(typeof rect.node.onmousedown).toBe('function') + }) + it('fires the event on mousedown', function() { + dispatchEvent(rect.mousedown(action), 'mousedown') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mousedown(action), 'mousedown') + expect(context).toBe(rect) + }) + }) + + describe('mouseup()', function() { + it('attaches an onmouseup event to the node of the element', function() { + expect(typeof rect.node.onmouseup).not.toBe('function') + rect.mouseup(action) + expect(typeof rect.node.onmouseup).toBe('function') + }) + it('fires the event on mouseup', function() { + dispatchEvent(rect.mouseup(action), 'mouseup') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mouseup(action), 'mouseup') + expect(context).toBe(rect) + }) + }) + + describe('mouseover()', function() { + it('attaches an onmouseover event to the node of the element', function() { + expect(typeof rect.node.onmouseover).not.toBe('function') + rect.mouseover(action) + expect(typeof rect.node.onmouseover).toBe('function') + }) + it('fires the event on mouseover', function() { + dispatchEvent(rect.mouseover(action), 'mouseover') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mouseover(action), 'mouseover') + expect(context).toBe(rect) + }) + }) + + describe('mouseout()', function() { + it('attaches an onmouseout event to the node of the element', function() { + expect(typeof rect.node.onmouseout).not.toBe('function') + rect.mouseout(action) + expect(typeof rect.node.onmouseout).toBe('function') + }) + it('fires the event on mouseout', function() { + dispatchEvent(rect.mouseout(action), 'mouseout') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mouseout(action), 'mouseout') + expect(context).toBe(rect) + }) + }) + + describe('mousemove()', function() { + it('attaches an onmousemove event to the node of the element', function() { + expect(typeof rect.node.onmousemove).not.toBe('function') + rect.mousemove(action) + expect(typeof rect.node.onmousemove).toBe('function') + }) + it('fires the event on mousemove', function() { + dispatchEvent(rect.mousemove(action), 'mousemove') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mousemove(action), 'mousemove') + expect(context).toBe(rect) + }) + }) + + describe('mouseenter()', function() { + it('attaches an onmouseenter event to the node of the element', function() { + expect(typeof rect.node.onmouseenter).not.toBe('function') + rect.mouseenter(action) + expect(typeof rect.node.onmouseenter).toBe('function') + }) + it('fires the event on mouseenter', function() { + dispatchEvent(rect.mouseenter(action), 'mouseenter') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mouseenter(action), 'mouseenter') + expect(context).toBe(rect) + }) + }) + + describe('mouseleave()', function() { + it('attaches an onmouseleave event to the node of the element', function() { + expect(typeof rect.node.onmouseleave).not.toBe('function') + rect.mouseleave(action) + expect(typeof rect.node.onmouseleave).toBe('function') + }) + it('fires the event on mouseleave', function() { + dispatchEvent(rect.mouseleave(action), 'mouseleave') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.mouseleave(action), 'mouseleave') + expect(context).toBe(rect) + }) + }) + + } else { + + describe('touchstart()', function() { + it('attaches an ontouchstart event to the node of the element', function() { + expect(typeof rect.node.ontouchstart).not.toBe('function') + rect.touchstart(action) + expect(typeof rect.node.ontouchstart).toBe('function') + }) + it('fires the event on touchstart', function() { + dispatchEvent(rect.touchstart(action), 'touchstart') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.touchstart(action), 'touchstart') + expect(context).toBe(rect) + }) + }) + + describe('touchmove()', function() { + it('attaches an ontouchmove event to the node of the element', function() { + expect(typeof rect.node.ontouchmove).not.toBe('function') + rect.touchmove(action) + expect(typeof rect.node.ontouchmove).toBe('function') + }) + it('fires the event on touchmove', function() { + dispatchEvent(rect.touchmove(action), 'touchmove') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.touchmove(action), 'touchmove') + expect(context).toBe(rect) + }) + }) + + describe('touchleave()', function() { + it('attaches an ontouchleave event to the node of the element', function() { + expect(typeof rect.node.ontouchleave).not.toBe('function') + rect.touchleave(action) + expect(typeof rect.node.ontouchleave).toBe('function') + }) + it('fires the event on touchleave', function() { + dispatchEvent(rect.touchleave(action), 'touchleave') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.touchleave(action), 'touchleave') + expect(context).toBe(rect) + }) + }) + + describe('touchend()', function() { + it('attaches an ontouchend event to the node of the element', function() { + expect(typeof rect.node.ontouchend).not.toBe('function') + rect.touchend(action) + expect(typeof rect.node.ontouchend).toBe('function') + }) + it('fires the event on touchend', function() { + dispatchEvent(rect.touchend(action), 'touchend') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.touchend(action), 'touchend') + expect(context).toBe(rect) + }) + }) + + describe('touchcancel()', function() { + it('attaches an ontouchcancel event to the node of the element', function() { + expect(typeof rect.node.ontouchcancel).not.toBe('function') + rect.touchcancel(action) + expect(typeof rect.node.ontouchcancel).toBe('function') + }) + it('fires the event on touchcancel', function() { + dispatchEvent(rect.touchcancel(action), 'touchcancel') + expect(toast).toBe('ready') + }) + it('applies the element as context', function() { + dispatchEvent(rect.touchcancel(action), 'touchcancel') + expect(context).toBe(rect) + }) + }) + + } + +})
\ No newline at end of file diff --git a/spec/spec/helper.js b/spec/spec/helper.js index a02d751..9cd88cd 100755 --- a/spec/spec/helper.js +++ b/spec/spec/helper.js @@ -13,7 +13,30 @@ imageUrl = '' // lorem ipsum text loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sodales\n imperdiet auctor. Nunc ultrices lectus at erat dictum pharetra\n elementum ante posuere. Duis turpis risus, blandit nec elementum et,\n posuere eget lacus. Aliquam et risus magna, eu aliquet nibh. Fusce\n consequat mi quis purus varius sagittis euismod urna interdum.\n Curabitur aliquet orci quis felis semper vulputate. Vestibulum ac nisi\n magna, id dictum diam. Proin sed metus vel magna blandit\n sodales. Pellentesque at neque ultricies nunc euismod rutrum ut in\n lorem. Mauris euismod tellus in tellus tempus interdum. Phasellus\n mattis sapien et leo feugiat dictum. Vestibulum at volutpat velit.' +// test for touch device +window.isTouchDevice = 'ontouchstart' in document.documentElement + // strip spaces from result function stripped(string) { return string.replace(/\s+/g, '') +} + +// dispatch an event +function dispatchEvent(element, name) { + var e + + if (document.createEvent) { + e = document.createEvent('HTMLEvents') + e.initEvent(name, true, true) + } else { + e = document.createEventObject() + e.eventType = name + } + + e.eventName = name + + if (document.createEvent) + element.node.dispatchEvent(e) + else + element.node.fireEvent('on' + name, e) }
\ No newline at end of file |