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

Commit 886f67d

Browse files
committed
fix: support mozRequestAnimationFrame
1 parent 3a27502 commit 886f67d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

test/patch/requestAnimationFrame.spec.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,57 @@ describe('requestAnimationFrame', function () {
5151
});
5252
});
5353

54+
describe('mozRequestAnimationFrame', function () {
55+
var flag, hasParent, skip = false;
56+
57+
it('should work', function (done) {
58+
59+
if (!window.mozRequestAnimationFrame) {
60+
console.log('WARNING: skipping mozRequestAnimationFrame test (missing this API)');
61+
return;
62+
}
63+
64+
// Some browsers (especially Safari) do not fire mozRequestAnimationFrame
65+
// if they are offscreen. We can disable this test for those browsers and
66+
// assume the patch works if setTimeout works, since they are mechanically
67+
// the same
68+
runs(function() {
69+
flag = false;
70+
window.mozRequestAnimationFrame(function () {
71+
flag = true;
72+
});
73+
setTimeout(function () {
74+
skip = true;
75+
flag = true;
76+
console.log('WARNING: skipping mozRequestAnimationFrame test (not firing rAF)');
77+
}, 50);
78+
});
79+
80+
waitsFor(function() {
81+
return flag;
82+
}, 'mozRequestAnimationFrame to run', 100);
83+
84+
runs(function() {
85+
flag = false;
86+
hasParent = false;
87+
88+
window.mozRequestAnimationFrame(function () {
89+
hasParent = !!window.zone.parent;
90+
flag = true;
91+
});
92+
});
93+
94+
waitsFor(function() {
95+
return flag || skip;
96+
}, 'mozRequestAnimationFrame to run', 100);
97+
98+
runs(function() {
99+
expect(hasParent || skip).toBe(true);
100+
});
101+
102+
});
103+
});
104+
54105
describe('webkitRequestAnimationFrame', function () {
55106
var flag, hasParent, skip = false;
56107

@@ -100,4 +151,4 @@ describe('webkitRequestAnimationFrame', function () {
100151
});
101152

102153
});
103-
});
154+
});

zone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ Zone.patch = function patch () {
309309

310310
Zone.patchSetFn(window, [
311311
'requestAnimationFrame',
312+
'mozRequestAnimationFrame',
312313
'webkitRequestAnimationFrame'
313314
]);
314315

0 commit comments

Comments
 (0)