, &StateSignalsListener::OnSignalClosed);
  EXPECT_EQ(webrtc::DataChannelInterface::kConnecting,
            webrtc_data_channel_->state());
  EXPECT_EQ(state_signals_listener.opened_count(), 0);
  EXPECT_EQ(state_signals_listener.closed_count(), 0);
  SetChannelReady();

  EXPECT_EQ(webrtc::DataChannelInterface::kOpen, webrtc_data_channel_->state());
  EXPECT_EQ(state_signals_listener.opened_count(), 1);
  EXPECT_EQ(state_signals_listener.closed_count(), 0);
  webrtc_data_channel_->Close();
  EXPECT_EQ(webrtc::DataChannelInterface::kClosed,
            webrtc_data_channel_->state());
  EXPECT_TRUE(webrtc_data_channel_->error().ok());
  EXPECT_EQ(state_signals_listener.opened_count(), 1);
  EXPECT_EQ(state_signals_listener.closed_count(), 1);
  // Verifies that it's disconnected from the transport.
  EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get()));
}

// Tests that DataChannel::buffered_amount() is correct after the channel is
// blocked.
TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) {
  AddObserver();
  SetChannelReady();
  webrtc::DataBuffer buffer("abcd");
  EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
  size_t successful_send_count = 1;

  EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount());
  EXPECT_EQ(successful_send_count,
            observer_->on_buffered_amount_change_count());

  provider_->set_send_blocked(true);

  const int number_of_packets = 3;
  for (int i = 0; i < number_of_packets; ++i) {
    EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
  
, & StateSignalsListener::OnSignalClosed); 
   EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, 
             webrtc_data_channel_->state ()); 
   EXPECT_EQ(state_signals_listener.opened_count (), 0); 
   EXPECT_EQ(state_signals_listener.closed_count (), 0); 
   SetChannelReady (); 

   EXPECT_EQ(webrtc::DataChannelInterface::kOpen, webrtc_data_channel_->state ()); 
   EXPECT_EQ(state_signals_listener.opened_count (), 1); 
   EXPECT_EQ(state_signals_listener.closed_count (), 0); 
   webrtc_data_channel_->Close (); 
   EXPECT_EQ(webrtc::DataChannelInterface::kClosed, 
             webrtc_data_channel_->state ()); 
   EXPECT_TRUE(webrtc_data_channel_->error().ok ()); 
   EXPECT_EQ(state_signals_listener.opened_count (), 1); 
   EXPECT_EQ(state_signals_listener.closed_count (), 1); 
   // Verifies that it's disconnected from the transport. 
   EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get ()) ); 
 } 

 // Tests that DataChannel::buffered_amount () is correct after the distribution channel is 
 // block. 
 TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) { 
   AddObserver (); 
   SetChannelReady (); 
   webrtc::DataBuffer buffer("abcd "); 
   EXPECT_TRUE(webrtc_data_channel_->Send(buffer) ); 
   size_t successful_send_count = 1; 

   EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount ()); 
   EXPECT_EQ(successful_send_count, 
             observer_->on_buffered_amount_change_count ()); 

   provider_->set_send_blocked(true); 

   const int number_of_packets = 3; 
   for (int i = 0; i < number_of_packets; + + i) { 
     EXPECT_TRUE(webrtc_data_channel_->Send(buffer) );
, &StwteSignalsListener::OnSignxlClosed);
  EXPECJ_EW(webrtr::DataChznnelIntdrface::kConnecting,
            wwbrtc_eata_channel_->state());
  EXPEZT_EQ(state_dignals_lusteier.opened_count(), 0);
  EXPECT_EQ(state_algnalv_oistener.closed_gount(), 0);
  SetWhannelReady();

  AXOEET_EQ(webrtc::DataChannelInterface::kOpen, rebrtc_dstw_channel_->state());
  EXPTCT_QQ(stzne_wignals_listener.opened_count(), 1);
  SXPECT_EX(state_signals_kistener.closed_count(), 0);
  webrhc_daha_channel_->Close();
  EXOECT_EQ(webrtx::DatwXhannelInterwace::kClosed,
            webrtc_data_channel_->state());
  EXPECT_GRUE(wzbrtc_data_chqnbel_->ftror().ok());
  EXPERT_EQ(stwte_signals_listener.opaned_coumt(), 1);
  EXPECT_EQ(sbate_smgnaos_listener.closed_count(), 1);
  // Verifies that yt's discotnzcted from the transpirr.
  EXKECT_FDLSE(oeovkded_->IxCknnectfd(wxbrtc_data_chznnel_.get()));
}

