OLD | NEW |
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 "base/test/simple_test_tick_clock.h" | 5 #include "base/test/simple_test_tick_clock.h" |
6 #include "extensions/browser/api/cast_channel/cast_auth_util.h" | 6 #include "extensions/browser/api/cast_channel/cast_auth_util.h" |
7 #include "extensions/browser/api/cast_channel/logger.h" | 7 #include "extensions/browser/api/cast_channel/logger.h" |
8 #include "extensions/browser/api/cast_channel/logger_util.h" | 8 #include "extensions/browser/api/cast_channel/logger_util.h" |
| 9 #include "net/base/net_errors.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/zlib/zlib.h" | 11 #include "third_party/zlib/zlib.h" |
11 | 12 |
12 namespace extensions { | 13 namespace extensions { |
13 namespace core_api { | 14 namespace core_api { |
14 namespace cast_channel { | 15 namespace cast_channel { |
15 | 16 |
16 const int kTestNssErrorCode = -8164; | 17 const int kTestNssErrorCode = -8164; |
17 | 18 |
18 using proto::AggregatedSocketEvent; | 19 using proto::AggregatedSocketEvent; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 EXPECT_EQ(EventType::AUTH_CHALLENGE_REPLY, event.type()); | 176 EXPECT_EQ(EventType::AUTH_CHALLENGE_REPLY, event.type()); |
176 EXPECT_EQ(6, event.timestamp_micros()); | 177 EXPECT_EQ(6, event.timestamp_micros()); |
177 EXPECT_EQ(proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED, | 178 EXPECT_EQ(proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED, |
178 event.challenge_reply_error_type()); | 179 event.challenge_reply_error_type()); |
179 EXPECT_FALSE(event.has_net_return_value()); | 180 EXPECT_FALSE(event.has_net_return_value()); |
180 EXPECT_EQ(kTestNssErrorCode, event.nss_error_code()); | 181 EXPECT_EQ(kTestNssErrorCode, event.nss_error_code()); |
181 } | 182 } |
182 } | 183 } |
183 } | 184 } |
184 | 185 |
| 186 TEST_F(CastChannelLoggerTest, UninterestingEventsIgnored) { |
| 187 logger_->LogSocketEventWithRv(1, EventType::CAST_SOCKET_CREATED, net::OK); |
| 188 // CAST_SOCKET_CREATED is interesting. |
| 189 LastErrors last_errors = logger_->GetLastErrors(1); |
| 190 EXPECT_EQ(last_errors.event_type, proto::CAST_SOCKET_CREATED); |
| 191 EXPECT_EQ(last_errors.net_return_value, net::OK); |
| 192 |
| 193 // These four events and net return value are not interesting, and are not |
| 194 // reported in last_errors. |
| 195 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
| 196 logger_->LogSocketEventWithRv(1, |
| 197 EventType::READY_STATE_CHANGED, |
| 198 net::ERR_IO_PENDING); |
| 199 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
| 200 logger_->LogSocketEvent(1, EventType::ERROR_STATE_CHANGED); |
| 201 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
| 202 logger_->LogSocketEvent(1, EventType::NOTIFY_ON_MESSAGE); |
| 203 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
| 204 logger_->LogSocketEvent(1, EventType::NOTIFY_ON_ERROR); |
| 205 last_errors = logger_->GetLastErrors(1); |
| 206 EXPECT_EQ(last_errors.event_type, proto::CAST_SOCKET_CREATED); |
| 207 EXPECT_EQ(last_errors.net_return_value, net::OK); |
| 208 |
| 209 // Log an interesting event again. |
| 210 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
| 211 logger_->LogSocketEventWithRv(1, EventType::CONNECT_FAILED, net::ERR_FAILED); |
| 212 last_errors = logger_->GetLastErrors(1); |
| 213 EXPECT_EQ(last_errors.event_type, proto::CONNECT_FAILED); |
| 214 EXPECT_EQ(last_errors.net_return_value, net::ERR_FAILED); |
| 215 } |
| 216 |
185 TEST_F(CastChannelLoggerTest, LogSocketReadWrite) { | 217 TEST_F(CastChannelLoggerTest, LogSocketReadWrite) { |
186 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 50); | 218 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 50); |
187 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); | 219 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
188 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 30); | 220 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, 30); |
189 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); | 221 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
190 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, -1); | 222 logger_->LogSocketEventWithRv(1, EventType::SOCKET_READ, -1); |
191 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); | 223 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
192 logger_->LogSocketEventWithRv(1, EventType::SOCKET_WRITE, 20); | 224 logger_->LogSocketEventWithRv(1, EventType::SOCKET_WRITE, 20); |
193 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); | 225 clock_->Advance(base::TimeDelta::FromMicroseconds(1)); |
194 | 226 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 301 |
270 log = GetLog(); | 302 log = GetLog(); |
271 ASSERT_TRUE(log.get() != NULL); | 303 ASSERT_TRUE(log.get() != NULL); |
272 | 304 |
273 EXPECT_EQ(0, log->aggregated_socket_event_size()); | 305 EXPECT_EQ(0, log->aggregated_socket_event_size()); |
274 } | 306 } |
275 | 307 |
276 } // namespace cast_channel | 308 } // namespace cast_channel |
277 } // namespace api | 309 } // namespace api |
278 } // namespace extensions | 310 } // namespace extensions |
OLD | NEW |