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

Commit

Permalink
fix: support mozRequestAnimationFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed May 30, 2014
1 parent 3a27502 commit 886f67d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
53 changes: 52 additions & 1 deletion test/patch/requestAnimationFrame.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,57 @@ describe('requestAnimationFrame', function () {
});
});

describe('mozRequestAnimationFrame', function () {
var flag, hasParent, skip = false;

it('should work', function (done) {

if (!window.mozRequestAnimationFrame) {
console.log('WARNING: skipping mozRequestAnimationFrame test (missing this API)');
return;
}

// Some browsers (especially Safari) do not fire mozRequestAnimationFrame
// if they are offscreen. We can disable this test for those browsers and
// assume the patch works if setTimeout works, since they are mechanically
// the same
runs(function() {
flag = false;
window.mozRequestAnimationFrame(function () {
flag = true;
});
setTimeout(function () {
skip = true;
flag = true;
console.log('WARNING: skipping mozRequestAnimationFrame test (not firing rAF)');
}, 50);
});

waitsFor(function() {
return flag;
}, 'mozRequestAnimationFrame to run', 100);

runs(function() {
flag = false;
hasParent = false;

window.mozRequestAnimationFrame(function () {
hasParent = !!window.zone.parent;
flag = true;
});
});

waitsFor(function() {
return flag || skip;
}, 'mozRequestAnimationFrame to run', 100);

runs(function() {
expect(hasParent || skip).toBe(true);
});

});
});

describe('webkitRequestAnimationFrame', function () {
var flag, hasParent, skip = false;

Expand Down Expand Up @@ -100,4 +151,4 @@ describe('webkitRequestAnimationFrame', function () {
});

});
});
});
1 change: 1 addition & 0 deletions zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ Zone.patch = function patch () {

Zone.patchSetFn(window, [
'requestAnimationFrame',
'mozRequestAnimationFrame',
'webkitRequestAnimationFrame'
]);

Expand Down

0 comments on commit 886f67d

Please sign in to comment.