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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/media/router/discovery/media_sink_discovery_metrics.h"
#include "base/metrics/histogram_macros.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/time/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::Bucket;
using testing::ElementsAre;
namespace media_router {
TEST(DialDeviceCountMetricsTest, RecordDeviceCountsIfNeeded) {
DialDeviceCountMetrics metrics;
base::SimpleTestClock clock;
metrics.SetClockForTest(&clock);
base::HistogramTester tester;
tester.ExpectTotalCount(
DialDeviceCountMetrics::kHistogramDialAvailableDeviceCount, 0);
tester.ExpectTotalCount(
DialDeviceCountMetrics::kHistogramDialKnownDeviceCount, 0);
// Only record one count within one hour.
clock.SetNow(base::Time::Now());
metrics.RecordDeviceCountsIfNeeded(6, 10);
metrics.RecordDeviceCountsIfNeeded(7, 10);
tester.ExpectTotalCount(
DialDeviceCountMetrics::kHistogramDialAvailableDeviceCount, 1);
tester.ExpectTotalCount(
DialDeviceCountMetrics::kHistogramDialKnownDeviceCount, 1);
tester.ExpectBucketCount(
DialDeviceCountMetrics::kHistogramDialAvailableDeviceCount, 6, 1);
tester.ExpectBucketCount(
DialDeviceCountMetrics::kHistogramDialKnownDeviceCount, 10, 1);
// Record another count.
clock.Advance(base::Hours(2));
metrics.RecordDeviceCountsIfNeeded(7, 10);
tester.ExpectTotalCount(
DialDeviceCountMetrics::kHistogramDialAvailableDeviceCount, 2);
tester.ExpectTotalCount(
DialDeviceCountMetrics::kHistogramDialKnownDeviceCount, 2);
tester.ExpectBucketCount(
DialDeviceCountMetrics::kHistogramDialAvailableDeviceCount, 6, 1);
tester.ExpectBucketCount(
DialDeviceCountMetrics::kHistogramDialAvailableDeviceCount, 7, 1);
tester.ExpectBucketCount(
DialDeviceCountMetrics::kHistogramDialKnownDeviceCount, 10, 2);
}
TEST(CastDeviceCountMetricsTest, RecordDeviceCountsIfNeeded) {
CastDeviceCountMetrics metrics;
base::SimpleTestClock clock;
metrics.SetClockForTest(&clock);
base::HistogramTester tester;
tester.ExpectTotalCount(
CastDeviceCountMetrics::kHistogramCastConnectedDeviceCount, 0);
tester.ExpectTotalCount(
CastDeviceCountMetrics::kHistogramCastKnownDeviceCount, 0);
// Only record one count within one hour.
clock.SetNow(base::Time::Now());
metrics.RecordDeviceCountsIfNeeded(6, 10);
metrics.RecordDeviceCountsIfNeeded(7, 10);
tester.ExpectTotalCount(
CastDeviceCountMetrics::kHistogramCastConnectedDeviceCount, 1);
tester.ExpectTotalCount(
CastDeviceCountMetrics::kHistogramCastKnownDeviceCount, 1);
tester.ExpectBucketCount(
CastDeviceCountMetrics::kHistogramCastConnectedDeviceCount, 6, 1);
tester.ExpectBucketCount(
CastDeviceCountMetrics::kHistogramCastKnownDeviceCount, 10, 1);
// Record another count.
clock.Advance(base::Hours(2));
metrics.RecordDeviceCountsIfNeeded(7, 10);
tester.ExpectTotalCount(
CastDeviceCountMetrics::kHistogramCastConnectedDeviceCount, 2);
tester.ExpectTotalCount(
CastDeviceCountMetrics::kHistogramCastKnownDeviceCount, 2);
tester.ExpectBucketCount(
CastDeviceCountMetrics::kHistogramCastConnectedDeviceCount, 6, 1);
tester.ExpectBucketCount(
CastDeviceCountMetrics::kHistogramCastConnectedDeviceCount, 7, 1);
tester.ExpectBucketCount(
CastDeviceCountMetrics::kHistogramCastKnownDeviceCount, 10, 2);
}
TEST(CastAnalyticsTest, RecordCastChannelConnectResult) {
const MediaRouterChannelConnectResults success =
MediaRouterChannelConnectResults::SUCCESS;
const MediaRouterChannelConnectResults failure =
MediaRouterChannelConnectResults::FAILURE;
base::HistogramTester tester;
tester.ExpectTotalCount(CastAnalytics::kHistogramCastChannelConnectResult, 0);
CastAnalytics::RecordCastChannelConnectResult(success);
CastAnalytics::RecordCastChannelConnectResult(failure);
CastAnalytics::RecordCastChannelConnectResult(success);
tester.ExpectTotalCount(CastAnalytics::kHistogramCastChannelConnectResult, 3);
EXPECT_THAT(
tester.GetAllSamples(CastAnalytics::kHistogramCastChannelConnectResult),
ElementsAre(Bucket(static_cast<int>(failure), 1),
Bucket(static_cast<int>(success), 2)));
}
TEST(CastAnalyticsTest, RecordDeviceChannelError) {
base::HistogramTester tester;
const MediaRouterChannelError error1 =
MediaRouterChannelError::AUTHENTICATION;
const MediaRouterChannelError error2 = MediaRouterChannelError::CONNECT;
const MediaRouterChannelError error3 =
MediaRouterChannelError::GENERAL_CERTIFICATE;
tester.ExpectTotalCount(CastAnalytics::kHistogramCastChannelError, 0);
CastAnalytics::RecordDeviceChannelError(error1);
CastAnalytics::RecordDeviceChannelError(error2);
CastAnalytics::RecordDeviceChannelError(error2);
CastAnalytics::RecordDeviceChannelError(error3);
tester.ExpectTotalCount(CastAnalytics::kHistogramCastChannelError, 4);
EXPECT_THAT(tester.GetAllSamples(CastAnalytics::kHistogramCastChannelError),
ElementsAre(Bucket(static_cast<int>(error1), 1),
Bucket(static_cast<int>(error2), 2),
Bucket(static_cast<int>(error3), 1)));
}
TEST(CastAnalyticsTest, RecordDeviceChannelOpenDuration) {
base::HistogramTester tester;
const base::TimeDelta delta = base::Milliseconds(10);
tester.ExpectTotalCount(CastAnalytics::kHistogramCastMdnsChannelOpenSuccess,
0);
CastAnalytics::RecordDeviceChannelOpenDuration(true, delta);
tester.ExpectUniqueSample(CastAnalytics::kHistogramCastMdnsChannelOpenSuccess,
delta.InMilliseconds(), 1);
tester.ExpectTotalCount(CastAnalytics::kHistogramCastMdnsChannelOpenFailure,
0);
CastAnalytics::RecordDeviceChannelOpenDuration(false, delta);
tester.ExpectUniqueSample(CastAnalytics::kHistogramCastMdnsChannelOpenFailure,
delta.InMilliseconds(), 1);
}
TEST(WiredDisplayDeviceCountMetricsTest, RecordWiredDisplaySinkCount) {
base::HistogramTester tester;
WiredDisplayDeviceCountMetrics metrics;
tester.ExpectTotalCount(
WiredDisplayDeviceCountMetrics::kHistogramWiredDisplayDeviceCount, 0);
// Only the first argument, the available sink count, is recorded.
metrics.RecordDeviceCounts(1, 1);
metrics.RecordDeviceCounts(200, 200);
metrics.RecordDeviceCounts(0, 0);
metrics.RecordDeviceCounts(25, 30);
metrics.RecordDeviceCounts(1, 0);
tester.ExpectTotalCount(
WiredDisplayDeviceCountMetrics::kHistogramWiredDisplayDeviceCount, 5);
EXPECT_THAT(
tester.GetAllSamples(
WiredDisplayDeviceCountMetrics::kHistogramWiredDisplayDeviceCount),
ElementsAre(
Bucket(0, 1), Bucket(1, 2), Bucket(25, 1),
Bucket(100, 1))); // Counts over 100 are all put in the 100 bucket.
}
} // namespace media_router
|