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

Unified 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: Update to check for error fields set 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/cast_channel/logger_unittest.cc
diff --git a/extensions/browser/api/cast_channel/logger_unittest.cc b/extensions/browser/api/cast_channel/logger_unittest.cc
index 3d1f964e42f585adfdee67fd8543fa8d0639dd2c..260c72ea6926814209186325184f234f1bf65024 100644
--- a/extensions/browser/api/cast_channel/logger_unittest.cc
+++ b/extensions/browser/api/cast_channel/logger_unittest.cc
@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
+
#include "base/test/simple_test_tick_clock.h"
#include "extensions/browser/api/cast_channel/cast_auth_util.h"
#include "extensions/browser/api/cast_channel/logger.h"
#include "extensions/browser/api/cast_channel/logger_util.h"
+#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/zlib.h"
@@ -112,7 +115,7 @@ TEST_F(CastChannelLoggerTest, BasicLogging) {
LastErrors last_errors = logger_->GetLastErrors(2);
EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
- EXPECT_EQ(last_errors.net_return_value, 0);
+ EXPECT_EQ(last_errors.net_return_value, net::OK);
EXPECT_EQ(last_errors.challenge_reply_error_type,
proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED);
EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode);
@@ -182,6 +185,60 @@ TEST_F(CastChannelLoggerTest, BasicLogging) {
}
}
+TEST_F(CastChannelLoggerTest, LogLastErrorEvents) {
+ // Net return value is set to an error
+ logger_->LogSocketEventWithRv(
+ 1, EventType::TCP_SOCKET_CONNECT, net::ERR_CONNECTION_FAILED);
+
+ LastErrors last_errors = logger_->GetLastErrors(1);
+ EXPECT_EQ(last_errors.event_type, proto::TCP_SOCKET_CONNECT);
+ EXPECT_EQ(last_errors.net_return_value, net::ERR_CONNECTION_FAILED);
+
+ // Challenge reply error set
+ clock_->Advance(base::TimeDelta::FromMicroseconds(1));
+ AuthResult auth_result = AuthResult::Create(
+ "Some error", AuthResult::ErrorType::ERROR_PEER_CERT_EMPTY);
+
+ logger_->LogSocketChallengeReplyEvent(2, auth_result);
+ last_errors = logger_->GetLastErrors(2);
+ EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
+ EXPECT_EQ(last_errors.challenge_reply_error_type,
+ proto::CHALLENGE_REPLY_ERROR_PEER_CERT_EMPTY);
+
+ // Logging a non-error event does not set the LastErrors for the channel.
+ clock_->Advance(base::TimeDelta::FromMicroseconds(1));
+ logger_->LogSocketEventWithRv(3, EventType::TCP_SOCKET_CONNECT, net::OK);
+ last_errors = logger_->GetLastErrors(3);
+ EXPECT_EQ(last_errors.event_type, proto::EVENT_TYPE_UNKNOWN);
+ EXPECT_EQ(last_errors.net_return_value, net::OK);
+ EXPECT_EQ(last_errors.challenge_reply_error_type,
+ proto::CHALLENGE_REPLY_ERROR_NONE);
+ EXPECT_EQ(last_errors.nss_error_code, 0);
+
+ // Now log a challenge reply error with NSS error code. LastErrors will be
+ // set.
+ clock_->Advance(base::TimeDelta::FromMicroseconds(1));
+ auth_result = AuthResult::CreateWithNSSError(
+ "Some error",
+ AuthResult::ErrorType::ERROR_WRONG_PAYLOAD_TYPE,
+ kTestNssErrorCode);
+ logger_->LogSocketChallengeReplyEvent(3, auth_result);
+ last_errors = logger_->GetLastErrors(3);
+ EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
+ EXPECT_EQ(last_errors.challenge_reply_error_type,
+ proto::CHALLENGE_REPLY_ERROR_WRONG_PAYLOAD_TYPE);
+ EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode);
+
+ // Logging a non-error event does not change the LastErrors for the channel.
+ clock_->Advance(base::TimeDelta::FromMicroseconds(1));
+ logger_->LogSocketEventWithRv(3, EventType::TCP_SOCKET_CONNECT, net::OK);
+ last_errors = logger_->GetLastErrors(3);
+ EXPECT_EQ(last_errors.event_type, proto::AUTH_CHALLENGE_REPLY);
+ EXPECT_EQ(last_errors.challenge_reply_error_type,
+ proto::CHALLENGE_REPLY_ERROR_WRONG_PAYLOAD_TYPE);
+ EXPECT_EQ(last_errors.nss_error_code, kTestNssErrorCode);
+}
+
TEST_F(CastChannelLoggerTest, LogSocketReadWrite) {
logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 50);
clock_->Advance(base::TimeDelta::FromMicroseconds(1));
@@ -274,5 +331,5 @@ TEST_F(CastChannelLoggerTest, Reset) {
}
} // namespace cast_channel
-} // namespace api
+} // namespace core_api
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698