| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_logger.h" | 5 #include "net/base/net_log_logger.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 logger.StopObserving(); | 71 logger.StopObserving(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithOneEvent) { | 74 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithOneEvent) { |
| 75 FILE* file = base::OpenFile(log_path_, "w"); | 75 FILE* file = base::OpenFile(log_path_, "w"); |
| 76 ASSERT_TRUE(file); | 76 ASSERT_TRUE(file); |
| 77 scoped_ptr<base::Value> constants(GetNetConstants()); | 77 scoped_ptr<base::Value> constants(GetNetConstants()); |
| 78 scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); | 78 scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); |
| 79 | 79 |
| 80 const int kDummyId = 1; | 80 const int kDummyId = 1; |
| 81 NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); | 81 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId); |
| 82 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, | 82 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, |
| 83 source, | 83 source, |
| 84 NetLog::PHASE_BEGIN, | 84 NetLog::PHASE_BEGIN, |
| 85 base::TimeTicks::Now(), | 85 base::TimeTicks::Now(), |
| 86 NULL); | 86 NULL); |
| 87 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); | 87 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); |
| 88 logger->OnAddEntry(entry); | 88 logger->OnAddEntry(entry); |
| 89 logger.reset(); | 89 logger.reset(); |
| 90 | 90 |
| 91 std::string input; | 91 std::string input; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 ASSERT_EQ(1u, events->GetSize()); | 102 ASSERT_EQ(1u, events->GetSize()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) { | 105 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) { |
| 106 FILE* file = base::OpenFile(log_path_, "w"); | 106 FILE* file = base::OpenFile(log_path_, "w"); |
| 107 ASSERT_TRUE(file); | 107 ASSERT_TRUE(file); |
| 108 scoped_ptr<base::Value> constants(GetNetConstants()); | 108 scoped_ptr<base::Value> constants(GetNetConstants()); |
| 109 scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); | 109 scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); |
| 110 | 110 |
| 111 const int kDummyId = 1; | 111 const int kDummyId = 1; |
| 112 NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); | 112 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId); |
| 113 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, | 113 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, |
| 114 source, | 114 source, |
| 115 NetLog::PHASE_BEGIN, | 115 NetLog::PHASE_BEGIN, |
| 116 base::TimeTicks::Now(), | 116 base::TimeTicks::Now(), |
| 117 NULL); | 117 NULL); |
| 118 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); | 118 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); |
| 119 | 119 |
| 120 // Add the entry multiple times. | 120 // Add the entry multiple times. |
| 121 logger->OnAddEntry(entry); | 121 logger->OnAddEntry(entry); |
| 122 logger->OnAddEntry(entry); | 122 logger->OnAddEntry(entry); |
| 123 logger.reset(); | 123 logger.reset(); |
| 124 | 124 |
| 125 std::string input; | 125 std::string input; |
| 126 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); | 126 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| 127 | 127 |
| 128 base::JSONReader reader; | 128 base::JSONReader reader; |
| 129 scoped_ptr<base::Value> root(reader.ReadToValue(input)); | 129 scoped_ptr<base::Value> root(reader.ReadToValue(input)); |
| 130 ASSERT_TRUE(root) << reader.GetErrorMessage(); | 130 ASSERT_TRUE(root) << reader.GetErrorMessage(); |
| 131 | 131 |
| 132 base::DictionaryValue* dict; | 132 base::DictionaryValue* dict; |
| 133 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 133 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 134 base::ListValue* events; | 134 base::ListValue* events; |
| 135 ASSERT_TRUE(dict->GetList("events", &events)); | 135 ASSERT_TRUE(dict->GetList("events", &events)); |
| 136 ASSERT_EQ(2u, events->GetSize()); | 136 ASSERT_EQ(2u, events->GetSize()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace | 139 } // namespace |
| 140 | 140 |
| 141 } // namespace net | 141 } // namespace net |
| OLD | NEW |