[M73 Dev][EFL] Disable VizDisplayCompositor for EFL port
[platform/framework/web/chromium-efl.git] / components / cast_channel / logger_unittest.cc
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 TEST(CastChannelLoggerTest, LogLastErrorEvents) {
18   scoped_refptr<Logger> logger(new Logger());
19
20   // Net return value is set to an error
21   logger->LogSocketEventWithRv(1, ChannelEvent::TCP_SOCKET_CONNECT,
22                                net::ERR_CONNECTION_FAILED);
23
24   LastError last_error = logger->GetLastError(1);
25   EXPECT_EQ(last_error.channel_event, ChannelEvent::TCP_SOCKET_CONNECT);
26   EXPECT_EQ(last_error.net_return_value, net::ERR_CONNECTION_FAILED);
27
28   // Challenge reply error set
29   AuthResult auth_result = AuthResult::CreateWithParseError(
30       "Some error", AuthResult::ErrorType::ERROR_PEER_CERT_EMPTY);
31
32   logger->LogSocketChallengeReplyEvent(2, auth_result);
33   last_error = logger->GetLastError(2);
34   EXPECT_EQ(last_error.channel_event, ChannelEvent::AUTH_CHALLENGE_REPLY);
35   EXPECT_EQ(last_error.challenge_reply_error,
36             ChallengeReplyError::PEER_CERT_EMPTY);
37
38   // Logging a non-error event does not set the LastError for the channel.
39   logger->LogSocketEventWithRv(3, ChannelEvent::TCP_SOCKET_CONNECT, net::OK);
40   last_error = logger->GetLastError(3);
41   EXPECT_EQ(last_error.channel_event, ChannelEvent::UNKNOWN);
42   EXPECT_EQ(last_error.net_return_value, net::OK);
43   EXPECT_EQ(last_error.challenge_reply_error, ChallengeReplyError::NONE);
44
45   // Now log a challenge reply error.  LastError will be set.
46   auth_result =
47       AuthResult("Some error failed", AuthResult::ERROR_WRONG_PAYLOAD_TYPE);
48   logger->LogSocketChallengeReplyEvent(3, auth_result);
49   last_error = logger->GetLastError(3);
50   EXPECT_EQ(last_error.channel_event, ChannelEvent::AUTH_CHALLENGE_REPLY);
51   EXPECT_EQ(last_error.challenge_reply_error,
52             ChallengeReplyError::WRONG_PAYLOAD_TYPE);
53
54   // Logging a non-error event does not change the LastError for the channel.
55   logger->LogSocketEventWithRv(3, ChannelEvent::TCP_SOCKET_CONNECT, net::OK);
56   last_error = logger->GetLastError(3);
57   EXPECT_EQ(last_error.channel_event, ChannelEvent::AUTH_CHALLENGE_REPLY);
58   EXPECT_EQ(last_error.challenge_reply_error,
59             ChallengeReplyError::WRONG_PAYLOAD_TYPE);
60 }
61
62 }  // namespace cast_channel