| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.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 17 matching lines...) Expand all Loading... |
| 28 TEST_F(NetLogLoggerTest, GeneratesValidJSONForNoEvents) { | 28 TEST_F(NetLogLoggerTest, GeneratesValidJSONForNoEvents) { |
| 29 { | 29 { |
| 30 // Create and destroy a logger. | 30 // Create and destroy a logger. |
| 31 FILE* file = file_util::OpenFile(log_path_, "w"); | 31 FILE* file = file_util::OpenFile(log_path_, "w"); |
| 32 ASSERT_TRUE(file); | 32 ASSERT_TRUE(file); |
| 33 scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); | 33 scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| 34 NetLogLogger logger(file, *constants); | 34 NetLogLogger logger(file, *constants); |
| 35 } | 35 } |
| 36 | 36 |
| 37 std::string input; | 37 std::string input; |
| 38 ASSERT_TRUE(file_util::ReadFileToString(log_path_, &input)); | 38 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| 39 | 39 |
| 40 base::JSONReader reader; | 40 base::JSONReader reader; |
| 41 scoped_ptr<base::Value> root(reader.ReadToValue(input)); | 41 scoped_ptr<base::Value> root(reader.ReadToValue(input)); |
| 42 ASSERT_TRUE(root) << reader.GetErrorMessage(); | 42 ASSERT_TRUE(root) << reader.GetErrorMessage(); |
| 43 | 43 |
| 44 base::DictionaryValue* dict; | 44 base::DictionaryValue* dict; |
| 45 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 45 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 46 base::ListValue* events; | 46 base::ListValue* events; |
| 47 ASSERT_TRUE(dict->GetList("events", &events)); | 47 ASSERT_TRUE(dict->GetList("events", &events)); |
| 48 ASSERT_EQ(0u, events->GetSize()); | 48 ASSERT_EQ(0u, events->GetSize()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 NetLog::Entry entry(NetLog::TYPE_PROXY_SERVICE, | 60 NetLog::Entry entry(NetLog::TYPE_PROXY_SERVICE, |
| 61 source, | 61 source, |
| 62 NetLog::PHASE_BEGIN, | 62 NetLog::PHASE_BEGIN, |
| 63 base::TimeTicks::Now(), | 63 base::TimeTicks::Now(), |
| 64 NULL, | 64 NULL, |
| 65 NetLog::LOG_BASIC); | 65 NetLog::LOG_BASIC); |
| 66 logger.OnAddEntry(entry); | 66 logger.OnAddEntry(entry); |
| 67 } | 67 } |
| 68 | 68 |
| 69 std::string input; | 69 std::string input; |
| 70 ASSERT_TRUE(file_util::ReadFileToString(log_path_, &input)); | 70 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| 71 | 71 |
| 72 base::JSONReader reader; | 72 base::JSONReader reader; |
| 73 scoped_ptr<base::Value> root(reader.ReadToValue(input)); | 73 scoped_ptr<base::Value> root(reader.ReadToValue(input)); |
| 74 ASSERT_TRUE(root) << reader.GetErrorMessage(); | 74 ASSERT_TRUE(root) << reader.GetErrorMessage(); |
| 75 | 75 |
| 76 base::DictionaryValue* dict; | 76 base::DictionaryValue* dict; |
| 77 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 77 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 78 base::ListValue* events; | 78 base::ListValue* events; |
| 79 ASSERT_TRUE(dict->GetList("events", &events)); | 79 ASSERT_TRUE(dict->GetList("events", &events)); |
| 80 ASSERT_EQ(1u, events->GetSize()); | 80 ASSERT_EQ(1u, events->GetSize()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 95 base::TimeTicks::Now(), | 95 base::TimeTicks::Now(), |
| 96 NULL, | 96 NULL, |
| 97 NetLog::LOG_BASIC); | 97 NetLog::LOG_BASIC); |
| 98 | 98 |
| 99 // Add the entry multiple times. | 99 // Add the entry multiple times. |
| 100 logger.OnAddEntry(entry); | 100 logger.OnAddEntry(entry); |
| 101 logger.OnAddEntry(entry); | 101 logger.OnAddEntry(entry); |
| 102 } | 102 } |
| 103 | 103 |
| 104 std::string input; | 104 std::string input; |
| 105 ASSERT_TRUE(file_util::ReadFileToString(log_path_, &input)); | 105 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| 106 | 106 |
| 107 base::JSONReader reader; | 107 base::JSONReader reader; |
| 108 scoped_ptr<base::Value> root(reader.ReadToValue(input)); | 108 scoped_ptr<base::Value> root(reader.ReadToValue(input)); |
| 109 ASSERT_TRUE(root) << reader.GetErrorMessage(); | 109 ASSERT_TRUE(root) << reader.GetErrorMessage(); |
| 110 | 110 |
| 111 base::DictionaryValue* dict; | 111 base::DictionaryValue* dict; |
| 112 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 112 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 113 base::ListValue* events; | 113 base::ListValue* events; |
| 114 ASSERT_TRUE(dict->GetList("events", &events)); | 114 ASSERT_TRUE(dict->GetList("events", &events)); |
| 115 ASSERT_EQ(2u, events->GetSize()); | 115 ASSERT_EQ(2u, events->GetSize()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace net | 118 } // namespace net |
| OLD | NEW |