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