| 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/base/trace_net_log_observer.h" | 5 #include "net/base/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/base/capturing_net_log.h" | 20 #include "net/base/capturing_net_log.h" |
| 21 #include "net/base/net_log.h" | 21 #include "net/base/net_log.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using base::debug::TraceLog; | 24 using base::trace_event::TraceLog; |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // TraceLog category for NetLog events. | 30 // TraceLog category for NetLog events. |
| 31 const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog"); | 31 const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog"); |
| 32 | 32 |
| 33 struct TraceEntryInfo { | 33 struct TraceEntryInfo { |
| 34 std::string category; | 34 std::string category; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ASSERT_TRUE(trace_value->GetAsList(&trace_events)); | 83 ASSERT_TRUE(trace_value->GetAsList(&trace_events)); |
| 84 | 84 |
| 85 trace_events_ = FilterNetLogTraceEvents(*trace_events); | 85 trace_events_ = FilterNetLogTraceEvents(*trace_events); |
| 86 | 86 |
| 87 if (!has_more_events) | 87 if (!has_more_events) |
| 88 run_loop->Quit(); | 88 run_loop->Quit(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 static void EnableTraceLog() { | 91 static void EnableTraceLog() { |
| 92 TraceLog::GetInstance()->SetEnabled( | 92 TraceLog::GetInstance()->SetEnabled( |
| 93 base::debug::CategoryFilter(kNetLogTracingCategory), | 93 base::trace_event::CategoryFilter(kNetLogTracingCategory), |
| 94 TraceLog::RECORDING_MODE, | 94 TraceLog::RECORDING_MODE, |
| 95 base::debug::TraceOptions()); | 95 base::trace_event::TraceOptions()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void EndTraceAndFlush() { | 98 void EndTraceAndFlush() { |
| 99 base::RunLoop run_loop; | 99 base::RunLoop run_loop; |
| 100 TraceLog::GetInstance()->SetDisabled(); | 100 TraceLog::GetInstance()->SetDisabled(); |
| 101 TraceLog::GetInstance()->Flush( | 101 TraceLog::GetInstance()->Flush( |
| 102 base::Bind(&TraceNetLogObserverTest::OnTraceDataCollected, | 102 base::Bind(&TraceNetLogObserverTest::OnTraceDataCollected, |
| 103 base::Unretained(this), | 103 base::Unretained(this), |
| 104 base::Unretained(&run_loop))); | 104 base::Unretained(&run_loop))); |
| 105 run_loop.Run(); | 105 run_loop.Run(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 CapturingNetLog* net_log() { | 138 CapturingNetLog* net_log() { |
| 139 return &net_log_; | 139 return &net_log_; |
| 140 } | 140 } |
| 141 | 141 |
| 142 TraceNetLogObserver* trace_net_log_observer() const { | 142 TraceNetLogObserver* trace_net_log_observer() const { |
| 143 return trace_net_log_observer_.get(); | 143 return trace_net_log_observer_.get(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 scoped_ptr<base::ListValue> trace_events_; | 147 scoped_ptr<base::ListValue> trace_events_; |
| 148 base::debug::TraceResultBuffer trace_buffer_; | 148 base::trace_event::TraceResultBuffer trace_buffer_; |
| 149 base::debug::TraceResultBuffer::SimpleOutput json_output_; | 149 base::trace_event::TraceResultBuffer::SimpleOutput json_output_; |
| 150 CapturingNetLog net_log_; | 150 CapturingNetLog net_log_; |
| 151 scoped_ptr<TraceNetLogObserver> trace_net_log_observer_; | 151 scoped_ptr<TraceNetLogObserver> trace_net_log_observer_; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 TEST_F(TraceNetLogObserverTest, TracingNotEnabled) { | 154 TEST_F(TraceNetLogObserverTest, TracingNotEnabled) { |
| 155 trace_net_log_observer()->WatchForTraceStart(net_log()); | 155 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 156 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 156 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); |
| 157 | 157 |
| 158 EndTraceAndFlush(); | 158 EndTraceAndFlush(); |
| 159 trace_net_log_observer()->StopWatchForTraceStart(); | 159 trace_net_log_observer()->StopWatchForTraceStart(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); | 369 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); |
| 370 EXPECT_EQ("bar", item1_params); | 370 EXPECT_EQ("bar", item1_params); |
| 371 | 371 |
| 372 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); | 372 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); |
| 373 EXPECT_TRUE(item2_params.empty()); | 373 EXPECT_TRUE(item2_params.empty()); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace | 376 } // namespace |
| 377 | 377 |
| 378 } // namespace net | 378 } // namespace net |
| OLD | NEW |