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

Side by Side Diff: net/log/trace_net_log_observer_unittest.cc

Issue 1109473003: Get rid of TestNetLog::CapturedEntry[List] typedefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "net/log/trace_net_log_observer.h" 5 #include "net/log/trace_net_log_observer.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "base/trace_event/trace_event_impl.h" 18 #include "base/trace_event/trace_event_impl.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "net/log/captured_net_log_entry.h"
20 #include "net/log/net_log.h" 21 #include "net/log/net_log.h"
21 #include "net/log/test_net_log.h" 22 #include "net/log/test_net_log.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 using base::trace_event::TraceLog; 25 using base::trace_event::TraceLog;
25 26
26 namespace net { 27 namespace net {
27 28
28 namespace { 29 namespace {
29 30
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 trace_net_log_observer()->WatchForTraceStart(net_log()); 150 trace_net_log_observer()->WatchForTraceStart(net_log());
150 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); 151 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE);
151 152
152 EndTraceAndFlush(); 153 EndTraceAndFlush();
153 trace_net_log_observer()->StopWatchForTraceStart(); 154 trace_net_log_observer()->StopWatchForTraceStart();
154 155
155 EXPECT_EQ(0u, trace_events()->GetSize()); 156 EXPECT_EQ(0u, trace_events()->GetSize());
156 } 157 }
157 158
158 TEST_F(TraceNetLogObserverTest, TraceEventCaptured) { 159 TEST_F(TraceNetLogObserverTest, TraceEventCaptured) {
159 TestNetLog::CapturedEntryList entries; 160 CapturedNetLogEntry::List entries;
160 net_log()->GetEntries(&entries); 161 net_log()->GetEntries(&entries);
161 EXPECT_TRUE(entries.empty()); 162 EXPECT_TRUE(entries.empty());
162 163
163 trace_net_log_observer()->WatchForTraceStart(net_log()); 164 trace_net_log_observer()->WatchForTraceStart(net_log());
164 EnableTraceLog(); 165 EnableTraceLog();
165 BoundNetLog bound_net_log = 166 BoundNetLog bound_net_log =
166 BoundNetLog::Make(net_log(), net::NetLog::SOURCE_NONE); 167 BoundNetLog::Make(net_log(), net::NetLog::SOURCE_NONE);
167 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); 168 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED);
168 bound_net_log.BeginEvent(NetLog::TYPE_URL_REQUEST_START_JOB); 169 bound_net_log.BeginEvent(NetLog::TYPE_URL_REQUEST_START_JOB);
169 bound_net_log.EndEvent(NetLog::TYPE_REQUEST_ALIVE); 170 bound_net_log.EndEvent(NetLog::TYPE_REQUEST_ALIVE);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 EnableTraceLog(); 217 EnableTraceLog();
217 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); 218 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED);
218 TraceLog::GetInstance()->SetDisabled(); 219 TraceLog::GetInstance()->SetDisabled();
219 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); 220 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE);
220 EnableTraceLog(); 221 EnableTraceLog();
221 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB); 222 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB);
222 223
223 EndTraceAndFlush(); 224 EndTraceAndFlush();
224 trace_net_log_observer()->StopWatchForTraceStart(); 225 trace_net_log_observer()->StopWatchForTraceStart();
225 226
226 TestNetLog::CapturedEntryList entries; 227 CapturedNetLogEntry::List entries;
227 net_log()->GetEntries(&entries); 228 net_log()->GetEntries(&entries);
228 EXPECT_EQ(3u, entries.size()); 229 EXPECT_EQ(3u, entries.size());
229 EXPECT_EQ(2u, trace_events()->GetSize()); 230 EXPECT_EQ(2u, trace_events()->GetSize());
230 const base::DictionaryValue* item1 = NULL; 231 const base::DictionaryValue* item1 = NULL;
231 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); 232 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1));
232 const base::DictionaryValue* item2 = NULL; 233 const base::DictionaryValue* item2 = NULL;
233 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); 234 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2));
234 235
235 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); 236 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
236 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); 237 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
(...skipping 19 matching lines...) Expand all
256 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) { 257 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) {
257 trace_net_log_observer()->WatchForTraceStart(net_log()); 258 trace_net_log_observer()->WatchForTraceStart(net_log());
258 EnableTraceLog(); 259 EnableTraceLog();
259 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); 260 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED);
260 trace_net_log_observer()->StopWatchForTraceStart(); 261 trace_net_log_observer()->StopWatchForTraceStart();
261 set_trace_net_log_observer(NULL); 262 set_trace_net_log_observer(NULL);
262 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); 263 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE);
263 264
264 EndTraceAndFlush(); 265 EndTraceAndFlush();
265 266
266 TestNetLog::CapturedEntryList entries; 267 CapturedNetLogEntry::List entries;
267 net_log()->GetEntries(&entries); 268 net_log()->GetEntries(&entries);
268 EXPECT_EQ(2u, entries.size()); 269 EXPECT_EQ(2u, entries.size());
269 EXPECT_EQ(1u, trace_events()->GetSize()); 270 EXPECT_EQ(1u, trace_events()->GetSize());
270 271
271 const base::DictionaryValue* item1 = NULL; 272 const base::DictionaryValue* item1 = NULL;
272 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); 273 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1));
273 274
274 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); 275 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
275 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); 276 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category);
276 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); 277 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id);
277 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), 278 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT),
278 actual_item1.phase); 279 actual_item1.phase);
279 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_CANCELLED), 280 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_CANCELLED),
280 actual_item1.name); 281 actual_item1.name);
281 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), 282 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type),
282 actual_item1.source_type); 283 actual_item1.source_type);
283 } 284 }
284 285
285 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileNotTracing) { 286 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileNotTracing) {
286 trace_net_log_observer()->WatchForTraceStart(net_log()); 287 trace_net_log_observer()->WatchForTraceStart(net_log());
287 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); 288 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED);
288 trace_net_log_observer()->StopWatchForTraceStart(); 289 trace_net_log_observer()->StopWatchForTraceStart();
289 set_trace_net_log_observer(NULL); 290 set_trace_net_log_observer(NULL);
290 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); 291 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE);
291 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB); 292 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB);
292 293
293 EndTraceAndFlush(); 294 EndTraceAndFlush();
294 295
295 TestNetLog::CapturedEntryList entries; 296 CapturedNetLogEntry::List entries;
296 net_log()->GetEntries(&entries); 297 net_log()->GetEntries(&entries);
297 EXPECT_EQ(3u, entries.size()); 298 EXPECT_EQ(3u, entries.size());
298 EXPECT_EQ(0u, trace_events()->GetSize()); 299 EXPECT_EQ(0u, trace_events()->GetSize());
299 } 300 }
300 301
301 TEST_F(TraceNetLogObserverTest, CreateObserverAfterTracingStarts) { 302 TEST_F(TraceNetLogObserverTest, CreateObserverAfterTracingStarts) {
302 set_trace_net_log_observer(NULL); 303 set_trace_net_log_observer(NULL);
303 EnableTraceLog(); 304 EnableTraceLog();
304 set_trace_net_log_observer(new TraceNetLogObserver()); 305 set_trace_net_log_observer(new TraceNetLogObserver());
305 trace_net_log_observer()->WatchForTraceStart(net_log()); 306 trace_net_log_observer()->WatchForTraceStart(net_log());
306 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); 307 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED);
307 trace_net_log_observer()->StopWatchForTraceStart(); 308 trace_net_log_observer()->StopWatchForTraceStart();
308 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); 309 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE);
309 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB); 310 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB);
310 311
311 EndTraceAndFlush(); 312 EndTraceAndFlush();
312 313
313 TestNetLog::CapturedEntryList entries; 314 CapturedNetLogEntry::List entries;
314 net_log()->GetEntries(&entries); 315 net_log()->GetEntries(&entries);
315 EXPECT_EQ(3u, entries.size()); 316 EXPECT_EQ(3u, entries.size());
316 EXPECT_EQ(0u, trace_events()->GetSize()); 317 EXPECT_EQ(0u, trace_events()->GetSize());
317 } 318 }
318 319
319 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { 320 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) {
320 trace_net_log_observer()->WatchForTraceStart(net_log()); 321 trace_net_log_observer()->WatchForTraceStart(net_log());
321 EnableTraceLog(); 322 EnableTraceLog();
322 NetLog::ParametersCallback net_log_callback; 323 NetLog::ParametersCallback net_log_callback;
323 std::string param = "bar"; 324 std::string param = "bar";
324 net_log_callback = NetLog::StringCallback("foo", &param); 325 net_log_callback = NetLog::StringCallback("foo", &param);
325 326
326 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED, net_log_callback); 327 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED, net_log_callback);
327 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); 328 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE);
328 329
329 EndTraceAndFlush(); 330 EndTraceAndFlush();
330 trace_net_log_observer()->StopWatchForTraceStart(); 331 trace_net_log_observer()->StopWatchForTraceStart();
331 332
332 TestNetLog::CapturedEntryList entries; 333 CapturedNetLogEntry::List entries;
333 net_log()->GetEntries(&entries); 334 net_log()->GetEntries(&entries);
334 EXPECT_EQ(2u, entries.size()); 335 EXPECT_EQ(2u, entries.size());
335 EXPECT_EQ(2u, trace_events()->GetSize()); 336 EXPECT_EQ(2u, trace_events()->GetSize());
336 const base::DictionaryValue* item1 = NULL; 337 const base::DictionaryValue* item1 = NULL;
337 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); 338 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1));
338 const base::DictionaryValue* item2 = NULL; 339 const base::DictionaryValue* item2 = NULL;
339 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); 340 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2));
340 341
341 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); 342 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
342 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); 343 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
(...skipping 20 matching lines...) Expand all
363 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); 364 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params));
364 EXPECT_EQ("bar", item1_params); 365 EXPECT_EQ("bar", item1_params);
365 366
366 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); 367 EXPECT_TRUE(item2->GetString("args.params", &item2_params));
367 EXPECT_TRUE(item2_params.empty()); 368 EXPECT_TRUE(item2_params.empty());
368 } 369 }
369 370
370 } // namespace 371 } // namespace
371 372
372 } // namespace net 373 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698