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

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

Issue 2554483002: netlog: Don't enable recording if the "netlog" tracing category is disabled. (Closed)
Patch Set: Address comments (better tests) Created 4 years 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
« no previous file with comments | « net/log/trace_net_log_observer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 net_log()->AddGlobalEntry(NetLogEventType::URL_REQUEST_START_JOB); 340 net_log()->AddGlobalEntry(NetLogEventType::URL_REQUEST_START_JOB);
341 341
342 EndTraceAndFlush(); 342 EndTraceAndFlush();
343 343
344 TestNetLogEntry::List entries; 344 TestNetLogEntry::List entries;
345 net_log()->GetEntries(&entries); 345 net_log()->GetEntries(&entries);
346 EXPECT_EQ(3u, entries.size()); 346 EXPECT_EQ(3u, entries.size());
347 EXPECT_EQ(0u, trace_events()->GetSize()); 347 EXPECT_EQ(0u, trace_events()->GetSize());
348 } 348 }
349 349
350 TEST_F(TraceNetLogObserverTest, DisabledCategoryDoesntEnableNetLog) {
351 // Note: This test and the next one don't use the NetLog instance from the
352 // test fixture as it always has an observer, thus making the return value of
353 // NetLog::IsCapturing() not useful. This is still TEST_F(), as mixing TEST()
354 // and TEST_F() is not allowed.
xunjieli 2016/12/05 15:57:04 This is okay. But alternatively you can use TEST i
xunjieli 2016/12/05 16:00:00 And move these two tests either to the top or afte
Benoit L 2016/12/05 16:44:25 Done.
Benoit L 2016/12/05 16:44:25 Done.
355 TraceNetLogObserver observer;
356 NetLog net_log;
357 observer.WatchForTraceStart(&net_log);
358
359 EXPECT_FALSE(net_log.IsCapturing());
360
361 std::string disabled_netlog_category =
362 std::string("-") + kNetLogTracingCategory;
363 TraceLog::GetInstance()->SetEnabled(
364 base::trace_event::TraceConfig(disabled_netlog_category, ""),
365 TraceLog::RECORDING_MODE);
366
367 EXPECT_FALSE(net_log.IsCapturing());
368 observer.StopWatchForTraceStart();
369 EXPECT_FALSE(net_log.IsCapturing());
370
371 TraceLog::GetInstance()->SetDisabled();
372 }
373
374 TEST_F(TraceNetLogObserverTest, CanEnableNetLog) {
375 TraceNetLogObserver observer;
376 NetLog net_log;
377 observer.WatchForTraceStart(&net_log);
378
379 EXPECT_FALSE(net_log.IsCapturing());
380
381 TraceLog::GetInstance()->SetEnabled(
382 base::trace_event::TraceConfig(kNetLogTracingCategory, ""),
383 TraceLog::RECORDING_MODE);
384
385 EXPECT_TRUE(net_log.IsCapturing());
386 observer.StopWatchForTraceStart();
387 EXPECT_FALSE(net_log.IsCapturing());
388
389 TraceLog::GetInstance()->SetDisabled();
390 }
391
350 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { 392 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) {
351 trace_net_log_observer()->WatchForTraceStart(net_log()); 393 trace_net_log_observer()->WatchForTraceStart(net_log());
352 EnableTraceLog(); 394 EnableTraceLog();
353 NetLogParametersCallback net_log_callback; 395 NetLogParametersCallback net_log_callback;
354 std::string param = "bar"; 396 std::string param = "bar";
355 net_log_callback = NetLog::StringCallback("foo", &param); 397 net_log_callback = NetLog::StringCallback("foo", &param);
356 398
357 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED, net_log_callback); 399 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED, net_log_callback);
358 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); 400 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE);
359 401
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); 436 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params));
395 EXPECT_EQ("bar", item1_params); 437 EXPECT_EQ("bar", item1_params);
396 438
397 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); 439 EXPECT_TRUE(item2->GetString("args.params", &item2_params));
398 EXPECT_TRUE(item2_params.empty()); 440 EXPECT_TRUE(item2_params.empty());
399 } 441 }
400 442
401 } // namespace 443 } // namespace
402 444
403 } // namespace net 445 } // namespace net
OLDNEW
« no previous file with comments | « net/log/trace_net_log_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698