| 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 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.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_buffer.h" | 17 #include "base/trace_event/trace_buffer.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "base/trace_event/trace_event_impl.h" | 19 #include "base/trace_event/trace_event_impl.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "net/log/net_log.h" | 21 #include "net/log/net_log.h" |
| 22 #include "net/log/net_log_event_type.h" |
| 23 #include "net/log/net_log_source_type.h" |
| 22 #include "net/log/test_net_log.h" | 24 #include "net/log/test_net_log.h" |
| 23 #include "net/log/test_net_log_entry.h" | 25 #include "net/log/test_net_log_entry.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 27 |
| 26 using base::trace_event::TraceLog; | 28 using base::trace_event::TraceLog; |
| 27 | 29 |
| 28 namespace net { | 30 namespace net { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 private: | 145 private: |
| 144 std::unique_ptr<base::ListValue> trace_events_; | 146 std::unique_ptr<base::ListValue> trace_events_; |
| 145 base::trace_event::TraceResultBuffer trace_buffer_; | 147 base::trace_event::TraceResultBuffer trace_buffer_; |
| 146 base::trace_event::TraceResultBuffer::SimpleOutput json_output_; | 148 base::trace_event::TraceResultBuffer::SimpleOutput json_output_; |
| 147 TestNetLog net_log_; | 149 TestNetLog net_log_; |
| 148 std::unique_ptr<TraceNetLogObserver> trace_net_log_observer_; | 150 std::unique_ptr<TraceNetLogObserver> trace_net_log_observer_; |
| 149 }; | 151 }; |
| 150 | 152 |
| 151 TEST_F(TraceNetLogObserverTest, TracingNotEnabled) { | 153 TEST_F(TraceNetLogObserverTest, TracingNotEnabled) { |
| 152 trace_net_log_observer()->WatchForTraceStart(net_log()); | 154 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 153 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 155 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 154 | 156 |
| 155 EndTraceAndFlush(); | 157 EndTraceAndFlush(); |
| 156 trace_net_log_observer()->StopWatchForTraceStart(); | 158 trace_net_log_observer()->StopWatchForTraceStart(); |
| 157 | 159 |
| 158 EXPECT_EQ(0u, trace_events()->GetSize()); | 160 EXPECT_EQ(0u, trace_events()->GetSize()); |
| 159 } | 161 } |
| 160 | 162 |
| 161 TEST_F(TraceNetLogObserverTest, TraceEventCaptured) { | 163 TEST_F(TraceNetLogObserverTest, TraceEventCaptured) { |
| 162 TestNetLogEntry::List entries; | 164 TestNetLogEntry::List entries; |
| 163 net_log()->GetEntries(&entries); | 165 net_log()->GetEntries(&entries); |
| 164 EXPECT_TRUE(entries.empty()); | 166 EXPECT_TRUE(entries.empty()); |
| 165 | 167 |
| 166 trace_net_log_observer()->WatchForTraceStart(net_log()); | 168 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 167 EnableTraceLog(); | 169 EnableTraceLog(); |
| 168 BoundNetLog bound_net_log = | 170 BoundNetLog bound_net_log = |
| 169 BoundNetLog::Make(net_log(), net::NetLog::SOURCE_NONE); | 171 BoundNetLog::Make(net_log(), net::NetLogSourceType::NONE); |
| 170 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); | 172 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED); |
| 171 bound_net_log.BeginEvent(NetLog::TYPE_URL_REQUEST_START_JOB); | 173 bound_net_log.BeginEvent(NetLogEventType::URL_REQUEST_START_JOB); |
| 172 bound_net_log.EndEvent(NetLog::TYPE_REQUEST_ALIVE); | 174 bound_net_log.EndEvent(NetLogEventType::REQUEST_ALIVE); |
| 173 | 175 |
| 174 net_log()->GetEntries(&entries); | 176 net_log()->GetEntries(&entries); |
| 175 EXPECT_EQ(3u, entries.size()); | 177 EXPECT_EQ(3u, entries.size()); |
| 176 EndTraceAndFlush(); | 178 EndTraceAndFlush(); |
| 177 trace_net_log_observer()->StopWatchForTraceStart(); | 179 trace_net_log_observer()->StopWatchForTraceStart(); |
| 178 EXPECT_EQ(3u, trace_events()->GetSize()); | 180 EXPECT_EQ(3u, trace_events()->GetSize()); |
| 179 const base::DictionaryValue* item1 = NULL; | 181 const base::DictionaryValue* item1 = NULL; |
| 180 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); | 182 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); |
| 181 const base::DictionaryValue* item2 = NULL; | 183 const base::DictionaryValue* item2 = NULL; |
| 182 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); | 184 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); |
| 183 const base::DictionaryValue* item3 = NULL; | 185 const base::DictionaryValue* item3 = NULL; |
| 184 ASSERT_TRUE(trace_events()->GetDictionary(2, &item3)); | 186 ASSERT_TRUE(trace_events()->GetDictionary(2, &item3)); |
| 185 | 187 |
| 186 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); | 188 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); |
| 187 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); | 189 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); |
| 188 TraceEntryInfo actual_item3 = GetTraceEntryInfoFromValue(*item3); | 190 TraceEntryInfo actual_item3 = GetTraceEntryInfoFromValue(*item3); |
| 189 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); | 191 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); |
| 190 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); | 192 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); |
| 191 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), | 193 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), |
| 192 actual_item1.phase); | 194 actual_item1.phase); |
| 193 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_CANCELLED), | 195 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::CANCELLED), |
| 194 actual_item1.name); | 196 actual_item1.name); |
| 195 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), | 197 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), |
| 196 actual_item1.source_type); | 198 actual_item1.source_type); |
| 197 | 199 |
| 198 EXPECT_EQ(kNetLogTracingCategory, actual_item2.category); | 200 EXPECT_EQ(kNetLogTracingCategory, actual_item2.category); |
| 199 EXPECT_EQ(base::StringPrintf("0x%d", entries[1].source.id), actual_item2.id); | 201 EXPECT_EQ(base::StringPrintf("0x%d", entries[1].source.id), actual_item2.id); |
| 200 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN), | 202 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN), |
| 201 actual_item2.phase); | 203 actual_item2.phase); |
| 202 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_URL_REQUEST_START_JOB), | 204 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::URL_REQUEST_START_JOB), |
| 203 actual_item2.name); | 205 actual_item2.name); |
| 204 EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type), | 206 EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type), |
| 205 actual_item2.source_type); | 207 actual_item2.source_type); |
| 206 | 208 |
| 207 EXPECT_EQ(kNetLogTracingCategory, actual_item3.category); | 209 EXPECT_EQ(kNetLogTracingCategory, actual_item3.category); |
| 208 EXPECT_EQ(base::StringPrintf("0x%d", entries[2].source.id), actual_item3.id); | 210 EXPECT_EQ(base::StringPrintf("0x%d", entries[2].source.id), actual_item3.id); |
| 209 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_END), | 211 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_END), |
| 210 actual_item3.phase); | 212 actual_item3.phase); |
| 211 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_REQUEST_ALIVE), | 213 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::REQUEST_ALIVE), |
| 212 actual_item3.name); | 214 actual_item3.name); |
| 213 EXPECT_EQ(NetLog::SourceTypeToString(entries[2].source.type), | 215 EXPECT_EQ(NetLog::SourceTypeToString(entries[2].source.type), |
| 214 actual_item3.source_type); | 216 actual_item3.source_type); |
| 215 } | 217 } |
| 216 | 218 |
| 217 TEST_F(TraceNetLogObserverTest, EnableAndDisableTracing) { | 219 TEST_F(TraceNetLogObserverTest, EnableAndDisableTracing) { |
| 218 trace_net_log_observer()->WatchForTraceStart(net_log()); | 220 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 219 EnableTraceLog(); | 221 EnableTraceLog(); |
| 220 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); | 222 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED); |
| 221 TraceLog::GetInstance()->SetDisabled(); | 223 TraceLog::GetInstance()->SetDisabled(); |
| 222 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 224 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 223 EnableTraceLog(); | 225 EnableTraceLog(); |
| 224 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB); | 226 net_log()->AddGlobalEntry(NetLogEventType::URL_REQUEST_START_JOB); |
| 225 | 227 |
| 226 EndTraceAndFlush(); | 228 EndTraceAndFlush(); |
| 227 trace_net_log_observer()->StopWatchForTraceStart(); | 229 trace_net_log_observer()->StopWatchForTraceStart(); |
| 228 | 230 |
| 229 TestNetLogEntry::List entries; | 231 TestNetLogEntry::List entries; |
| 230 net_log()->GetEntries(&entries); | 232 net_log()->GetEntries(&entries); |
| 231 EXPECT_EQ(3u, entries.size()); | 233 EXPECT_EQ(3u, entries.size()); |
| 232 EXPECT_EQ(2u, trace_events()->GetSize()); | 234 EXPECT_EQ(2u, trace_events()->GetSize()); |
| 233 const base::DictionaryValue* item1 = NULL; | 235 const base::DictionaryValue* item1 = NULL; |
| 234 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); | 236 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); |
| 235 const base::DictionaryValue* item2 = NULL; | 237 const base::DictionaryValue* item2 = NULL; |
| 236 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); | 238 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); |
| 237 | 239 |
| 238 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); | 240 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); |
| 239 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); | 241 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); |
| 240 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); | 242 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); |
| 241 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); | 243 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); |
| 242 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), | 244 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), |
| 243 actual_item1.phase); | 245 actual_item1.phase); |
| 244 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_CANCELLED), | 246 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::CANCELLED), |
| 245 actual_item1.name); | 247 actual_item1.name); |
| 246 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), | 248 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), |
| 247 actual_item1.source_type); | 249 actual_item1.source_type); |
| 248 | 250 |
| 249 EXPECT_EQ(kNetLogTracingCategory, actual_item2.category); | 251 EXPECT_EQ(kNetLogTracingCategory, actual_item2.category); |
| 250 EXPECT_EQ(base::StringPrintf("0x%d", entries[2].source.id), actual_item2.id); | 252 EXPECT_EQ(base::StringPrintf("0x%d", entries[2].source.id), actual_item2.id); |
| 251 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), | 253 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), |
| 252 actual_item2.phase); | 254 actual_item2.phase); |
| 253 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_URL_REQUEST_START_JOB), | 255 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::URL_REQUEST_START_JOB), |
| 254 actual_item2.name); | 256 actual_item2.name); |
| 255 EXPECT_EQ(NetLog::SourceTypeToString(entries[2].source.type), | 257 EXPECT_EQ(NetLog::SourceTypeToString(entries[2].source.type), |
| 256 actual_item2.source_type); | 258 actual_item2.source_type); |
| 257 } | 259 } |
| 258 | 260 |
| 259 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) { | 261 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) { |
| 260 trace_net_log_observer()->WatchForTraceStart(net_log()); | 262 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 261 EnableTraceLog(); | 263 EnableTraceLog(); |
| 262 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); | 264 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED); |
| 263 trace_net_log_observer()->StopWatchForTraceStart(); | 265 trace_net_log_observer()->StopWatchForTraceStart(); |
| 264 set_trace_net_log_observer(NULL); | 266 set_trace_net_log_observer(NULL); |
| 265 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 267 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 266 | 268 |
| 267 EndTraceAndFlush(); | 269 EndTraceAndFlush(); |
| 268 | 270 |
| 269 TestNetLogEntry::List entries; | 271 TestNetLogEntry::List entries; |
| 270 net_log()->GetEntries(&entries); | 272 net_log()->GetEntries(&entries); |
| 271 EXPECT_EQ(2u, entries.size()); | 273 EXPECT_EQ(2u, entries.size()); |
| 272 EXPECT_EQ(1u, trace_events()->GetSize()); | 274 EXPECT_EQ(1u, trace_events()->GetSize()); |
| 273 | 275 |
| 274 const base::DictionaryValue* item1 = NULL; | 276 const base::DictionaryValue* item1 = NULL; |
| 275 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); | 277 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); |
| 276 | 278 |
| 277 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); | 279 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); |
| 278 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); | 280 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); |
| 279 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); | 281 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); |
| 280 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), | 282 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), |
| 281 actual_item1.phase); | 283 actual_item1.phase); |
| 282 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_CANCELLED), | 284 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::CANCELLED), |
| 283 actual_item1.name); | 285 actual_item1.name); |
| 284 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), | 286 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), |
| 285 actual_item1.source_type); | 287 actual_item1.source_type); |
| 286 } | 288 } |
| 287 | 289 |
| 288 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileNotTracing) { | 290 TEST_F(TraceNetLogObserverTest, DestroyObserverWhileNotTracing) { |
| 289 trace_net_log_observer()->WatchForTraceStart(net_log()); | 291 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 290 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); | 292 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED); |
| 291 trace_net_log_observer()->StopWatchForTraceStart(); | 293 trace_net_log_observer()->StopWatchForTraceStart(); |
| 292 set_trace_net_log_observer(NULL); | 294 set_trace_net_log_observer(NULL); |
| 293 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 295 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 294 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB); | 296 net_log()->AddGlobalEntry(NetLogEventType::URL_REQUEST_START_JOB); |
| 295 | 297 |
| 296 EndTraceAndFlush(); | 298 EndTraceAndFlush(); |
| 297 | 299 |
| 298 TestNetLogEntry::List entries; | 300 TestNetLogEntry::List entries; |
| 299 net_log()->GetEntries(&entries); | 301 net_log()->GetEntries(&entries); |
| 300 EXPECT_EQ(3u, entries.size()); | 302 EXPECT_EQ(3u, entries.size()); |
| 301 EXPECT_EQ(0u, trace_events()->GetSize()); | 303 EXPECT_EQ(0u, trace_events()->GetSize()); |
| 302 } | 304 } |
| 303 | 305 |
| 304 TEST_F(TraceNetLogObserverTest, CreateObserverAfterTracingStarts) { | 306 TEST_F(TraceNetLogObserverTest, CreateObserverAfterTracingStarts) { |
| 305 set_trace_net_log_observer(NULL); | 307 set_trace_net_log_observer(NULL); |
| 306 EnableTraceLog(); | 308 EnableTraceLog(); |
| 307 set_trace_net_log_observer(new TraceNetLogObserver()); | 309 set_trace_net_log_observer(new TraceNetLogObserver()); |
| 308 trace_net_log_observer()->WatchForTraceStart(net_log()); | 310 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 309 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED); | 311 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED); |
| 310 trace_net_log_observer()->StopWatchForTraceStart(); | 312 trace_net_log_observer()->StopWatchForTraceStart(); |
| 311 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 313 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 312 net_log()->AddGlobalEntry(NetLog::TYPE_URL_REQUEST_START_JOB); | 314 net_log()->AddGlobalEntry(NetLogEventType::URL_REQUEST_START_JOB); |
| 313 | 315 |
| 314 EndTraceAndFlush(); | 316 EndTraceAndFlush(); |
| 315 | 317 |
| 316 TestNetLogEntry::List entries; | 318 TestNetLogEntry::List entries; |
| 317 net_log()->GetEntries(&entries); | 319 net_log()->GetEntries(&entries); |
| 318 EXPECT_EQ(3u, entries.size()); | 320 EXPECT_EQ(3u, entries.size()); |
| 319 EXPECT_EQ(0u, trace_events()->GetSize()); | 321 EXPECT_EQ(0u, trace_events()->GetSize()); |
| 320 } | 322 } |
| 321 | 323 |
| 322 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { | 324 TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { |
| 323 trace_net_log_observer()->WatchForTraceStart(net_log()); | 325 trace_net_log_observer()->WatchForTraceStart(net_log()); |
| 324 EnableTraceLog(); | 326 EnableTraceLog(); |
| 325 NetLog::ParametersCallback net_log_callback; | 327 NetLog::ParametersCallback net_log_callback; |
| 326 std::string param = "bar"; | 328 std::string param = "bar"; |
| 327 net_log_callback = NetLog::StringCallback("foo", ¶m); | 329 net_log_callback = NetLog::StringCallback("foo", ¶m); |
| 328 | 330 |
| 329 net_log()->AddGlobalEntry(NetLog::TYPE_CANCELLED, net_log_callback); | 331 net_log()->AddGlobalEntry(NetLogEventType::CANCELLED, net_log_callback); |
| 330 net_log()->AddGlobalEntry(NetLog::TYPE_REQUEST_ALIVE); | 332 net_log()->AddGlobalEntry(NetLogEventType::REQUEST_ALIVE); |
| 331 | 333 |
| 332 EndTraceAndFlush(); | 334 EndTraceAndFlush(); |
| 333 trace_net_log_observer()->StopWatchForTraceStart(); | 335 trace_net_log_observer()->StopWatchForTraceStart(); |
| 334 | 336 |
| 335 TestNetLogEntry::List entries; | 337 TestNetLogEntry::List entries; |
| 336 net_log()->GetEntries(&entries); | 338 net_log()->GetEntries(&entries); |
| 337 EXPECT_EQ(2u, entries.size()); | 339 EXPECT_EQ(2u, entries.size()); |
| 338 EXPECT_EQ(2u, trace_events()->GetSize()); | 340 EXPECT_EQ(2u, trace_events()->GetSize()); |
| 339 const base::DictionaryValue* item1 = NULL; | 341 const base::DictionaryValue* item1 = NULL; |
| 340 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); | 342 ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); |
| 341 const base::DictionaryValue* item2 = NULL; | 343 const base::DictionaryValue* item2 = NULL; |
| 342 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); | 344 ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); |
| 343 | 345 |
| 344 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); | 346 TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); |
| 345 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); | 347 TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); |
| 346 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); | 348 EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); |
| 347 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); | 349 EXPECT_EQ(base::StringPrintf("0x%d", entries[0].source.id), actual_item1.id); |
| 348 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), | 350 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), |
| 349 actual_item1.phase); | 351 actual_item1.phase); |
| 350 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_CANCELLED), | 352 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::CANCELLED), |
| 351 actual_item1.name); | 353 actual_item1.name); |
| 352 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), | 354 EXPECT_EQ(NetLog::SourceTypeToString(entries[0].source.type), |
| 353 actual_item1.source_type); | 355 actual_item1.source_type); |
| 354 | 356 |
| 355 EXPECT_EQ(kNetLogTracingCategory, actual_item2.category); | 357 EXPECT_EQ(kNetLogTracingCategory, actual_item2.category); |
| 356 EXPECT_EQ(base::StringPrintf("0x%d", entries[1].source.id), actual_item2.id); | 358 EXPECT_EQ(base::StringPrintf("0x%d", entries[1].source.id), actual_item2.id); |
| 357 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), | 359 EXPECT_EQ(std::string(1, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT), |
| 358 actual_item2.phase); | 360 actual_item2.phase); |
| 359 EXPECT_EQ(NetLog::EventTypeToString(NetLog::TYPE_REQUEST_ALIVE), | 361 EXPECT_EQ(NetLog::EventTypeToString(NetLogEventType::REQUEST_ALIVE), |
| 360 actual_item2.name); | 362 actual_item2.name); |
| 361 EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type), | 363 EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type), |
| 362 actual_item2.source_type); | 364 actual_item2.source_type); |
| 363 | 365 |
| 364 std::string item1_params; | 366 std::string item1_params; |
| 365 std::string item2_params; | 367 std::string item2_params; |
| 366 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); | 368 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); |
| 367 EXPECT_EQ("bar", item1_params); | 369 EXPECT_EQ("bar", item1_params); |
| 368 | 370 |
| 369 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); | 371 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); |
| 370 EXPECT_TRUE(item2_params.empty()); | 372 EXPECT_TRUE(item2_params.empty()); |
| 371 } | 373 } |
| 372 | 374 |
| 373 } // namespace | 375 } // namespace |
| 374 | 376 |
| 375 } // namespace net | 377 } // namespace net |
| OLD | NEW |