Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: webrtc/pc/channel_unittest.cc

Issue 2184083004: Un-flaking TestSrtpError by using a fake clock. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2009 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/base/array_view.h" 13 #include "webrtc/base/array_view.h"
14 #include "webrtc/base/buffer.h" 14 #include "webrtc/base/buffer.h"
15 #include "webrtc/base/fakeclock.h"
15 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
16 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
17 #include "webrtc/media/base/fakemediaengine.h" 18 #include "webrtc/media/base/fakemediaengine.h"
18 #include "webrtc/media/base/fakertp.h" 19 #include "webrtc/media/base/fakertp.h"
19 #include "webrtc/media/base/mediachannel.h" 20 #include "webrtc/media/base/mediachannel.h"
20 #include "webrtc/media/base/testutils.h" 21 #include "webrtc/media/base/testutils.h"
21 #include "webrtc/p2p/base/faketransportcontroller.h" 22 #include "webrtc/p2p/base/faketransportcontroller.h"
22 #include "webrtc/pc/channel.h" 23 #include "webrtc/pc/channel.h"
23 24
24 #define MAYBE_SKIP_TEST(feature) \ 25 #define MAYBE_SKIP_TEST(feature) \
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 // So we need to pass in pl_type so that the packet can pass through 1746 // So we need to pass in pl_type so that the packet can pass through
1746 // the bundle filter before it can be processed by the srtp filter. 1747 // the bundle filter before it can be processed by the srtp filter.
1747 // The packet is not a valid srtp packet because it is too short. 1748 // The packet is not a valid srtp packet because it is too short.
1748 static unsigned const char kBadPacket[] = { 1749 static unsigned const char kBadPacket[] = {
1749 0x84, static_cast<unsigned char>(pl_type), 1750 0x84, static_cast<unsigned char>(pl_type),
1750 0x00, 0x01, 1751 0x00, 0x01,
1751 0x00, 0x00, 1752 0x00, 0x00,
1752 0x00, 0x00, 1753 0x00, 0x00,
1753 0x00, 0x00, 1754 0x00, 0x00,
1754 0x00, 0x01}; 1755 0x00, 0x01};
1756
1757 // Using fake clock because this tests that SRTP errors are signaled at
1758 // specific times based on set_signal_silent_time.
1759 rtc::ScopedFakeClock fake_clock;
1760 // Some code uses a time of 0 as a special value, so we must start with
1761 // a non-zero time.
1762 // TODO(deadbeef): Fix this.
1763 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1764
1755 CreateChannels(RTCP | SECURE, RTCP | SECURE); 1765 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1756 EXPECT_FALSE(channel1_->secure()); 1766 EXPECT_FALSE(channel1_->secure());
1757 EXPECT_FALSE(channel2_->secure()); 1767 EXPECT_FALSE(channel2_->secure());
1758 EXPECT_TRUE(SendInitiate()); 1768 EXPECT_TRUE(SendInitiate());
1759 EXPECT_TRUE(SendAccept()); 1769 EXPECT_TRUE(SendAccept());
1760 EXPECT_TRUE(channel1_->secure()); 1770 EXPECT_TRUE(channel1_->secure());
1761 EXPECT_TRUE(channel2_->secure()); 1771 EXPECT_TRUE(channel2_->secure());
1762 channel2_->srtp_filter()->set_signal_silent_time(250); 1772 channel2_->srtp_filter()->set_signal_silent_time(250);
1763 channel2_->srtp_filter()->SignalSrtpError.connect( 1773 channel2_->srtp_filter()->SignalSrtpError.connect(
1764 &error_handler, &SrtpErrorHandler::OnSrtpError); 1774 &error_handler, &SrtpErrorHandler::OnSrtpError);
1765 1775
1766 // Testing failures in sending packets. 1776 // Testing failures in sending packets.
1767 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), 1777 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1768 rtc::PacketOptions()); 1778 rtc::PacketOptions());
1769 WaitForThreads(); 1779 WaitForThreads();
1770 // The first failure will trigger an error. 1780 // The first failure will trigger an error.
1771 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); 1781 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
1772 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); 1782 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1773 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; 1783 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
1774 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; 1784 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1775 // The next 250 ms failures will not trigger an error. 1785 // The next 250 ms failures will not trigger an error.
1776 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), 1786 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1777 rtc::PacketOptions()); 1787 rtc::PacketOptions());
1778 // Wait for a while to ensure no message comes in. 1788 // Wait for a while to ensure no message comes in.
1779 WaitForThreads(); 1789 WaitForThreads();
1780 rtc::Thread::Current()->ProcessMessages(200); 1790 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
1781 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_); 1791 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
1782 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); 1792 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1783 // Wait for a little more - the error will be triggered again. 1793 // Wait for a little more - the error will be triggered again.
1784 rtc::Thread::Current()->ProcessMessages(200); 1794 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
1785 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), 1795 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1786 rtc::PacketOptions()); 1796 rtc::PacketOptions());
1787 WaitForThreads(); 1797 WaitForThreads();
1788 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); 1798 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
1789 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); 1799 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1790 1800
1791 // Testing failures in receiving packets. 1801 // Testing failures in receiving packets.
1792 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; 1802 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
1793 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; 1803 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1794 1804
1795 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { 1805 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1796 cricket::TransportChannel* transport_channel = 1806 cricket::TransportChannel* transport_channel =
1797 channel2_->transport_channel(); 1807 channel2_->transport_channel();
1798 transport_channel->SignalReadPacket( 1808 transport_channel->SignalReadPacket(
1799 transport_channel, reinterpret_cast<const char*>(kBadPacket), 1809 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1800 sizeof(kBadPacket), rtc::PacketTime(), 0); 1810 sizeof(kBadPacket), rtc::PacketTime(), 0);
1801 }); 1811 });
1802 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); 1812 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
1803 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); 1813 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1814 // Terminate channels before the fake clock is destroyed.
1815 EXPECT_TRUE(SendTerminate());
1804 } 1816 }
1805 1817
1806 void TestOnReadyToSend() { 1818 void TestOnReadyToSend() {
1807 CreateChannels(RTCP, RTCP); 1819 CreateChannels(RTCP, RTCP);
1808 TransportChannel* rtp = channel1_->transport_channel(); 1820 TransportChannel* rtp = channel1_->transport_channel();
1809 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); 1821 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1810 EXPECT_FALSE(media_channel1_->ready_to_send()); 1822 EXPECT_FALSE(media_channel1_->ready_to_send());
1811 1823
1812 network_thread_->Invoke<void>(RTC_FROM_HERE, 1824 network_thread_->Invoke<void>(RTC_FROM_HERE,
1813 [rtp] { rtp->SignalReadyToSend(rtp); }); 1825 [rtp] { rtp->SignalReadyToSend(rtp); });
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 }; 3606 };
3595 rtc::CopyOnWriteBuffer payload(data, 3); 3607 rtc::CopyOnWriteBuffer payload(data, 3);
3596 cricket::SendDataResult result; 3608 cricket::SendDataResult result;
3597 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); 3609 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3598 EXPECT_EQ(params.ssrc, 3610 EXPECT_EQ(params.ssrc,
3599 media_channel1_->last_sent_data_params().ssrc); 3611 media_channel1_->last_sent_data_params().ssrc);
3600 EXPECT_EQ("foo", media_channel1_->last_sent_data()); 3612 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3601 } 3613 }
3602 3614
3603 // TODO(pthatcher): TestSetReceiver? 3615 // TODO(pthatcher): TestSetReceiver?
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698