OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/bounded_file_net_log_observer.h" | 5 #include "net/log/bounded_file_net_log_observer.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
17 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
22 #include "net/log/net_log.h" | 22 #include "net/log/net_log_entry.h" |
23 #include "net/log/net_log_event_type.h" | 23 #include "net/log/net_log_event_type.h" |
| 24 #include "net/log/net_log_parameters_callback_typedef.h" |
| 25 #include "net/log/net_log_source.h" |
24 #include "net/log/net_log_source_type.h" | 26 #include "net/log/net_log_source_type.h" |
25 #include "net/log/net_log_util.h" | 27 #include "net/log/net_log_util.h" |
26 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
27 #include "net/url_request/url_request_context.h" | 29 #include "net/url_request/url_request_context.h" |
28 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 | 32 |
31 namespace net { | 33 namespace net { |
32 | 34 |
33 namespace { | 35 namespace { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // Sends |num_entries_to_add| number of events of size |entry_size| to | 90 // Sends |num_entries_to_add| number of events of size |entry_size| to |
89 // |logger_|. | 91 // |logger_|. |
90 // | 92 // |
91 // |entry_size| must be >= 101, since the size of entries without a message, | 93 // |entry_size| must be >= 101, since the size of entries without a message, |
92 // |base_entry_size|, is dependent on TimeTicks formatting, and | 94 // |base_entry_size|, is dependent on TimeTicks formatting, and |
93 // |base_entry_size| can be up to 101 and cannot be shortened. | 95 // |base_entry_size| can be up to 101 and cannot be shortened. |
94 void AddEntries(int num_entries_to_add, size_t entry_size) { | 96 void AddEntries(int num_entries_to_add, size_t entry_size) { |
95 // Get base size of event. | 97 // Get base size of event. |
96 const int kDummyId = 0; | 98 const int kDummyId = 0; |
97 std::string message = ""; | 99 std::string message = ""; |
98 NetLog::ParametersCallback callback = | 100 NetLogParametersCallback callback = |
99 NetLog::StringCallback("message", &message); | 101 NetLog::StringCallback("message", &message); |
100 NetLog::Source source(NetLogSourceType::HTTP2_SESSION, kDummyId); | 102 NetLogSource source(NetLogSourceType::HTTP2_SESSION, kDummyId); |
101 NetLog::EntryData base_entry_data(NetLogEventType::PAC_JAVASCRIPT_ERROR, | 103 NetLogEntryData base_entry_data(NetLogEventType::PAC_JAVASCRIPT_ERROR, |
102 source, NetLogEventPhase::BEGIN, | 104 source, NetLogEventPhase::BEGIN, |
103 base::TimeTicks::Now(), &callback); | 105 base::TimeTicks::Now(), &callback); |
104 NetLog::Entry base_entry(&base_entry_data, | 106 NetLogEntry base_entry(&base_entry_data, |
105 NetLogCaptureMode::IncludeSocketBytes()); | 107 NetLogCaptureMode::IncludeSocketBytes()); |
106 std::unique_ptr<base::Value> value(base_entry.ToValue()); | 108 std::unique_ptr<base::Value> value(base_entry.ToValue()); |
107 std::string json; | 109 std::string json; |
108 base::JSONWriter::Write(*value, &json); | 110 base::JSONWriter::Write(*value, &json); |
109 size_t base_entry_size = json.size(); | 111 size_t base_entry_size = json.size(); |
110 | 112 |
111 // The maximum value of base::TimeTicks::Now() will be the maximum value of | 113 // The maximum value of base::TimeTicks::Now() will be the maximum value of |
112 // int64_t, and if the maximum number of digits are included, the | 114 // int64_t, and if the maximum number of digits are included, the |
113 // |base_entry_size| could be up to 101 characters. Check that the event | 115 // |base_entry_size| could be up to 101 characters. Check that the event |
114 // format does not include additional padding. | 116 // format does not include additional padding. |
115 DCHECK_LE(base_entry_size, 101u); | 117 DCHECK_LE(base_entry_size, 101u); |
116 | 118 |
117 // |entry_size| should be at least as big as the largest possible base | 119 // |entry_size| should be at least as big as the largest possible base |
118 // entry. | 120 // entry. |
119 EXPECT_GE(entry_size, 101u); | 121 EXPECT_GE(entry_size, 101u); |
120 | 122 |
121 // |entry_size| cannot be smaller than the minimum event size. | 123 // |entry_size| cannot be smaller than the minimum event size. |
122 EXPECT_GE(entry_size, base_entry_size); | 124 EXPECT_GE(entry_size, base_entry_size); |
123 | 125 |
124 for (int i = 0; i < num_entries_to_add; i++) { | 126 for (int i = 0; i < num_entries_to_add; i++) { |
125 source = NetLog::Source(NetLogSourceType::HTTP2_SESSION, i); | 127 source = NetLogSource(NetLogSourceType::HTTP2_SESSION, i); |
126 std::string id = std::to_string(i); | 128 std::string id = std::to_string(i); |
127 | 129 |
128 // String size accounts for the number of digits in id so that all events | 130 // String size accounts for the number of digits in id so that all events |
129 // are the same size. | 131 // are the same size. |
130 message = std::string(entry_size - base_entry_size - id.size() + 1, 'x'); | 132 message = std::string(entry_size - base_entry_size - id.size() + 1, 'x'); |
131 callback = NetLog::StringCallback("message", &message); | 133 callback = NetLog::StringCallback("message", &message); |
132 NetLog::EntryData entry_data(NetLogEventType::PAC_JAVASCRIPT_ERROR, | 134 NetLogEntryData entry_data(NetLogEventType::PAC_JAVASCRIPT_ERROR, source, |
133 source, NetLogEventPhase::BEGIN, | 135 NetLogEventPhase::BEGIN, |
134 base::TimeTicks::Now(), &callback); | 136 base::TimeTicks::Now(), &callback); |
135 NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes()); | 137 NetLogEntry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes()); |
136 logger_->OnAddEntry(entry); | 138 logger_->OnAddEntry(entry); |
137 } | 139 } |
138 } | 140 } |
139 | 141 |
140 protected: | 142 protected: |
141 base::FilePath log_path_; | 143 base::FilePath log_path_; |
142 NetLog net_log_; | 144 NetLog net_log_; |
143 std::unique_ptr<base::Thread> file_thread_; | 145 std::unique_ptr<base::Thread> file_thread_; |
144 std::unique_ptr<BoundedFileNetLogObserver> logger_; | 146 std::unique_ptr<BoundedFileNetLogObserver> logger_; |
145 | 147 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 ASSERT_EQ(1u, events->GetSize()); | 851 ASSERT_EQ(1u, events->GetSize()); |
850 | 852 |
851 // Make sure additional information is present, but don't validate it. | 853 // Make sure additional information is present, but don't validate it. |
852 base::DictionaryValue* tab_info; | 854 base::DictionaryValue* tab_info; |
853 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); | 855 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); |
854 } | 856 } |
855 | 857 |
856 } // namespace | 858 } // namespace |
857 | 859 |
858 } // namespace net | 860 } // namespace net |
OLD | NEW |