logger_unittest.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <string>
  7. #include "components/cast_channel/cast_auth_util.h"
  8. #include "components/cast_channel/logger.h"
  9. #include "net/base/net_errors.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace cast_channel {
  12. TEST(CastChannelLoggerTest, LogLastErrorEvents) {
  13. scoped_refptr<Logger> logger(new Logger());
  14. // Net return value is set to an error
  15. logger->LogSocketEventWithRv(1, ChannelEvent::TCP_SOCKET_CONNECT,
  16. net::ERR_CONNECTION_FAILED);
  17. LastError last_error = logger->GetLastError(1);
  18. EXPECT_EQ(last_error.channel_event, ChannelEvent::TCP_SOCKET_CONNECT);
  19. EXPECT_EQ(last_error.net_return_value, net::ERR_CONNECTION_FAILED);
  20. // Challenge reply error set
  21. AuthResult auth_result = AuthResult::CreateWithParseError(
  22. "Some error", AuthResult::ErrorType::ERROR_PEER_CERT_EMPTY);
  23. logger->LogSocketChallengeReplyEvent(2, auth_result);
  24. last_error = logger->GetLastError(2);
  25. EXPECT_EQ(last_error.channel_event, ChannelEvent::AUTH_CHALLENGE_REPLY);
  26. EXPECT_EQ(last_error.challenge_reply_error,
  27. ChallengeReplyError::PEER_CERT_EMPTY);
  28. // Logging a non-error event does not set the LastError for the channel.
  29. logger->LogSocketEventWithRv(3, ChannelEvent::TCP_SOCKET_CONNECT, net::OK);
  30. last_error = logger->GetLastError(3);
  31. EXPECT_EQ(last_error.channel_event, ChannelEvent::UNKNOWN);
  32. EXPECT_EQ(last_error.net_return_value, net::OK);
  33. EXPECT_EQ(last_error.challenge_reply_error, ChallengeReplyError::NONE);
  34. // Now log a challenge reply error. LastError will be set.
  35. auth_result =
  36. AuthResult("Some error failed", AuthResult::ERROR_WRONG_PAYLOAD_TYPE);
  37. logger->LogSocketChallengeReplyEvent(3, auth_result);
  38. last_error = logger->GetLastError(3);
  39. EXPECT_EQ(last_error.channel_event, ChannelEvent::AUTH_CHALLENGE_REPLY);
  40. EXPECT_EQ(last_error.challenge_reply_error,
  41. ChallengeReplyError::WRONG_PAYLOAD_TYPE);
  42. // Logging a non-error event does not change the LastError for the channel.
  43. logger->LogSocketEventWithRv(3, ChannelEvent::TCP_SOCKET_CONNECT, net::OK);
  44. last_error = logger->GetLastError(3);
  45. EXPECT_EQ(last_error.channel_event, ChannelEvent::AUTH_CHALLENGE_REPLY);
  46. EXPECT_EQ(last_error.challenge_reply_error,
  47. ChallengeReplyError::WRONG_PAYLOAD_TYPE);
  48. }
  49. } // namespace cast_channel