Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
|
Taylor Brandstetter
2017/03/01 19:18:09
nit: File should be named "_unittest.cc" (singular
Zhi Huang
2017/03/02 23:35:39
Done.
| |
| 2 * Copyright 2017 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 <memory> | |
| 12 | |
| 13 #include "webrtc/base/gunit.h" | |
| 14 #include "webrtc/media/base/fakemediaengine.h" | |
| 15 #include "webrtc/ortc/ortcfactory.h" | |
| 16 #include "webrtc/ortc/testrtpparameters.h" | |
| 17 #include "webrtc/p2p/base/fakepackettransport.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 | |
| 21 static const char kTestKeyParams1[] = | |
| 22 "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; | |
| 23 static const char kTestKeyParams2[] = | |
| 24 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; | |
| 25 | |
| 26 static const cricket::CryptoParams kTestCryptoParams1(1, | |
| 27 "AES_CM_128_HMAC_SHA1_80", | |
| 28 kTestKeyParams1, | |
| 29 ""); | |
| 30 static const cricket::CryptoParams kTestCryptoParams2(1, | |
| 31 "AES_CM_128_HMAC_SHA1_80", | |
| 32 kTestKeyParams2, | |
| 33 ""); | |
| 34 | |
| 35 // This test uses fake packet transports and a fake media engine, in order to | |
| 36 // test the SrtpTransport at only an API level. Any end-to-end test should go in | |
| 37 // ortcfactory_integrationtest.cc instead. | |
| 38 class SrtpTransportTest : public testing::Test { | |
| 39 public: | |
| 40 SrtpTransportTest() { | |
| 41 fake_media_engine_ = new cricket::FakeMediaEngine(); | |
| 42 // Note: This doesn't need to use fake network classes, since it uses | |
| 43 // FakePacketTransports. | |
| 44 auto result = OrtcFactory::Create( | |
| 45 nullptr, nullptr, nullptr, nullptr, nullptr, | |
| 46 std::unique_ptr<cricket::MediaEngineInterface>(fake_media_engine_)); | |
| 47 ortc_factory_ = result.MoveValue(); | |
| 48 rtp_transport_controller_ = | |
| 49 ortc_factory_->CreateRtpTransportController().MoveValue(); | |
| 50 | |
| 51 fake_packet_transport_.reset(new rtc::FakePacketTransport("fake")); | |
| 52 auto srtp_transport_result = ortc_factory_->CreateSrtpTransport( | |
| 53 rtcp_parameters_, fake_packet_transport_.get(), nullptr, | |
| 54 rtp_transport_controller_.get()); | |
| 55 srtp_transport_ = srtp_transport_result.MoveValue(); | |
| 56 } | |
| 57 | |
| 58 protected: | |
| 59 // Owned by |ortc_factory_|. | |
| 60 cricket::FakeMediaEngine* fake_media_engine_; | |
| 61 std::unique_ptr<OrtcFactoryInterface> ortc_factory_; | |
| 62 std::unique_ptr<RtpTransportControllerInterface> rtp_transport_controller_; | |
| 63 std::unique_ptr<SrtpTransportInterface> srtp_transport_; | |
| 64 RtcpParameters rtcp_parameters_; | |
| 65 std::unique_ptr<rtc::FakePacketTransport> fake_packet_transport_; | |
| 66 }; | |
| 67 | |
| 68 // Tests that setting the SRTP send/receive key twice is not supported. | |
| 69 TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKeyForSender) { | |
|
Taylor Brandstetter
2017/03/01 19:18:09
Could you split this into two tests; one for setti
Zhi Huang
2017/03/02 23:35:39
Done.
| |
| 70 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 71 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 72 EXPECT_EQ(srtp_transport_->SetSrtpSendKey(kTestCryptoParams2).type(), | |
| 73 RTCErrorType::UNSUPPORTED_OPERATION); | |
| 74 EXPECT_EQ(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams1).type(), | |
| 75 RTCErrorType::UNSUPPORTED_OPERATION); | |
| 76 auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
| 77 srtp_transport_.get()); | |
| 78 EXPECT_TRUE(sender_result.ok()); | |
| 79 auto receiver_result = ortc_factory_->CreateRtpReceiver( | |
| 80 cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get()); | |
| 81 EXPECT_TRUE(receiver_result.ok()); | |
| 82 } | |
| 83 | |
| 84 class SrtpTransportTestWithMediaType | |
| 85 : public SrtpTransportTest, | |
| 86 public ::testing::WithParamInterface<cricket::MediaType> {}; | |
| 87 | |
| 88 // Tests that the senders cannot be created before setting the keys. | |
| 89 TEST_P(SrtpTransportTestWithMediaType, CreateSenderBeforeSettingKeys) { | |
| 90 auto sender_result = | |
| 91 ortc_factory_->CreateRtpSender(GetParam(), srtp_transport_.get()); | |
| 92 EXPECT_FALSE(sender_result.ok()); | |
|
Taylor Brandstetter
2017/03/01 19:18:09
nit: Verify that the error is "UNSUPPORTED_PARAMET
Zhi Huang
2017/03/02 23:35:40
Done.
| |
| 93 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 94 sender_result = | |
| 95 ortc_factory_->CreateRtpSender(GetParam(), srtp_transport_.get()); | |
| 96 EXPECT_FALSE(sender_result.ok()); | |
|
Taylor Brandstetter
2017/03/01 19:18:09
nit: Add comment saying something along the lines
Zhi Huang
2017/03/02 23:35:39
Done.
| |
| 97 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 98 sender_result = | |
| 99 ortc_factory_->CreateRtpSender(GetParam(), srtp_transport_.get()); | |
| 100 EXPECT_TRUE(sender_result.ok()); | |
| 101 } | |
| 102 | |
| 103 // Tests that the receivers cannot be created before setting the keys. | |
| 104 TEST_P(SrtpTransportTestWithMediaType, CreateReceiverBeforeSettingKeys) { | |
| 105 auto receiver_result = | |
| 106 ortc_factory_->CreateRtpReceiver(GetParam(), srtp_transport_.get()); | |
| 107 EXPECT_FALSE(receiver_result.ok()); | |
| 108 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 109 receiver_result = | |
| 110 ortc_factory_->CreateRtpReceiver(GetParam(), srtp_transport_.get()); | |
| 111 EXPECT_FALSE(receiver_result.ok()); | |
| 112 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 113 receiver_result = | |
| 114 ortc_factory_->CreateRtpReceiver(GetParam(), srtp_transport_.get()); | |
| 115 EXPECT_TRUE(receiver_result.ok()); | |
| 116 } | |
| 117 | |
| 118 INSTANTIATE_TEST_CASE_P(SenderCreatationTest, | |
| 119 SrtpTransportTestWithMediaType, | |
| 120 ::testing::Values(cricket::MEDIA_TYPE_AUDIO, | |
| 121 cricket::MEDIA_TYPE_VIDEO)); | |
|
Taylor Brandstetter
2017/03/01 19:18:09
This is smart! I should have done this with some o
| |
| 122 | |
| 123 } // namespace webrtc | |
| OLD | NEW |