@@ -253,6 +253,33 @@ describe('CdkDrag', () => {
253253 expect ( mousedownEvent . preventDefault ) . toHaveBeenCalled ( ) ;
254254 } ) ) ;
255255
256+ it ( 'should not start dragging an element with a fake mousedown event' , fakeAsync ( ( ) => {
257+ const fixture = createComponent ( StandaloneDraggable ) ;
258+ fixture . detectChanges ( ) ;
259+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
260+ const event = createMouseEvent ( 'mousedown' , 0 , 0 ) ;
261+
262+ Object . defineProperties ( event , {
263+ offsetX : { get : ( ) => 0 } ,
264+ offsetY : { get : ( ) => 0 }
265+ } ) ;
266+
267+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
268+
269+ dispatchEvent ( dragElement , event ) ;
270+ fixture . detectChanges ( ) ;
271+
272+ dispatchMouseEvent ( document , 'mousemove' , 20 , 100 ) ;
273+ fixture . detectChanges ( ) ;
274+ dispatchMouseEvent ( document , 'mousemove' , 50 , 100 ) ;
275+ fixture . detectChanges ( ) ;
276+
277+ dispatchMouseEvent ( document , 'mouseup' ) ;
278+ fixture . detectChanges ( ) ;
279+
280+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
281+ } ) ) ;
282+
256283 } ) ;
257284
258285 describe ( 'touch dragging' , ( ) => {
@@ -350,6 +377,34 @@ describe('CdkDrag', () => {
350377
351378 expect ( touchstartEvent . preventDefault ) . not . toHaveBeenCalled ( ) ;
352379 } ) ) ;
380+
381+ it ( 'should not start dragging an element with a fake touchstart event' , fakeAsync ( ( ) => {
382+ const fixture = createComponent ( StandaloneDraggable ) ;
383+ fixture . detectChanges ( ) ;
384+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
385+ const event = createTouchEvent ( 'touchstart' , 50 , 50 ) as TouchEvent ;
386+
387+ Object . defineProperties ( event . touches [ 0 ] , {
388+ identifier : { get : ( ) => - 1 } ,
389+ radiusX : { get : ( ) => null } ,
390+ radiusY : { get : ( ) => null }
391+ } ) ;
392+
393+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
394+
395+ dispatchEvent ( dragElement , event ) ;
396+ fixture . detectChanges ( ) ;
397+
398+ dispatchTouchEvent ( document , 'touchmove' , 20 , 100 ) ;
399+ fixture . detectChanges ( ) ;
400+ dispatchTouchEvent ( document , 'touchmove' , 50 , 100 ) ;
401+ fixture . detectChanges ( ) ;
402+
403+ dispatchTouchEvent ( document , 'touchend' ) ;
404+ fixture . detectChanges ( ) ;
405+
406+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
407+ } ) ) ;
353408 } ) ;
354409
355410 it ( 'should dispatch an event when the user has started dragging' , fakeAsync ( ( ) => {
0 commit comments