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. 4 5 #include "content/renderer/media/webrtc_uma_histograms.h" 6 7 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 using ::testing::_; 11 12 namespace content { 13 14 class MockPerSessionWebRTCAPIMetrics : public PerSessionWebRTCAPIMetrics { 15 public: 16 MockPerSessionWebRTCAPIMetrics() {} 17 18 using PerSessionWebRTCAPIMetrics::LogUsageOnlyOnce; 19 20 MOCK_METHOD1(LogUsage, void(JavaScriptAPIName)); 21 }; 22 23 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetUserMedia) { 24 MockPerSessionWebRTCAPIMetrics metrics; 25 EXPECT_CALL(metrics, LogUsage(_)).Times(1); 26 metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA); 27 } 28 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); 34 } 35 36 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetMediaDevices) { 37 MockPerSessionWebRTCAPIMetrics metrics; 38 EXPECT_CALL(metrics, LogUsage(_)).Times(1); 39 metrics.LogUsageOnlyOnce(WEBKIT_GET_MEDIA_DEVICES); 40 } 41 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); 47 } 48 49 TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingRTCPeerConnection) { 50 MockPerSessionWebRTCAPIMetrics metrics; 51 EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)); 52 metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION); 53 } 54 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); 61 } 62 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); 77 } 78 79 } // namespace content 80