2015-05-27 17:57:54 -04:00
|
|
|
import {
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2015-11-06 20:34:07 -05:00
|
|
|
import {PromiseWrapper} from 'angular2/src/facade/async';
|
|
|
|
import {Json, isBlank, isPresent} from 'angular2/src/facade/lang';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {
|
|
|
|
WebDriverExtension,
|
|
|
|
IOsDriverExtension,
|
|
|
|
WebDriverAdapter,
|
|
|
|
Injector,
|
2015-10-11 01:11:13 -04:00
|
|
|
bind,
|
|
|
|
provide
|
2015-05-27 17:57:54 -04:00
|
|
|
} from 'benchpress/common';
|
|
|
|
|
|
|
|
import {TraceEventFactory} from '../trace_event_factory';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('ios driver extension', () => {
|
|
|
|
var log;
|
|
|
|
var extension;
|
|
|
|
|
|
|
|
var normEvents = new TraceEventFactory('timeline', 'pid0');
|
|
|
|
|
|
|
|
function createExtension(perfRecords = null) {
|
|
|
|
if (isBlank(perfRecords)) {
|
|
|
|
perfRecords = [];
|
|
|
|
}
|
|
|
|
log = [];
|
2015-10-11 01:11:13 -04:00
|
|
|
extension =
|
|
|
|
Injector.resolveAndCreate([
|
|
|
|
IOsDriverExtension.BINDINGS,
|
2015-10-12 14:30:34 -04:00
|
|
|
provide(WebDriverAdapter, {useValue: new MockDriverAdapter(log, perfRecords)})
|
2015-10-11 01:11:13 -04:00
|
|
|
])
|
|
|
|
.get(IOsDriverExtension);
|
2015-05-27 17:57:54 -04:00
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should throw on forcing gc', () => {
|
|
|
|
expect(() => createExtension().gc()).toThrowError('Force GC is not supported on iOS');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mark the timeline via console.time()', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension()
|
|
|
|
.timeBegin('someName')
|
|
|
|
.then((_) => {
|
|
|
|
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should mark the timeline via console.timeEnd()', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension()
|
|
|
|
.timeEnd('someName')
|
|
|
|
.then((_) => {
|
|
|
|
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should mark the timeline via console.time() and console.timeEnd()',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension()
|
|
|
|
.timeEnd('name1', 'name2')
|
|
|
|
.then((_) => {
|
2015-07-10 05:29:41 -04:00
|
|
|
expect(log)
|
|
|
|
.toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
2015-05-27 17:57:54 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('readPerfLog', () => {
|
|
|
|
|
|
|
|
it('should execute a dummy script before reading them',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
// 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();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should report FunctionCall records as "script"', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension([durationRecord('FunctionCall', 1, 5)])
|
|
|
|
.readPerfLog()
|
|
|
|
.then((events) => {
|
|
|
|
expect(events)
|
|
|
|
.toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should ignore FunctionCalls from webdriver', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension([internalScriptRecord(1, 5)])
|
|
|
|
.readPerfLog()
|
|
|
|
.then((events) => {
|
|
|
|
expect(events).toEqual([]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should report begin time', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension([timeBeginRecord('someName', 12)])
|
|
|
|
.readPerfLog()
|
|
|
|
.then((events) => {
|
|
|
|
expect(events).toEqual([normEvents.markStart('someName', 12)]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should report end timestamps', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension([timeEndRecord('someName', 12)])
|
|
|
|
.readPerfLog()
|
|
|
|
.then((events) => {
|
|
|
|
expect(events).toEqual([normEvents.markEnd('someName', 12)]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers']
|
|
|
|
.forEach((recordType) => {
|
|
|
|
it(`should report ${recordType}`, inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension([durationRecord(recordType, 0, 1)])
|
|
|
|
.readPerfLog()
|
|
|
|
.then((events) => {
|
|
|
|
expect(events).toEqual([
|
|
|
|
normEvents.start('render', 0),
|
|
|
|
normEvents.end('render', 1),
|
|
|
|
]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should walk children', inject([AsyncTestCompleter], (async) => {
|
|
|
|
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)
|
|
|
|
]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should match safari browsers', () => {
|
|
|
|
expect(createExtension().supports({'browserName': 'safari'})).toBe(true);
|
|
|
|
|
|
|
|
expect(createExtension().supports({'browserName': 'Safari'})).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function timeBeginRecord(name, time) {
|
|
|
|
return {'type': 'Time', 'startTime': time, 'data': {'message': name}};
|
|
|
|
}
|
|
|
|
|
|
|
|
function timeEndRecord(name, time) {
|
|
|
|
return {'type': 'TimeEnd', 'startTime': time, 'data': {'message': name}};
|
|
|
|
}
|
|
|
|
|
|
|
|
function durationRecord(type, startTime, endTime, children = null) {
|
|
|
|
if (isBlank(children)) {
|
|
|
|
children = [];
|
|
|
|
}
|
|
|
|
return {'type': type, 'startTime': startTime, 'endTime': endTime, 'children': children};
|
|
|
|
}
|
|
|
|
|
|
|
|
function internalScriptRecord(startTime, endTime) {
|
|
|
|
return {
|
|
|
|
'type': 'FunctionCall',
|
|
|
|
'startTime': startTime,
|
|
|
|
'endTime': endTime,
|
|
|
|
'data': {'scriptName': 'InjectedScript'}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockDriverAdapter extends WebDriverAdapter {
|
2015-08-28 14:29:19 -04:00
|
|
|
constructor(private _log: any[], private _perfRecords: any[]) { super(); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
executeScript(script) {
|
2015-06-17 14:17:21 -04:00
|
|
|
this._log.push(['executeScript', script]);
|
2015-05-27 17:57:54 -04:00
|
|
|
return PromiseWrapper.resolve(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
logs(type) {
|
2015-06-17 14:17:21 -04:00
|
|
|
this._log.push(['logs', type]);
|
2015-05-27 17:57:54 -04:00
|
|
|
if (type === 'performance') {
|
|
|
|
return PromiseWrapper.resolve(this._perfRecords.map(function(record) {
|
|
|
|
return {
|
|
|
|
'message': Json.stringify(
|
|
|
|
{'message': {'method': 'Timeline.eventRecorded', 'params': {'record': record}}})
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|