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

Side by Side Diff: net/log/net_log_unittest.cc

Issue 1084533002: Rename NetLogLogger and CapturingNetLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename NetLogLogger and CapturingNetLog(removed compiler error for chromeOS) Created 5 years, 8 months 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
« no previous file with comments | « net/log/net_log_unittest.h ('k') | net/log/test_net_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/log/net_log_unittest.h" 5 #include "net/log/net_log_unittest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/simple_thread.h" 10 #include "base/threading/simple_thread.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 namespace { 16 namespace {
17 17
18 const int kThreads = 10; 18 const int kThreads = 10;
19 const int kEvents = 100; 19 const int kEvents = 100;
20 20
21 base::Value* NetLogLevelCallback(NetLog::LogLevel log_level) { 21 base::Value* NetLogLevelCallback(NetLog::LogLevel log_level) {
22 base::DictionaryValue* dict = new base::DictionaryValue(); 22 base::DictionaryValue* dict = new base::DictionaryValue();
23 dict->SetInteger("log_level", log_level); 23 dict->SetInteger("log_level", log_level);
24 return dict; 24 return dict;
25 } 25 }
26 26
27 TEST(NetLogTest, Basic) { 27 TEST(NetLogTest, Basic) {
28 CapturingNetLog net_log; 28 TestNetLog net_log;
29 CapturingNetLog::CapturedEntryList entries; 29 TestNetLog::CapturedEntryList entries;
30 net_log.GetEntries(&entries); 30 net_log.GetEntries(&entries);
31 EXPECT_EQ(0u, entries.size()); 31 EXPECT_EQ(0u, entries.size());
32 32
33 net_log.AddGlobalEntry(NetLog::TYPE_CANCELLED); 33 net_log.AddGlobalEntry(NetLog::TYPE_CANCELLED);
34 34
35 net_log.GetEntries(&entries); 35 net_log.GetEntries(&entries);
36 ASSERT_EQ(1u, entries.size()); 36 ASSERT_EQ(1u, entries.size());
37 EXPECT_EQ(NetLog::TYPE_CANCELLED, entries[0].type); 37 EXPECT_EQ(NetLog::TYPE_CANCELLED, entries[0].type);
38 EXPECT_EQ(NetLog::SOURCE_NONE, entries[0].source.type); 38 EXPECT_EQ(NetLog::SOURCE_NONE, entries[0].source.type);
39 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); 39 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id);
40 EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase); 40 EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase);
41 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); 41 EXPECT_GE(base::TimeTicks::Now(), entries[0].time);
42 EXPECT_FALSE(entries[0].params); 42 EXPECT_FALSE(entries[0].params);
43 } 43 }
44 44
45 // Check that the correct LogLevel is sent to NetLog Value callbacks. 45 // Check that the correct LogLevel is sent to NetLog Value callbacks.
46 TEST(NetLogTest, LogLevels) { 46 TEST(NetLogTest, LogLevels) {
47 CapturingNetLog net_log; 47 TestNetLog net_log;
48 for (int log_level = NetLog::LOG_ALL; log_level < NetLog::LOG_NONE; 48 for (int log_level = NetLog::LOG_ALL; log_level < NetLog::LOG_NONE;
49 ++log_level) { 49 ++log_level) {
50 net_log.SetLogLevel(static_cast<NetLog::LogLevel>(log_level)); 50 net_log.SetLogLevel(static_cast<NetLog::LogLevel>(log_level));
51 EXPECT_EQ(log_level, net_log.GetLogLevel()); 51 EXPECT_EQ(log_level, net_log.GetLogLevel());
52 52
53 net_log.AddGlobalEntry(NetLog::TYPE_SOCKET_ALIVE, 53 net_log.AddGlobalEntry(NetLog::TYPE_SOCKET_ALIVE,
54 base::Bind(NetLogLevelCallback)); 54 base::Bind(NetLogLevelCallback));
55 55
56 CapturingNetLog::CapturedEntryList entries; 56 TestNetLog::CapturedEntryList entries;
57 net_log.GetEntries(&entries); 57 net_log.GetEntries(&entries);
58 58
59 ASSERT_EQ(1u, entries.size()); 59 ASSERT_EQ(1u, entries.size());
60 EXPECT_EQ(NetLog::TYPE_SOCKET_ALIVE, entries[0].type); 60 EXPECT_EQ(NetLog::TYPE_SOCKET_ALIVE, entries[0].type);
61 EXPECT_EQ(NetLog::SOURCE_NONE, entries[0].source.type); 61 EXPECT_EQ(NetLog::SOURCE_NONE, entries[0].source.type);
62 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); 62 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id);
63 EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase); 63 EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase);
64 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); 64 EXPECT_GE(base::TimeTicks::Now(), entries[0].time);
65 65
66 int logged_log_level; 66 int logged_log_level;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 NetLog net_log; 345 NetLog net_log;
346 346
347 // Run a bunch of threads to completion, each of which will repeatedly add 347 // Run a bunch of threads to completion, each of which will repeatedly add
348 // and remove an observer, and set its logging level. 348 // and remove an observer, and set its logging level.
349 RunTestThreads<AddRemoveObserverTestThread>(&net_log); 349 RunTestThreads<AddRemoveObserverTestThread>(&net_log);
350 } 350 }
351 351
352 } // namespace 352 } // namespace
353 353
354 } // namespace net 354 } // namespace net
OLDNEW
« no previous file with comments | « net/log/net_log_unittest.h ('k') | net/log/test_net_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698