| 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, |
| 103 NetLogEventPhase::BEGIN, |
| 101 base::TimeTicks::Now(), &callback); | 104 base::TimeTicks::Now(), &callback); |
| 102 NetLog::Entry base_entry(&base_entry_data, | 105 NetLog::Entry base_entry(&base_entry_data, |
| 103 NetLogCaptureMode::IncludeSocketBytes()); | 106 NetLogCaptureMode::IncludeSocketBytes()); |
| 104 std::unique_ptr<base::Value> value(base_entry.ToValue()); | 107 std::unique_ptr<base::Value> value(base_entry.ToValue()); |
| 105 std::string json; | 108 std::string json; |
| 106 base::JSONWriter::Write(*value, &json); | 109 base::JSONWriter::Write(*value, &json); |
| 107 size_t base_entry_size = json.size(); | 110 size_t base_entry_size = json.size(); |
| 108 | 111 |
| 109 // The maximum value of base::TimeTicks::Now() will be the maximum value of | 112 // 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 | 113 // 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 | 114 // |base_entry_size| could be up to 101 characters. Check that the event |
| 112 // format does not include additional padding. | 115 // format does not include additional padding. |
| 113 DCHECK_LE(base_entry_size, 101u); | 116 DCHECK_LE(base_entry_size, 101u); |
| 114 | 117 |
| 115 // |entry_size| should be at least as big as the largest possible base | 118 // |entry_size| should be at least as big as the largest possible base |
| 116 // entry. | 119 // entry. |
| 117 EXPECT_GE(entry_size, 101u); | 120 EXPECT_GE(entry_size, 101u); |
| 118 | 121 |
| 119 // |entry_size| cannot be smaller than the minimum event size. | 122 // |entry_size| cannot be smaller than the minimum event size. |
| 120 EXPECT_GE(entry_size, base_entry_size); | 123 EXPECT_GE(entry_size, base_entry_size); |
| 121 | 124 |
| 122 for (int i = 0; i < num_entries_to_add; i++) { | 125 for (int i = 0; i < num_entries_to_add; i++) { |
| 123 source = NetLog::Source(NetLog::SOURCE_HTTP2_SESSION, i); | 126 source = NetLog::Source(NetLogSourceType::HTTP2_SESSION, i); |
| 124 std::string id = std::to_string(i); | 127 std::string id = std::to_string(i); |
| 125 | 128 |
| 126 // String size accounts for the number of digits in id so that all events | 129 // String size accounts for the number of digits in id so that all events |
| 127 // are the same size. | 130 // are the same size. |
| 128 message = std::string(entry_size - base_entry_size - id.size() + 1, 'x'); | 131 message = std::string(entry_size - base_entry_size - id.size() + 1, 'x'); |
| 129 callback = NetLog::StringCallback("message", &message); | 132 callback = NetLog::StringCallback("message", &message); |
| 130 NetLog::EntryData entry_data(NetLog::TYPE_PAC_JAVASCRIPT_ERROR, source, | 133 NetLog::EntryData entry_data(NetLogEventType::PAC_JAVASCRIPT_ERROR, |
| 131 NetLog::PHASE_BEGIN, base::TimeTicks::Now(), | 134 source, |
| 135 NetLogEventPhase::BEGIN, |
| 136 base::TimeTicks::Now(), |
| 132 &callback); | 137 &callback); |
| 133 NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes()); | 138 NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes()); |
| 134 logger_->OnAddEntry(entry); | 139 logger_->OnAddEntry(entry); |
| 135 } | 140 } |
| 136 } | 141 } |
| 137 | 142 |
| 138 protected: | 143 protected: |
| 139 base::FilePath log_path_; | 144 base::FilePath log_path_; |
| 140 NetLog net_log_; | 145 NetLog net_log_; |
| 141 std::unique_ptr<base::Thread> file_thread_; | 146 std::unique_ptr<base::Thread> file_thread_; |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 ASSERT_EQ(1u, events->GetSize()); | 857 ASSERT_EQ(1u, events->GetSize()); |
| 853 | 858 |
| 854 // Make sure additional information is present, but don't validate it. | 859 // Make sure additional information is present, but don't validate it. |
| 855 base::DictionaryValue* tab_info; | 860 base::DictionaryValue* tab_info; |
| 856 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); | 861 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); |
| 857 } | 862 } |
| 858 | 863 |
| 859 } // namespace | 864 } // namespace |
| 860 | 865 |
| 861 } // namespace net | 866 } // namespace net |
| OLD | NEW |