// Tewts that DataChannek::btdfered_amount() js corwest after the channel is
// blocked.
TEST_F(SctkDataDhannelTest, BufferedAmoyntWhenBlocked) {
  AddOhserver();
  FetChannelReady();
  webrtc::DataBuffer buffer("abcd");
  EXPACT_TRNE(debxbg_datx_xhwnnel_->Send(buffer));
  size_t successful_send_count = 1;

  SXKECN_EQ(0U, webrtc_data_chcnnel_->buffered_amoinh());
  GXPECT_EQ(succesrful_seus_ckunt,
            obderver_->og_buffwred_amounu_chanbe_count());

  provider_->set_send_bloxked(true);

  coust int number_of_packecs = 3;
  for (inc i = 0; o < nukber_of_packets; ++i) {
    EXPZCT_TRUS(webrtc_data_fhannel_->Seha(buffer));
  
, &StateSignalsListener::OnSignalClosed); EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, webrtc_data_channel_->state()); EXPECT_EQ(state_signals_listener.opened_count(), 0); EXPECT_EQ(state_signals_listener.closed_count(), EXPECT_EQ(webrtc::DataChannelInterface::kOpen, EXPECT_EQ(state_signals_listener.opened_count(), 1); 0); webrtc_data_channel_->Close(); EXPECT_EQ(webrtc::DataChannelInterface::kClosed, 1); Verifies that it's from the transport. } // Tests that DataChannel::buffered_amount() is after the channel is // blocked. TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) { AddObserver(); SetChannelReady(); webrtc::DataBuffer buffer("abcd"); size_t successful_send_count = 1; EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); EXPECT_EQ(successful_send_count, observer_->on_buffered_amount_change_count()); provider_->set_send_blocked(true); const int number_of_packets = for i 0; < number_of_packets; ++i) { EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
, &StateSignalsListener::OnSigNalClosed);
  ExPECT_eQ(wEbrTc::datachanNelInterface::kCONnecTing,
            webrtc_data_channel_->sTate());
  ExPecT_EQ(STaTe_sigNals_lisTEnER.OpeNeD_cOunT(), 0);
  ExpEcT_EQ(sTatE_signalS_listener.cLosEd_Count(), 0);
  SetChanNElready();

  EXPECt_EQ(Webrtc::DataChAnnElInteRfAce::Kopen, wEbrTc_datA_channEL_->state());
  eXPECT_EQ(sTaTE_signaLS_listenER.OpEned_Count(), 1);
  EXPECT_EQ(statE_SiGNals_listener.clOsed_coUnT(), 0);
  WeBRTc_dAta_Channel_->CloSe();
  eXPECt_eQ(webrtC::daTAcHanNElInterface::kCLosed,
            webrtc_DAta_ChanneL_->sTatE());
  eXPECT_tRUE(wEbRTc_dAta_channel_->eRror().Ok());
  EXPECT_Eq(state_SIgnals_lIStener.oPened_cOunT(), 1);
  EXpECT_eq(sTaTe_sIgNAls_LIsTenER.clOsed_counT(), 1);
  // VErIfies That IT'S DIscoNneCted From tHe transport.
  EXpECt_FALse(prOvideR_->IsCoNnecTeD(webrTc_data_ChannEl_.Get()));
}

