Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: net/base/net_log_logger_unittest.cc

Issue 642403002: git cl format the first third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_SPDY_SESSION, kDummyId);
82 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, 82 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source,
83 source, 83 NetLog::PHASE_BEGIN, base::TimeTicks::Now(),
84 NetLog::PHASE_BEGIN,
85 base::TimeTicks::Now(),
86 NULL); 84 NULL);
87 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); 85 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL);
88 logger->OnAddEntry(entry); 86 logger->OnAddEntry(entry);
89 logger.reset(); 87 logger.reset();
90 88
91 std::string input; 89 std::string input;
92 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); 90 ASSERT_TRUE(base::ReadFileToString(log_path_, &input));
93 91
94 base::JSONReader reader; 92 base::JSONReader reader;
95 scoped_ptr<base::Value> root(reader.ReadToValue(input)); 93 scoped_ptr<base::Value> root(reader.ReadToValue(input));
96 ASSERT_TRUE(root) << reader.GetErrorMessage(); 94 ASSERT_TRUE(root) << reader.GetErrorMessage();
97 95
98 base::DictionaryValue* dict; 96 base::DictionaryValue* dict;
99 ASSERT_TRUE(root->GetAsDictionary(&dict)); 97 ASSERT_TRUE(root->GetAsDictionary(&dict));
100 base::ListValue* events; 98 base::ListValue* events;
101 ASSERT_TRUE(dict->GetList("events", &events)); 99 ASSERT_TRUE(dict->GetList("events", &events));
102 ASSERT_EQ(1u, events->GetSize()); 100 ASSERT_EQ(1u, events->GetSize());
103 } 101 }
104 102
105 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) { 103 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) {
106 FILE* file = base::OpenFile(log_path_, "w"); 104 FILE* file = base::OpenFile(log_path_, "w");
107 ASSERT_TRUE(file); 105 ASSERT_TRUE(file);
108 scoped_ptr<base::Value> constants(GetNetConstants()); 106 scoped_ptr<base::Value> constants(GetNetConstants());
109 scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); 107 scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants));
110 108
111 const int kDummyId = 1; 109 const int kDummyId = 1;
112 NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); 110 NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId);
113 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, 111 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source,
114 source, 112 NetLog::PHASE_BEGIN, base::TimeTicks::Now(),
115 NetLog::PHASE_BEGIN,
116 base::TimeTicks::Now(),
117 NULL); 113 NULL);
118 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); 114 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL);
119 115
120 // Add the entry multiple times. 116 // Add the entry multiple times.
121 logger->OnAddEntry(entry); 117 logger->OnAddEntry(entry);
122 logger->OnAddEntry(entry); 118 logger->OnAddEntry(entry);
123 logger.reset(); 119 logger.reset();
124 120
125 std::string input; 121 std::string input;
126 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); 122 ASSERT_TRUE(base::ReadFileToString(log_path_, &input));
127 123
128 base::JSONReader reader; 124 base::JSONReader reader;
129 scoped_ptr<base::Value> root(reader.ReadToValue(input)); 125 scoped_ptr<base::Value> root(reader.ReadToValue(input));
130 ASSERT_TRUE(root) << reader.GetErrorMessage(); 126 ASSERT_TRUE(root) << reader.GetErrorMessage();
131 127
132 base::DictionaryValue* dict; 128 base::DictionaryValue* dict;
133 ASSERT_TRUE(root->GetAsDictionary(&dict)); 129 ASSERT_TRUE(root->GetAsDictionary(&dict));
134 base::ListValue* events; 130 base::ListValue* events;
135 ASSERT_TRUE(dict->GetList("events", &events)); 131 ASSERT_TRUE(dict->GetList("events", &events));
136 ASSERT_EQ(2u, events->GetSize()); 132 ASSERT_EQ(2u, events->GetSize());
137 } 133 }
138 134
139 } // namespace 135 } // namespace
140 136
141 } // namespace net 137 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698