1effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
2effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// found in the LICENSE file.
4effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
5effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/renderer/media/webrtc_uma_histograms.h"
6effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
7effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "testing/gmock/include/gmock/gmock.h"
8effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "testing/gtest/include/gtest/gtest.h"
9effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochusing ::testing::_;
11effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
12effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochnamespace content {
13effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass MockPerSessionWebRTCAPIMetrics : public PerSessionWebRTCAPIMetrics {
15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public:
16effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MockPerSessionWebRTCAPIMetrics() {}
17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
18effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  using PerSessionWebRTCAPIMetrics::LogUsageOnlyOnce;
19effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
20effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MOCK_METHOD1(LogUsage, void(JavaScriptAPIName));
21effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch};
22effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
23effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetUserMedia) {
24effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MockPerSessionWebRTCAPIMetrics metrics;
25effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_CALL(metrics, LogUsage(_)).Times(1);
26effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA);
27effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
29effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST(PerSessionWebRTCAPIMetrics, CallOngoingGetUserMedia) {
30effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MockPerSessionWebRTCAPIMetrics metrics;
31effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.IncrementStreamCounter();
32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_CALL(metrics, LogUsage(WEBKIT_GET_USER_MEDIA)).Times(1);
33effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA);
34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
3646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetMediaDevices) {
3746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  MockPerSessionWebRTCAPIMetrics metrics;
3846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_CALL(metrics, LogUsage(_)).Times(1);
3946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  metrics.LogUsageOnlyOnce(WEBKIT_GET_MEDIA_DEVICES);
4046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
4146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST(PerSessionWebRTCAPIMetrics, CallOngoingGetMediaDevices) {
4346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  MockPerSessionWebRTCAPIMetrics metrics;
4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  metrics.IncrementStreamCounter();
4546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_CALL(metrics, LogUsage(WEBKIT_GET_MEDIA_DEVICES)).Times(1);
4646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  metrics.LogUsageOnlyOnce(WEBKIT_GET_MEDIA_DEVICES);
4746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
4846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
49effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST(PerSessionWebRTCAPIMetrics, NoCallOngoingRTCPeerConnection) {
50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MockPerSessionWebRTCAPIMetrics metrics;
51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION));
52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
53effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
55effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST(PerSessionWebRTCAPIMetrics, NoCallOngoingMultiplePC) {
56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MockPerSessionWebRTCAPIMetrics metrics;
57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
58effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
60effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
61effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
62effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
63effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST(PerSessionWebRTCAPIMetrics, BeforeAfterCallMultiplePC) {
64effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  MockPerSessionWebRTCAPIMetrics metrics;
65effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
66effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
67effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
68effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.IncrementStreamCounter();
69effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.IncrementStreamCounter();
70effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
71effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.DecrementStreamCounter();
72effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
73effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.DecrementStreamCounter();
74effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
75effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
76effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
77effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
78effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
79effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}  // namespace content
80