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