From c839f78b8f2d8d910bc2bfc9e41b3e3b67090ec1 Mon Sep 17 00:00:00 2001 From: Traxmaxx Date: Tue, 4 Mar 2014 18:54:08 +0100 Subject: [PATCH] fix($$RAFProvider): check for webkitCancelRequestAnimationFrame Android 4.3 only supports webkitCancelRequestAnimationFrame. Closes #6526 --- src/ng/raf.js | 3 ++- test/ng/rafSpec.js | 32 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) 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(); + }); + }); });