tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

media_engine_unittest.cc (3628B)


      1 /*
      2 *  Copyright (c) 2020 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 "media/base/media_engine.h"
     12 
     13 #include <cstdint>
     14 #include <optional>
     15 #include <vector>
     16 
     17 #include "api/audio/audio_device.h"
     18 #include "api/field_trials_view.h"
     19 #include "api/rtp_parameters.h"
     20 #include "api/rtp_transceiver_direction.h"
     21 #include "api/scoped_refptr.h"
     22 #include "call/audio_state.h"
     23 #include "media/base/codec.h"
     24 #include "rtc_base/system/file_wrapper.h"
     25 #include "test/gmock.h"
     26 #include "test/gtest.h"
     27 
     28 using ::testing::ElementsAre;
     29 using ::testing::Field;
     30 using ::testing::Return;
     31 using ::testing::StrEq;
     32 using ::webrtc::RtpExtension;
     33 using ::webrtc::RtpHeaderExtensionCapability;
     34 using ::webrtc::RtpTransceiverDirection;
     35 
     36 namespace webrtc {
     37 namespace {
     38 
     39 class MockRtpHeaderExtensionQueryInterface
     40    : public RtpHeaderExtensionQueryInterface {
     41 public:
     42  MOCK_METHOD(std::vector<RtpHeaderExtensionCapability>,
     43              GetRtpHeaderExtensions,
     44              (const FieldTrialsView*),
     45              (const, override));
     46 };
     47 
     48 }  // namespace
     49 
     50 TEST(MediaEngineTest, ReturnsNotStoppedHeaderExtensions) {
     51  MockRtpHeaderExtensionQueryInterface mock;
     52  std::vector<RtpHeaderExtensionCapability> extensions(
     53      {RtpHeaderExtensionCapability("uri1", 1,
     54                                    RtpTransceiverDirection::kInactive),
     55       RtpHeaderExtensionCapability("uri2", 2,
     56                                    RtpTransceiverDirection::kSendRecv),
     57       RtpHeaderExtensionCapability("uri3", 3,
     58                                    RtpTransceiverDirection::kStopped),
     59       RtpHeaderExtensionCapability("uri4", 4,
     60                                    RtpTransceiverDirection::kSendOnly),
     61       RtpHeaderExtensionCapability("uri5", 5,
     62                                    RtpTransceiverDirection::kRecvOnly)});
     63  EXPECT_CALL(mock, GetRtpHeaderExtensions).WillOnce(Return(extensions));
     64  EXPECT_THAT(GetDefaultEnabledRtpHeaderExtensions(mock, nullptr),
     65              ElementsAre(Field(&RtpExtension::uri, StrEq("uri1")),
     66                          Field(&RtpExtension::uri, StrEq("uri2")),
     67                          Field(&RtpExtension::uri, StrEq("uri4")),
     68                          Field(&RtpExtension::uri, StrEq("uri5"))));
     69 }
     70 
     71 // This class mocks methods declared as pure virtual in the interface.
     72 // Since the tests are aiming to check the patterns of overrides, the
     73 // functions with default implementations are not mocked.
     74 class MostlyMockVoiceEngineInterface : public VoiceEngineInterface {
     75 public:
     76  MOCK_METHOD(std::vector<RtpHeaderExtensionCapability>,
     77              GetRtpHeaderExtensions,
     78              (const FieldTrialsView*),
     79              (const, override));
     80  MOCK_METHOD(void, Init, (), (override));
     81  MOCK_METHOD(scoped_refptr<AudioState>, GetAudioState, (), (const, override));
     82  MOCK_METHOD(std::vector<Codec>&, LegacySendCodecs, (), (const, override));
     83  MOCK_METHOD(std::vector<Codec>&, LegacyRecvCodecs, (), (const, override));
     84  MOCK_METHOD(bool,
     85              StartAecDump,
     86              (FileWrapper file, int64_t max_size_bytes),
     87              (override));
     88  MOCK_METHOD(void, StopAecDump, (), (override));
     89  MOCK_METHOD(std::optional<AudioDeviceModule::Stats>,
     90              GetAudioDeviceStats,
     91              (),
     92              (override));
     93 };
     94 
     95 }  // namespace webrtc