| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {ifEnvSupports} from '../test-util'; | 
					
						
							|  |  |  | declare const window: any; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('requestAnimationFrame', function() { | 
					
						
							|  |  |  |   const functions = | 
					
						
							|  |  |  |       ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   functions.forEach(function(fnName) { | 
					
						
							|  |  |  |     describe(fnName, ifEnvSupports(fnName, function() { | 
					
						
							|  |  |  |                const originalTimeout: number = (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL; | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                beforeEach(() => { | 
					
						
							|  |  |  |                  (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 10000; | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                afterEach(() => { | 
					
						
							|  |  |  |                  (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = originalTimeout; | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |                const rAF = window[fnName]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                it('should be tolerant of invalid arguments', function() { | 
					
						
							|  |  |  |                  // rAF throws an error on invalid arguments, so expect that.
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                  expect(function() { | 
					
						
							|  |  |  |                    rAF(null); | 
					
						
							|  |  |  |                  }).toThrow(); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |                }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                it('should bind to same zone when called recursively', function(done) { | 
					
						
							|  |  |  |                  Zone.current.fork({name: 'TestZone'}).run(() => { | 
					
						
							|  |  |  |                    let frames = 0; | 
					
						
							|  |  |  |                    let previousTimeStamp = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    function frameCallback(timestamp: number) { | 
					
						
							|  |  |  |                      expect(timestamp).toMatch(/^[\d.]+$/); | 
					
						
							|  |  |  |                      // expect previous <= current
 | 
					
						
							|  |  |  |                      expect(previousTimeStamp).not.toBeGreaterThan(timestamp); | 
					
						
							|  |  |  |                      previousTimeStamp = timestamp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                      if (frames++ > 15) { | 
					
						
							|  |  |  |                        (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = originalTimeout; | 
					
						
							|  |  |  |                        return done(); | 
					
						
							|  |  |  |                      } | 
					
						
							|  |  |  |                      rAF(frameCallback); | 
					
						
							|  |  |  |                    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    rAF(frameCallback); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |