Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / media / webrtc_uma_histograms_unittest.cc
blob0a090cf6f3c0890c49cd673c2620e66dd93e3b27
1 // Copyright 2014 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.
5 #include "content/renderer/media/webrtc_uma_histograms.h"
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using ::testing::_;
12 namespace content {
14 class MockPerSessionWebRTCAPIMetrics : public PerSessionWebRTCAPIMetrics {
15 public:
16 MockPerSessionWebRTCAPIMetrics() {}
18 using PerSessionWebRTCAPIMetrics::LogUsageOnlyOnce;
20 MOCK_METHOD1(LogUsage, void(JavaScriptAPIName));
23 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetUserMedia) {
24 MockPerSessionWebRTCAPIMetrics metrics;
25 EXPECT_CALL(metrics, LogUsage(_)).Times(1);
26 metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA);
29 TEST(PerSessionWebRTCAPIMetrics, CallOngoingGetUserMedia) {
30 MockPerSessionWebRTCAPIMetrics metrics;
31 metrics.IncrementStreamCounter();
32 EXPECT_CALL(metrics, LogUsage(WEBKIT_GET_USER_MEDIA)).Times(1);
33 metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA);
36 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetMediaDevices) {
37 MockPerSessionWebRTCAPIMetrics metrics;
38 EXPECT_CALL(metrics, LogUsage(_)).Times(1);
39 metrics.LogUsageOnlyOnce(WEBKIT_GET_MEDIA_DEVICES);
42 TEST(PerSessionWebRTCAPIMetrics, CallOngoingGetMediaDevices) {
43 MockPerSessionWebRTCAPIMetrics metrics;
44 metrics.IncrementStreamCounter();
45 EXPECT_CALL(metrics, LogUsage(WEBKIT_GET_MEDIA_DEVICES)).Times(1);
46 metrics.LogUsageOnlyOnce(WEBKIT_GET_MEDIA_DEVICES);
49 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingRTCPeerConnection) {
50 MockPerSessionWebRTCAPIMetrics metrics;
51 EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION));
52 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
55 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingMultiplePC) {
56 MockPerSessionWebRTCAPIMetrics metrics;
57 EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
58 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
59 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
60 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
63 TEST(PerSessionWebRTCAPIMetrics, BeforeAfterCallMultiplePC) {
64 MockPerSessionWebRTCAPIMetrics metrics;
65 EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
66 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
67 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
68 metrics.IncrementStreamCounter();
69 metrics.IncrementStreamCounter();
70 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
71 metrics.DecrementStreamCounter();
72 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
73 metrics.DecrementStreamCounter();
74 EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
75 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
76 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
79 } // namespace content