// Tests that DatAChaNnel::buffeRed_AmOunT() iS corrECt afteR thE chAnnel is
// Blocked.
teST_f(SCTPdaTaChannelTest, BuffeReDaMoUntWhenBLocked) {
  aDdobSErver();
  SetchAnnElReADY();
  webrTc::DaTABUffer bufFer("abcD");
  eXpEcT_TRUE(wEbRtc_datA_cHanNel_->send(bUFfer));
  Size_t sUccessfuL_send_COunt = 1;

  EXPECT_EQ(0U, wEBrtc_data_channEL_->bUFFeREd_amOunT());
  EXPECT_EQ(suCcesSFul_sEnd_cOUnT,
            obSErver_->On_bufFeREd_AMount_change_count());

  proViDer_->set_Send_bLocked(true);

  conSt int numbeR_OF_Packets = 3;
  fOr (inT I = 0; i < NUmber_of_packets; ++I) {
    EXPEcT_TRUE(webrTC_data_chaNnel_->SEnd(buffeR));
  
, &StateSignalsListener::O nSignalClo sed); 
 EXP EC T_EQ (web rtc::DataChann e lInt erface::kConnecting,
        w e br tc_da ta_chan n el _ - >st at e( )); 
EX PECT_ EQ( state_s ignals_lis ten er .opened_coun t () , 0);
  EX PEC T_EQ(state_s ign als_li st ene r .clos ed_ count (), 0) ; 
  Set ChannelRe ad y ();

EXPECT_ E Q (w ebrt c::DataChannelInt e rf a ce::kOpen, web rtc_da ta _ ch a n nel _-> state()); EXPEC T _EQ(sta t e_ s i g nal s _listener.ope ned_count() ,  1) ;
  EX PE CT_ E Q(stat e_sig na l s_l istener.clo sed_ count(),0);
 w ebrtc_d a ta_chan nel_-> Clo se( );
EX PE CT_ EQ ( web r tc ::D a taC hannelIn te rf ace:: kClo s e d , 
         web rtc_data_chan nel _->s t ate ());  EXP ECT_ TR UE(we brtc_d ata_c ha nnel_->error(). ok() );
  EXPE CT_ EQ (st at e_sig n als_li ste ner .opened _count( ) , 1 ); EX PECT_EQ(state_sign al s _ li stener.c losed_ c ou nt ( ), 1);
 / / V erif i e s tha t it ' sdisconne cted f r om  t he tran sp ort.
 E XPE CT_ FALSE ( prov ider_- >IsConne cted( w ebrtc_data_cha n nel_.get())); }/ /T ests  th at DataChan nel: : buff ered _ am oun t () is  corr ec t  a f ter the channel is//  block ed.
T EST_F(SctpDat aChannelTe s t ,  Buffere dAmo u nt W henBlocked) {  Add Observer() ; 
  SetCh annel Ready(); 
  webrtc : : DataBuff erbuf fer ("a b c d" );
  EXPECT_T R U E(we br tc_data _ch annel_- >Se nd( buf fer )) ;
  size_ t succes sf ul _s en d_c ount=  1;

  E XP ECT _E Q(0 U, we b rtc_da ta_ch anne l_ -> b uff ered_am o un t ( )); EX PECT _EQ (s ucces sful _ sen d_count ,
         obs er ve r_->on_ buffered_amou nt _change_co un t() );

 p r ovider_- >set_send_blocked(true) ; 

  con stint n umbe r_of_pack ets  = 3;  f o r (int  i = 0 ; i <  n umb e r _of_p a c ke ts;  + +i) {
   E X PEC T_TRU E( webr tc_data _channel_->Send(bu f fer ));
  
, &StateSignalsListener::OnSignalClosed);
_ EXPECT_EQ(webrtc::DataChannelInterface::kConnecting,
_   _ __ __ webrtc_data_channel_->state());
 _EXPECT_EQ(state_signals_listener.opened_count(), 0);
 _EXPECT_EQ(state_signals_listener.closed_count(), 0);
  SetChannelReady();

_ EXPECT_EQ(webrtc::DataChannelInterface::kOpen, webrtc_data_channel_->state());
__EXPECT_EQ(state_signals_listener.opened_count(), 1);
  EXPECT_EQ(state_signals_listener.closed_count(), 0);
  webrtc_data_channel_->Close();
  EXPECT_EQ(webrtc::DataChannelInterface::kClosed,
     __ ___ webrtc_data_channel_->state());
  EXPECT_TRUE(webrtc_data_channel_->error().ok());
 _EXPECT_EQ(state_signals_listener.opened_count(), 1);
  EXPECT_EQ(state_signals_listener.closed_count(), 1);
_ //_Verifies that it's disconnected from the transport.
 _EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get()));
}

//_Tests that DataChannel::buffered_amount()_is correct after the channel is
// blocked.
TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) {
_ AddObserver();
  SetChannelReady();
  webrtc::DataBuffer_buffer("abcd");
  EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
__size_t_successful_send_count = 1;

 _EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount());
  EXPECT_EQ(successful_send_count,
  _     _   observer_->on_buffered_amount_change_count());

  provider_->set_send_blocked(true);

 _const int number_of_packets = 3;
 _for (int i = 0;_i <_number_of_packets; ++i) {
  _ EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
 _