2015-06-01 20:33:51 -04:00
|
|
|
export {verifyNoBrowserErrors} from './e2e_util';
|
2015-05-30 11:17:27 -04:00
|
|
|
|
2015-06-01 20:33:51 -04:00
|
|
|
import {bind, Options} from 'benchpress/benchpress';
|
2015-05-30 11:17:27 -04:00
|
|
|
|
2015-06-01 20:33:51 -04:00
|
|
|
export function runClickBenchmark(config) {
|
2015-05-30 11:17:27 -04:00
|
|
|
var buttons = config.buttons.map(function(selector) { return $(selector); });
|
|
|
|
config.work = function() { buttons.forEach(function(button) { button.click(); }); };
|
|
|
|
return runBenchmark(config);
|
|
|
|
}
|
|
|
|
|
2015-06-01 20:33:51 -04:00
|
|
|
export function runBenchmark(config) {
|
2015-05-30 11:17:27 -04:00
|
|
|
return getScaleFactor(browser.params.benchmark.scaling)
|
|
|
|
.then(function(scaleFactor) {
|
|
|
|
var description = {};
|
|
|
|
var urlParams = [];
|
|
|
|
if (config.params) {
|
|
|
|
config.params.forEach(function(param) {
|
|
|
|
var name = param.name;
|
|
|
|
var value = applyScaleFactor(param.value, scaleFactor, param.scale);
|
|
|
|
urlParams.push(name + '=' + value);
|
|
|
|
description[name] = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var url = encodeURI(config.url + '?' + urlParams.join('&'));
|
|
|
|
return browser.get(url).then(function() {
|
2015-06-01 20:33:51 -04:00
|
|
|
return global['benchpressRunner'].sample({
|
2015-05-30 11:17:27 -04:00
|
|
|
id: config.id,
|
|
|
|
execute: config.work,
|
|
|
|
prepare: config.prepare,
|
|
|
|
microMetrics: config.microMetrics,
|
2015-06-01 20:33:51 -04:00
|
|
|
bindings: [bind(Options.SAMPLE_DESCRIPTION).toValue(description)]
|
2015-05-30 11:17:27 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getScaleFactor(possibleScalings) {
|
|
|
|
return browser.executeScript('return navigator.userAgent')
|
|
|
|
.then(function(userAgent: string) {
|
|
|
|
var scaleFactor = 1;
|
|
|
|
possibleScalings.forEach(function(entry) {
|
|
|
|
if (userAgent.match(entry.userAgent)) {
|
|
|
|
scaleFactor = entry.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return scaleFactor;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function applyScaleFactor(value, scaleFactor, method) {
|
|
|
|
if (method === 'log2') {
|
|
|
|
return value + Math.log(scaleFactor) / Math.LN2;
|
|
|
|
} else if (method === 'sqrt') {
|
|
|
|
return value * Math.sqrt(scaleFactor);
|
|
|
|
} else if (method === 'linear') {
|
|
|
|
return value * scaleFactor;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|