src/connectivity/bluetooth/core/bt-host/l2cap/bredr_dynamic_channel_unittest.cc
TEST_F(L2CAP_BrEdrDynamicChannelTest,
       DisconnectOnInconsistentChannelModeNegotiationFailureWhenPeerConfigRequestIsLast) {
  EXPECT_OUTBOUND_REQ(*sig(), kConnectionRequest, kConnReq.view(),
                      {SignalingChannel::Status::kSuccess, kOkConnRsp.view()});
  EXPECT_OUTBOUND_REQ(*sig(), kConfigurationRequest, kOutboundConfigReqWithErtm.view(),
                      {SignalingChannel::Status::kSuccess, kInboundEmptyConfigRsp.view()});
  EXPECT_OUTBOUND_REQ(*sig(), kDisconnectionRequest, kDisconReq.view(),
                      {SignalingChannel::Status::kSuccess, kDisconRsp.view()});

  int open_cb_count = 0;

  auto open_cb = [&open_cb_count](const DynamicChannel* chan) {
    if (open_cb_count == 0) {
      ASSERT_FALSE(chan);
    }
    open_cb_count++;
  };

  registry()->OpenOutbound(kPsm, std::move(open_cb), kERTMChannelParams);

  RETURN_IF_FATAL(RunLoopUntilIdle());

  sig()->ReceiveResponses(ext_info_transaction_id(), {{SignalingChannel::Status::kSuccess,
                                                       kExtendedFeaturesInfoRspWithERTM.view()}});
  // Request ERTM.
  RunLoopUntilIdle();

  // Peer requests basic mode.
  RETURN_IF_FATAL(
      sig()->ReceiveExpect(kConfigurationRequest, kInboundConfigReq, kOutboundOkConfigRsp));

  // Disconnect
  RunLoopUntilIdle();
  EXPECT_EQ(1, open_cb_count);
}
// Local config with ERTM incorrectly accepted by peer, then peer requests basic mode which
// the local device must accept. These modes are incompatible, so the local device should
// disconnect.
Local config with ERTM incorrectly accepted by peer, then peer requests basic mode which
the local device must accept. These modes are incompatible, so the local device should
disconnect.
Local config with ERTM incorrectly accepted by peer then peer requests basic mode which the local device must accept . These modes are incompatible so the local device should disconnect .
TEST_F(L2CAP_BrEdrDynamicChannelTest,
       DisconnectOnInconsistentChannelModeNegotiationFailureWhenPeerConfigRequestIsLast) {
  EXPECT_OUTBOUND_REQ(*sig(), kConnectionRequest, kConnReq.view(),
                      {SignalingChannel::Status::kSuccess, kOkConnRsp.view()});
  EXPECT_OUTBOUND_REQ(*sig(), kConfigurationRequest, kOutboundConfigReqWithErtm.view(),
                      {SignalingChannel::Status::kSuccess, kInboundEmptyConfigRsp.view()});
  EXPECT_OUTBOUND_REQ(*sig(), kDisconnectionRequest, kDisconReq.view(),
                      {SignalingChannel::Status::kSuccess, kDisconRsp.view()});
  int open_cb_count = 0;
  auto open_cb = [&open_cb_count](const DynamicChannel* chan) {
    if (open_cb_count == 0) {
      ASSERT_FALSE(chan);
    }
    open_cb_count++;
  };
  registry()->OpenOutbound(kPsm, std::move(open_cb), kERTMChannelParams);
  RETURN_IF_FATAL(RunLoopUntilIdle());
  sig()->ReceiveResponses(ext_info_transaction_id(), {{SignalingChannel::Status::kSuccess,
                                                       kExtendedFeaturesInfoRspWithERTM.view()}});
  RunLoopUntilIdle();
  RETURN_IF_FATAL(
      sig()->ReceiveExpect(kConfigurationRequest, kInboundConfigReq, kOutboundOkConfigRsp));
  RunLoopUntilIdle();
  EXPECT_EQ(1, open_cb_count);
}
TEST_F ( L2CAP_BrEdrDynamicChannelTest , DisconnectOnInconsistentChannelModeNegotiationFailureWhenPeerConfigRequestIsLast ) { EXPECT_OUTBOUND_REQ ( * sig ( ) , kConnectionRequest , kConnReq . view ( ) , { SignalingChannel :: Status :: kSuccess , kOkConnRsp . view ( ) } ) ; EXPECT_OUTBOUND_REQ ( * sig ( ) , kConfigurationRequest , kOutboundConfigReqWithErtm . view ( ) , { SignalingChannel :: Status :: kSuccess , kInboundEmptyConfigRsp . view ( ) } ) ; EXPECT_OUTBOUND_REQ ( * sig ( ) , kDisconnectionRequest , kDisconReq . view ( ) , { SignalingChannel :: Status :: kSuccess , kDisconRsp . view ( ) } ) ; int open_cb_count = 0 ; auto open_cb = [ & open_cb_count ] ( const DynamicChannel * chan ) { if ( open_cb_count == 0 ) { ASSERT_FALSE ( chan ) ; } open_cb_count ++ ; } ; registry ( ) -> OpenOutbound ( kPsm , std :: move ( open_cb ) , kERTMChannelParams ) ; RETURN_IF_FATAL ( RunLoopUntilIdle ( ) ) ; sig ( ) -> ReceiveResponses ( ext_info_transaction_id ( ) , { { SignalingChannel :: Status :: kSuccess , kExtendedFeaturesInfoRspWithERTM . view ( ) } } ) ; RunLoopUntilIdle ( ) ; RETURN_IF_FATAL ( sig ( ) -> ReceiveExpect ( kConfigurationRequest , kInboundConfigReq , kOutboundOkConfigRsp ) ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( 1 , open_cb_count ) ; }
Local config with ERTM incorrectly accepted by peer, then peer requests basic mode which
the local device must accept.
Local config with ERTM incorrectly accepted by peer then peer requests basic mode which the local device must accept .
// Request ERTM. // Peer requests basic mode. // Disconnect