blob: 3e60e87ba37b5aa98f7bb28d3b683cc709b67eb8 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/chrome/chrome_test_utils.html">
<link rel="import" href="/tracing/extras/importer/trace_event_importer.html">
<link rel="import" href="/tracing/extras/rail/stub_rail_interaction_record.html">
<link rel="import" href="/tracing/model/model.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
var test_utils = tr.c.TestUtils;
test('layoutInfo', function() {
var model = tr.e.chrome.ChromeTestUtils.newChromeModel(function(model) {
// TODO(benjhayden): Create
model.rendererMain.sliceGroup.pushSlice(test_utils.newSliceEx({
title: 'FrameView::layout',
start: 0,
duration: 100
}));
});
var modelHelper = new tr.e.audits.ChromeModelHelper(model);
var rir = new tr.e.rail.RAILInteractionRecord(
model, 'simple', 'rail_response', 0, 100);
rir.associatedEvents.push(model.rendererMain.sliceGroup.slices[0]);
rir.updateArgs();
assert.equal(rir.args.layoutInfo.timeInLayout, 100);
});
// This basically just tests weightedAverage2.
test('railScore', function() {
var ir = new tr.e.rail.StubRAILInteractionRecord({
start: 0, end: 100,
railTypeName: 'rail_idle',
normalizedUserComfort: 0,
normalizedEfficiency: 0
});
assert.closeTo(0, ir.railScore, 1e-5);
ir = new tr.e.rail.StubRAILInteractionRecord({
start: 0, end: 100,
railTypeName: 'rail_idle',
normalizedUserComfort: 1,
normalizedEfficiency: 1
});
assert.closeTo(1, ir.railScore, 1e-5);
ir = new tr.e.rail.StubRAILInteractionRecord({
start: 0, end: 100,
railTypeName: 'rail_idle',
normalizedUserComfort: 1,
normalizedEfficiency: 0
});
assert.closeTo(0.42388, ir.railScore, 1e-5);
ir = new tr.e.rail.StubRAILInteractionRecord({
start: 0, end: 100,
railTypeName: 'rail_idle',
normalizedUserComfort: 0,
normalizedEfficiency: 1
});
assert.closeTo(0.15536, ir.railScore, 1e-5);
});
test('userFriendlyRailTypeName', function() {
// Invalid names shouldn't be modified.
var result = tr.e.rail.userFriendlyRailTypeName('not_a_rail_type_name');
assert.equal('not_a_rail_type_name', result);
result = tr.e.rail.userFriendlyRailTypeName('rail_');
assert.equal('rail_', result);
// Some valid things.
result = tr.e.rail.userFriendlyRailTypeName('rail_animate');
assert.equal('Animate', result);
result = tr.e.rail.userFriendlyRailTypeName('rail_b');
assert.equal('B', result);
result = tr.e.rail.userFriendlyRailTypeName('rail_123');
assert.equal('123', result);
});
});
</script>