| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #include <stddef.h> | |
| 6 #include <stdint.h> | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "components/cast_channel/cast_auth_util.h" | |
| 11 #include "components/cast_channel/logger.h" | |
| 12 #include "net/base/net_errors.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace cast_channel { | |
| 16 | |
| 17 using proto::EventType; | |
| 18 using proto::Log; | |
| 19 using proto::SocketEvent; | |
| 20 | |
| 21 TEST(CastChannelLoggerTest, LogLastErrorEvents) { | |
| 22 scoped_refptr<Logger> logger(new Logger()); | |
| 23 | |
| 24 // Net return value is set to an error | |
| 25 logger->LogSocketEventWithRv(1, EventType::TCP_SOCKET_CONNECT, | |
| 26 net::ERR_CONNECTION_FAILED); | |
| 27 | |
| 28 LastErrors last_errors = logger->GetLastErrors(1); | |
| 29 EXPECT_EQ(last_errors.event_type, proto::TCP_SOCKET_CONNECT); | |
| 30 EXPECT_EQ(last_errors.net_return_value, net::ERR_CONNECTION_FAILED); | |
| 31 | |
| 32 // Challenge reply error set | |
| 33 AuthResult auth_result = AuthResult::CreateWithParseError( | |
| 34 "Some error", AuthResult::ErrorType::ERROR_PEER_CERT_EMPTY); | |
| 35 | |
| 36 logger->LogSocketChallengeReplyEvent(2, auth_result); | |
| 37 last_errors = logger->GetLastErrors(2); | |
| 38 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY); | |
| 39 EXPECT_EQ(last_errors.challenge_reply_error_type, | |
| 40 proto::CHALLENGE_REPLY_ERROR_PEER_CERT_EMPTY); | |
| 41 | |
| 42 // Logging a non-error event does not set the LastErrors for the channel. | |
| 43 logger->LogSocketEventWithRv(3, EventType::TCP_SOCKET_CONNECT, net::OK); | |
| 44 last_errors = logger->GetLastErrors(3); | |
| 45 EXPECT_EQ(last_errors.event_type, proto::EVENT_TYPE_UNKNOWN); | |
| 46 EXPECT_EQ(last_errors.net_return_value, net::OK); | |
| 47 EXPECT_EQ(last_errors.challenge_reply_error_type, | |
| 48 proto::CHALLENGE_REPLY_ERROR_NONE); | |
| 49 | |
| 50 // Now log a challenge reply error. LastErrors will be set. | |
| 51 auth_result = | |
| 52 AuthResult("Some error failed", AuthResult::ERROR_WRONG_PAYLOAD_TYPE); | |
| 53 logger->LogSocketChallengeReplyEvent(3, auth_result); | |
| 54 last_errors = logger->GetLastErrors(3); | |
| 55 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY); | |
| 56 EXPECT_EQ(last_errors.challenge_reply_error_type, | |
| 57 proto::CHALLENGE_REPLY_ERROR_WRONG_PAYLOAD_TYPE); | |
| 58 | |
| 59 // Logging a non-error event does not change the LastErrors for the channel. | |
| 60 logger->LogSocketEventWithRv(3, EventType::TCP_SOCKET_CONNECT, net::OK); | |
| 61 last_errors = logger->GetLastErrors(3); | |
| 62 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY); | |
| 63 EXPECT_EQ(last_errors.challenge_reply_error_type, | |
| 64 proto::CHALLENGE_REPLY_ERROR_WRONG_PAYLOAD_TYPE); | |
| 65 } | |
| 66 | |
| 67 } // namespace cast_channel | |
| OLD | NEW |