Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: extensions/browser/api/cast_channel/logger_unittest.cc

Issue 580923002: Ignore uninteresting events when recording the last errors to report (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to miu's comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/api/cast_channel/logger.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string>
6
5 #include "base/test/simple_test_tick_clock.h" 7 #include "base/test/simple_test_tick_clock.h"
6 #include "extensions/browser/api/cast_channel/cast_auth_util.h" 8 #include "extensions/browser/api/cast_channel/cast_auth_util.h"
7 #include "extensions/browser/api/cast_channel/logger.h" 9 #include "extensions/browser/api/cast_channel/logger.h"
8 #include "extensions/browser/api/cast_channel/logger_util.h" 10 #include "extensions/browser/api/cast_channel/logger_util.h"
11 #include "net/base/net_errors.h"
9 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/zlib/zlib.h" 13 #include "third_party/zlib/zlib.h"
11 14
12 namespace extensions { 15 namespace extensions {
13 namespace core_api { 16 namespace core_api {
14 namespace cast_channel { 17 namespace cast_channel {
15 18
16 const int kTestNssErrorCode = -8164; 19 const int kTestNssErrorCode = -8164;
17 20
18 using proto::AggregatedSocketEvent; 21 using proto::AggregatedSocketEvent;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); 108 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
106 109
107 auth_result = 110 auth_result =
108 AuthResult::CreateWithNSSError("Parsing failed", 111 AuthResult::CreateWithNSSError("Parsing failed",
109 AuthResult::ERROR_NSS_CERT_PARSING_FAILED, 112 AuthResult::ERROR_NSS_CERT_PARSING_FAILED,
110 kTestNssErrorCode); 113 kTestNssErrorCode);
111 logger_->LogSocketChallengeReplyEvent(2, auth_result); 114 logger_->LogSocketChallengeReplyEvent(2, auth_result);
112 115
113 LastErrors last_errors = logger_->GetLastErrors(2); 116 LastErrors last_errors = logger_->GetLastErrors(2);
114 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY); 117 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
115 EXPECT_EQ(last_errors.net_return_value, 0); 118 EXPECT_EQ(last_errors.net_return_value, net::OK);
116 EXPECT_EQ(last_errors.challenge_reply_error_type, 119 EXPECT_EQ(last_errors.challenge_reply_error_type,
117 proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED); 120 proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED);
118 EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode); 121 EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode);
119 122
120 scoped_ptr<Log> log = GetLog(); 123 scoped_ptr<Log> log = GetLog();
121 ASSERT_TRUE(log.get() != NULL); 124 ASSERT_TRUE(log.get() != NULL);
122 125
123 ASSERT_EQ(2, log->aggregated_socket_event_size()); 126 ASSERT_EQ(2, log->aggregated_socket_event_size());
124 { 127 {
125 const AggregatedSocketEvent& aggregated_socket_event = 128 const AggregatedSocketEvent& aggregated_socket_event =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 EXPECT_EQ(EventType::AUTH_CHALLENGE_REPLY, event.type()); 178 EXPECT_EQ(EventType::AUTH_CHALLENGE_REPLY, event.type());
176 EXPECT_EQ(6, event.timestamp_micros()); 179 EXPECT_EQ(6, event.timestamp_micros());
177 EXPECT_EQ(proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED, 180 EXPECT_EQ(proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED,
178 event.challenge_reply_error_type()); 181 event.challenge_reply_error_type());
179 EXPECT_FALSE(event.has_net_return_value()); 182 EXPECT_FALSE(event.has_net_return_value());
180 EXPECT_EQ(kTestNssErrorCode, event.nss_error_code()); 183 EXPECT_EQ(kTestNssErrorCode, event.nss_error_code());
181 } 184 }
182 } 185 }
183 } 186 }
184 187
188 TEST_F(CastChannelLoggerTest, LogLastErrorEvents) {
189 // Net return value is set to an error
190 logger_->LogSocketEventWithRv(
191 1, EventType::TCP_SOCKET_CONNECT, net::ERR_CONNECTION_FAILED);
192
193 LastErrors last_errors = logger_->GetLastErrors(1);
194 EXPECT_EQ(last_errors.event_type, proto::TCP_SOCKET_CONNECT);
195 EXPECT_EQ(last_errors.net_return_value, net::ERR_CONNECTION_FAILED);
196
197 // Challenge reply error set
198 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
199 AuthResult auth_result = AuthResult::Create(
200 "Some error", AuthResult::ErrorType::ERROR_PEER_CERT_EMPTY);
201
202 logger_->LogSocketChallengeReplyEvent(2, auth_result);
203 last_errors = logger_->GetLastErrors(2);
204 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
205 EXPECT_EQ(last_errors.challenge_reply_error_type,
206 proto::CHALLENGE_REPLY_ERROR_PEER_CERT_EMPTY);
207
208 // Logging a non-error event does not set the LastErrors for the channel.
209 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
210 logger_->LogSocketEventWithRv(3, EventType::TCP_SOCKET_CONNECT, net::OK);
211 last_errors = logger_->GetLastErrors(3);
212 EXPECT_EQ(last_errors.event_type, proto::EVENT_TYPE_UNKNOWN);
213 EXPECT_EQ(last_errors.net_return_value, net::OK);
214 EXPECT_EQ(last_errors.challenge_reply_error_type,
215 proto::CHALLENGE_REPLY_ERROR_NONE);
216 EXPECT_EQ(last_errors.nss_error_code, 0);
217
218 // Now log a challenge reply error with NSS error code. LastErrors will be
219 // set.
220 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
221 auth_result = AuthResult::CreateWithNSSError(
222 "Some error",
223 AuthResult::ErrorType::ERROR_WRONG_PAYLOAD_TYPE,
224 kTestNssErrorCode);
225 logger_->LogSocketChallengeReplyEvent(3, auth_result);
226 last_errors = logger_->GetLastErrors(3);
227 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
228 EXPECT_EQ(last_errors.challenge_reply_error_type,
229 proto::CHALLENGE_REPLY_ERROR_WRONG_PAYLOAD_TYPE);
230 EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode);
231
232 // Logging a non-error event does not change the LastErrors for the channel.
233 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
234 logger_->LogSocketEventWithRv(3, EventType::TCP_SOCKET_CONNECT, net::OK);
235 last_errors = logger_->GetLastErrors(3);
236 EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
237 EXPECT_EQ(last_errors.challenge_reply_error_type,
238 proto::CHALLENGE_REPLY_ERROR_WRONG_PAYLOAD_TYPE);
239 EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode);
240 }
241
185 TEST_F(CastChannelLoggerTest, LogSocketReadWrite) { 242 TEST_F(CastChannelLoggerTest, LogSocketReadWrite) {
186 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 50); 243 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 50);
187 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); 244 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
188 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 30); 245 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 30);
189 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); 246 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
190 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, -1); 247 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, -1);
191 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); 248 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
192 logger_->LogSocketEventWithRv(1, EventType::SOCKET_WRITE, 20); 249 logger_->LogSocketEventWithRv(1, EventType::SOCKET_WRITE, 20);
193 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); 250 clock_->Advance(base::TimeDelta::FromMicroseconds(1));
194 251
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 324
268 logger_->Reset(); 325 logger_->Reset();
269 326
270 log = GetLog(); 327 log = GetLog();
271 ASSERT_TRUE(log.get() != NULL); 328 ASSERT_TRUE(log.get() != NULL);
272 329
273 EXPECT_EQ(0, log->aggregated_socket_event_size()); 330 EXPECT_EQ(0, log->aggregated_socket_event_size());
274 } 331 }
275 332
276 } // namespace cast_channel 333 } // namespace cast_channel
277 } // namespace api 334 } // namespace core_api
278 } // namespace extensions 335 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/logger.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698