1 /*
2  *  Copyright 2019 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "rtc_base/experiments/keyframe_interval_settings.h"
12 
13 #include "test/field_trial.h"
14 #include "test/gtest.h"
15 
16 namespace webrtc {
17 namespace {
18 
TEST(KeyframeIntervalSettingsTest,ParsesMinKeyframeSendIntervalMs)19 TEST(KeyframeIntervalSettingsTest, ParsesMinKeyframeSendIntervalMs) {
20   EXPECT_FALSE(KeyframeIntervalSettings::ParseFromFieldTrials()
21                    .MinKeyframeSendIntervalMs());
22 
23   test::ScopedFieldTrials field_trials(
24       "WebRTC-KeyframeInterval/min_keyframe_send_interval_ms:100/");
25   EXPECT_EQ(KeyframeIntervalSettings::ParseFromFieldTrials()
26                 .MinKeyframeSendIntervalMs(),
27             100);
28 }
29 
TEST(KeyframeIntervalSettingsTest,ParsesMaxWaitForKeyframeMs)30 TEST(KeyframeIntervalSettingsTest, ParsesMaxWaitForKeyframeMs) {
31   EXPECT_FALSE(
32       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForKeyframeMs());
33 
34   test::ScopedFieldTrials field_trials(
35       "WebRTC-KeyframeInterval/max_wait_for_keyframe_ms:100/");
36   EXPECT_EQ(
37       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForKeyframeMs(),
38       100);
39 }
40 
TEST(KeyframeIntervalSettingsTest,ParsesMaxWaitForFrameMs)41 TEST(KeyframeIntervalSettingsTest, ParsesMaxWaitForFrameMs) {
42   EXPECT_FALSE(
43       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForFrameMs());
44 
45   test::ScopedFieldTrials field_trials(
46       "WebRTC-KeyframeInterval/max_wait_for_frame_ms:100/");
47   EXPECT_EQ(
48       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForFrameMs(),
49       100);
50 }
51 
TEST(KeyframeIntervalSettingsTest,ParsesAllValues)52 TEST(KeyframeIntervalSettingsTest, ParsesAllValues) {
53   test::ScopedFieldTrials field_trials(
54       "WebRTC-KeyframeInterval/"
55       "min_keyframe_send_interval_ms:100,"
56       "max_wait_for_keyframe_ms:101,"
57       "max_wait_for_frame_ms:102/");
58   EXPECT_EQ(KeyframeIntervalSettings::ParseFromFieldTrials()
59                 .MinKeyframeSendIntervalMs(),
60             100);
61   EXPECT_EQ(
62       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForKeyframeMs(),
63       101);
64   EXPECT_EQ(
65       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForFrameMs(),
66       102);
67 }
68 
TEST(KeyframeIntervalSettingsTest,DoesNotParseAllValuesWhenIncorrectlySet)69 TEST(KeyframeIntervalSettingsTest, DoesNotParseAllValuesWhenIncorrectlySet) {
70   EXPECT_FALSE(
71       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForFrameMs());
72 
73   test::ScopedFieldTrials field_trials(
74       "WebRTC-KeyframeInterval/"
75       "min_keyframe_send_interval_ms:a,"
76       "max_wait_for_keyframe_ms:b,"
77       "max_wait_for_frame_ms:c/");
78   EXPECT_FALSE(KeyframeIntervalSettings::ParseFromFieldTrials()
79                    .MinKeyframeSendIntervalMs());
80   EXPECT_FALSE(
81       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForKeyframeMs());
82   EXPECT_FALSE(
83       KeyframeIntervalSettings::ParseFromFieldTrials().MaxWaitForFrameMs());
84 }
85 
86 }  // namespace
87 }  // namespace webrtc
88