Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($$RAFProvider): check for webkitCancelRequestAnimationFrame
Browse files Browse the repository at this point in the history
Android 4.3 only supports webkitCancelRequestAnimationFrame.

Closes #6526
  • Loading branch information
Traxmaxx authored and matsko committed Mar 19, 2014
1 parent 3dd9572 commit e84da22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/ng/raf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions test/ng/rafSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}]);

Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit e84da22

Please sign in to comment.