From f1586a6c3585be94a7ea61d83602dfa60da4ef5c Mon Sep 17 00:00:00 2001 From: Scott Hunter Date: Mon, 8 Dec 2014 16:01:57 -0500 Subject: [PATCH] Ignore any events that bubble up to the document while testing. Avoids triggering the browser's built-in "middle click to scroll" behavior when running specs. --- Specs/Core/ScreenSpaceEventHandlerSpec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Specs/Core/ScreenSpaceEventHandlerSpec.js b/Specs/Core/ScreenSpaceEventHandlerSpec.js index aacb7c918710..36921a4c143e 100644 --- a/Specs/Core/ScreenSpaceEventHandlerSpec.js +++ b/Specs/Core/ScreenSpaceEventHandlerSpec.js @@ -56,7 +56,20 @@ defineSuite([ return cloningSpy; } + var eventsToStop = 'pointerdown pointerup pointermove mousedown mouseup mousemove touchstart touchend touchmove dblclick wheel mousewheel DOMMouseScroll'.split(' '); + + function stop(event) { + event.stopPropagation(); + event.preventDefault(); + } + beforeEach(function() { + // ignore events that bubble up to the document. + // this prevents triggering the browser's "middle click to scroll" behavior + eventsToStop.forEach(function(e) { + document.addEventListener(e, stop, false); + }); + element = document.createElement('div'); element.style.position = 'absolute'; element.style.top = '0'; @@ -74,6 +87,10 @@ defineSuite([ afterEach(function() { document.body.removeChild(element); handler = !handler.isDestroyed() && handler.destroy(); + + eventsToStop.forEach(function(e) { + document.removeEventListener(e, stop, false); + }); }); describe('setInputAction', function() {