| 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 json_output_.json_output, | 78 json_output_.json_output, |
| 79 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN)); | 79 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN)); |
| 80 | 80 |
| 81 ASSERT_TRUE(trace_value) << json_output_.json_output; | 81 ASSERT_TRUE(trace_value) << json_output_.json_output; |
| 82 base::ListValue* trace_events = NULL; | 82 base::ListValue* trace_events = NULL; |
| 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 message_loop_proxy_->PostTask(FROM_HERE, run_loop->QuitClosure()); |
| 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::debug::CategoryFilter(kNetLogTracingCategory), |
| 94 TraceLog::RECORDING_MODE, | 94 TraceLog::RECORDING_MODE, |
| 95 base::debug::TraceOptions()); | 95 base::debug::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 message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 101 TraceLog::GetInstance()->Flush( | 102 TraceLog::GetInstance()->Flush( |
| 102 base::Bind(&TraceNetLogObserverTest::OnTraceDataCollected, | 103 base::Bind(&TraceNetLogObserverTest::OnTraceDataCollected, |
| 103 base::Unretained(this), | 104 base::Unretained(this), |
| 104 base::Unretained(&run_loop))); | 105 base::Unretained(&run_loop))); |
| 105 run_loop.Run(); | 106 run_loop.Run(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void set_trace_net_log_observer(TraceNetLogObserver* trace_net_log_observer) { | 109 void set_trace_net_log_observer(TraceNetLogObserver* trace_net_log_observer) { |
| 109 trace_net_log_observer_.reset(trace_net_log_observer); | 110 trace_net_log_observer_.reset(trace_net_log_observer); |
| 110 } | 111 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 TraceNetLogObserver* trace_net_log_observer() const { | 143 TraceNetLogObserver* trace_net_log_observer() const { |
| 143 return trace_net_log_observer_.get(); | 144 return trace_net_log_observer_.get(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 scoped_ptr<base::ListValue> trace_events_; | 148 scoped_ptr<base::ListValue> trace_events_; |
| 148 base::debug::TraceResultBuffer trace_buffer_; | 149 base::debug::TraceResultBuffer trace_buffer_; |
| 149 base::debug::TraceResultBuffer::SimpleOutput json_output_; | 150 base::debug::TraceResultBuffer::SimpleOutput json_output_; |
| 150 CapturingNetLog net_log_; | 151 CapturingNetLog net_log_; |
| 151 scoped_ptr<TraceNetLogObserver> trace_net_log_observer_; | 152 scoped_ptr<TraceNetLogObserver> trace_net_log_observer_; |
| 153 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 152 }; | 154 }; |
| 153 | 155 |
| 154 TEST_F(TraceNetLogObserverTest, TracingNotEnabled) { | 156 TEST_F(TraceNetLogObserverTest, TracingNotEnabled) { |
| 155 trace_net_log_observer()->WatchForTraceStart(net_log()); | 157 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 156 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 158 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); |
| 157 | 159 |
| 158 EndTraceAndFlush(); | 160 EndTraceAndFlush(); |
| 159 trace_net_log_observer()->StopWatchForTraceStart(); | 161 trace_net_log_observer()->StopWatchForTraceStart(); |
| 160 | 162 |
| 161 EXPECT_EQ(0u, trace_events()->GetSize()); | 163 EXPECT_EQ(0u, trace_events()->GetSize()); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); | 371 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); |
| 370 EXPECT_EQ("bar", item1_params); | 372 EXPECT_EQ("bar", item1_params); |
| 371 | 373 |
| 372 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); | 374 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); |
| 373 EXPECT_TRUE(item2_params.empty()); | 375 EXPECT_TRUE(item2_params.empty()); |
| 374 } | 376 } |
| 375 | 377 |
| 376 } // namespace | 378 } // namespace |
| 377 | 379 |
| 378 } // namespace net | 380 } // namespace net |
| OLD | NEW |