| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  | import {Injector, IOsDriverExtension, WebDriverAdapter, WebDriverExtension} from '../../index'; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | import {TraceEventFactory} from '../trace_event_factory'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:42:55 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   describe('ios driver extension', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     let log: any[]; | 
					
						
							|  |  |  |     let extension: IOsDriverExtension; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const normEvents = new TraceEventFactory('timeline', 'pid0'); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     function createExtension(perfRecords: any[]|null = null): WebDriverExtension { | 
					
						
							| 
									
										
										
										
											2016-09-30 09:26:53 -07:00
										 |  |  |       if (!perfRecords) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |         perfRecords = []; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       log = []; | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |       extension = | 
					
						
							| 
									
										
											  
											
												perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js:  105,864(34,190 gzip)
    Static: bundle.js:  154,889(33,555 gzip)
                            645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
  MyClass,
  {provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
  {provide: MyClass, deps: [Dep1,...]},
  {provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
  `Injector.create` as a replacement.
closes #18496
											
										 
											2017-08-03 12:33:29 -07:00
										 |  |  |           Injector | 
					
						
							|  |  |  |               .create([ | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |                 IOsDriverExtension.PROVIDERS, | 
					
						
							|  |  |  |                 {provide: WebDriverAdapter, useValue: new MockDriverAdapter(log, perfRecords)} | 
					
						
							|  |  |  |               ]) | 
					
						
							|  |  |  |               .get(IOsDriverExtension); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |       return extension; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw on forcing gc', () => { | 
					
						
							|  |  |  |       expect(() => createExtension().gc()).toThrowError('Force GC is not supported on iOS'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 22:16:02 +02:00
										 |  |  |     it('should mark the timeline via console.time()', done => { | 
					
						
							|  |  |  |       createExtension().timeBegin('someName').then((_) => { | 
					
						
							|  |  |  |         expect(log).toEqual([['executeScript', `console.time('someName');`]]); | 
					
						
							|  |  |  |         done(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should mark the timeline via console.timeEnd()', done => { | 
					
						
							|  |  |  |       createExtension().timeEnd('someName', null).then((_) => { | 
					
						
							|  |  |  |         expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]); | 
					
						
							|  |  |  |         done(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should mark the timeline via console.time() and console.timeEnd()', done => { | 
					
						
							|  |  |  |       createExtension().timeEnd('name1', 'name2').then((_) => { | 
					
						
							|  |  |  |         expect(log).toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]); | 
					
						
							|  |  |  |         done(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('readPerfLog', () => { | 
					
						
							| 
									
										
										
										
											2021-05-23 22:16:02 +02:00
										 |  |  |       it('should execute a dummy script before reading them', done => { | 
					
						
							|  |  |  |         // TODO(tbosch): This seems to be a bug in ChromeDriver:
 | 
					
						
							|  |  |  |         // Sometimes it does not report the newest events of the performance log
 | 
					
						
							|  |  |  |         // to the WebDriver client unless a script is executed...
 | 
					
						
							|  |  |  |         createExtension([]).readPerfLog().then((_) => { | 
					
						
							|  |  |  |           expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]); | 
					
						
							|  |  |  |           done(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should report FunctionCall records as "script"', done => { | 
					
						
							|  |  |  |         createExtension([durationRecord('FunctionCall', 1, 5)]).readPerfLog().then((events) => { | 
					
						
							|  |  |  |           expect(events).toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]); | 
					
						
							|  |  |  |           done(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should ignore FunctionCalls from webdriver', done => { | 
					
						
							|  |  |  |         createExtension([internalScriptRecord(1, 5)]).readPerfLog().then((events) => { | 
					
						
							|  |  |  |           expect(events).toEqual([]); | 
					
						
							|  |  |  |           done(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should report begin time', done => { | 
					
						
							|  |  |  |         createExtension([timeBeginRecord('someName', 12)]).readPerfLog().then((events) => { | 
					
						
							|  |  |  |           expect(events).toEqual([normEvents.markStart('someName', 12)]); | 
					
						
							|  |  |  |           done(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should report end timestamps', done => { | 
					
						
							|  |  |  |         createExtension([timeEndRecord('someName', 12)]).readPerfLog().then((events) => { | 
					
						
							|  |  |  |           expect(events).toEqual([normEvents.markEnd('someName', 12)]); | 
					
						
							|  |  |  |           done(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       ['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers'] | 
					
						
							|  |  |  |           .forEach((recordType) => { | 
					
						
							| 
									
										
										
										
											2021-05-23 22:16:02 +02:00
										 |  |  |             it(`should report ${recordType}`, done => { | 
					
						
							|  |  |  |               createExtension([durationRecord(recordType, 0, 1)]).readPerfLog().then((events) => { | 
					
						
							|  |  |  |                 expect(events).toEqual([ | 
					
						
							|  |  |  |                   normEvents.start('render', 0), | 
					
						
							|  |  |  |                   normEvents.end('render', 1), | 
					
						
							|  |  |  |                 ]); | 
					
						
							|  |  |  |                 done(); | 
					
						
							|  |  |  |               }); | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 22:16:02 +02:00
										 |  |  |       it('should walk children', done => { | 
					
						
							|  |  |  |         createExtension([durationRecord('FunctionCall', 1, 5, [timeBeginRecord('someName', 2)])]) | 
					
						
							|  |  |  |             .readPerfLog() | 
					
						
							|  |  |  |             .then((events) => { | 
					
						
							|  |  |  |               expect(events).toEqual([ | 
					
						
							|  |  |  |                 normEvents.start('script', 1), normEvents.markStart('someName', 2), | 
					
						
							|  |  |  |                 normEvents.end('script', 5) | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |               done(); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should match safari browsers', () => { | 
					
						
							|  |  |  |         expect(createExtension().supports({'browserName': 'safari'})).toBe(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(createExtension().supports({'browserName': 'Safari'})).toBe(true); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  | function timeBeginRecord(name: string, time: number) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   return {'type': 'Time', 'startTime': time, 'data': {'message': name}}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  | function timeEndRecord(name: string, time: number) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   return {'type': 'TimeEnd', 'startTime': time, 'data': {'message': name}}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-24 09:56:50 -07:00
										 |  |  | function durationRecord( | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     type: string, startTime: number, endTime: number, children: any[]|null = null) { | 
					
						
							| 
									
										
										
										
											2016-09-30 09:26:53 -07:00
										 |  |  |   if (!children) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |     children = []; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return {'type': type, 'startTime': startTime, 'endTime': endTime, 'children': children}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  | function internalScriptRecord(startTime: number, endTime: number) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   return { | 
					
						
							|  |  |  |     'type': 'FunctionCall', | 
					
						
							|  |  |  |     'startTime': startTime, | 
					
						
							|  |  |  |     'endTime': endTime, | 
					
						
							|  |  |  |     'data': {'scriptName': 'InjectedScript'} | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockDriverAdapter extends WebDriverAdapter { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   constructor(private _log: any[], private _perfRecords: any[]) { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |   executeScript(script: string) { | 
					
						
							| 
									
										
										
										
											2015-06-17 11:17:21 -07:00
										 |  |  |     this._log.push(['executeScript', script]); | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     return Promise.resolve(null); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-24 09:56:50 -07:00
										 |  |  |   logs(type: string): Promise<any[]> { | 
					
						
							| 
									
										
										
										
											2015-06-17 11:17:21 -07:00
										 |  |  |     this._log.push(['logs', type]); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |     if (type === 'performance') { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |       return Promise.resolve(this._perfRecords.map(function(record) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |         return { | 
					
						
							| 
									
										
										
										
											2016-10-19 13:42:39 -07:00
										 |  |  |           'message': JSON.stringify( | 
					
						
							|  |  |  |               {'message': {'method': 'Timeline.eventRecorded', 'params': {'record': record}}}, null, | 
					
						
							|  |  |  |               2) | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |         }; | 
					
						
							|  |  |  |       })); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |       return null!; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |