1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Metrics
8 // Any changes to the logging done in these functions should be matched
9 // with the checks done in IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics).
10 // See metrics_apitest.cc.
11 chrome.test.runTests([
12 function recordUserAction() {
14 chrome.metricsPrivate.recordUserAction('test.ua.1');
16 // Log a metric more than once.
17 chrome.metricsPrivate.recordUserAction('test.ua.2');
18 chrome.metricsPrivate.recordUserAction('test.ua.2');
20 chrome.test.succeed();
23 function recordValue() {
24 chrome.metricsPrivate.recordValue({
25 'metricName': 'test.h.1',
26 'type': 'histogram-log',
32 chrome.metricsPrivate.recordValue({
33 'metricName': 'test.h.2',
34 'type': 'histogram-linear',
40 chrome.metricsPrivate.recordPercentage('test.h.3', 42);
41 chrome.metricsPrivate.recordPercentage('test.h.3', 42);
43 chrome.test.succeed();
46 function recordSparseValue() {
47 chrome.metricsPrivate.recordSparseValue('test.sparse.1', 42);
48 chrome.metricsPrivate.recordSparseValue('test.sparse.2', 24);
49 chrome.metricsPrivate.recordSparseValue('test.sparse.2', 24);
50 chrome.metricsPrivate.recordSparseValue('test.sparse.3', 1);
51 chrome.metricsPrivate.recordSparseValue('test.sparse.3', 2);
52 chrome.metricsPrivate.recordSparseValue('test.sparse.3', 2);
53 chrome.metricsPrivate.recordSparseValue('test.sparse.3', 3);
54 chrome.metricsPrivate.recordSparseValue('test.sparse.3', 3);
55 chrome.metricsPrivate.recordSparseValue('test.sparse.3', 3);
57 chrome.test.succeed();
60 function recordTimes() {
61 chrome.metricsPrivate.recordTime('test.time', 42);
62 chrome.metricsPrivate.recordMediumTime('test.medium.time', 42 * 1000);
63 chrome.metricsPrivate.recordLongTime('test.long.time', 42 * 1000 * 60);
65 chrome.test.succeed();
68 function recordCounts() {
69 chrome.metricsPrivate.recordCount('test.count', 420000);
70 chrome.metricsPrivate.recordMediumCount('test.medium.count', 4200);
71 chrome.metricsPrivate.recordSmallCount('test.small.count', 42);
73 chrome.test.succeed();
76 function getFieldTrial() {
77 var test1Callback = function(group) {
78 chrome.test.assertEq('', group);
79 chrome.metricsPrivate.getFieldTrial('apitestfieldtrial2', test2Callback);
82 var test2Callback = function(group) {
83 chrome.test.assertEq('group1', group);
84 chrome.test.succeed();
87 chrome.metricsPrivate.getFieldTrial('apitestfieldtrial1', test1Callback);
90 function getVariationParams1() {
91 chrome.metricsPrivate.getVariationParams(
92 'apitestfieldtrial1', function(params) {
93 chrome.test.assertEq(undefined, chrome.runtime.lastError);
94 chrome.test.assertEq(undefined, params);
95 chrome.test.succeed();
99 function getVariationParams2() {
100 chrome.metricsPrivate.getVariationParams(
101 'apitestfieldtrial2', function(params) {
102 chrome.test.assertEq(undefined, chrome.runtime.lastError);
103 chrome.test.assertEq({a: 'aa', b: 'bb'}, params);
104 chrome.test.succeed();
108 function testBucketSizeChanges() {
110 'metricName': 'test.bucketchange.linear',
111 'type': 'histogram-linear',
117 'metricName': 'test.bucketchange.linear',
118 'type': 'histogram-linear',
124 'metricName': 'test.bucketchange.log',
125 'type': 'histogram-log',
131 'metricName': 'test.bucketchange.log',
132 'type': 'histogram-log',
138 chrome.metricsPrivate.recordValue(linear1, 42);
139 // This one should be rejected because the bucket count is different.
140 // We check for sample count == 2 in metrics_apitest.cc
141 chrome.metricsPrivate.recordValue(linear2, 42);
142 chrome.metricsPrivate.recordValue(linear1, 42);
144 chrome.metricsPrivate.recordValue(log1, 42);
145 // This one should be rejected because the bucket count is different.
146 // We check for sample count == 2 in metrics_apitest.cc
147 chrome.metricsPrivate.recordValue(log2, 42);
148 chrome.metricsPrivate.recordValue(log1, 42);
150 chrome.test.succeed();