2016-08-03 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
import {Injector, OpaqueToken} from '@angular/core';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {Options} from './common_options';
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
export type PerfLogEvent = {
|
2016-09-15 10:49:05 -04:00
|
|
|
[key: string]: any
|
|
|
|
} & {
|
2016-09-15 12:25:45 -04:00
|
|
|
ph?: 'X' | 'B' | 'E' | 'I',
|
2016-08-26 19:34:08 -04:00
|
|
|
ts?: number,
|
|
|
|
dur?: number,
|
|
|
|
name?: string,
|
|
|
|
pid?: string,
|
2016-09-15 12:25:45 -04:00
|
|
|
args?: {
|
|
|
|
encodedDataLength?: number,
|
|
|
|
usedHeapSize?: number,
|
|
|
|
majorGc?: boolean,
|
|
|
|
url?: string,
|
|
|
|
method?: string
|
|
|
|
}
|
2016-08-26 19:34:08 -04:00
|
|
|
};
|
2016-08-03 18:00:07 -04:00
|
|
|
|
2015-05-27 17:57:54 -04:00
|
|
|
/**
|
|
|
|
* A WebDriverExtension implements extended commands of the webdriver protocol
|
|
|
|
* for a given browser, independent of the WebDriverAdapter.
|
|
|
|
* Needs one implementation for every supported Browser.
|
|
|
|
*/
|
2015-09-25 17:48:17 -04:00
|
|
|
export abstract class WebDriverExtension {
|
2016-08-26 19:34:08 -04:00
|
|
|
static provideFirstSupported(childTokens: any[]): any[] {
|
2015-06-26 18:59:18 -04:00
|
|
|
var res = [
|
2016-06-02 20:30:40 -04:00
|
|
|
{
|
|
|
|
provide: _CHILDREN,
|
|
|
|
useFactory: (injector: Injector) => childTokens.map(token => injector.get(token)),
|
|
|
|
deps: [Injector]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: WebDriverExtension,
|
2016-09-09 13:37:47 -04:00
|
|
|
useFactory: (children: WebDriverExtension[], capabilities: {[key: string]: any}) => {
|
2016-08-26 19:34:08 -04:00
|
|
|
var delegate: WebDriverExtension;
|
2016-06-02 20:30:40 -04:00
|
|
|
children.forEach(extension => {
|
|
|
|
if (extension.supports(capabilities)) {
|
|
|
|
delegate = extension;
|
|
|
|
}
|
|
|
|
});
|
2016-09-30 12:26:53 -04:00
|
|
|
if (!delegate) {
|
2016-08-25 03:50:16 -04:00
|
|
|
throw new Error('Could not find a delegate for given capabilities!');
|
2016-06-02 20:30:40 -04:00
|
|
|
}
|
|
|
|
return delegate;
|
|
|
|
},
|
|
|
|
deps: [_CHILDREN, Options.CAPABILITIES]
|
|
|
|
}
|
2015-05-27 17:57:54 -04:00
|
|
|
];
|
2015-06-26 18:59:18 -04:00
|
|
|
return res;
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
2016-08-25 03:50:16 -04:00
|
|
|
gc(): Promise<any> { throw new Error('NYI'); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-25 03:50:16 -04:00
|
|
|
timeBegin(name: string): Promise<any> { throw new Error('NYI'); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-25 03:50:16 -04:00
|
|
|
timeEnd(name: string, restartName: string): Promise<any> { throw new Error('NYI'); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Format:
|
|
|
|
* - cat: category of the event
|
|
|
|
* - name: event name: 'script', 'gc', 'render', ...
|
2016-09-15 12:25:45 -04:00
|
|
|
* - ph: phase: 'B' (begin), 'E' (end), 'X' (Complete event), 'I' (Instant event)
|
2015-05-27 17:57:54 -04:00
|
|
|
* - ts: timestamp in ms, e.g. 12345
|
|
|
|
* - pid: process id
|
|
|
|
* - args: arguments, e.g. {heapSize: 1234}
|
|
|
|
*
|
|
|
|
* Based on [Chrome Trace Event
|
|
|
|
*Format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/edit)
|
|
|
|
**/
|
2016-08-26 19:34:08 -04:00
|
|
|
readPerfLog(): Promise<PerfLogEvent[]> { throw new Error('NYI'); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-25 03:50:16 -04:00
|
|
|
perfLogFeatures(): PerfLogFeatures { throw new Error('NYI'); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
supports(capabilities: {[key: string]: any}): boolean { return true; }
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export class PerfLogFeatures {
|
|
|
|
render: boolean;
|
|
|
|
gc: boolean;
|
2015-06-09 18:19:26 -04:00
|
|
|
frameCapture: boolean;
|
2015-12-09 20:15:55 -05:00
|
|
|
userTiming: boolean;
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2015-12-09 20:15:55 -05:00
|
|
|
constructor(
|
|
|
|
{render = false, gc = false, frameCapture = false, userTiming = false}:
|
|
|
|
{render?: boolean, gc?: boolean, frameCapture?: boolean, userTiming?: boolean} = {}) {
|
2015-05-27 17:57:54 -04:00
|
|
|
this.render = render;
|
|
|
|
this.gc = gc;
|
2015-06-09 18:19:26 -04:00
|
|
|
this.frameCapture = frameCapture;
|
2015-12-09 20:15:55 -05:00
|
|
|
this.userTiming = userTiming;
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _CHILDREN = new OpaqueToken('WebDriverExtension.children');
|