Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / remoting / protocol / jingle_session_unittest.cc
index dcca077..2f95100 100644 (file)
@@ -105,6 +105,10 @@ class JingleSessionTest : public testing::Test {
     session->set_config(SessionConfig::ForTest());
   }
 
+  void DeleteSession() {
+    host_session_.reset();
+  }
+
   void OnClientChannelCreated(scoped_ptr<net::StreamSocket> socket) {
     client_channel_callback_.OnDone(socket.get());
     client_socket_ = socket.Pass();
@@ -132,7 +136,7 @@ class JingleSessionTest : public testing::Test {
     client_session_.reset();
   }
 
-  void CreateSessionManagers(int auth_round_trips,
+  void CreateSessionManagers(int auth_round_trips, int messages_till_start,
                         FakeAuthenticator::Action auth_action) {
     host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid));
     client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid));
@@ -153,7 +157,8 @@ class JingleSessionTest : public testing::Test {
     host_server_->Init(host_signal_strategy_.get(), &host_server_listener_);
 
     scoped_ptr<AuthenticatorFactory> factory(
-        new FakeHostAuthenticatorFactory(auth_round_trips, auth_action, true));
+        new FakeHostAuthenticatorFactory(auth_round_trips,
+          messages_till_start, auth_action, true));
     host_server_->set_authenticator_factory(factory.Pass());
 
     EXPECT_CALL(client_server_listener_, OnSessionManagerReady())
@@ -169,6 +174,11 @@ class JingleSessionTest : public testing::Test {
                          &client_server_listener_);
   }
 
+  void CreateSessionManagers(int auth_round_trips,
+                             FakeAuthenticator::Action auth_action) {
+    CreateSessionManagers(auth_round_trips, 0, auth_action);
+  }
+
   void CloseSessionManager() {
     if (host_server_.get()) {
       host_server_->Close();
@@ -196,6 +206,9 @@ class JingleSessionTest : public testing::Test {
       EXPECT_CALL(host_session_event_handler_,
                   OnSessionStateChange(Session::CONNECTED))
           .Times(AtMost(1));
+      EXPECT_CALL(host_session_event_handler_,
+                  OnSessionStateChange(Session::AUTHENTICATING))
+          .Times(AtMost(1));
       if (expect_fail) {
         EXPECT_CALL(host_session_event_handler_,
                     OnSessionStateChange(Session::FAILED))
@@ -217,6 +230,9 @@ class JingleSessionTest : public testing::Test {
       EXPECT_CALL(client_session_event_handler_,
                   OnSessionStateChange(Session::CONNECTED))
           .Times(AtMost(1));
+      EXPECT_CALL(client_session_event_handler_,
+                  OnSessionStateChange(Session::AUTHENTICATING))
+          .Times(AtMost(1));
       if (expect_fail) {
         EXPECT_CALL(client_session_event_handler_,
                     OnSessionStateChange(Session::FAILED))
@@ -375,6 +391,60 @@ TEST_F(JingleSessionTest, TestStreamChannel) {
   tester.CheckResults();
 }
 
+TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) {
+  CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
+
+  EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
+      .WillOnce(DoAll(
+          WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)),
+          SetArgumentPointee<1>(protocol::SessionManager::ACCEPT)));
+
+  EXPECT_CALL(host_session_event_handler_,
+      OnSessionStateChange(Session::CONNECTED))
+      .Times(AtMost(1));
+
+  EXPECT_CALL(host_session_event_handler_,
+      OnSessionStateChange(Session::AUTHENTICATING))
+      .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession));
+
+  scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
+      FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true));
+
+  client_session_ = client_server_->Connect(
+      kHostJid, authenticator.Pass(),
+      CandidateSessionConfig::CreateDefault());
+
+  base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(JingleSessionTest, DeleteSessionOnAuth) {
+  // Same as the previous test, but set messages_till_started to 2 in
+  // CreateSessionManagers so that the session will goes into the
+  // AUTHENTICATING state after two message exchanges.
+  CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT);
+
+  EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _))
+      .WillOnce(DoAll(
+          WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)),
+          SetArgumentPointee<1>(protocol::SessionManager::ACCEPT)));
+
+  EXPECT_CALL(host_session_event_handler_,
+      OnSessionStateChange(Session::CONNECTED))
+      .Times(AtMost(1));
+
+  EXPECT_CALL(host_session_event_handler_,
+      OnSessionStateChange(Session::AUTHENTICATING))
+      .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession));
+
+  scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
+      FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true));
+
+  client_session_ = client_server_->Connect(
+      kHostJid, authenticator.Pass(),
+      CandidateSessionConfig::CreateDefault());
+  base::RunLoop().RunUntilIdle();
+}
+
 // Verify that data can be sent over a multiplexed channel.
 TEST_F(JingleSessionTest, TestMuxStreamChannel) {
   CreateSessionManagers(1, FakeAuthenticator::ACCEPT);