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

Side by Side Diff: talk/app/webrtc/datachannel_unittest.cc

Issue 1393563002: Moving MediaStreamSignaling logic into PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Cleaning up comments, fixing naming, etc. Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 13 matching lines...) Expand all
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/datachannel.h" 28 #include "talk/app/webrtc/datachannel.h"
29 #include "talk/app/webrtc/sctputils.h" 29 #include "talk/app/webrtc/sctputils.h"
30 #include "talk/app/webrtc/test/fakedatachannelprovider.h" 30 #include "talk/app/webrtc/test/fakedatachannelprovider.h"
31 #include "webrtc/base/gunit.h" 31 #include "webrtc/base/gunit.h"
32 32
33 using webrtc::DataChannel; 33 using webrtc::DataChannel;
34 using webrtc::SctpSidAllocator;
34 35
35 class FakeDataChannelObserver : public webrtc::DataChannelObserver { 36 class FakeDataChannelObserver : public webrtc::DataChannelObserver {
36 public: 37 public:
37 FakeDataChannelObserver() 38 FakeDataChannelObserver()
38 : messages_received_(0), 39 : messages_received_(0),
39 on_state_change_count_(0), 40 on_state_change_count_(0),
40 on_buffered_amount_change_count_(0) {} 41 on_buffered_amount_change_count_(0) {}
41 42
42 void OnStateChange() { 43 void OnStateChange() {
43 ++on_state_change_count_; 44 ++on_state_change_count_;
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, 500 EXPECT_EQ(webrtc::DataChannelInterface::kOpen,
500 webrtc_data_channel_->state()); 501 webrtc_data_channel_->state());
501 } 502 }
502 503
503 // Tests that a channel can be closed without being opened or assigned an sid. 504 // Tests that a channel can be closed without being opened or assigned an sid.
504 TEST_F(SctpDataChannelTest, NeverOpened) { 505 TEST_F(SctpDataChannelTest, NeverOpened) {
505 provider_.set_transport_available(true); 506 provider_.set_transport_available(true);
506 webrtc_data_channel_->OnTransportChannelCreated(); 507 webrtc_data_channel_->OnTransportChannelCreated();
507 webrtc_data_channel_->Close(); 508 webrtc_data_channel_->Close();
508 } 509 }
510
511 class SctpSidAllocatorTest : public testing::Test {
512 protected:
513 SctpSidAllocator allocator_;
514 };
515
516 // Verifies that an even SCTP id is allocated for SSL_CLIENT and an odd id for
517 // SSL_SERVER.
518 TEST_F(SctpSidAllocatorTest, SctpIdAllocationBasedOnRole) {
519 int id;
520 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &id));
521 EXPECT_EQ(1, id);
522 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &id));
523 EXPECT_EQ(0, id);
524 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &id));
525 EXPECT_EQ(3, id);
526 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &id));
527 EXPECT_EQ(2, id);
528 }
529
530 // Verifies that SCTP ids of existing DataChannels are not reused.
531 TEST_F(SctpSidAllocatorTest, SctpIdAllocationNoReuse) {
532 int old_id = 1;
533 EXPECT_TRUE(allocator_.ReserveSctpSid(old_id));
534
535 int new_id;
536 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &new_id));
537 EXPECT_NE(old_id, new_id);
538
539 old_id = 0;
540 EXPECT_TRUE(allocator_.ReserveSctpSid(old_id));
541 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &new_id));
542 EXPECT_NE(old_id, new_id);
543 }
544
545 // Verifies that SCTP ids of removed DataChannels can be reused.
546 TEST_F(SctpSidAllocatorTest, SctpIdReusedForRemovedDataChannel) {
547 int odd_id = 1;
548 int even_id = 0;
549 EXPECT_TRUE(allocator_.ReserveSctpSid(odd_id));
550 EXPECT_TRUE(allocator_.ReserveSctpSid(even_id));
551
552 int allocated_id = -1;
553 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &allocated_id));
554 EXPECT_EQ(odd_id + 2, allocated_id);
555
556 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &allocated_id));
557 EXPECT_EQ(even_id + 2, allocated_id);
558
559 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &allocated_id));
560 EXPECT_EQ(odd_id + 4, allocated_id);
561
562 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &allocated_id));
563 EXPECT_EQ(even_id + 4, allocated_id);
564
565 allocator_.ReleaseSctpSid(odd_id);
566 allocator_.ReleaseSctpSid(even_id);
567
568 // Verifies that removed ids are reused.
569 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &allocated_id));
570 EXPECT_EQ(odd_id, allocated_id);
571
572 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &allocated_id));
573 EXPECT_EQ(even_id, allocated_id);
574
575 // Verifies that used higher ids are not reused.
576 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_SERVER, &allocated_id));
577 EXPECT_EQ(odd_id + 6, allocated_id);
578
579 EXPECT_TRUE(allocator_.AllocateSctpSid(rtc::SSL_CLIENT, &allocated_id));
580 EXPECT_EQ(even_id + 6, allocated_id);
581 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698