Chromium Code Reviews| 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 "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 Loading... | |
| 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) { | |
|
xunjieli
2016/12/05 14:55:01
Thanks for working on this. The change looks good.
| |
| 351 set_trace_net_log_observer(new TraceNetLogObserver()); | |
| 352 trace_net_log_observer()->WatchForTraceStart(net_log()); | |
| 353 | |
| 354 std::string disabled_netlog_category = | |
| 355 std::string("-") + kNetLogTracingCategory; | |
| 356 TraceLog::GetInstance()->SetEnabled( | |
| 357 base::trace_event::TraceConfig(disabled_netlog_category, ""), | |
| 358 TraceLog::RECORDING_MODE); | |
| 359 | |
| 360 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); | |
| 361 | |
| 362 trace_net_log_observer()->StopWatchForTraceStart(); | |
| 363 | |
| 364 EndTraceAndFlush(); | |
| 365 TestNetLogEntry::List entries; | |
| 366 net_log()->GetEntries(&entries); | |
| 367 EXPECT_EQ(1u, entries.size()); | |
| 368 EXPECT_EQ(0u, trace_events()->GetSize()); | |
| 369 } | |
| 370 | |
| 350 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { | 371 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { |
| 351 trace_net_log_observer()->WatchForTraceStart(net_log()); | 372 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 352 EnableTraceLog(); | 373 EnableTraceLog(); |
| 353 NetLogParametersCallback net_log_callback; | 374 NetLogParametersCallback net_log_callback; |
| 354 std::string param = "bar"; | 375 std::string param = "bar"; |
| 355 net_log_callback = NetLog::StringCallback("foo", ¶m); | 376 net_log_callback = NetLog::StringCallback("foo", ¶m); |
| 356 | 377 |
| 357 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED, net_log_callback); | 378 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED, net_log_callback); |
| 358 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); | 379 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 359 | 380 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); | 415 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); |
| 395 EXPECT_EQ("bar", item1_params); | 416 EXPECT_EQ("bar", item1_params); |
| 396 | 417 |
| 397 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); | 418 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); |
| 398 EXPECT_TRUE(item2_params.empty()); | 419 EXPECT_TRUE(item2_params.empty()); |
| 399 } | 420 } |
| 400 | 421 |
| 401 } // namespace | 422 } // namespace |
| 402 | 423 |
| 403 } // namespace net | 424 } // namespace net |
| OLD | NEW |