OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/net/passive_log_collector.h" | 5 #include "chrome/browser/net/passive_log_collector.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/url_request/url_request_netlog_params.h" | 10 #include "net/url_request/url_request_netlog_params.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 typedef PassiveLogCollector::RequestTracker RequestTracker; | 15 typedef PassiveLogCollector::RequestTracker RequestTracker; |
16 typedef PassiveLogCollector::SourceInfoList SourceInfoList; | 16 typedef PassiveLogCollector::SourceInfoList SourceInfoList; |
17 typedef PassiveLogCollector::SocketTracker SocketTracker; | 17 typedef PassiveLogCollector::SocketTracker SocketTracker; |
18 using net::NetLog; | 18 using net::NetLog; |
19 | 19 |
20 const NetLog::SourceType kSourceType = NetLog::SOURCE_NONE; | 20 const NetLog::SourceType kSourceType = NetLog::SOURCE_NONE; |
21 | 21 |
22 PassiveLogCollector::Entry MakeStartLogEntryWithURL(int source_id, | 22 ChromeNetLog::Entry MakeStartLogEntryWithURL(int source_id, |
23 const std::string& url) { | 23 const std::string& url) { |
24 return PassiveLogCollector::Entry( | 24 return ChromeNetLog::Entry( |
25 0, | 25 0, |
26 NetLog::TYPE_URL_REQUEST_START_JOB, | 26 NetLog::TYPE_URL_REQUEST_START_JOB, |
27 base::TimeTicks(), | 27 base::TimeTicks(), |
28 NetLog::Source(kSourceType, source_id), | 28 NetLog::Source(kSourceType, source_id), |
29 NetLog::PHASE_BEGIN, | 29 NetLog::PHASE_BEGIN, |
30 new URLRequestStartEventParameters(GURL(url), "GET", 0, net::LOW)); | 30 new URLRequestStartEventParameters(GURL(url), "GET", 0, net::LOW)); |
31 } | 31 } |
32 | 32 |
33 PassiveLogCollector::Entry MakeStartLogEntry(int source_id) { | 33 ChromeNetLog::Entry MakeStartLogEntry(int source_id) { |
34 return MakeStartLogEntryWithURL(source_id, | 34 return MakeStartLogEntryWithURL(source_id, |
35 StringPrintf("http://req%d", source_id)); | 35 StringPrintf("http://req%d", source_id)); |
36 } | 36 } |
37 | 37 |
38 PassiveLogCollector::Entry MakeEndLogEntry(int source_id) { | 38 ChromeNetLog::Entry MakeEndLogEntry(int source_id) { |
39 return PassiveLogCollector::Entry( | 39 return ChromeNetLog::Entry( |
40 0, | 40 0, |
41 NetLog::TYPE_REQUEST_ALIVE, | 41 NetLog::TYPE_REQUEST_ALIVE, |
42 base::TimeTicks(), | 42 base::TimeTicks(), |
43 NetLog::Source(kSourceType, source_id), | 43 NetLog::Source(kSourceType, source_id), |
44 NetLog::PHASE_END, | 44 NetLog::PHASE_END, |
45 NULL); | 45 NULL); |
46 } | 46 } |
47 | 47 |
48 bool OrderBySourceID(const PassiveLogCollector::SourceInfo& a, | 48 bool OrderBySourceID(const PassiveLogCollector::SourceInfo& a, |
49 const PassiveLogCollector::SourceInfo& b) { | 49 const PassiveLogCollector::SourceInfo& b) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ASSERT_EQ(2u, GetDeadSources(tracker).size()); | 169 ASSERT_EQ(2u, GetDeadSources(tracker).size()); |
170 EXPECT_EQ(url2, GetDeadSources(tracker)[0].GetURL()); | 170 EXPECT_EQ(url2, GetDeadSources(tracker)[0].GetURL()); |
171 EXPECT_EQ(url3, GetDeadSources(tracker)[1].GetURL()); | 171 EXPECT_EQ(url3, GetDeadSources(tracker)[1].GetURL()); |
172 } | 172 } |
173 | 173 |
174 TEST(SpdySessionTracker, MovesToGraveyard) { | 174 TEST(SpdySessionTracker, MovesToGraveyard) { |
175 PassiveLogCollector::SpdySessionTracker tracker; | 175 PassiveLogCollector::SpdySessionTracker tracker; |
176 EXPECT_EQ(0u, GetLiveSources(tracker).size()); | 176 EXPECT_EQ(0u, GetLiveSources(tracker).size()); |
177 EXPECT_EQ(0u, GetDeadSources(tracker).size()); | 177 EXPECT_EQ(0u, GetDeadSources(tracker).size()); |
178 | 178 |
179 PassiveLogCollector::Entry begin( | 179 ChromeNetLog::Entry begin( |
180 0u, | 180 0u, |
181 NetLog::TYPE_SPDY_SESSION, | 181 NetLog::TYPE_SPDY_SESSION, |
182 base::TimeTicks(), | 182 base::TimeTicks(), |
183 NetLog::Source(NetLog::SOURCE_SPDY_SESSION, 1), | 183 NetLog::Source(NetLog::SOURCE_SPDY_SESSION, 1), |
184 NetLog::PHASE_BEGIN, | 184 NetLog::PHASE_BEGIN, |
185 NULL); | 185 NULL); |
186 | 186 |
187 tracker.OnAddEntry(begin); | 187 tracker.OnAddEntry(begin); |
188 EXPECT_EQ(1u, GetLiveSources(tracker).size()); | 188 EXPECT_EQ(1u, GetLiveSources(tracker).size()); |
189 EXPECT_EQ(0u, GetDeadSources(tracker).size()); | 189 EXPECT_EQ(0u, GetDeadSources(tracker).size()); |
190 | 190 |
191 PassiveLogCollector::Entry end( | 191 ChromeNetLog::Entry end( |
192 0u, | 192 0u, |
193 NetLog::TYPE_SPDY_SESSION, | 193 NetLog::TYPE_SPDY_SESSION, |
194 base::TimeTicks(), | 194 base::TimeTicks(), |
195 NetLog::Source(NetLog::SOURCE_SPDY_SESSION, 1), | 195 NetLog::Source(NetLog::SOURCE_SPDY_SESSION, 1), |
196 NetLog::PHASE_END, | 196 NetLog::PHASE_END, |
197 NULL); | 197 NULL); |
198 | 198 |
199 tracker.OnAddEntry(end); | 199 tracker.OnAddEntry(end); |
200 EXPECT_EQ(0u, GetLiveSources(tracker).size()); | 200 EXPECT_EQ(0u, GetLiveSources(tracker).size()); |
201 EXPECT_EQ(1u, GetDeadSources(tracker).size()); | 201 EXPECT_EQ(1u, GetDeadSources(tracker).size()); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 log.OnAddEntry(net::NetLog::TYPE_REQUEST_ALIVE, | 485 log.OnAddEntry(net::NetLog::TYPE_REQUEST_ALIVE, |
486 base::TimeTicks(), | 486 base::TimeTicks(), |
487 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, i), | 487 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, i), |
488 net::NetLog::PHASE_END, | 488 net::NetLog::PHASE_END, |
489 NULL); | 489 NULL); |
490 } | 490 } |
491 | 491 |
492 // To pass, this should simply not have DCHECK-ed above. | 492 // To pass, this should simply not have DCHECK-ed above. |
493 } | 493 } |
494 | 494 |
OLD | NEW |