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

fix($$RAFProvider): check for webkitCancelRequestAnimationFrame #6743

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});