| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 18:10:09 +03:00
										 |  |  | import {AsyncTestCompleter, describe, expect, fit, inject, it} from '@angular/core/testing/src/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | import {ChromeDriverExtension, Injector, Options, 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('chrome driver extension', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const CHROME45_USER_AGENT = | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |         '"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2499.0 Safari/537.36"'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     let log: any[]; | 
					
						
							|  |  |  |     let extension: ChromeDriverExtension; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const blinkEvents = new TraceEventFactory('blink.console', 'pid0'); | 
					
						
							|  |  |  |     const v8Events = new TraceEventFactory('v8', 'pid0'); | 
					
						
							|  |  |  |     const v8EventsOtherProcess = new TraceEventFactory('v8', 'pid1'); | 
					
						
							|  |  |  |     const chromeTimelineEvents = | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |         new TraceEventFactory('disabled-by-default-devtools.timeline', 'pid0'); | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const chrome45TimelineEvents = new TraceEventFactory('devtools.timeline', 'pid0'); | 
					
						
							|  |  |  |     const chromeTimelineV8Events = new TraceEventFactory('devtools.timeline,v8', 'pid0'); | 
					
						
							|  |  |  |     const chromeBlinkTimelineEvents = new TraceEventFactory('blink,devtools.timeline', 'pid0'); | 
					
						
							|  |  |  |     const chromeBlinkUserTimingEvents = new TraceEventFactory('blink.user_timing', 'pid0'); | 
					
						
							|  |  |  |     const benchmarkEvents = new TraceEventFactory('benchmark', 'pid0'); | 
					
						
							|  |  |  |     const normEvents = new TraceEventFactory('timeline', 'pid0'); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |     function createExtension( | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |         perfRecords: any[]|null = null, userAgent: string|null = null, | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |         messageMethod = 'Tracing.dataCollected'): WebDriverExtension { | 
					
						
							| 
									
										
										
										
											2016-09-30 09:26:53 -07:00
										 |  |  |       if (!perfRecords) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |         perfRecords = []; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-03-02 09:37:01 -08:00
										 |  |  |       if (userAgent == null) { | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |         userAgent = CHROME45_USER_AGENT; | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |       log = []; | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |       extension = Injector | 
					
						
							|  |  |  |                       .create([ | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |                         ChromeDriverExtension.PROVIDERS, { | 
					
						
							|  |  |  |                           provide: WebDriverAdapter, | 
					
						
							|  |  |  |                           useValue: new MockDriverAdapter(log, perfRecords, messageMethod) | 
					
						
							|  |  |  |                         }, | 
					
						
							| 
									
										
										
										
											2018-12-07 10:23:43 -08:00
										 |  |  |                         {provide: Options.USER_AGENT, useValue: userAgent}, | 
					
						
							|  |  |  |                         {provide: Options.RAW_PERFLOG_PATH, useValue: null} | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |                       ]) | 
					
						
							|  |  |  |                       .get(ChromeDriverExtension); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |       return extension; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |     it('should force gc via window.gc()', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |          createExtension().gc().then((_) => { | 
					
						
							|  |  |  |            expect(log).toEqual([['executeScript', 'window.gc()']]); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |     it('should clear the perf logs and mark the timeline via performance.mark() on the first call', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2017-04-17 09:18:35 -07:00
										 |  |  |          createExtension().timeBegin('someName').then(() => { | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |            expect(log).toEqual([ | 
					
						
							|  |  |  |              ['logs', 'performance'], ['executeScript', `performance.mark('someName-bpstart');`] | 
					
						
							|  |  |  |            ]); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |     it('should mark the timeline via performance.mark() on the second call', | 
					
						
							| 
									
										
										
										
											2017-04-17 09:18:35 -07:00
										 |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          const ext = createExtension(); | 
					
						
							|  |  |  |          ext.timeBegin('someName') | 
					
						
							|  |  |  |              .then((_) => { | 
					
						
							|  |  |  |                log.splice(0, log.length); | 
					
						
							|  |  |  |                ext.timeBegin('someName'); | 
					
						
							|  |  |  |              }) | 
					
						
							|  |  |  |              .then(() => { | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |                expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]); | 
					
						
							| 
									
										
										
										
											2017-04-17 09:18:35 -07:00
										 |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |     it('should mark the timeline via performance.mark()', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |          createExtension().timeEnd('someName', null).then((_) => { | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |            expect(log).toEqual([['executeScript', `performance.mark('someName-bpend');`]]); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 13:58:00 -07:00
										 |  |  |     it('should mark the timeline via performance.mark() with start and end of a test', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |          createExtension().timeEnd('name1', 'name2').then((_) => { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |            expect(log).toEqual([ | 
					
						
							|  |  |  |              ['executeScript', `performance.mark('name1-bpend');performance.mark('name2-bpstart');`] | 
					
						
							|  |  |  |            ]); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should normalize times to ms and forward ph and pid event properties', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension([chromeTimelineV8Events.complete('FunctionCall', 1100, 5500, null)]) | 
					
						
							|  |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([ | 
					
						
							|  |  |  |                  normEvents.complete('script', 1.1, 5.5, null), | 
					
						
							|  |  |  |                ]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should normalize "tdur" to "dur"', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |          const event: any = chromeTimelineV8Events.create('X', 'FunctionCall', 1100, null); | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |          event['tdur'] = 5500; | 
					
						
							|  |  |  |          createExtension([event]).readPerfLog().then((events) => { | 
					
						
							|  |  |  |            expect(events).toEqual([ | 
					
						
							|  |  |  |              normEvents.complete('script', 1.1, 5.5, null), | 
					
						
							|  |  |  |            ]); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should report FunctionCall events as "script"', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension([chromeTimelineV8Events.start('FunctionCall', 0)]) | 
					
						
							|  |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([ | 
					
						
							|  |  |  |                  normEvents.start('script', 0), | 
					
						
							|  |  |  |                ]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 08:51:55 -07:00
										 |  |  |     it('should report EvaluateScript events as "script"', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension([chromeTimelineV8Events.start('EvaluateScript', 0)]) | 
					
						
							|  |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([ | 
					
						
							|  |  |  |                  normEvents.start('script', 0), | 
					
						
							|  |  |  |                ]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should report minor gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension([ | 
					
						
							|  |  |  |            chromeTimelineV8Events.start('MinorGC', 1000, {'usedHeapSizeBefore': 1000}), | 
					
						
							|  |  |  |            chromeTimelineV8Events.end('MinorGC', 2000, {'usedHeapSizeAfter': 0}), | 
					
						
							|  |  |  |          ]) | 
					
						
							|  |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events.length).toEqual(2); | 
					
						
							|  |  |  |                expect(events[0]).toEqual( | 
					
						
							|  |  |  |                    normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': false})); | 
					
						
							|  |  |  |                expect(events[1]).toEqual( | 
					
						
							|  |  |  |                    normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': false})); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should report major gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension( | 
					
						
							|  |  |  |              [ | 
					
						
							|  |  |  |                chromeTimelineV8Events.start('MajorGC', 1000, {'usedHeapSizeBefore': 1000}), | 
					
						
							|  |  |  |                chromeTimelineV8Events.end('MajorGC', 2000, {'usedHeapSizeAfter': 0}), | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |              ], | 
					
						
							|  |  |  |              ) | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events.length).toEqual(2); | 
					
						
							|  |  |  |                expect(events[0]).toEqual( | 
					
						
							|  |  |  |                    normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': true})); | 
					
						
							|  |  |  |                expect(events[1]).toEqual( | 
					
						
							|  |  |  |                    normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': true})); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     ['Layout', 'UpdateLayerTree', 'Paint'].forEach((recordType) => { | 
					
						
							|  |  |  |       it(`should report ${recordType} as "render"`, | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |            createExtension( | 
					
						
							|  |  |  |                [ | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |                  chrome45TimelineEvents.start(recordType, 1234), | 
					
						
							|  |  |  |                  chrome45TimelineEvents.end(recordType, 2345) | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                ], | 
					
						
							|  |  |  |                ) | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |                .readPerfLog() | 
					
						
							|  |  |  |                .then((events) => { | 
					
						
							|  |  |  |                  expect(events).toEqual([ | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |                    normEvents.start('render', 1.234), | 
					
						
							|  |  |  |                    normEvents.end('render', 2.345), | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |                  ]); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it(`should report UpdateLayoutTree as "render"`, | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension( | 
					
						
							|  |  |  |              [ | 
					
						
							|  |  |  |                chromeBlinkTimelineEvents.start('UpdateLayoutTree', 1234), | 
					
						
							|  |  |  |                chromeBlinkTimelineEvents.end('UpdateLayoutTree', 2345) | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |              ], | 
					
						
							|  |  |  |              ) | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([ | 
					
						
							|  |  |  |                  normEvents.start('render', 1.234), | 
					
						
							|  |  |  |                  normEvents.end('render', 2.345), | 
					
						
							|  |  |  |                ]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should ignore FunctionCalls from webdriver', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension([chromeTimelineV8Events.start( | 
					
						
							|  |  |  |                              'FunctionCall', 0, {'data': {'scriptName': 'InjectedScript'}})]) | 
					
						
							|  |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-09 13:40:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should ignore FunctionCalls with empty scriptName', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |          createExtension( | 
					
						
							|  |  |  |              [chromeTimelineV8Events.start('FunctionCall', 0, {'data': {'scriptName': ''}})]) | 
					
						
							|  |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should report navigationStart', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-09-15 08:51:55 -07:00
										 |  |  |          createExtension([chromeBlinkUserTimingEvents.instant('navigationStart', 1234)]) | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							| 
									
										
										
										
											2016-09-15 08:51:55 -07:00
										 |  |  |                expect(events).toEqual([normEvents.instant('navigationStart', 1.234)]); | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-12-10 01:15:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |     it('should report receivedData', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |          createExtension( | 
					
						
							|  |  |  |              [chrome45TimelineEvents.instant( | 
					
						
							|  |  |  |                  'ResourceReceivedData', 1234, {'data': {'encodedDataLength': 987}})], | 
					
						
							|  |  |  |              ) | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual( | 
					
						
							|  |  |  |                    [normEvents.instant('receivedData', 1.234, {'encodedDataLength': 987})]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should report sendRequest', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |          createExtension( | 
					
						
							|  |  |  |              [chrome45TimelineEvents.instant( | 
					
						
							|  |  |  |                  'ResourceSendRequest', 1234, | 
					
						
							|  |  |  |                  {'data': {'url': 'http://here', 'requestMethod': 'GET'}})], | 
					
						
							|  |  |  |              ) | 
					
						
							| 
									
										
										
										
											2016-09-15 07:49:05 -07:00
										 |  |  |              .readPerfLog() | 
					
						
							|  |  |  |              .then((events) => { | 
					
						
							|  |  |  |                expect(events).toEqual([normEvents.instant( | 
					
						
							|  |  |  |                    'sendRequest', 1.234, {'url': 'http://here', 'method': 'GET'})]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('readPerfLog (common)', () => { | 
					
						
							|  |  |  |       it('should execute a dummy script before reading them', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |            // 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']]); | 
					
						
							|  |  |  |              async.done(); | 
					
						
							|  |  |  |            }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ['Rasterize', 'CompositeLayers'].forEach((recordType) => { | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |         it(`should report ${recordType} as "render"`, | 
					
						
							|  |  |  |            inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |              createExtension( | 
					
						
							|  |  |  |                  [ | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |                    chromeTimelineEvents.start(recordType, 1234), | 
					
						
							|  |  |  |                    chromeTimelineEvents.end(recordType, 2345) | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                  ], | 
					
						
							|  |  |  |                  ) | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |                  .readPerfLog() | 
					
						
							|  |  |  |                  .then((events) => { | 
					
						
							|  |  |  |                    expect(events).toEqual([ | 
					
						
							|  |  |  |                      normEvents.start('render', 1.234), | 
					
						
							|  |  |  |                      normEvents.end('render', 2.345), | 
					
						
							|  |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('frame metrics', () => { | 
					
						
							|  |  |  |         it('should report ImplThreadRenderingStats as frame event', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |            inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |              createExtension([benchmarkEvents.instant( | 
					
						
							|  |  |  |                                  'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100, | 
					
						
							|  |  |  |                                  {'data': {'frame_count': 1}})]) | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |                  .readPerfLog() | 
					
						
							|  |  |  |                  .then((events) => { | 
					
						
							|  |  |  |                    expect(events).toEqual([ | 
					
						
							| 
									
										
										
										
											2016-09-15 08:51:55 -07:00
										 |  |  |                      normEvents.instant('frame', 1.1), | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should not report ImplThreadRenderingStats with zero frames', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |            inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |              createExtension([benchmarkEvents.instant( | 
					
						
							|  |  |  |                                  'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100, | 
					
						
							|  |  |  |                                  {'data': {'frame_count': 0}})]) | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |                  .readPerfLog() | 
					
						
							|  |  |  |                  .then((events) => { | 
					
						
							|  |  |  |                    expect(events).toEqual([]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should throw when ImplThreadRenderingStats contains more than one frame', | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |            inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |              createExtension([benchmarkEvents.instant( | 
					
						
							|  |  |  |                                  'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100, | 
					
						
							|  |  |  |                                  {'data': {'frame_count': 2}})]) | 
					
						
							|  |  |  |                  .readPerfLog() | 
					
						
							|  |  |  |                  .catch((err): any => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |                    expect(() => { | 
					
						
							|  |  |  |                      throw err; | 
					
						
							|  |  |  |                    }).toThrowError('multi-frame render stats not supported'); | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |       it('should report begin timestamps', | 
					
						
							|  |  |  |          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |            createExtension([blinkEvents.create('S', 'someName', 1000)]) | 
					
						
							|  |  |  |                .readPerfLog() | 
					
						
							|  |  |  |                .then((events) => { | 
					
						
							|  |  |  |                  expect(events).toEqual([normEvents.markStart('someName', 1.0)]); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |       it('should report end timestamps', | 
					
						
							|  |  |  |          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-09-03 11:48:24 -07:00
										 |  |  |            createExtension([blinkEvents.create('F', 'someName', 1000)]) | 
					
						
							|  |  |  |                .readPerfLog() | 
					
						
							|  |  |  |                .then((events) => { | 
					
						
							|  |  |  |                  expect(events).toEqual([normEvents.markEnd('someName', 1.0)]); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |       it('should throw an error on buffer overflow', | 
					
						
							|  |  |  |          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |            createExtension( | 
					
						
							|  |  |  |                [ | 
					
						
							|  |  |  |                  chromeTimelineEvents.start('FunctionCall', 1234), | 
					
						
							|  |  |  |                ], | 
					
						
							|  |  |  |                CHROME45_USER_AGENT, 'Tracing.bufferUsage') | 
					
						
							|  |  |  |                .readPerfLog() | 
					
						
							|  |  |  |                .catch((err): any => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |                  expect(() => { | 
					
						
							|  |  |  |                    throw err; | 
					
						
							|  |  |  |                  }).toThrowError('The DevTools trace buffer filled during the test!'); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should match chrome browsers', () => { | 
					
						
							|  |  |  |         expect(createExtension().supports({'browserName': 'chrome'})).toBe(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(createExtension().supports({'browserName': 'Chrome'})).toBe(true); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockDriverAdapter extends WebDriverAdapter { | 
					
						
							| 
									
										
										
										
											2015-08-28 11:29:19 -07:00
										 |  |  |   constructor(private _log: any[], private _events: any[], private _messageMethod: string) { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |     super(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-10-04 15:57:37 -07:00
										 |  |  |       return Promise.resolve(this._events.map( | 
					
						
							|  |  |  |           (event) => ({ | 
					
						
							| 
									
										
										
										
											2016-10-19 13:42:39 -07:00
										 |  |  |             'message': JSON.stringify( | 
					
						
							|  |  |  |                 {'message': {'method': this._messageMethod, 'params': event}}, null, 2) | 
					
						
							| 
									
										
										
										
											2016-10-04 15:57:37 -07:00
										 |  |  |           }))); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |