diff --git a/src/ng/raf.js b/src/ng/raf.js index e07adbfed5ce..bb1f47ed5e65 100644 --- a/src/ng/raf.js +++ b/src/ng/raf.js @@ -8,7 +8,8 @@ function $$RAFProvider(){ //rAF var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame || - $window.mozCancelAnimationFrame; + $window.mozCancelAnimationFrame || + $window.webkitCancelRequestAnimationFrame; var rafSupported = !!requestAnimationFrame; var raf = rafSupported diff --git a/test/ng/rafSpec.js b/test/ng/rafSpec.js index 8bf76efd03b0..7c67b8c9409f 100644 --- a/test/ng/rafSpec.js +++ b/test/ng/rafSpec.js @@ -38,11 +38,8 @@ describe('$$rAF', function() { //we need to create our own injector to work around the ngMock overrides var injector = createInjector(['ng', function($provide) { $provide.value('$timeout', timeoutSpy); - $provide.decorator('$window', function($delegate) { - $delegate.requestAnimationFrame = false; - $delegate.webkitRequestAnimationFrame = false; - $delegate.mozRequestAnimationFrame = false; - return $delegate; + $provide.value('$window', { + location : window.location, }); }]); @@ -76,4 +73,29 @@ describe('$$rAF', function() { } })); }); + + describe('mobile', function() { + it('should provide a cancellation method for an older version of Android', function() { + //we need to create our own injector to work around the ngMock overrides + var injector = createInjector(['ng', function($provide) { + $provide.value('$window', { + location : window.location, + webkitRequestAnimationFrame: jasmine.createSpy('$window.webkitRequestAnimationFrame'), + webkitCancelRequestAnimationFrame: jasmine.createSpy('$window.webkitCancelRequestAnimationFrame') + }); + }]); + + var $$rAF = injector.get('$$rAF'); + var $window = injector.get('$window'); + var cancel = $$rAF(function() {}); + + expect($$rAF.supported).toBe(true); + + try { + cancel(); + } catch(e) {} + + expect($window.webkitCancelRequestAnimationFrame).toHaveBeenCalled(); + }); + }); });