1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<!DOCTYPE html>
<!--
Copyright 2021 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/metrics/blink/resource_metric.html">
<link rel="import" href="/tracing/value/histogram_set.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
test('blinkRequestResourceCount_general', function() {
const model = tr.e.chrome.ChromeTestUtils.newChromeModel(function(model) {
const rendererProcess = model.rendererProcess;
const mainThread = model.rendererMain;
const mainFrame = { id: '0xdeadbeef', is_main: true };
const emitEvent = (time, cat, title, url, duration) => {
mainThread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
cat,
title,
start: time,
duration,
args: {url},
}));
};
emitEvent(1000, 'blink', 'ResourceFetcher::requestResource', 'A.js', 0.1);
emitEvent(2001, 'blink', 'ignore', 'A.js', 0.1);
emitEvent(2002, 'ignore', 'ignore', 'A.js', 0.1);
emitEvent(3200, 'blink', 'ResourceFetcher::requestResource', 'b.js', 0.1);
emitEvent(4201, 'ignore', 'ResourceFetcher::requestResource', 'b.js', 0.1);
});
const histograms = new tr.v.HistogramSet();
tr.metrics.blinkResourceMetric(histograms, model);
const histogram = histograms.getHistogramNamed('blinkRequestResourceCount');
assert.strictEqual(histogram.sampleValues.length, 1);
assert.strictEqual(histogram.running.count, 1);
assert.strictEqual(histogram.running.mean, 2);
});
});
|