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

Side by Side Diff: chrome/browser/net/passive_log_collector_unittest.cc

Issue 1556018: Add support for attaching custom parameters to NetLog events. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address willchan's comments Created 10 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace { 12 namespace {
13 13
14 typedef PassiveLogCollector::RequestTracker RequestTracker; 14 typedef PassiveLogCollector::RequestTracker RequestTracker;
15 typedef PassiveLogCollector::RequestInfoList RequestInfoList; 15 typedef PassiveLogCollector::RequestInfoList RequestInfoList;
16 16
17 const net::NetLog::SourceType kSourceType = net::NetLog::SOURCE_NONE; 17 const net::NetLog::SourceType kSourceType = net::NetLog::SOURCE_NONE;
18 18
19 net::NetLog::Entry MakeStartLogEntryWithURL(int source_id, 19 net::CapturingNetLog::Entry MakeStartLogEntryWithURL(int source_id,
20 const std::string& url) { 20 const std::string& url) {
21 net::NetLog::Entry entry; 21 return net::CapturingNetLog::Entry(
22 entry.source.type = kSourceType; 22 net::NetLog::TYPE_URL_REQUEST_START,
23 entry.source.id = source_id; 23 base::TimeTicks(),
24 entry.type = net::NetLog::Entry::TYPE_EVENT; 24 net::NetLog::Source(kSourceType, source_id),
25 entry.event = net::NetLog::Event(net::NetLog::TYPE_REQUEST_ALIVE, 25 net::NetLog::PHASE_BEGIN,
26 net::NetLog::PHASE_BEGIN); 26 new net::NetLogStringParameter(url));
27 entry.string = url;
28 return entry;
29 } 27 }
30 28
31 net::NetLog::Entry MakeStartLogEntry(int source_id) { 29 net::CapturingNetLog::Entry MakeStartLogEntry(int source_id) {
32 return MakeStartLogEntryWithURL(source_id, 30 return MakeStartLogEntryWithURL(source_id,
33 StringPrintf("http://req%d", source_id)); 31 StringPrintf("http://req%d", source_id));
34 } 32 }
35 33
36 net::NetLog::Entry MakeEndLogEntry(int source_id) { 34 net::CapturingNetLog::Entry MakeEndLogEntry(int source_id) {
37 net::NetLog::Entry entry; 35 return net::CapturingNetLog::Entry(
38 entry.source.type = kSourceType; 36 net::NetLog::TYPE_REQUEST_ALIVE,
39 entry.source.id = source_id; 37 base::TimeTicks(),
40 entry.type = net::NetLog::Entry::TYPE_EVENT; 38 net::NetLog::Source(kSourceType, source_id),
41 entry.event = net::NetLog::Event(net::NetLog::TYPE_REQUEST_ALIVE, 39 net::NetLog::PHASE_END,
42 net::NetLog::PHASE_END); 40 NULL);
43 return entry;
44 } 41 }
45 42
46 static const int kMaxNumLoadLogEntries = 1; 43 static const int kMaxNumLoadLogEntries = 1;
47 44
48 TEST(RequestTrackerTest, BasicBounded) { 45 TEST(RequestTrackerTest, BasicBounded) {
49 RequestTracker tracker(NULL); 46 RequestTracker tracker(NULL);
50 EXPECT_FALSE(tracker.IsUnbounded()); 47 EXPECT_FALSE(tracker.IsUnbounded());
51 EXPECT_EQ(0u, tracker.GetLiveRequests().size()); 48 EXPECT_EQ(0u, tracker.GetLiveRequests().size());
52 EXPECT_EQ(0u, tracker.GetRecentlyDeceased().size()); 49 EXPECT_EQ(0u, tracker.GetRecentlyDeceased().size());
53 50
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 RequestInfoList recent_reqs = tracker.GetRecentlyDeceased(); 124 RequestInfoList recent_reqs = tracker.GetRecentlyDeceased();
128 125
129 ASSERT_EQ(kMaxSize, recent_reqs.size()); 126 ASSERT_EQ(kMaxSize, recent_reqs.size());
130 127
131 for (size_t i = 0; i < kMaxSize; ++i) { 128 for (size_t i = 0; i < kMaxSize; ++i) {
132 std::string url = StringPrintf("http://req%" PRIuS, i); 129 std::string url = StringPrintf("http://req%" PRIuS, i);
133 EXPECT_EQ(url, recent_reqs[i].url); 130 EXPECT_EQ(url, recent_reqs[i].url);
134 } 131 }
135 } 132 }
136 133
137 // Check that very long URLs are truncated.
138 TEST(RequestTrackerTest, GraveyardURLBounded) {
139 RequestTracker tracker(NULL);
140 EXPECT_FALSE(tracker.IsUnbounded());
141
142 std::string big_url("http://");
143 big_url.resize(2 * RequestTracker::kMaxGraveyardURLSize, 'x');
144
145 tracker.OnAddEntry(MakeStartLogEntryWithURL(1, big_url));
146 tracker.OnAddEntry(MakeEndLogEntry(1));
147
148 ASSERT_EQ(1u, tracker.GetRecentlyDeceased().size());
149 EXPECT_EQ(RequestTracker::kMaxGraveyardURLSize,
150 tracker.GetRecentlyDeceased()[0].url.size());
151 }
152
153 // Check that we exclude "chrome://" URLs from being saved into the recent 134 // Check that we exclude "chrome://" URLs from being saved into the recent
154 // requests list (graveyard). 135 // requests list (graveyard).
155 TEST(RequestTrackerTest, GraveyardIsFiltered) { 136 TEST(RequestTrackerTest, GraveyardIsFiltered) {
156 RequestTracker tracker(NULL); 137 RequestTracker tracker(NULL);
157 EXPECT_FALSE(tracker.IsUnbounded()); 138 EXPECT_FALSE(tracker.IsUnbounded());
158 139
159 // This will be excluded. 140 // This will be excluded.
160 std::string url1 = "chrome://dontcare/"; 141 std::string url1 = "chrome://dontcare/";
161 tracker.OnAddEntry(MakeStartLogEntryWithURL(1, url1)); 142 tracker.OnAddEntry(MakeStartLogEntryWithURL(1, url1));
162 tracker.OnAddEntry(MakeEndLogEntry(1)); 143 tracker.OnAddEntry(MakeEndLogEntry(1));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 for (size_t i = kMaxSize; i < 2 * kMaxSize; ++i) { 185 for (size_t i = kMaxSize; i < 2 * kMaxSize; ++i) {
205 tracker.OnAddEntry(MakeStartLogEntry(i)); 186 tracker.OnAddEntry(MakeStartLogEntry(i));
206 tracker.OnAddEntry(MakeEndLogEntry(i)); 187 tracker.OnAddEntry(MakeEndLogEntry(i));
207 } 188 }
208 189
209 // We should only have kMaxGraveyardSize entries now. 190 // We should only have kMaxGraveyardSize entries now.
210 ASSERT_EQ(kMaxSize, tracker.GetRecentlyDeceased().size()); 191 ASSERT_EQ(kMaxSize, tracker.GetRecentlyDeceased().size());
211 } 192 }
212 193
213 } // namespace 194 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/net/passive_log_collector.cc ('k') | chrome/browser/net/view_net_internals_job_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698