OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/net_log_unittest.h" | 5 #include "net/base/net_log_unittest.h" |
6 #include "net/base/net_log_util.h" | 6 #include "net/base/net_log_util.h" |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 namespace { | 11 namespace { |
12 | 12 |
13 CapturingNetLog::Entry MakeEventEntry(int t, | 13 CapturingNetLog::Entry MakeEventEntry(int t, |
14 NetLog::EventType event_type, | 14 NetLog::EventType event_type, |
15 NetLog::EventPhase event_phase) { | 15 NetLog::EventPhase event_phase) { |
16 return CapturingNetLog::Entry(event_type, | 16 return CapturingNetLog::Entry(event_type, |
17 MakeTime(t), | 17 MakeTime(t), |
18 NetLog::Source(), | 18 NetLog::Source(), |
19 event_phase, | 19 event_phase, |
20 NULL); | 20 NULL); |
21 } | 21 } |
22 | 22 |
23 CapturingNetLog::Entry MakeStringEntry(int t, const std::string& string) { | |
24 return CapturingNetLog::Entry(NetLog::TYPE_TODO_STRING, | |
25 MakeTime(t), | |
26 NetLog::Source(), | |
27 NetLog::PHASE_NONE, | |
28 new NetLogStringParameter(string)); | |
29 } | |
30 | |
31 TEST(NetLogUtilTest, Basic) { | 23 TEST(NetLogUtilTest, Basic) { |
32 CapturingNetLog::EntryList log; | 24 CapturingNetLog::EntryList log; |
33 | 25 |
34 log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL, | 26 log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL, |
35 NetLog::PHASE_BEGIN)); | 27 NetLog::PHASE_BEGIN)); |
36 log.push_back( | 28 log.push_back( |
37 MakeEventEntry(5, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, | 29 MakeEventEntry(5, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, |
38 NetLog::PHASE_BEGIN)); | 30 NetLog::PHASE_BEGIN)); |
39 log.push_back( | 31 log.push_back( |
40 MakeEventEntry(8, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, | 32 MakeEventEntry(8, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, |
(...skipping 12 matching lines...) Expand all Loading... |
53 "t=131: -HOST_RESOLVER_IMPL", | 45 "t=131: -HOST_RESOLVER_IMPL", |
54 NetLogUtil::PrettyPrintAsEventTree(log, 0)); | 46 NetLogUtil::PrettyPrintAsEventTree(log, 0)); |
55 } | 47 } |
56 | 48 |
57 TEST(NetLogUtilTest, Basic2) { | 49 TEST(NetLogUtilTest, Basic2) { |
58 CapturingNetLog::EntryList log; | 50 CapturingNetLog::EntryList log; |
59 | 51 |
60 log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL, | 52 log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL, |
61 NetLog::PHASE_BEGIN)); | 53 NetLog::PHASE_BEGIN)); |
62 | 54 |
63 log.push_back(MakeStringEntry(12, "Sup foo")); | 55 // Attach a string parameter to a CANCELLED event. |
64 log.push_back(MakeStringEntry(14, "Multiline\nString")); | 56 CapturingNetLog::Entry e = |
| 57 MakeEventEntry(12, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE); |
| 58 e.extra_parameters = |
| 59 new NetLogStringParameter("string_name", "string_value"); |
| 60 log.push_back(e); |
65 | 61 |
66 log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL, | 62 log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL, |
67 NetLog::PHASE_END)); | 63 NetLog::PHASE_END)); |
68 | 64 |
69 EXPECT_EQ( | 65 EXPECT_EQ( |
70 "t= 1: +HOST_RESOLVER_IMPL [dt=130]\n" | 66 "t= 1: +HOST_RESOLVER_IMPL [dt=130]\n" |
71 "t= 12: \"Sup foo\"\n" | 67 "t= 12: CANCELLED\n" |
72 "t= 14: \"Multiline\n" | 68 "{\n" |
73 "String\"\n" | 69 " \"string_name\": \"string_value\"\n" |
74 "t=131: -HOST_RESOLVER_IMPL", | 70 "}\n" |
75 NetLogUtil::PrettyPrintAsEventTree(log, 0)); | 71 "t=131: -HOST_RESOLVER_IMPL", |
| 72 NetLogUtil::PrettyPrintAsEventTree(log, 0)); |
76 } | 73 } |
77 | 74 |
78 TEST(NetLogUtilTest, UnmatchedOpen) { | 75 TEST(NetLogUtilTest, UnmatchedOpen) { |
79 CapturingNetLog::EntryList log; | 76 CapturingNetLog::EntryList log; |
80 | 77 |
81 log.push_back(MakeEventEntry(3, NetLog::TYPE_HOST_RESOLVER_IMPL, | 78 log.push_back(MakeEventEntry(3, NetLog::TYPE_HOST_RESOLVER_IMPL, |
82 NetLog::PHASE_BEGIN)); | 79 NetLog::PHASE_BEGIN)); |
83 // Note that there is no matching call to PHASE_END for all of the following. | 80 // Note that there is no matching call to PHASE_END for all of the following. |
84 log.push_back( | 81 log.push_back( |
85 MakeEventEntry( | 82 MakeEventEntry( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 "t=1: CANCELLED\n" | 123 "t=1: CANCELLED\n" |
127 "t=2: CANCELLED\n" | 124 "t=2: CANCELLED\n" |
128 "t=3: CANCELLED\n" | 125 "t=3: CANCELLED\n" |
129 " ... Truncated 4 entries ...\n" | 126 " ... Truncated 4 entries ...\n" |
130 "t=9: -TCP_CONNECT", | 127 "t=9: -TCP_CONNECT", |
131 NetLogUtil::PrettyPrintAsEventTree(log, 4)); | 128 NetLogUtil::PrettyPrintAsEventTree(log, 4)); |
132 } | 129 } |
133 | 130 |
134 } // namespace | 131 } // namespace |
135 } // namespace net | 132 } // namespace net |
OLD | NEW |